r80828 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r80827‎ | r80828 | r80829 >
Date:18:45, 23 January 2011
Author:platonides
Status:ok (Comments)
Tags:
Comment:
Accept being passed a null Title to startExternalParse(), at the callers responsibility.
Added a note about getUserSig() side-effects.
Modified paths:
  • /trunk/phase3/includes/parser/Parser.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/parser/Parser.php
@@ -4125,6 +4125,9 @@
41264126 # Because mOutputType is OT_WIKI, this will only process {{subst:xxx}} type tags
41274127 $text = $this->replaceVariables( $text );
41284128
 4129+ # This works almost by chance, as the replaceVariables are done before the getUserSig(),
 4130+ # which may corrupt this parser instance via its wfMsgExt( parsemag ) call-
 4131+
41294132 # Signatures
41304133 $sigText = $this->getUserSig( $user );
41314134 $text = strtr( $text, array(
@@ -4170,6 +4173,8 @@
41714174 * validated, ready-to-insert wikitext.
41724175 * If you have pre-fetched the nickname or the fancySig option, you can
41734176 * specify them here to save a database query.
 4177+ * Do not reuse this parser instance after calling getUserSig(),
 4178+ * as it may have changed if it's the $wgParser.
41744179 *
41754180 * @param $user User
41764181 * @param $nickname String: nickname to use or false to use user's default nickname
@@ -4288,7 +4293,7 @@
42894294 * Set up some variables which are usually set up in parse()
42904295 * so that an external function can call some class members with confidence
42914296 */
4292 - public function startExternalParse( Title $title, ParserOptions $options, $outputType, $clearState = true ) {
 4297+ public function startExternalParse( Title $title = null, ParserOptions $options, $outputType, $clearState = true ) {
42934298 $this->setTitle( $title );
42944299 $this->mOptions = $options;
42954300 $this->setOutputType( $outputType );

Comments

#Comment by 😂 (talk | contribs)   21:32, 24 January 2011

You cannot have optional parameters before required ones.

#Comment by Platonides (talk | contribs)   21:54, 24 January 2011

That = null there is perfectly legal. It means that $title can be a Title object or NULL.

#Comment by 😂 (talk | contribs)   22:05, 24 January 2011

You mean you can't pass null when hinting Title?

#Comment by Platonides (talk | contribs)   23:03, 24 January 2011

Exactly. To be able to pass null you have to do "Title $var = null"

Status & tagging log