r85804 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r85803‎ | r85804 | r85805 >
Date:17:27, 11 April 2011
Author:pcopp
Status:resolved (Comments)
Tags:
Comment:
Make ParserFunctions work with HipHop.
* When using HipHop, is_callable() returns false for objects which have only a __call() method instead of the requested one.
* Work around this by removing the ParserFunctions_HookStub hack.
* To retain the behavior that the code of ParserFunctions_body.php is only loaded when needed, turn it into a static class.
* Defer the registering of the ParserClearState hook until a relevant function is called.
Modified paths:
  • /trunk/extensions/ParserFunctions/ParserFunctions.php (modified) (history)
  • /trunk/extensions/ParserFunctions/ParserFunctions_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ParserFunctions/ParserFunctions_body.php
@@ -1,22 +1,38 @@
22 <?php
33
44 class ExtParserFunctions {
5 - var $mExprParser;
6 - var $mTimeCache = array();
7 - var $mTimeChars = 0;
8 - var $mMaxTimeChars = 6000; # ~10 seconds
 5+ static $mExprParser;
 6+ static $mConvertParser;
 7+ static $mTimeCache = array();
 8+ static $mTimeChars = 0;
 9+ static $mMaxTimeChars = 6000; # ~10 seconds
910
10 - function clearState( $parser ) {
11 - $this->mTimeChars = 0;
 11+ public static function clearState( $parser ) {
 12+ self::$mTimeChars = 0;
1213 $parser->pf_ifexist_breakdown = array();
1314 $parser->pf_markerRegex = null;
1415 return true;
1516 }
1617
1718 /**
 19+ * Register ParserClearState hook.
 20+ * We defer this until needed to avoid the loading of the code of this file
 21+ * when no parser function is actually called.
 22+ */
 23+ public static function registerClearHook() {
 24+ static $done = false;
 25+ if( !$done ) {
 26+ global $wgHooks;
 27+ $wgHooks['ParserClearState'][] = __CLASS__ . '::clearState';
 28+ $done = true;
 29+ }
 30+ }
 31+
 32+ /**
1833 * Get the marker regex. Cached.
1934 */
20 - function getMarkerRegex( $parser ) {
 35+ public static function getMarkerRegex( $parser ) {
 36+ self::registerClearHook();
2137 if ( isset( $parser->pf_markerRegex ) ) {
2238 return $parser->pf_markerRegex;
2339 }
@@ -43,31 +59,31 @@
4460 }
4561
4662 // Removes unique markers from passed parameters, used by string functions.
47 - private function killMarkers ( $parser, $text ) {
48 - return preg_replace( $this->getMarkerRegex( $parser ), '' , $text );
 63+ private static function killMarkers ( $parser, $text ) {
 64+ return preg_replace( self::getMarkerRegex( $parser ), '' , $text );
4965 }
5066
5167 /**
5268 * @return ExprParser
5369 */
54 - function &getExprParser() {
55 - if ( !isset( $this->mExprParser ) ) {
56 - $this->mExprParser = new ExprParser;
 70+ public static function &getExprParser() {
 71+ if ( !isset( self::$mExprParser ) ) {
 72+ self::$mExprParser = new ExprParser;
5773 }
58 - return $this->mExprParser;
 74+ return self::$mExprParser;
5975 }
6076
61 - function expr( $parser, $expr = '' ) {
 77+ public static function expr( $parser, $expr = '' ) {
6278 try {
63 - return $this->getExprParser()->doExpression( $expr );
 79+ return self::getExprParser()->doExpression( $expr );
6480 } catch ( ExprError $e ) {
6581 return $e->getMessage();
6682 }
6783 }
6884
69 - function ifexpr( $parser, $expr = '', $then = '', $else = '' ) {
 85+ public static function ifexpr( $parser, $expr = '', $then = '', $else = '' ) {
7086 try {
71 - $ret = $this->getExprParser()->doExpression( $expr );
 87+ $ret = self::getExprParser()->doExpression( $expr );
7288 if ( is_numeric( $ret ) ) {
7389 $ret = floatval( $ret );
7490 }
@@ -81,18 +97,18 @@
8298 }
8399 }
84100
85 - function ifexprObj( $parser, $frame, $args ) {
 101+ public static function ifexprObj( $parser, $frame, $args ) {
86102 $expr = isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : '';
87103 $then = isset( $args[1] ) ? $args[1] : '';
88104 $else = isset( $args[2] ) ? $args[2] : '';
89 - $result = $this->ifexpr( $parser, $expr, $then, $else );
 105+ $result = self::ifexpr( $parser, $expr, $then, $else );
90106 if ( is_object( $result ) ) {
91107 $result = trim( $frame->expand( $result ) );
92108 }
93109 return $result;
94110 }
95111
96 - function ifHook( $parser, $test = '', $then = '', $else = '' ) {
 112+ public static function ifHook( $parser, $test = '', $then = '', $else = '' ) {
97113 if ( $test !== '' ) {
98114 return $then;
99115 } else {
@@ -100,7 +116,7 @@
101117 }
102118 }
103119
104 - function ifObj( $parser, $frame, $args ) {
 120+ public static function ifObj( $parser, $frame, $args ) {
105121 $test = isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : '';
106122 if ( $test !== '' ) {
107123 return isset( $args[1] ) ? trim( $frame->expand( $args[1] ) ) : '';
@@ -109,7 +125,7 @@
110126 }
111127 }
112128
113 - function ifeq( $parser, $left = '', $right = '', $then = '', $else = '' ) {
 129+ public static function ifeq( $parser, $left = '', $right = '', $then = '', $else = '' ) {
114130 if ( $left == $right ) {
115131 return $then;
116132 } else {
@@ -117,7 +133,7 @@
118134 }
119135 }
120136
121 - function ifeqObj( $parser, $frame, $args ) {
 137+ public static function ifeqObj( $parser, $frame, $args ) {
122138 $left = isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : '';
123139 $right = isset( $args[1] ) ? trim( $frame->expand( $args[1] ) ) : '';
124140 if ( $left == $right ) {
@@ -127,7 +143,7 @@
128144 }
129145 }
130146
131 - function iferror( $parser, $test = '', $then = '', $else = false ) {
 147+ public static function iferror( $parser, $test = '', $then = '', $else = false ) {
132148 if ( preg_match( '/<(?:strong|span|p|div)\s(?:[^\s>]*\s+)*?class="(?:[^"\s>]*\s+)*?error(?:\s[^">]*)?"/', $test ) ) {
133149 return $then;
134150 } elseif ( $else === false ) {
@@ -137,11 +153,11 @@
138154 }
139155 }
140156
141 - function iferrorObj( $parser, $frame, $args ) {
 157+ public static function iferrorObj( $parser, $frame, $args ) {
142158 $test = isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : '';
143159 $then = isset( $args[1] ) ? $args[1] : false;
144160 $else = isset( $args[2] ) ? $args[2] : false;
145 - $result = $this->iferror( $parser, $test, $then, $else );
 161+ $result = self::iferror( $parser, $test, $then, $else );
146162 if ( $result === false ) {
147163 return '';
148164 } else {
@@ -149,7 +165,7 @@
150166 }
151167 }
152168
153 - function switchHook( $parser /*,...*/ ) {
 169+ public static function switchHook( $parser /*,...*/ ) {
154170 $args = func_get_args();
155171 array_shift( $args );
156172 $primary = trim( array_shift( $args ) );
@@ -188,7 +204,7 @@
189205 }
190206 }
191207
192 - function switchObj( $parser, $frame, $args ) {
 208+ public static function switchObj( $parser, $frame, $args ) {
193209 if ( count( $args ) == 0 ) {
194210 return '';
195211 }
@@ -248,7 +264,7 @@
249265 * Following subpage link syntax instead of standard path syntax, an
250266 * initial slash is treated as a relative path, and vice versa.
251267 */
252 - public function rel2abs( $parser , $to = '' , $from = '' ) {
 268+ public static function rel2abs( $parser , $to = '' , $from = '' ) {
253269
254270 $from = trim( $from );
255271 if ( $from == '' ) {
@@ -302,9 +318,10 @@
303319 return implode( '/' , $newExploded );
304320 }
305321
306 - function incrementIfexistCount( $parser, $frame ) {
 322+ public static function incrementIfexistCount( $parser, $frame ) {
307323 // Don't let this be called more than a certain number of times. It tends to make the database explode.
308324 global $wgExpensiveParserFunctionLimit;
 325+ self::registerClearHook();
309326 $parser->mExpensiveFunctionCount++;
310327 if ( $frame ) {
311328 $pdbk = $frame->getPDBK( 1 );
@@ -316,11 +333,11 @@
317334 return $parser->mExpensiveFunctionCount <= $wgExpensiveParserFunctionLimit;
318335 }
319336
320 - function ifexist( $parser, $title = '', $then = '', $else = '' ) {
321 - return $this->ifexistCommon( $parser, false, $title, $then, $else );
 337+ public static function ifexist( $parser, $title = '', $then = '', $else = '' ) {
 338+ return self::ifexistCommon( $parser, false, $title, $then, $else );
322339 }
323340
324 - function ifexistCommon( $parser, $frame, $titletext = '', $then = '', $else = '' ) {
 341+ public static function ifexistCommon( $parser, $frame, $titletext = '', $then = '', $else = '' ) {
325342 global $wgContLang;
326343 $title = Title::newFromText( $titletext );
327344 $wgContLang->findVariantLink( $titletext, $title, true );
@@ -329,7 +346,7 @@
330347 /* If namespace is specified as NS_MEDIA, then we want to
331348 * check the physical file, not the "description" page.
332349 */
333 - if ( !$this->incrementIfexistCount( $parser, $frame ) ) {
 350+ if ( !self::incrementIfexistCount( $parser, $frame ) ) {
334351 return $else;
335352 }
336353 $file = wfFindFile( $title );
@@ -354,7 +371,7 @@
355372 } else {
356373 $pdbk = $title->getPrefixedDBkey();
357374 $lc = LinkCache::singleton();
358 - if ( !$this->incrementIfexistCount( $parser, $frame ) ) {
 375+ if ( !self::incrementIfexistCount( $parser, $frame ) ) {
359376 return $else;
360377 }
361378 if ( 0 != ( $id = $lc->getGoodLinkID( $pdbk ) ) ) {
@@ -374,12 +391,12 @@
375392 return $else;
376393 }
377394
378 - function ifexistObj( $parser, $frame, $args ) {
 395+ public static function ifexistObj( $parser, $frame, $args ) {
379396 $title = isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : '';
380397 $then = isset( $args[1] ) ? $args[1] : null;
381398 $else = isset( $args[2] ) ? $args[2] : null;
382399
383 - $result = $this->ifexistCommon( $parser, $frame, $title, $then, $else );
 400+ $result = self::ifexistCommon( $parser, $frame, $title, $then, $else );
384401 if ( $result === null ) {
385402 return '';
386403 } else {
@@ -387,10 +404,11 @@
388405 }
389406 }
390407
391 - function time( $parser, $format = '', $date = '', $local = false ) {
 408+ public static function time( $parser, $format = '', $date = '', $local = false ) {
392409 global $wgContLang, $wgLocaltimezone;
393 - if ( isset( $this->mTimeCache[$format][$date][$local] ) ) {
394 - return $this->mTimeCache[$format][$date][$local];
 410+ self::registerClearHook();
 411+ if ( isset( self::$mTimeCache[$format][$date][$local] ) ) {
 412+ return self::$mTimeCache[$format][$date][$local];
395413 }
396414
397415 # compute the timestamp string $ts
@@ -462,19 +480,19 @@
463481 if ( $invalidTime ) {
464482 $result = '<strong class="error">' . wfMsgForContent( 'pfunc_time_error' ) . '</strong>';
465483 } else {
466 - $this->mTimeChars += strlen( $format );
467 - if ( $this->mTimeChars > $this->mMaxTimeChars ) {
 484+ self::$mTimeChars += strlen( $format );
 485+ if ( self::$mTimeChars > self::$mMaxTimeChars ) {
468486 return '<strong class="error">' . wfMsgForContent( 'pfunc_time_too_long' ) . '</strong>';
469487 } else {
470488 $result = $wgContLang->sprintfDate( $format, $ts );
471489 }
472490 }
473 - $this->mTimeCache[$format][$date][$local] = $result;
 491+ self::$mTimeCache[$format][$date][$local] = $result;
474492 return $result;
475493 }
476494
477 - function localTime( $parser, $format = '', $date = '' ) {
478 - return $this->time( $parser, $format, $date, true );
 495+ public static function localTime( $parser, $format = '', $date = '' ) {
 496+ return self::time( $parser, $format, $date, true );
479497 }
480498
481499 /**
@@ -487,7 +505,7 @@
488506 * @param int $offset Offset starting at 1
489507 * @return string
490508 */
491 - public function titleparts( $parser, $title = '', $parts = 0, $offset = 0 ) {
 509+ public static function titleparts( $parser, $title = '', $parts = 0, $offset = 0 ) {
492510 $parts = intval( $parts );
493511 $offset = intval( $offset );
494512 $ntitle = Title::newFromText( $title );
@@ -514,17 +532,17 @@
515533 * Get a ConvertParser object
516534 * @return ConvertParser
517535 */
518 - protected function &getConvertParser() {
519 - if ( !isset( $this->mConvertParser ) ) {
520 - $this->mConvertParser = new ConvertParser;
 536+ protected static function &getConvertParser() {
 537+ if ( !isset( self::$mConvertParser ) ) {
 538+ self::$mConvertParser = new ConvertParser;
521539 }
522 - return $this->mConvertParser;
 540+ return self::$mConvertParser;
523541 }
524542
525 - public function convert( /*...*/ ) {
 543+ public static function convert( /*...*/ ) {
526544 try {
527545 $args = func_get_args();
528 - return $this->getConvertParser()->execute( $args );
 546+ return self::getConvertParser()->execute( $args );
529547 } catch ( ConvertError $e ) {
530548 return $e->getMessage();
531549 }
@@ -537,7 +555,7 @@
538556 }
539557
540558 // Generates error message. Called when string is too long.
541 - private function tooLongError() {
 559+ private static function tooLongError() {
542560 global $wgPFStringLengthLimit, $wgContLang;
543561 return '<strong class="error">' .
544562 wfMsgExt( 'pfunc_string_too_long',
@@ -551,10 +569,10 @@
552570 *
553571 * Reports number of characters in string.
554572 */
555 - function runLen ( $parser, $inStr = '' ) {
 573+ public static function runLen ( $parser, $inStr = '' ) {
556574 wfProfileIn( __METHOD__ );
557575
558 - $inStr = $this->killMarkers( $parser, (string)$inStr );
 576+ $inStr = self::killMarkers( $parser, (string)$inStr );
559577 $len = mb_strlen( $inStr );
560578
561579 wfProfileOut( __METHOD__ );
@@ -569,16 +587,16 @@
570588 * Note: If the needle is an empty string, single space is used instead.
571589 * Note: If the needle is not found, empty string is returned.
572590 */
573 - function runPos ( $parser, $inStr = '', $inNeedle = '', $inOffset = 0 ) {
 591+ public static function runPos ( $parser, $inStr = '', $inNeedle = '', $inOffset = 0 ) {
574592 wfProfileIn( __METHOD__ );
575593
576 - $inStr = $this->killMarkers( $parser, (string)$inStr );
577 - $inNeedle = $this->killMarkers( $parser, (string)$inNeedle );
 594+ $inStr = self::killMarkers( $parser, (string)$inStr );
 595+ $inNeedle = self::killMarkers( $parser, (string)$inNeedle );
578596
579 - if ( !$this->checkLength( $inStr ) ||
580 - !$this->checkLength( $inNeedle ) ) {
 597+ if ( !self::checkLength( $inStr ) ||
 598+ !self::checkLength( $inNeedle ) ) {
581599 wfProfileOut( __METHOD__ );
582 - return $this->tooLongError();
 600+ return self::tooLongError();
583601 }
584602
585603 if ( $inNeedle == '' ) { $inNeedle = ' '; }
@@ -598,16 +616,16 @@
599617 * Note: If the needle is an empty string, single space is used instead.
600618 * Note: If the needle is not found, -1 is returned.
601619 */
602 - function runRPos ( $parser, $inStr = '', $inNeedle = '' ) {
 620+ public static function runRPos ( $parser, $inStr = '', $inNeedle = '' ) {
603621 wfProfileIn( __METHOD__ );
604622
605 - $inStr = $this->killMarkers( $parser, (string)$inStr );
606 - $inNeedle = $this->killMarkers( $parser, (string)$inNeedle );
 623+ $inStr = self::killMarkers( $parser, (string)$inStr );
 624+ $inNeedle = self::killMarkers( $parser, (string)$inNeedle );
607625
608 - if ( !$this->checkLength( $inStr ) ||
609 - !$this->checkLength( $inNeedle ) ) {
 626+ if ( !self::checkLength( $inStr ) ||
 627+ !self::checkLength( $inNeedle ) ) {
610628 wfProfileOut( __METHOD__ );
611 - return $this->tooLongError();
 629+ return self::tooLongError();
612630 }
613631
614632 if ( $inNeedle == '' ) { $inNeedle = ' '; }
@@ -631,14 +649,14 @@
632650 * Note: A negative value for "length" returns a string reduced in
633651 * length by that amount.
634652 */
635 - function runSub ( $parser, $inStr = '', $inStart = 0, $inLength = 0 ) {
 653+ public static function runSub ( $parser, $inStr = '', $inStart = 0, $inLength = 0 ) {
636654 wfProfileIn( __METHOD__ );
637655
638 - $inStr = $this->killMarkers( $parser, (string)$inStr );
 656+ $inStr = self::killMarkers( $parser, (string)$inStr );
639657
640 - if ( !$this->checkLength( $inStr ) ) {
 658+ if ( !self::checkLength( $inStr ) ) {
641659 wfProfileOut( __METHOD__ );
642 - return $this->tooLongError();
 660+ return self::tooLongError();
643661 }
644662
645663 if ( intval( $inLength ) == 0 ) {
@@ -658,16 +676,16 @@
659677 *
660678 * Note: If "substr" is empty, a single space is used.
661679 */
662 - function runCount ( $parser, $inStr = '', $inSubStr = '' ) {
 680+ public static function runCount ( $parser, $inStr = '', $inSubStr = '' ) {
663681 wfProfileIn( __METHOD__ );
664682
665 - $inStr = $this->killMarkers( $parser, (string)$inStr );
666 - $inSubStr = $this->killMarkers( $parser, (string)$inSubStr );
 683+ $inStr = self::killMarkers( $parser, (string)$inStr );
 684+ $inSubStr = self::killMarkers( $parser, (string)$inSubStr );
667685
668 - if ( !$this->checkLength( $inStr ) ||
669 - !$this->checkLength( $inSubStr ) ) {
 686+ if ( !self::checkLength( $inStr ) ||
 687+ !self::checkLength( $inSubStr ) ) {
670688 wfProfileOut( __METHOD__ );
671 - return $this->tooLongError();
 689+ return self::tooLongError();
672690 }
673691
674692 if ( $inSubStr == '' ) { $inSubStr = ' '; }
@@ -687,20 +705,20 @@
688706 * Note: Armored against replacements that would generate huge strings.
689707 * Note: If "from" is an empty string, single space is used instead.
690708 */
691 - function runReplace( $parser, $inStr = '',
 709+ public static function runReplace( $parser, $inStr = '',
692710 $inReplaceFrom = '', $inReplaceTo = '', $inLimit = -1 ) {
693711 global $wgPFStringLengthLimit;
694712 wfProfileIn( __METHOD__ );
695713
696 - $inStr = $this->killMarkers( $parser, (string)$inStr );
697 - $inReplaceFrom = $this->killMarkers( $parser, (string)$inReplaceFrom );
698 - $inReplaceTo = $this->killMarkers( $parser, (string)$inReplaceTo );
 714+ $inStr = self::killMarkers( $parser, (string)$inStr );
 715+ $inReplaceFrom = self::killMarkers( $parser, (string)$inReplaceFrom );
 716+ $inReplaceTo = self::killMarkers( $parser, (string)$inReplaceTo );
699717
700 - if ( !$this->checkLength( $inStr ) ||
701 - !$this->checkLength( $inReplaceFrom ) ||
702 - !$this->checkLength( $inReplaceTo ) ) {
 718+ if ( !self::checkLength( $inStr ) ||
 719+ !self::checkLength( $inReplaceFrom ) ||
 720+ !self::checkLength( $inReplaceTo ) ) {
703721 wfProfileOut( __METHOD__ );
704 - return $this->tooLongError();
 722+ return self::tooLongError();
705723 }
706724
707725 if ( $inReplaceFrom == '' ) { $inReplaceFrom = ' '; }
@@ -725,9 +743,9 @@
726744 $result = preg_replace( '/' . $inReplaceFrom . '/u',
727745 $inReplaceTo, $inStr, $limit );
728746
729 - if ( !$this->checkLength( $result ) ) {
 747+ if ( !self::checkLength( $result ) ) {
730748 wfProfileOut( __METHOD__ );
731 - return $this->tooLongError();
 749+ return self::tooLongError();
732750 }
733751
734752 wfProfileOut( __METHOD__ );
@@ -745,18 +763,18 @@
746764 * Note: If the divider is an empty string, single space is used instead.
747765 * Note: Empty string is returned if there are not enough exploded chunks.
748766 */
749 - function runExplode ( $parser, $inStr = '', $inDiv = '', $inPos = 0, $inLim = null ) {
 767+ public static function runExplode ( $parser, $inStr = '', $inDiv = '', $inPos = 0, $inLim = null ) {
750768 wfProfileIn( __METHOD__ );
751769
752 - $inStr = $this->killMarkers( $parser, (string)$inStr );
753 - $inDiv = $this->killMarkers( $parser, (string)$inDiv );
 770+ $inStr = self::killMarkers( $parser, (string)$inStr );
 771+ $inDiv = self::killMarkers( $parser, (string)$inDiv );
754772
755773 if ( $inDiv == '' ) { $inDiv = ' '; }
756774
757 - if ( !$this->checkLength( $inStr ) ||
758 - !$this->checkLength( $inDiv ) ) {
 775+ if ( !self::checkLength( $inStr ) ||
 776+ !self::checkLength( $inDiv ) ) {
759777 wfProfileOut( __METHOD__ );
760 - return $this->tooLongError();
 778+ return self::tooLongError();
761779 }
762780
763781 $inDiv = preg_quote( $inDiv, '/' );
@@ -780,13 +798,13 @@
781799 *
782800 * Decodes URL-encoded (like%20that) strings.
783801 */
784 - function runUrlDecode( $parser, $inStr = '' ) {
 802+ public static function runUrlDecode( $parser, $inStr = '' ) {
785803 wfProfileIn( __METHOD__ );
786804
787 - $inStr = $this->killMarkers( $parser, (string)$inStr );
788 - if ( !$this->checkLength( $inStr ) ) {
 805+ $inStr = self::killMarkers( $parser, (string)$inStr );
 806+ if ( !self::checkLength( $inStr ) ) {
789807 wfProfileOut( __METHOD__ );
790 - return $this->tooLongError();
 808+ return self::tooLongError();
791809 }
792810
793811 $result = urldecode( $inStr );
Index: trunk/extensions/ParserFunctions/ParserFunctions.php
@@ -30,7 +30,6 @@
3131 $wgPFEnableStringFunctions = false;
3232
3333 /** REGISTRATION */
34 -$wgExtensionFunctions[] = 'wfSetupParserFunctions';
3534 $wgExtensionCredits['parserhook'][] = array(
3635 'path' => __FILE__,
3736 'name' => 'ParserFunctions',
@@ -51,79 +50,46 @@
5251 $wgParserTestFiles[] = dirname( __FILE__ ) . "/stringFunctionTests.txt";
5352 $wgParserTestFiles[] = dirname( __FILE__ ) . "/convertTests.txt";
5453
55 -function wfSetupParserFunctions() {
56 - global $wgPFHookStub, $wgHooks;
 54+$wgHooks['ParserFirstCallInit'][] = 'wfRegisterParserFunctions';
5755
58 - $wgPFHookStub = new ParserFunctions_HookStub;
 56+function wfRegisterParserFunctions( $parser ) {
 57+ global $wgPFEnableStringFunctions;
5958
60 - $wgHooks['ParserFirstCallInit'][] = array( &$wgPFHookStub, 'registerParser' );
61 -
62 - $wgHooks['ParserClearState'][] = array( &$wgPFHookStub, 'clearState' );
63 -}
64 -
65 -/**
66 - * Stub class to defer loading of the bulk of the code until a parser function is
67 - * actually used.
68 - */
69 -class ParserFunctions_HookStub {
70 - var $realObj;
71 -
72 - function registerParser( $parser ) {
73 - global $wgPFEnableStringFunctions;
74 -
75 - if ( defined( get_class( $parser ) . '::SFH_OBJECT_ARGS' ) ) {
76 - // These functions accept DOM-style arguments
77 - $parser->setFunctionHook( 'if', array( &$this, 'ifObj' ), SFH_OBJECT_ARGS );
78 - $parser->setFunctionHook( 'ifeq', array( &$this, 'ifeqObj' ), SFH_OBJECT_ARGS );
79 - $parser->setFunctionHook( 'switch', array( &$this, 'switchObj' ), SFH_OBJECT_ARGS );
80 - $parser->setFunctionHook( 'ifexist', array( &$this, 'ifexistObj' ), SFH_OBJECT_ARGS );
81 - $parser->setFunctionHook( 'ifexpr', array( &$this, 'ifexprObj' ), SFH_OBJECT_ARGS );
82 - $parser->setFunctionHook( 'iferror', array( &$this, 'iferrorObj' ), SFH_OBJECT_ARGS );
83 - } else {
84 - $parser->setFunctionHook( 'if', array( &$this, 'ifHook' ) );
85 - $parser->setFunctionHook( 'ifeq', array( &$this, 'ifeq' ) );
86 - $parser->setFunctionHook( 'switch', array( &$this, 'switchHook' ) );
87 - $parser->setFunctionHook( 'ifexist', array( &$this, 'ifexist' ) );
88 - $parser->setFunctionHook( 'ifexpr', array( &$this, 'ifexpr' ) );
89 - $parser->setFunctionHook( 'iferror', array( &$this, 'iferror' ) );
90 - }
91 -
92 - $parser->setFunctionHook( 'expr', array( &$this, 'expr' ) );
93 - $parser->setFunctionHook( 'time', array( &$this, 'time' ) );
94 - $parser->setFunctionHook( 'timel', array( &$this, 'localTime' ) );
95 - $parser->setFunctionHook( 'rel2abs', array( &$this, 'rel2abs' ) );
96 - $parser->setFunctionHook( 'titleparts', array( &$this, 'titleparts' ) );
97 - $parser->setFunctionHook( 'convert', array( &$this, 'convert' ) );
98 -
99 - // String Functions
100 - if ( $wgPFEnableStringFunctions ) {
101 - $parser->setFunctionHook( 'len', array( &$this, 'runLen' ) );
102 - $parser->setFunctionHook( 'pos', array( &$this, 'runPos' ) );
103 - $parser->setFunctionHook( 'rpos', array( &$this, 'runRPos' ) );
104 - $parser->setFunctionHook( 'sub', array( &$this, 'runSub' ) );
105 - $parser->setFunctionHook( 'count', array( &$this, 'runCount' ) );
106 - $parser->setFunctionHook( 'replace', array( &$this, 'runReplace' ) );
107 - $parser->setFunctionHook( 'explode', array( &$this, 'runExplode' ) );
108 - $parser->setFunctionHook( 'urldecode', array( &$this, 'runUrlDecode' ) );
109 - }
110 -
111 - return true;
 59+ if ( defined( get_class( $parser ) . '::SFH_OBJECT_ARGS' ) ) {
 60+ // These functions accept DOM-style arguments
 61+ $parser->setFunctionHook( 'if', 'ExtParserFunctions::ifObj', SFH_OBJECT_ARGS );
 62+ $parser->setFunctionHook( 'ifeq', 'ExtParserFunctions::ifeqObj', SFH_OBJECT_ARGS );
 63+ $parser->setFunctionHook( 'switch', 'ExtParserFunctions::switchObj', SFH_OBJECT_ARGS );
 64+ $parser->setFunctionHook( 'ifexist', 'ExtParserFunctions::ifexistObj', SFH_OBJECT_ARGS );
 65+ $parser->setFunctionHook( 'ifexpr', 'ExtParserFunctions::ifexprObj', SFH_OBJECT_ARGS );
 66+ $parser->setFunctionHook( 'iferror', 'ExtParserFunctions::iferrorObj', SFH_OBJECT_ARGS );
 67+ } else {
 68+ $parser->setFunctionHook( 'if', 'ExtParserFunctions::ifHook' );
 69+ $parser->setFunctionHook( 'ifeq', 'ExtParserFunctions::ifeq' );
 70+ $parser->setFunctionHook( 'switch', 'ExtParserFunctions::switchHook' );
 71+ $parser->setFunctionHook( 'ifexist', 'ExtParserFunctions::ifexist' );
 72+ $parser->setFunctionHook( 'ifexpr', 'ExtParserFunctions::ifexpr' );
 73+ $parser->setFunctionHook( 'iferror', 'ExtParserFunctions::iferror' );
11274 }
11375
114 - /** Defer ParserClearState */
115 - function clearState( $parser ) {
116 - if ( !is_null( $this->realObj ) ) {
117 - $this->realObj->clearState( $parser );
118 - }
119 - return true;
120 - }
 76+ $parser->setFunctionHook( 'expr', 'ExtParserFunctions::expr' );
 77+ $parser->setFunctionHook( 'time', 'ExtParserFunctions::time' );
 78+ $parser->setFunctionHook( 'timel', 'ExtParserFunctions::localTime' );
 79+ $parser->setFunctionHook( 'rel2abs', 'ExtParserFunctions::rel2abs' );
 80+ $parser->setFunctionHook( 'titleparts', 'ExtParserFunctions::titleparts' );
 81+ $parser->setFunctionHook( 'convert', 'ExtParserFunctions::convert' );
12182
122 - /** Pass through function call */
123 - function __call( $name, $args ) {
124 - if ( is_null( $this->realObj ) ) {
125 - $this->realObj = new ExtParserFunctions;
126 - $this->realObj->clearState( $args[0] );
127 - }
128 - return call_user_func_array( array( $this->realObj, $name ), $args );
 83+ // String Functions
 84+ if ( $wgPFEnableStringFunctions ) {
 85+ $parser->setFunctionHook( 'len', 'ExtParserFunctions::runLen' );
 86+ $parser->setFunctionHook( 'pos', 'ExtParserFunctions::runPos' );
 87+ $parser->setFunctionHook( 'rpos', 'ExtParserFunctions::runRPos' );
 88+ $parser->setFunctionHook( 'sub', 'ExtParserFunctions::runSub' );
 89+ $parser->setFunctionHook( 'count', 'ExtParserFunctions::runCount' );
 90+ $parser->setFunctionHook( 'replace', 'ExtParserFunctions::runReplace' );
 91+ $parser->setFunctionHook( 'explode', 'ExtParserFunctions::runExplode' );
 92+ $parser->setFunctionHook( 'urldecode', 'ExtParserFunctions::runUrlDecode' );
12993 }
 94+
 95+ return true;
13096 }

Sign-offs

UserFlagDate
Tim Starlinginspected07:17, 5 September 2011

Follow-up revisions

RevisionCommit summaryAuthorDate
r85948Made checkLength static to fix many STRICT errorsreedy14:17, 13 April 2011

Comments

#Comment by Reedy (talk | contribs)   14:19, 13 April 2011

Please make sure you enable the PHP STRICT stuff when testing stuff.

You caused a STRICT warning/error which was fixed in r85948

See Manual:How_to_debug

error_reporting(E_ALL | E_STRICT);
ini_set("display_errors", 1);

Thanks!

#Comment by P.Copp (talk | contribs)   15:08, 13 April 2011

No idea how I missed that one. Anyway, thanks for the fix!

Status & tagging log