Page MenuHomePhabricator

Classes like Parser should use $mTitle member rather than $wgTitle
Open, NormalPublic

Description

$this->mTitle has been introduced to Parser and EditPage quite some time ago, and most of its members use it. Some member functions insist on using $wgTitle, however, which is not only incorrect but breaks the API. I'm personally starting a crusade against $wgTitle in these two classes, but maybe others could start similar crusades against global variables in code segments they know well.


Version: 1.12.x
Severity: normal

Details

Reference
bz12710

Event Timeline

bzimport raised the priority of this task from to Normal.Nov 21 2014, 10:06 PM
bzimport added a project: MediaWiki-General.
bzimport set Reference to bz12710.
bzimport added a subscriber: Unknown Object (MLST).
Catrope created this task.Jan 20 2008, 6:52 PM

Parser only uses $wgTitle when the relevant entry point does not provide a title in a parameter.

For robustness, the API should set $wgTitle.

(In reply to comment #1)

Parser only uses $wgTitle when the relevant entry point does not provide a
title in a parameter.

I found one instance in which it didn't (see r29918), I don't know if there are more.

For robustness, the API should set $wgTitle.

True, but classes like Parser and EditPage should be usable on pages different from $wgTitle as well, and therefore shouldn't rely on it.

(In reply to comment #2)

(In reply to comment #1)

Parser only uses $wgTitle when the relevant entry point does not provide a
title in a parameter.

I found one instance in which it didn't (see r29918), I don't know if there are
more.

Found another one, see bug 16129 comment #3.

For robustness, the API should set $wgTitle.

True, but classes like Parser and EditPage should be usable on pages different
from $wgTitle as well, and therefore shouldn't rely on it.

Bumping this point.

Krinkle set Security to None.
Krinkle removed a subscriber: Unknown Object (MLST).
TTO added a subscriber: TTO.Jan 11 2016, 4:55 AM

https://gerrit.wikimedia.org/r/#/c/263030/ removes some of the last uses of $wgTitle in EditPage and Parser.

If that patch is merged, there will be no uses of $wgTitle left in EditPage, and only two particularly stubborn uses will remain in Parser (Parser::cleanSig when the second parameter is false, and Parser::extractSections when the title on the Parser object is not set).

Restricted Application added a subscriber: Aklapper. · View Herald TranscriptJan 11 2016, 4:55 AM
Catrope removed a subscriber: Catrope.Jan 15 2016, 11:00 PM
Legoktm renamed this task from Classes like Parser and EditPage should use $mTitle member rather than $wgTitle to Classes like Parser should use $mTitle member rather than $wgTitle.Sep 22 2017, 9:37 PM
Legoktm added a subscriber: Legoktm.
Krinkle added a subscriber: Krinkle.

Looks like a good chunk of this was phased out since, but some of the methods still use it:

Parser.php
class Parser {
	
	public function cleanSig( $text, $parsing = false ) {
		if ( !$parsing ) {
			global $wgTitle;
			$magicScopeVariable = $this->lock();
			$this->startParse( $wgTitle, new ParserOptions, self::OT_PREPROCESS, true );
		}
		
	}
	public function transformMsg( $text, $options, $title = null ) {
		
		if ( !$title ) {
			global $wgTitle;
			$title = $wgTitle;
		}
		
	}
	private function extractSections( $text, $sectionId, $mode, $newText = '' ) {
		global $wgTitle;
		
		$this->startParse( $wgTitle, new ParserOptions, self::OT_PLAIN, true );
		
	}

As of writing, none of these are deprecated.