r84326 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r84325‎ | r84326 | r84327 >
Date:13:33, 19 March 2011
Author:ialex
Status:resolved (Comments)
Tags:
Comment:
Use ParserFirstCallInit hook to register parser hooks and functions instead of extension functions
Modified paths:
  • /trunk/extensions/DynamicPageList/DPLSetup.php (modified) (history)
  • /trunk/extensions/DynamicPageList/DynamicPageList.php (modified) (history)
  • /trunk/extensions/DynamicPageList/DynamicPageListMigration.php (modified) (history)
  • /trunk/extensions/HTMLets/HTMLets.php (modified) (history)
  • /trunk/extensions/IMStatus/IMStatus.php (modified) (history)
  • /trunk/extensions/JIRA/JIRA.php (modified) (history)
  • /trunk/extensions/LabeledSectionTransclusion/lsth.php (modified) (history)
  • /trunk/extensions/MathStatFunctions/MathStatFunctions.php (modified) (history)
  • /trunk/extensions/Memorize/Memorize.php (modified) (history)
  • /trunk/extensions/MiniDonation/MiniDonation.php (modified) (history)

Diff [purge]

Index: trunk/extensions/JIRA/JIRA.php
@@ -50,11 +50,11 @@
5151 'url' => 'http://www.mediawiki.org/wiki/Extension:JIRA',
5252 );
5353
54 -$wgExtensionFunctions[] = 'efJIRASetup';
 54+$wgHooks['ParserFirstCallInit'][] = 'efJIRASetHook';
5555
56 -function efJIRASetup() {
57 -global $wgParser;
58 - $wgParser->setHook( 'jiralist', 'efJIRARender' );
 56+function efJIRASetHook( $parser ) {
 57+ $parser->setHook( 'jiralist', 'efJIRARender' );
 58+ return true;
5959 }
6060
6161 function efJIRARender( $input, $args, $parser ) {
Index: trunk/extensions/MathStatFunctions/MathStatFunctions.php
@@ -14,8 +14,10 @@
1515 );
1616
1717 $wgExtensionMessagesFiles['MathStatFunctions'] = dirname( __FILE__ ) . '/MathStatFunctions.i18n.php';
18 -$wgExtensionFunctions[] = 'wfSetupMathStatFunctions';
 18+$wgHooks['ParserFirstCallInit'][] = 'wfSetupMathStatFunctions';
1919
 20+$wgExtMathStatFunctions = null;
 21+
2022 /**
2123 * \brief Exception class identifying that ParserFunctions is not available
2224 */
@@ -417,40 +419,42 @@
418420 }
419421 }
420422
421 -function wfSetupMathStatFunctions() {
 423+function wfSetupMathStatFunctions( $parser ) {
422424 global $wgParser, $wgExtMathStatFunctions;
423425
424426 try {
425 - $wgExtMathStatFunctions = new ExtMathStatFunctions;
 427+ if ( $wgExtMathStatFunctions === null ) {
 428+ $wgExtMathStatFunctions = new ExtMathStatFunctions;
 429+ }
426430 }
427431 catch ( ParserFunctionsNotFoundException $e ) {
428432 throw new FatalError( 'in ' . $e->getFile() . ' on line ' . $e->getLine() . ': ' . $e->getMessage() );
429433 }
430434
431 - $wgParser->setFunctionHook( 'const', array( &$wgExtMathStatFunctions, 'constHook' ) );
432 - $wgParser->setFunctionHook( 'median', array( &$wgExtMathStatFunctions, 'medianHook' ) );
433 - $wgParser->setFunctionHook( 'mean', array( &$wgExtMathStatFunctions, 'meanHook' ) );
434 - $wgParser->setFunctionHook( 'exp', array( &$wgExtMathStatFunctions, 'expHook' ) );
435 - $wgParser->setFunctionHook( 'log', array( &$wgExtMathStatFunctions, 'logHook' ) );
436 - $wgParser->setFunctionHook( 'ln', array( &$wgExtMathStatFunctions, 'lnHook' ) );
437 - $wgParser->setFunctionHook( 'tan', array( &$wgExtMathStatFunctions, 'tanHook' ) );
438 - $wgParser->setFunctionHook( 'atan', array( &$wgExtMathStatFunctions, 'atanHook' ) );
439 - $wgParser->setFunctionHook( 'tanh', array( &$wgExtMathStatFunctions, 'tanhHook' ) );
440 - $wgParser->setFunctionHook( 'atanh', array( &$wgExtMathStatFunctions, 'atanhHook' ) );
441 - $wgParser->setFunctionHook( 'cot', array( &$wgExtMathStatFunctions, 'cotHook' ) );
442 - $wgParser->setFunctionHook( 'acot', array( &$wgExtMathStatFunctions, 'acotHook' ) );
443 - $wgParser->setFunctionHook( 'cos', array( &$wgExtMathStatFunctions, 'cosHook' ) );
444 - $wgParser->setFunctionHook( 'acos', array( &$wgExtMathStatFunctions, 'acosHook' ) );
445 - $wgParser->setFunctionHook( 'cosh', array( &$wgExtMathStatFunctions, 'coshHook' ) );
446 - $wgParser->setFunctionHook( 'acosh', array( &$wgExtMathStatFunctions, 'acoshHook' ) );
447 - $wgParser->setFunctionHook( 'sec', array( &$wgExtMathStatFunctions, 'secHook' ) );
448 - $wgParser->setFunctionHook( 'asec', array( &$wgExtMathStatFunctions, 'asecHook' ) );
449 - $wgParser->setFunctionHook( 'sin', array( &$wgExtMathStatFunctions, 'sinHook' ) );
450 - $wgParser->setFunctionHook( 'asin', array( &$wgExtMathStatFunctions, 'asinHook' ) );
451 - $wgParser->setFunctionHook( 'sinh', array( &$wgExtMathStatFunctions, 'sinhHook' ) );
452 - $wgParser->setFunctionHook( 'asinh', array( &$wgExtMathStatFunctions, 'asinhHook' ) );
453 - $wgParser->setFunctionHook( 'csc', array( &$wgExtMathStatFunctions, 'cscHook' ) );
454 - $wgParser->setFunctionHook( 'acsc', array( &$wgExtMathStatFunctions, 'acscHook' ) );
 435+ $parser->setFunctionHook( 'const', array( &$wgExtMathStatFunctions, 'constHook' ) );
 436+ $parser->setFunctionHook( 'median', array( &$wgExtMathStatFunctions, 'medianHook' ) );
 437+ $parser->setFunctionHook( 'mean', array( &$wgExtMathStatFunctions, 'meanHook' ) );
 438+ $parser->setFunctionHook( 'exp', array( &$wgExtMathStatFunctions, 'expHook' ) );
 439+ $parser->setFunctionHook( 'log', array( &$wgExtMathStatFunctions, 'logHook' ) );
 440+ $parser->setFunctionHook( 'ln', array( &$wgExtMathStatFunctions, 'lnHook' ) );
 441+ $parser->setFunctionHook( 'tan', array( &$wgExtMathStatFunctions, 'tanHook' ) );
 442+ $parser->setFunctionHook( 'atan', array( &$wgExtMathStatFunctions, 'atanHook' ) );
 443+ $parser->setFunctionHook( 'tanh', array( &$wgExtMathStatFunctions, 'tanhHook' ) );
 444+ $parser->setFunctionHook( 'atanh', array( &$wgExtMathStatFunctions, 'atanhHook' ) );
 445+ $parser->setFunctionHook( 'cot', array( &$wgExtMathStatFunctions, 'cotHook' ) );
 446+ $parser->setFunctionHook( 'acot', array( &$wgExtMathStatFunctions, 'acotHook' ) );
 447+ $parser->setFunctionHook( 'cos', array( &$wgExtMathStatFunctions, 'cosHook' ) );
 448+ $parser->setFunctionHook( 'acos', array( &$wgExtMathStatFunctions, 'acosHook' ) );
 449+ $parser->setFunctionHook( 'cosh', array( &$wgExtMathStatFunctions, 'coshHook' ) );
 450+ $parser->setFunctionHook( 'acosh', array( &$wgExtMathStatFunctions, 'acoshHook' ) );
 451+ $parser->setFunctionHook( 'sec', array( &$wgExtMathStatFunctions, 'secHook' ) );
 452+ $parser->setFunctionHook( 'asec', array( &$wgExtMathStatFunctions, 'asecHook' ) );
 453+ $parser->setFunctionHook( 'sin', array( &$wgExtMathStatFunctions, 'sinHook' ) );
 454+ $parser->setFunctionHook( 'asin', array( &$wgExtMathStatFunctions, 'asinHook' ) );
 455+ $parser->setFunctionHook( 'sinh', array( &$wgExtMathStatFunctions, 'sinhHook' ) );
 456+ $parser->setFunctionHook( 'asinh', array( &$wgExtMathStatFunctions, 'asinhHook' ) );
 457+ $parser->setFunctionHook( 'csc', array( &$wgExtMathStatFunctions, 'cscHook' ) );
 458+ $parser->setFunctionHook( 'acsc', array( &$wgExtMathStatFunctions, 'acscHook' ) );
455459
456460 return true;
457461 }
Index: trunk/extensions/Memorize/Memorize.php
@@ -30,14 +30,13 @@
3131 if( !defined( 'MEDIAWIKI' ) )
3232 die( -1 );
3333
34 -$wgExtensionFunctions[] = "wfMemorize";
 34+$wgHooks['ParserFirstCallInit'][] = 'wfMemorizeSetHook';
3535 $wgHooks['BeforePageDisplay'][] = 'addMemorizeJavascriptAndCSS';
3636
3737
38 -function wfMemorize() {
39 - global $wgParser;
40 -
41 - $wgParser->setHook( 'memorize', 'renderMemorize' );
 38+function wfMemorizeSetHook( $parser ) {
 39+ $parser->setHook( 'memorize', 'renderMemorize' );
 40+ return true;
4241 }
4342
4443 function renderMemorize( $input, $argv, &$parser ) {
Index: trunk/extensions/MiniDonation/MiniDonation.php
@@ -8,13 +8,12 @@
99 'descriptionmsg' => 'donationform-desc',
1010 );
1111
12 -$wgExtensionFunctions[] = 'wfSetupMiniDonation';
 12+$wgHooks['ParserFirstCallInit'][] = 'wfSetupMiniDonation';
1313 $wgExtensionMessagesFiles['MiniDonation'] = dirname(__FILE__) . '/MiniDonation.i18n.php';
1414
15 -function wfSetupMiniDonation() {
16 - global $wgParser;
17 -
18 - $wgParser->setHook( 'donationform', 'wfMiniDonationHook' );
 15+function wfSetupMiniDonation( $parser ) {
 16+ $parser->setHook( 'donationform', 'wfMiniDonationHook' );
 17+ return true;
1918 }
2019
2120 function wfMiniDonationHook( $text, $params, $parser ) {
Index: trunk/extensions/IMStatus/IMStatus.php
@@ -53,17 +53,16 @@
5454 //*********** MANDATORY parameters - end
5555
5656 //Tag creation
57 -$wgExtensionFunctions[] = "wfIMStatusPCR";
58 -function wfIMStatusPCR()
59 -{
60 - global $wgParser;
61 - $wgParser->setHook( "aim", "RenderAIM" );
62 - $wgParser->setHook( "gtalk", "RenderGTalk" );
63 - $wgParser->setHook( "icq", "RenderICQ" );
64 - $wgParser->setHook( "livemessenger", "RenderLiveMessenger" );
65 - $wgParser->setHook( "skype", "RenderSkype" );
66 - $wgParser->setHook( "xfire", "RenderXfire" );
67 - $wgParser->setHook( "yahoo", "RenderYahoo" );
 57+$wgHooks['ParserFirstCallInit'][] = 'wfIMStatusPCR';
 58+function wfIMStatusPCR( $parser ) {
 59+ $parser->setHook( 'aim', 'RenderAIM' );
 60+ $parser->setHook( 'gtalk', 'RenderGTalk' );
 61+ $parser->setHook( 'icq', 'RenderICQ' );
 62+ $parser->setHook( 'livemessenger', 'RenderLiveMessenger' );
 63+ $parser->setHook( 'skype', 'RenderSkype' );
 64+ $parser->setHook( 'xfire', 'RenderXfire' );
 65+ $parser->setHook( 'yahoo', 'RenderYahoo' );
 66+ return true;
6867 }
6968
7069 // FIXME: below should be put in its own class file and use PARSERFIRSTCALLINIT to optimise resource usage
Index: trunk/extensions/LabeledSectionTransclusion/lsth.php
@@ -27,14 +27,13 @@
2828 # Standard initialisation code
2929 ##
3030
31 -$wgExtensionFunctions[] = "wfLabeledSectionTransclusionHeading";
 31+$wgHooks['ParserFirstCallInit'][] = 'wfLabeledSectionTransclusionHeading';
3232 $wgHooks['LanguageGetMagic'][] = 'wfLabeledSectionTransclusionHeadingMagic';
3333 $wgParserTestFiles[] = dirname( __FILE__ ) . "/lsthParserTests.txt";
3434
35 -function wfLabeledSectionTransclusionHeading()
36 -{
37 - global $wgParser;
38 - $wgParser->setFunctionHook( 'lsth', 'wfLstIncludeHeading' );
 35+function wfLabeledSectionTransclusionHeading( $parser ) {
 36+ $parser->setFunctionHook( 'lsth', 'wfLstIncludeHeading' );
 37+ return true;
3938 }
4039
4140 function wfLabeledSectionTransclusionHeadingMagic( &$magicWords, $langCode ) {
Index: trunk/extensions/HTMLets/HTMLets.php
@@ -51,11 +51,11 @@
5252
5353 $wgHTMLetsDirectory = null;
5454
55 -$wgExtensionFunctions[] = "wfHTMLetsExtension";
 55+$wgHooks['ParserFirstCallInit'][] = 'wfHTMLetsSetHook';
5656
57 -function wfHTMLetsExtension() {
58 - global $wgParser;
59 - $wgParser->setHook( "htmlet", "wfRenderHTMLet" );
 57+function wfHTMLetsSetHook( $parser ) {
 58+ $parser->setHook( 'htmlet', 'wfRenderHTMLet' );
 59+ return true;
6060 }
6161
6262 # The callback function for converting the input text to HTML output
Index: trunk/extensions/DynamicPageList/DynamicPageList.php
@@ -58,7 +58,7 @@
5959 // we also register the tag <DynamicPageList> because DPL is downward compatible with Extension:Intersection
6060 // This means that your LocalSettings.php MUST NO LONGER include Extension:Intersection;
6161
62 -$wgExtensionFunctions[] = array( 'ExtDynamicPageList', 'setupDPL' );
 62+$wgHooks['ParserFirstCallInit'][] = 'ExtDynamicPageList::setupDPL';
6363
6464 $wgHooks['LanguageGetMagic'][] = 'ExtDynamicPageList__languageGetMagic';
6565
@@ -80,4 +80,4 @@
8181 ExtDynamicPageList::$DPLVersion = $DPLVersion;
8282
8383 // use full functionality by default
84 -ExtDynamicPageList::setFunctionalRichness( 4 );
\ No newline at end of file
 84+ExtDynamicPageList::setFunctionalRichness( 4 );
Index: trunk/extensions/DynamicPageList/DPLSetup.php
@@ -1173,29 +1173,28 @@
11741174 self::$functionalRichness = $level;
11751175 }
11761176
1177 - public static function setupDPL() {
1178 - global $wgParser;
1179 -
 1177+ public static function setupDPL( $parser ) {
11801178 // DPL offers the same functionality as Intersection; so we register the <DynamicPageList> tag
11811179 // in case LabeledSection Extension is not installed we need to remove section markers
1182 - $wgParser->setHook( 'section', array( __CLASS__, 'removeSectionMarkers' ) );
1183 - $wgParser->setHook( 'DPL', array( __CLASS__, 'dplTag' ) );
1184 - $wgParser->setHook( 'DynamicPageList', array( __CLASS__, 'intersectionTag' ) );
 1180+ $parser->setHook( 'section', array( __CLASS__, 'removeSectionMarkers' ) );
 1181+ $parser->setHook( 'DPL', array( __CLASS__, 'dplTag' ) );
 1182+ $parser->setHook( 'DynamicPageList', array( __CLASS__, 'intersectionTag' ) );
11851183
1186 - $wgParser->setFunctionHook( 'dpl', array( __CLASS__, 'dplParserFunction' ) );
1187 - $wgParser->setFunctionHook( 'dplnum', array( __CLASS__, 'dplNumParserFunction' ) );
1188 - $wgParser->setFunctionHook( 'dplchapter', array( __CLASS__, 'dplChapterParserFunction' ) );
1189 - $wgParser->setFunctionHook( 'dplmatrix', array( __CLASS__, 'dplMatrixParserFunction' ) );
 1184+ $parser->setFunctionHook( 'dpl', array( __CLASS__, 'dplParserFunction' ) );
 1185+ $parser->setFunctionHook( 'dplnum', array( __CLASS__, 'dplNumParserFunction' ) );
 1186+ $parser->setFunctionHook( 'dplchapter', array( __CLASS__, 'dplChapterParserFunction' ) );
 1187+ $parser->setFunctionHook( 'dplmatrix', array( __CLASS__, 'dplMatrixParserFunction' ) );
11901188
11911189 self::commonSetup();
 1190+ return true;
11921191 }
11931192
11941193 public static function setupMigration() {
11951194 // DPL offers the same functionality as Intersection under the tag name <Intersection>
1196 - global $wgParser;
1197 - $wgParser->setHook( 'Intersection', array( __CLASS__, 'intersectionTag' ) );
 1195+ $parser->setHook( 'Intersection', array( __CLASS__, 'intersectionTag' ) );
11981196
11991197 self::commonSetup();
 1198+ return true;
12001199 }
12011200
12021201 private static function commonSetup() {
Index: trunk/extensions/DynamicPageList/DynamicPageListMigration.php
@@ -39,7 +39,7 @@
4040 // A call to ExtDynamicPageList::setFunctionalRichness(n) with n>0 will provide additional functionality
4141 // for the <Intersection> tag; so you can try out additional features without bothering anyone.
4242
43 -$wgExtensionFunctions[] = array( 'ExtDynamicPageList', 'setupMigration' );
 43+$wgHooks['ParserFirstCallIntit'][] = 'ExtDynamicPageList::setupMigration';
4444
4545 $wgHooks['LanguageGetMagic'][] = 'ExtDynamicPageList__languageGetMagic';
4646

Follow-up revisions

RevisionCommit summaryAuthorDate
r90392Fix for r84326: added missing parameterialex11:17, 19 June 2011

Comments

#Comment by Aaron Schulz (talk | contribs)   21:39, 17 June 2011
+ public static function setupMigration() { 

Where is the $parser argument?

#Comment by IAlex (talk | contribs)   11:17, 19 June 2011

Fixed in r90392.

Status & tagging log