r37639 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r37638‎ | r37639 | r37640 >
Date:11:45, 14 July 2008
Author:catrope
Status:old
Tags:
Comment:
Redircite:
* Use the ParserFirstCallInit hook so $wgParser isn't unstubbed on every single request
* Rename the global $markerList to $redirciteMarkerList to prevent naming collisions
Modified paths:
  • /trunk/extensions/redircite/redircite.php (modified) (history)

Diff [purge]

Index: trunk/extensions/redircite/redircite.php
@@ -16,7 +16,6 @@
1717 *
1818 */
1919
20 -$wgExtensionFunctions[] = 'redircite_setup';
2120 $wgExtensionCredits['other'][] = array(
2221 'name' => 'redircite',
2322 'author' => 'Roan Kattouw',
@@ -25,19 +24,20 @@
2625 'url' => 'http://www.mediawiki.org/wiki/Extension:Redircite'
2726 );
2827
29 -function redircite_setup() {
30 - global $wgParser, $wgHooks;
31 - $wgParser->setHook('redircite', 'redircite_render');
32 - $wgHooks['ParserAfterTidy'][] = 'redircite_afterTidy';
 28+$wgHooks['ParserAfterTidy'][] = 'redircite_afterTidy';
 29+$wgHooks['ParserFirstCallInit'][] = 'redircite_setup';
 30+function redircite_setup($parser) {
 31+ $parser->setHook('redircite', 'redircite_render');
 32+ return true;
3333 }
3434
35 -$markerList = array();
 35+$redirciteMarkerList = array();
3636 function redircite_render($input, $args, $parser) {
37 - // Generate HTML code and add it to the $markerList array
 37+ // Generate HTML code and add it to the $redirciteMarkerList array
3838 // Add "xx-redircite-marker-NUMBER-redircite-xx" to the output,
39 - // which will be translated to the HTML stored in $markerList by
 39+ // which will be translated to the HTML stored in $redirciteMarkerList by
4040 // redircite_afterTidy()
41 - global $markerList;
 41+ global $redirciteMarkerList;
4242 $lparse = clone $parser;
4343 $link1 = $lparse->parse("[[$input]]", $parser->mTitle, $parser->mOptions, false, false);
4444 $link1text = $link1->getText();
@@ -54,16 +54,16 @@
5555 $link2 = $lparse->parse("[[{$title2->getPrefixedText()}|$input]]", $parser->mTitle, $parser->mOptions, false, false);
5656 $link2text = $link2->getText();
5757
58 - $marker = "xx-redircite-marker-" . count($markerList) . "-redircite-xx";
59 - $markerList[] = "<span onmouseout='this.firstChild.innerHTML = \"$input\";' onmouseover='this.firstChild.innerHTML = \"{$title2->getPrefixedText()}\";'>$link2text</span>";
 58+ $marker = "xx-redircite-marker-" . count($redirciteMarkerList) . "-redircite-xx";
 59+ $redirciteMarkerList[] = "<span onmouseout='this.firstChild.innerHTML = \"$input\";' onmouseover='this.firstChild.innerHTML = \"{$title2->getPrefixedText()}\";'>$link2text</span>";
6060 return $marker;
6161 }
6262
6363 function redircite_afterTidy(&$parser, &$text) {
6464 // Translate the markers added by redircite_render() to the HTML
65 - // associated with them through $markerList
66 - global $markerList;
67 - foreach($markerList as $i => $output)
 65+ // associated with them through $redirciteMarkerList
 66+ global $redirciteMarkerList;
 67+ foreach($redirciteMarkerList as $i => $output)
6868 $text = preg_replace("/xx-redircite-marker-$i-redircite-xx/", $output, $text);
6969 return true;
7070 }
\ No newline at end of file

Status & tagging log