Does media wiki support links inside highlighted code? - mediawiki

Assume I have the following code section:
<syntaxhighlight lang = "php">
function my_func($str) {
$arr = split($str, ' ');
}
</syntaxhighlight>
This would be highlighted with the help of Geshi extension. However, I would also like to make split as a url link to the external site with documentation explaining what this function does. Is there like any way to do that in MediaWiki for the highlighted code?

Since Geshi works like the <pre> tag to display the code is displayed as typed instead of parsing it as wikicode, mediawiki can't parse anything inside it. Therefore its impossible to add a 'normal' link using wiki code.
Good news is that GeSHi already have exactly what you need!
First, you will need to set in localSettings.php:
$wgSyntaxHighlightKeywordLinks = true;
By doing that it will each function will be a link to http://www.php.net/<function name> (since your example is using php code).
If what you want is a link to somewhere else (your own site maybe), you will need to edit the 'URLS' array in $IP/SyntaxHighlight_GeSHi/geshi/geshi/php.php
(more information on GeSHi's documentation)
And if you will need links on functions for other languages other than php, just edit the according file instead. For example:
$IP/SyntaxHighlight_GeSHi/geshi/geshi/lolcode.php

Related

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

MediaWiki: How to update a link status programmatically

My extension renders additional links on a page (that is adds some <a href='...'>...</a> to the page text (in HtmlPageLinkRendererEnd hook)).
See small arrows in https://withoutvowels.org/wiki/Tanakh:Genesis_1:1 for an example. The arrows are automatically added by my extension (sorry, at the time of writing this the source code is not yet released).
The problem is that red/blue ("new") status is not updated for links which I add.
Please explain how to make Wikipedia to update color of my links as appropriate together with regular [[...]] MediaWiki links.
My current workaround is to run php maintenance/update.php. It is a very bad workaround. How to do it better?
Normally you'd use LinkRenderer to create the links and LinkBatch to make the page existence check efficient (you don't want a separate SQL query for each link). You can't really do that in HtmlPageLinkRendererEnd since you only learn about the links one by one.
The way the parser deals with this is that it replaces links with a placeholder and collects them in a list, then after parsing is mostly done it looks them all up at once and then switches the placeholders with the rendered links. You can probably hook into somthing that happens between the two (e.g. ParserAfterParse), get the list of links from the parser and use them to build a list of your own links.
With valuable help of Wikitech-l mailing list, I found a solution.
The solution is to use ParserAfterTidy hook.
public static function onParserAfterTidy( &$parser, &$text ) {
# ...
$parserOutput = $parser->getOutput();
foreach($parserOutput->getLinks() as ...) {
# ...
$parserOutput->addLink( Title::newFromDBkey(...) );
}
}

Prefix a URL with CSS

I am pulling the content of a bunch of customer reviews from a website using a tiny piece of PHP, though the title of each review contains the URL to the original review on the website that it comes from, which is great, except that the URL that is pulled does not contain to originating websites full address.
So on my website, the link does not work. You can see it in action here:
http://www.clearpandb.co.uk/new2016/feedback.php try clicking one of the review titles.
Is there any way to fix this with CSS? I think all it needs is a prefix to the original site. What is pulled from the originating site is just e.g. "/job/view/1971050", which when clicked tries to find this on my site (obviously won't find it). So I need to prefix it with "www.mybuilder.com" so that it works.
If the above isn't possible, a last resort might be to just disable the URL (without removing the title text itself) just so that there isn't a bunch of broken links.
PHP being used:
<?php
include_once('simple_html_dom.php');
$target_url = "https://www.mybuilder.com/profile/view/clear_plumbing_and_building_ltd/feedback";
$html = new simple_html_dom();
$html->load_file($target_url);
foreach($html->find('li[class=job-view-feedback]') as $jobviewfeedback){
echo $jobviewfeedback;
}
?>
I'm using a modified version of this tutorial for this:
http://www.makeuseof.com/tag/build-webcrawler-part-2
Which makes use of the a "helper" called "Simple HTML DOM".
Any help or pointers in the right direction are much appreciated, thanks in advance!
Can you edit that PHP? If so, do a PHP string replace on $jobviewfeedback... search for href="/ and replace with href="http://www.mybuilder.com/
so instead of
echo $jobviewfeedback;
you'd have
echo str_replace('href="/', 'href="http://www.mybuilder.com/', $jobviewfeedback);

Eclipse - how to extend HTML editor to add custom tags?

I write an application and inside of HTML code I have custom tags (of course these tags are parsed on server side and end user gets them as valid HTML code). Example of custom tag usage:
<html>
<body>
...
<Gallery type="grid" title="My Gallery" />
...
</body>
</html>
1.) How can I have eclipse recognize my custom tags inside of HTML code and add syntax highlighting to them?
2.) How can I add auto-suggestions to my custom tags? For example if I type "<Gallery " press "Ctrl+Space" - in the list of available attributes it shows me "type" and "title" and if I type "<Gallery type=" press "Ctrl+Space" I would see list of available values only for tag "Gallery" and its attribute "type".
Thanks in advance!
Not really what you want, but maybe it helps you:
You can try the Aptana Plug-in for Eclipse. It allows to write your own regular expression for HTML validation, so a custom tag would be ignored by the validator.
E.g.:
.gallery.
Eclipse allows you to add simple auto-suggestions via Templates. On
Eclipse 3.7.1 (Indigo) + PHP Dev Tools (PDT) 3.0.0: Window > Preferences > Web > HTML Files > Editor > Templates
Sadly, there is no easy way: you have to roll your own parser for this, and then add both your extra elements and the base grammar (HTML) to it.
If you have your parser, you could use it to do syntax highlighting (strictly speaking, for that simple lexing is enough); and a good parser can support content assist (auto-suggestions in your terminology).
Caveats:
Creating a parser for HTML is not an easy task. Maybe by aiming at a more often used subset is feasible.
If a parser exists, the editor parts are still hard to get well.
Some help on the other hand: you could use some text editor generators to ease your work:
Eclipse IMP http://www.eclipse.org/imp/ can in theory handle any type of parser, but currently it is most optimized for LPG. The documentation is scarce, but the developers are helpful in the forums.
Xtext http://www.eclipse.org/Xtext/ got quite a hype for creating text editors for DSLs. The generated editors are quite nice out of the box, but is not the best solution for large files. Has a really helpful developer community.
EMFText http://www.emftext.org/index.php/EMFText is a lesser known entity - I don't know it in details, but I guess, it is similar to Xtext.
I know its been a long time since this Q was asked,
but I hope this might help others like myself that reach this in search of a solution.
So, When using Eclipse (Mars.1 Release (4.5.1) - and possibly earlier - I did not check).
Go to Window - Prefrences
Then in the dialog that opens go to Web - HTML Files - Editor - Validation.
On the right side:
under Ignore specified element names in validation and enter the list of custom elements you use. (e.g. Gallery,tab,tabset,my-element-directives-*)
you might also like to go under Ignore specified attribute names in validation do the same for your custom attributes.(e.g. ng-*,my-attr-directives-*)
Two things to note:
After letting eclipse do a full validation you must also close the file and reopen it to have the warnings removed from the source code.
Using this method would ignore those attributes under any element. I don't think there is a simple way to tell it to ignore some-attribute only if its a child of some-element.
I find templates are an ok alternative but let's see if we can encourage a more robust solution; please take a moment and vote for this: https://bugs.eclipse.org/bugs/show_bug.cgi?id=422584
You need to add a new HTML template.To add a new template, complete the following steps:
1) From the Window menu, select Preferences.
2) In the Preferences page, select Web and XML > HTML Files > HTML Templates.
3) Click New.
4) Enter the new template name and a brief description of the template.
5) Using the Context drop-down list, specify the context in which the template is available.
6) In the Pattern field, enter the appropriate tags, attributes, or attribute values (the content of the template) to be inserted by content assist.
7) If you want to insert a variable, click the Variable button and select the variable to be inserted. For example, the word_selection variable indicates the word that is selected at the beginning of template insertion, and the cursor variable determines where the cursor will be after the template is inserted in the HTML document.
8) Click OK to save the new template.
You can edit, remove, import, or export a template by using the same Preferences page.
Reference : http://help.eclipse.org/kepler/index.jsp?topic=%2Forg.eclipse.wst.sse.doc.user%2Ftopics%2Ftsrcedt024.html

Localizing a Google Chrome Web App

I'm trying to add localization support to a Google Chrome Web App and, while it is easy to define strings for manifest and CSS files, it is somewhat more difficult for HTML pages.
In the manifest and in CSS files I can simply define localization strings like so:
__MSG_name__
but this doesn't work with HTML pages.
I can make a JavaScript function to fire onload that does the job like so:
document.title = chrome.i18n.getMessage("name");
document.querySelector("span.name").innerHTML = chrome.i18n.getMessage("name");
but this seems awfully ineffecient. Furthermore, I would like to be able to specify the page metadata; application-name and description, pulling the values from the localization files. What would be the best way of doing all this?
Thanks for your help.
Please refer to this documentation:
http://code.google.com/chrome/extensions/i18n.html
If you want to add localized content within HTML, you would need to do it via JavaScript as you mentioned before. That is the only way you can do it.
chrome.i18n.getMessage("name")
It isn't inefficient to do that, you can place your JavaScript at the end of the document (right before the end body tag) and it will fill up the text with respect to the locale.
Dunno if i understand exactly what you are trying to do but you could dynamically retrieve the LANG attribute (using .getAttribute("lang") or .lang) of the targeted tag and serve accordingly the proper values.