r109006 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r109005‎ | r109006 | r109007 >
Date:22:08, 15 January 2012
Author:ialex
Status:ok (Comments)
Tags:
Comment:
* Use Parser::recursivePreprocess() if available instead of calling transformMsg() on a new Parser instance
* Otherwise use Parser::preprocess() instead of Parser::transformMsg()
Modified paths:
  • /trunk/extensions/Video/VideoGalleryPopulate.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Video/VideoGalleryPopulate.php
@@ -13,14 +13,12 @@
1414
1515 $wgHooks['ParserFirstCallInit'][] = 'wfVideoGalleryPopulate';
1616
17 -function wfVideoGalleryPopulate( &$parser ) {
 17+function wfVideoGalleryPopulate( $parser ) {
1818 $parser->setHook( 'videogallerypopulate', 'VideoGalleryPopulate' );
1919 return true;
2020 }
2121
2222 function VideoGalleryPopulate( $input, $args, $parser ) {
23 - global $wgOut;
24 -
2523 $parser->disableCache();
2624
2725 $category = ( isset( $args['category'] ) ) ? $args['category'] : '';
@@ -30,9 +28,13 @@
3129 return '';
3230 }
3331
34 - // Why do we initialize a new instance of Parser here, I wonder?
35 - $parser = new Parser();
36 - $category = $parser->transformMsg( $category, $wgOut->parserOptions() );
 32+ // Use Parser::recursivePreprocess() if available instead of creating another Parser instance
 33+ if ( is_callable( array( $parser, 'recursivePreprocess' ) ) ) {
 34+ $category = $parser->recursivePreprocess( $category );
 35+ } else {
 36+ $newParser = new Parser();
 37+ $category = $newParser->preprocess( $category, $parser->getTitle(), $parser->getOptions() );
 38+ }
3739 $category_title = Title::newFromText( $category );
3840 if( !( $category_title instanceof Title ) ) {
3941 return '';
@@ -75,4 +77,4 @@
7678 }
7779
7880 return $gallery->toHtml();
79 -}
\ No newline at end of file
 81+}

Comments

#Comment by Nikerabbit (talk | contribs)   07:11, 16 January 2012

Ooh, just what I need for Translate too.

Status & tagging log