r84414 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r84413‎ | r84414 | r84415 >
Date:20:04, 20 March 2011
Author:ialex
Status:deferred
Tags:
Comment:
Use ParserFirstCallInit hook to register parser hooks and functions instead of extension functions
Modified paths:
  • /trunk/extensions/News/News.php (modified) (history)
  • /trunk/extensions/PageBy/PageBy.php (modified) (history)
  • /trunk/extensions/PageCSS/PageCSS.php (modified) (history)
  • /trunk/extensions/Player/Player.php (modified) (history)
  • /trunk/extensions/Plotters/Plotters.php (modified) (history)
  • /trunk/extensions/QPoll/qp_user.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Plotters/Plotters.php
@@ -33,8 +33,7 @@
3434 'url' => 'http://www.mediawiki.org/wiki/Extension:Plotters',
3535 );
3636
37 -$wgExtensionFunctions[] = "efPlotters";
38 -
 37+$wgHooks['ParserFirstCallInit'][] = 'efPlottersSetHooks';
3938 $wgHooks['OutputPageParserOutput'][] = 'PlottersParserOutput';
4039 if( version_compare( $wgVersion, '1.16alpha', '<' ) ) {
4140 $wgHooks['LanguageGetMagic'][] = 'PlottersLanguageGetMagic';
@@ -165,11 +164,10 @@
166165 }
167166 }
168167
169 -function efPlotters() {
170 - global $wgParser;
171 -
172 - $wgParser->setHook( 'plot', 'initPlotters' );
173 - $wgParser->setFunctionHook( 'plot', 'initPlottersPF' );
 168+function efPlottersSetHooks( $parser ) {
 169+ $parser->setHook( 'plot', 'initPlotters' );
 170+ $parser->setFunctionHook( 'plot', 'initPlottersPF' );
 171+ return true;
174172 }
175173
176174 function initPlottersPF( $parser ) {
Index: trunk/extensions/PageBy/PageBy.php
@@ -24,13 +24,13 @@
2525
2626 $dir = dirname(__FILE__) . '/';
2727 $wgExtensionMessagesFiles['PageBy'] = $dir . 'PageBy.i18n.php';
28 -$wgExtensionFunctions[] = "wfPageByExtension";
 28+$wgHooks['ParserFirstCallInit'][] = "wfPageBySetHooks";
2929
3030 $wgAutoloadClasses['PageByRenderer'] = $dir. 'PageByRenderer.php';
3131
32 -function wfPageByExtension() {
33 - global $wgParser;
34 - $wgParser->setHook( "pageby", "newsxRenderPageBy" );
 32+function wfPageBySetHooks( $parser ) {
 33+ $parser->setHook( 'pageby', 'newsxRenderPageBy' );
 34+ return true;
3535 }
3636
3737 function newsxRenderPageBy( $page, $argv, $parser ) {
Index: trunk/extensions/QPoll/qp_user.php
@@ -251,7 +251,7 @@
252252 /**
253253 * Register the extension with the WikiText parser.
254254 */
255 - static function onParserFirstCallInit() {
 255+ static function onParserFirstCallInit( $parser ) {
256256 global $wgOut, $wgTitle;
257257 if ( !is_object( $wgTitle ) || $wgTitle->getNamespace() === NS_SPECIAL ) {
258258 # special page will add it's proper module itself;
@@ -274,13 +274,12 @@
275275 $wgOut->addExtensionStyle( self::$ScriptPath . '/qp_user_rtl.css' );
276276 }
277277 }
278 - global $wgParser;
279278 global $wgQPollFunctionsHook;
280279 # setup tag hook
281 - $wgParser->setHook( 'qpoll', array( 'qp_Setup', 'renderPoll' ) );
 280+ $parser->setHook( 'qpoll', array( 'qp_Setup', 'renderPoll' ) );
282281 $wgQPollFunctionsHook = new qp_FunctionsHook();
283282 # setup function hook
284 - $wgParser->setFunctionHook( 'qpuserchoice', array( &$wgQPollFunctionsHook, 'qpuserchoice' ), SFH_OBJECT_ARGS );
 283+ $parser->setFunctionHook( 'qpuserchoice', array( &$wgQPollFunctionsHook, 'qpuserchoice' ), SFH_OBJECT_ARGS );
285284 return true;
286285 }
287286
Index: trunk/extensions/Player/Player.php
@@ -23,7 +23,7 @@
2424 'descriptionmsg' => 'player-desc',
2525 );
2626
27 -$wgExtensionFunctions[] = "playerSetup";
 27+$wgHooks['ParserFirstCallInit'][] = 'playerSetup';
2828 $wgHooks['OutputPageParserOutput'][] = 'playerParserOutput';
2929
3030 $dir = dirname(__FILE__) . '/';
@@ -44,10 +44,9 @@
4545
4646 require_once( dirname( __FILE__ ) . '/PlayerDefaultSettings.php' );
4747
48 -function playerSetup() {
49 - global $wgParser;
50 -
51 - $wgParser->setHook( "player", "renderPlayerTag" );
 48+function playerSetup( $parser ) {
 49+ $parser->setHook( 'player', 'renderPlayerTag' );
 50+ return true;
5251 }
5352
5453 function renderPlayerTag( $name, $args, &$parser ) {
@@ -123,7 +122,7 @@
124123 * Hook callback that injects messages and things into the <head> tag
125124 * Does nothing if $parserOutput->mPlayerTag is not set
126125 */
127 -function playerParserOutput( &$outputPage, &$parserOutput ) {
 126+function playerParserOutput( &$outputPage, $parserOutput ) {
128127 if ( !empty( $parserOutput->mPlayerTag ) ) {
129128 Player::setHeaders( $outputPage );
130129 }
Index: trunk/extensions/News/News.php
@@ -29,21 +29,20 @@
3030 $wgNewsFeedURLPattern = false; // pattern for feed-URLs; useful when using rewrites for canonical feed URLs
3131 $wgNewsFeedUserPattern = false; // pattern to use for the author-field in feed items.
3232
33 -$wgExtensionFunctions[] = "wfNewsExtension";
34 -
3533 $wgAutoloadClasses['NewsRenderer'] = dirname( __FILE__ ) . '/NewsRenderer.php';
3634 $wgAutoloadClasses['NewsFeedPage'] = dirname( __FILE__ ) . '/NewsRenderer.php';
3735 $wgHooks['ArticleFromTitle'][] = 'wfNewsArticleFromTitle';
3836 $wgHooks['SkinTemplateOutputPageBeforeExec'][] = 'wfNewsSkinTemplateOutputPageBeforeExec';
 37+$wgHooks['ParserFirstCallInit'][] = 'wfNewsSetHooks';
3938
4039 //FIXME: find a way to override the feed URLs generated by OutputPage::getHeadLinks
4140
42 -function wfNewsExtension() {
43 - global $wgParser;
44 - $wgParser->setHook( "news", "wfNewsTag" );
45 - $wgParser->setHook( "newsfeed", "wfNewsFeedTag" );
46 - $wgParser->setHook( "newsfeedlink", "wfNewsFeedLinkTag" );
47 - wfLoadExtensionMessages( 'NewsExtension' );
 41+function wfNewsSetHooks( $parser ) {
 42+ $parser->setHook( 'news', 'wfNewsTag' );
 43+ $parser->setHook( 'newsfeed', 'wfNewsFeedTag' );
 44+ $parser->setHook( 'newsfeedlink', 'wfNewsFeedLinkTag' );
 45+
 46+ return true;
4847 }
4948
5049 function wfNewsTag( $templatetext, $argv, $parser ) {
Index: trunk/extensions/PageCSS/PageCSS.php
@@ -11,7 +11,6 @@
1212 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
1313 */
1414
15 -$wgExtensionFunctions[] = array( 'CssHook', 'setup' );
1615 $wgExtensionCredits['parserhook'][] = array(
1716 'path' => __FILE__,
1817 'name' => 'Page CSS',
@@ -20,11 +19,13 @@
2120 'author' => 'Ævar Arnfjörð Bjarmason'
2221 );
2322
 23+$wgHooks['ParserFirstCallInit'][] = 'CssHook::setup';
 24+
2425 class CssHook {
2526
26 - public static function setup() {
27 - global $wgParser;
28 - $wgParser->setHook( 'css', array( 'CssHook', 'parse' ) );
 27+ public static function setup( $parser ) {
 28+ $parser->setHook( 'css', array( 'CssHook', 'parse' ) );
 29+ return true;
2930 }
3031
3132 public static function parse( $content, array $args, Parser $parser ) {

Status & tagging log