r81816 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r81815‎ | r81816 | r81817 >
Date:15:19, 9 February 2011
Author:ialex
Status:ok (Comments)
Tags:
Comment:
* Add a amtitle param to meta=allmessages

Only used used when amenableparser is passed; the user can now define the page used for {{PAGENAME}} and related stuff instead of being hardcoded to "API"
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/Message.php (modified) (history)
  • /trunk/phase3/includes/MessageCache.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryAllmessages.php (modified) (history)
  • /trunk/phase3/includes/parser/Parser.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/parser/Parser.php
@@ -4269,10 +4269,10 @@
42704270 *
42714271 * @param $text String: the text to preprocess
42724272 * @param $options ParserOptions: options
 4273+ * @param $title Title object or null to use $wgTitle
42734274 * @return String
42744275 */
4275 - public function transformMsg( $text, $options ) {
4276 - global $wgTitle;
 4276+ public function transformMsg( $text, $options, $title = null ) {
42774277 static $executing = false;
42784278
42794279 # Guard against infinite recursion
@@ -4282,8 +4282,11 @@
42834283 $executing = true;
42844284
42854285 wfProfileIn( __METHOD__ );
4286 - $title = $wgTitle;
42874286 if ( !$title ) {
 4287+ global $wgTitle;
 4288+ $title = $wgTitle;
 4289+ }
 4290+ if ( !$title ) {
42884291 # It's not uncommon having a null $wgTitle in scripts. See r80898
42894292 # Create a ghost title in such case
42904293 $title = Title::newFromText( 'Dwimmerlaik' );
Index: trunk/phase3/includes/MessageCache.php
@@ -729,7 +729,7 @@
730730 return $message;
731731 }
732732
733 - function transform( $message, $interface = false, $language = null ) {
 733+ function transform( $message, $interface = false, $language = null, $title = null ) {
734734 // Avoid creating parser if nothing to transform
735735 if( strpos( $message, '{{' ) === false ) {
736736 return $message;
@@ -754,7 +754,7 @@
755755 $popts->setInterfaceMessage( $interface );
756756 $popts->setTargetLanguage( $language );
757757 $popts->setUserLang( $language );
758 - $message = $this->mParser->transformMsg( $message, $popts );
 758+ $message = $this->mParser->transformMsg( $message, $popts, $title );
759759 }
760760 return $message;
761761 }
Index: trunk/phase3/includes/api/ApiQueryAllmessages.php
@@ -50,6 +50,17 @@
5151 $langObj = Language::factory( $params['lang'] );
5252 }
5353
 54+ if ( $params['enableparser'] ) {
 55+ if ( !is_null( $params['title'] ) ) {
 56+ $title = Title::newFromText( $params['title'] );
 57+ if ( !$title ) {
 58+ $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) );
 59+ }
 60+ } else {
 61+ $title = Title::newFromText( 'API' );
 62+ }
 63+ }
 64+
5465 $prop = array_flip( (array)$params['prop'] );
5566
5667 // Determine which messages should we print
@@ -101,7 +112,7 @@
102113 } else {
103114 // Check if the parser is enabled:
104115 if ( $params['enableparser'] ) {
105 - $msgString = $msg->text();
 116+ $msgString = $msg->title( $title )->text();
106117 } else {
107118 $msgString = $msg->plain();
108119 }
@@ -158,6 +169,7 @@
159170 'lang' => null,
160171 'from' => null,
161172 'to' => null,
 173+ 'title' => null,
162174 );
163175 }
164176
@@ -167,6 +179,7 @@
168180 'prop' => 'Which properties to get',
169181 'enableparser' => array( 'Set to enable parser, will preprocess the wikitext of message',
170182 'Will substitute magic words, handle templates etc.' ),
 183+ 'title' => 'Page name to use as context when parsing message (for enableparser option)',
171184 'args' => 'Arguments to be substituted into message',
172185 'filter' => 'Return only messages that contain this string',
173186 'lang' => 'Return messages in this language',
Index: trunk/phase3/includes/Message.php
@@ -95,6 +95,11 @@
9696 protected $useDatabase = true;
9797
9898 /**
 99+ * Title object to use as context
 100+ */
 101+ protected $title = null;
 102+
 103+ /**
99104 * Constructor.
100105 * @param $key: message key, or array of message keys to try and use the first non-empty message for
101106 * @param $params Array message parameters
@@ -239,6 +244,17 @@
240245 }
241246
242247 /**
 248+ * Set the Title object to use as context when transforming the message
 249+ *
 250+ * @param $title Title object
 251+ * @return Message: $this
 252+ */
 253+ public function title( $title ) {
 254+ $this->title = $title;
 255+ return $this;
 256+ }
 257+
 258+ /**
243259 * Returns the message parsed from wikitext to HTML.
244260 * TODO: in PHP >= 5.2.0, we can make this a magic method,
245261 * and then we can do, eg:
@@ -395,7 +411,7 @@
396412 * @return Wikitext with {{-constructs replaced with their values.
397413 */
398414 protected function transformText( $string ) {
399 - return MessageCache::singleton()->transform( $string, $this->interface, $this->language );
 415+ return MessageCache::singleton()->transform( $string, $this->interface, $this->language, $this->title );
400416 }
401417
402418 /**
Index: trunk/phase3/RELEASE-NOTES
@@ -163,6 +163,7 @@
164164 * Expose list of skins in meta=siteinfo
165165 * (bug 26548) Add iiurlparam param to query=imageinfo and query=stashimageinfo
166166 * (bug 27205) aiprop=metadata and aiprop=parsedcomment need help text
 167+* Add a amtitle param to meta=allmessages
167168
168169 === Languages updated in 1.18 ===
169170

Comments

#Comment by Platonides (talk | contribs)   15:17, 10 February 2011

Remove that $wgTitle from Parser and move the checking up to MessageCache.

#Comment by IAlex (talk | contribs)   15:45, 10 February 2011

Not a good idea, that function is called from various places:

./extensions/DynamicPageList/DPL.php:			$string = $parser->transformMsg( $string, $parserOptions );
./extensions/DynamicPageList/DPLMain.php:									$title = Title::newFromText( $localParser->transformMsg( $sPar, $pOptions ) );
./extensions/DynamicPageList/DPLMain.php:								$title = Title::newFromText( $localParser->transformMsg( $sParam, $pOptions ) );
./extensions/DynamicPageList/DPLMain.php:					$title = Title::newFromText( $localParser->transformMsg( $sArg, $pOptions ) );
./extensions/DynamicPageList/DPLMain.php:						$sNs = $localParser->transformMsg( $sParam, $pOptions );
./extensions/DynamicPageList/DPLMain.php:					$sNs = $localParser->transformMsg( $sArg, $pOptions );
./extensions/DynamicPageList/DPLMain.php:					$sTitleGE = str_replace( ' ', '_', $localParser->transformMsg( $sArg, $pOptions ) );
./extensions/DynamicPageList/DPLMain.php:					$sTitleLE = str_replace( ' ', '_', $localParser->transformMsg( $sArg, $pOptions ) );
./extensions/DynamicPageList/DPLMain.php:					$aTitleMatch = explode( '|', str_replace( ' ', '\_', $localParser->transformMsg( $sArg, $pOptions ) ) );
./extensions/DynamicPageList/DPLMain.php:					$aNotTitleMatch = explode( '|', str_replace( ' ', '_', $localParser->transformMsg( $sArg, $pOptions ) ) );
./extensions/GoogleNewsSitemap/GoogleNewsSitemap_body.php:		// $title = Title::newFromText( $parser->transformMsg( $category, $poptions ) );
./extensions/GoogleNewsSitemap/GoogleNewsSitemap_body.php:			$feed =  Title::newFromText( $parser->transformMsg( 'Published', $poptions ) );
./extensions/intersection/DynamicPageList.php:				$title = Title::newFromText( $parser->transformMsg($sArg, $poptions) );
./extensions/intersection/DynamicPageList.php:				$title = Title::newFromText( $parser->transformMsg($sArg, $poptions) );
./extensions/intersection/DynamicPageList.php:				$sGalleryCaption =  $parser->transformMsg( $sArg, $poptions );
./extensions/RdfRedland/test/includes/GlobalFunctions.php:			$message = $wgParser->transformMsg($message, $wgMessageCache->getParserOptions() );
./extensions/SemanticNotifyMe/includes/SMW_NotifyProcessor.php:		$rawquery = $parser->transformMsg( $rawquery, $parserOptions );
./extensions/SemanticNotifyMe/includes/SMW_NotifyProcessor.smw15.php:		$rawquery = $parser->transformMsg( $rawquery, $parserOptions );
./extensions/SocialProfile/UserStats/UserStatsClass.php:			$ctgTitle = Title::newFromText( $parser->transformMsg( trim( $ctg ), $wgOut->parserOptions() ) );
./extensions/SocialProfile/UserStats/UserStatsClass.php:		$ctgTitle = Title::newFromText( $parser->transformMsg( trim( $ctg ), $wgOut->parserOptions() ) );
./includes/MessageCache.php:			$message = $this->mParser->transformMsg( $message, $popts, $title );
./tests/parser/parserTest.inc:			$out = $parser->transformMsg( $input, $options );
./tests/phpunit/includes/ExtraParserTest.php:		$oldTitle = $wgTitle; $wgTitle = $title; # Used by transformMsg()
./tests/phpunit/includes/parser/NewParserTest.php:						$out = $parser->transformMsg( $input, $options );

Status & tagging log