How can I substitute a magic word only when transcluding template without using #invoke? - mediawiki

I'm trying to make a template that shows the time it was placed. I tried this:
This is a template ({{<includeonly>subst:</includeonly>CURRENTTIMESTAMP}})
but when transcluded it would show up as This is a template ({{subst:CURRENTTIMESTAMP}}) instead of substituting the timestamp. I then tried
This is a template ({{{{{|safesubst:}}}CURRENTTIMESTAMP}})
but that didn't substitute it; the timestamp would keep updating. Next, I tried
This is a template ({{<includeonly>{{{|safesubst:}}}</includeonly>CURRENTTIMESTAMP}})
but no dice.
I know it's possible with {{#invoke:}} but I don't have that option. Could someone help me out?

Consider how templates are stored. If you recursively subst the template, the contents of the template are stored in the wikitext of the including page, with CURRENTTIMESTAMP replaced with the actual timestamp. If you do not subst the template, the wikitext will only contain {{MyTemplate}}, and the timestamp of the edit is not stored anywhere; when the the parser renders the article and encounters CURRENTTIMESTAMP, it will just use the current timestamp. There is no way around that, #invoke or not.
What you can do is make the timestamp into a parameter, so in the including page you would write {{MyTemplate|{{subst:CURRENTTIMESTAMP}}}} and then the timestamp gets stored in the page. You can create a wrapper template with that exact content so that users only have to type {{subst:MyTemplateWrapper}} which is a bit easier. You can even make the template show an error / add an error category when used without substing, although that's a bit more involved.

Related

Multiple Alias Routes to base Razor Page

I'm pretty new to Razor Pages, and I'm trying to figure out how to replicate routing I have in my current Angular Page.
I have a base razor page that will be populated with different data depending on which parameter is passed to it. This is easy enough, and I know how to do this. However, my problem is in the routing because I want to be able to pass a readable parameter that is based off of the base URL. For example, I want to be able to do:
https://myURL/Band1
https://myURL/Band2
and have both point to the same page (but not the Index Page), consume the parameter "Band1" or "Band2" to display the associated information.
I understand how to consume the parameter, and how to get data, what I'm not clear on is how to do this routing based on the base URL. I can see how I'd do it if it were https://myURL/b/Band1 since I'd make a "b" page and accept parameters.
But how does one do this without that intervening segment of the URL? I need to be able to do this to not break existing links.
Thanks!
The docs for Razor Pages suggest you can create a page named Index.cshtml, which will act as the default where no page is specified in the URL.
Edit
If you want to preserve the parameterless index page, but have your page take its place when the additional URL part is provided, try the following in your page:
#page "/{bandName}"

Create a Talk/Discuss link in a MediaWiki Plug-in

I am creating a MediaWiki plug-in that lists many files. For each file, I want to print a [Talk] or [Discuss] link. (It seems that the original name was talk but that it was renamed to discuss.) These links should be red if the page does not exist and blue if it does exist.
There should be a way to add such links in OutputPage.php, but I can't figure it out.
I know about these functions "foo":
$page = WikiPage::factory ( $title )
$talk = $title->getTalkPage()
But I'm not sure how to get $title from foo.
I'm also not sure how to change $talk into the appropriate HTML. I'd rather not add it to the output stream, because I'm building a lot of HTML separately, but I suppose I can refactor so that instead of passing my strings around, I pass around a handle to the output.
Why don't you use OutputPage::addWikiText() to add the appropriate link without worrying about the technical details: [[{{ns:11}}:Foo|Text]] for example.
Alternatively you can get $title from OutputPage::getTitle() for the current page, or from Title::newFromText() for any title you want to use. You can get $talk directly by specifying the correct namespace constant, which might be even easier than the trip via a WikiPage object.
Correct styling for the link can be done with the helper methods Title::exists() and one of the appropriate helpers for generating urls for pages.
See also https://doc.wikimedia.org/mediawiki-core/master/php/classTitle.html

Creating custom SSRS handler for field with HTML

I have an SSRS 2008 report with a field that contains and is configured to render as HTML. Some of the text in this field may contain IMG tags, and the IMG tag is not among the tags SSRS natively supports within its HTML rendering extension.
I am trying to find a way to write a custom handler to hook into the processing of this field that will let me look at the raw HTML before the SSRS handler processes it, in the hopes of grabbing IMG tags, extracting the SRC URL and getting the raw bytes of an image to insert on the fly in a way SSRS will accept, yet retaining the HTML SSRS will render.
From what I've read and seen so far, if a field is marked to render as HTML, the SSRS processor grabs it and parses it entirely before any handler could modify it, meaning the IMG tag is (would be) discarded before I could do anything with it (or even know it was present). The only option I see is to turn off the HTML rendering entirely, thus losing the benefit of the tags SSRS can recognize.
EDIT: Per Jamie's response below, I'm beginning to think the "2nd half" of this issue may prove harder than I realized: Is it even possible to programmatically add an Image to an SSRS Report at runtime (obviously through code/custom assembly)? That is, I'd like to write some code that might look something like this (pseudocode)
'Conceptual Pseudocode I'd like to be able to write
'for dynamic addition of Image element in SSRS report
'Is this even possible?? Is there a documented Report
'object model??
Public Function AddImage(imageBytes() as Byte) as Image
Dim newImage as New Image()
newImage.SetBytes(imageBytes)
Report.Add(newImage)
return newImage
End Function
I'm hoping I'm just overlooking something simple that prevents me from grabbing the raw, unprocessed HTML, and someone else might be able to point me in the right direction on how to grab it.
EDIT: I have created and implemented this solution within the SSRS development environment and it works. WOOHOO :) It did require some hoop-jumping with creating a Single-Threaded Apartment thread to host the WebBrowser control, and to create a message pump, but it does work! **
As I was literally typing up the message to a co-worker that this issue was a non-starter, I did have a bit of an inspiration on a way to solve this problem. I know this post hasn't generated a great deal of response, but just in case someone else finds themselves in a similar problem, I'm going to share what I've implemented in a "petri dish" scenario that, provided I get all the code permission issues resolved, should allow me a decent solution to this problem.
With SSRS inability to handle an IMG tag insurmountable, I actually thought of an idea that took the HTML rendering away from SSRS entirely. To do this, I created custom code that hands off the HTML rendering to a WebBrowser control, then copies the rendered result as an image. It does the following:
Instantiates a WebBrowser control of a given width and height.
Sets the DocumentText property of that control to the HTML from TinyMCE
Waits for the DocumentText to completely render.
Creates a bitmap equal to the size of the control.
Uses the undocumented and presumably unsupported DrawToBitmap method of the WebBrowser to draw the rendered HTML to a bitmap.
Copies the Bitmap to an Image
Saves the Image as a .png file
Returns the path to the .png as the result of the function.
In SSRS, I plan to replace the erstwhile HTML text field with an external Image control that will then call the above method and render the image file. I may alter that to simply draw the image to the SSRS Image control directly, but that's a final detail I'll resolve later. I think this basic design is going to work. Its a little kludgey, but I think it will work.
I have some permissions issues to work out with the code that SSRS will allow me to call at runtime, but I'm confident I'll get those sorted out (even if I end up moving the code to a separate assembly). Once this is tested and working, I plan to mark this as the answer.
Thanks to those who offered suggestions.
I've done something similar with success: We had an HTML "Comment" field that was collected on a web form. For a particular report we wanted to truncate this field to the first 1000 characters or so, but preserve valid HTML.
So I created a C# .dll & class with a public function:
public static string TruncateHtml(string html, int characters)
{
...
}
(I used the HtmlAgilityPack for most of the HTML parsing, and to create and close off my new HTML string, while I kept track of the content length.)
Then I could call that code with the fully qualified path to the function in an SSRS expression:
=ReportHtmlHandler.HtmlTruncate.TruncateHtml(Fields!Comment.Value, 1000)
I could have added a calculated field to my dataset with this, but I was only using this value for one field, so I kept it at the field expression level.
All of this code gets called well before the HTML is processed or rendered by SSRS. I'm sure that any original IMG tag will be in the string.
This approach might work for you, possibly create a ExtractImg function which could be set as the source of an img on the report. I think some of the tricky bits for your requirement will be to handle multiple images as well as embedding the extracted img. But you might be able to do this simply with a external reference to an image. I haven't done much with external images in SSRS.
An MSDN blog entry on calling a custom dll from SSRS: http://support.microsoft.com/kb/920769

How to store html characters in mysql and display them correctly

Not sure if I am asking this correctly. But I am using a Jquery HTML Editor cleditor so that the users can load html text. When I insert this into my db(mysql) and want to display the outcome it takes out any html characters it had like: <p>, <span>, and so on. So when I go view it, it shows like this:
class=\"noticia_texto\">jlasdfklsfklaf
which obviously it's not readable. Help please? Should I be using anything at the time of inserting or displaying or both? Also my datatype is set to Blob.
MySQL does NOT strip html tags. If they're being removed upon insertion (or retrieval), then it's something in your code doing it, not MySQL.
Given that the quotes in your snippet are escaped, you've almost certainly got magic_quotes enabled, and/or a home-brew SQL escaping function run amok.

Mediawiki 1.16: Template documentation example usage

I'm writing template documentation for a wiki and wanted to include a working example of the template. However, I wrote the template to auto-categorize various fields and the entire template itself is also auto-categorized.
This means if I simply call on the template, it will categorize the doc page...and because the actual template page transcludes the doc page, the template page will also be categorized.
Is there a way to prevent these categories from automatically kicking in?
Something like the following should do the trick. Wrap the categorization in your template inside a parserfunction:
{{#ifeq: {{NAMESPACE}} | Help || [[Category:Some_Category]] }}
This sets the category when the template is transcluded onto a page that is not in the "Help" namespace.
Another option is to allow a parameter such as demo to avoid including the category.
If you don't mind being slightly cryptic, you could do the category in the template as {{{cat|[[Category:Some_Category]]}}}; then specifying the parameter as {{my template|cat=}} will prevent the category inclusion.
I'm not sure if I understand the question completely (what is "auto-categorize various fields"?). I am assuming here that you want to show a template "in action" on a documentation page - without attaching some categories (those categories the documentation page usually attaches to articles using this template) to the documentation page.
So
<onlyinclude>[[Category:Some_Category]]</onlyinclude>
will not do the job - as the template is in fact included. Right?
Try passing a parameter categorize=false to the template to indicate that categories are not to be attached in this case:
{{#ifeq:{{{categorize|}}}|false||[[Category:Some_Category]]}}
The double pipe after "false" means: if(categorize==false) then (empty), else [[Category:Some_Category]] - i.e. it is an equivalent construction for if(NOT(categorize==false))...
Good luck and thanks for all the fish,
Achim