Last modified: 2014-07-01 20:23:54 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T25307, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 23307 - ($wgTitle) Send $wgTitle to the fiery pit from whence it came
Send $wgTitle to the fiery pit from whence it came
Status: NEW
Product: MediaWiki
Classification: Unclassified
General/Unknown (Other open bugs)
All All
: Low normal with 3 votes (vote)
: ---
Assigned To: Nobody - You can work on this!
Depends on: 12710 25393 57562
Blocks: code_quality global-vars
  Show dependency treegraph
Reported: 2010-04-24 14:10 UTC by Chad H.
Modified: 2014-07-01 20:23 UTC (History)
11 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Description Chad H. 2010-04-24 14:10:42 UTC
$wgTitle is by far the most evil global we have. It needs to go away. It constantly gets in the way of doing things properly, and people use it not knowing how bad it is.

Suggest we make killing this a higher priority for 1.17. Other globals are bad too, but this one is really really bad.
Comment 1 Sam Reed (reedy) 2010-04-24 22:15:39 UTC

172 usages in phase3 including comments? :(
Comment 2 tisane2718 2010-04-26 02:35:20 UTC
Before getting rid of $wgTitle, hooks such as AlternateEdit and ParserBeforeStrip should be modified to provide a $title parameter. The manual page on $wgTitle clearly warns about the problems with that global, but sometimes there's no alternative to using it, the way hooks are currently set up.
Comment 3 Roan Kattouw 2010-04-26 08:59:17 UTC
ParserBeforeStrip is passed a $parser parameter, so you can grab the title with $parser->getTitle() . Similarly, you can use $ep->getArticle()->getTitle() in AlternateEdit.
Comment 4 Sam Reed (reedy) 2010-04-26 19:49:55 UTC
Looks like from the API's pov, we can just nuke all the "usages" when they've been removed elsewhere etc.

We're just keeping some crappy compatibility by assigning wgTitle to the one we're currently abusing
Comment 5 Max Semenik 2010-05-29 09:44:26 UTC
The situation is even more grave than I thought, adding the following to parserTests.php indicates that even Parser is dependant on it:

class DummyTitle {
	public function __call( $name, $args ) {
		throw new MWException( "\$wgTitle::$name() called" );

$wgTitle = new DummyTitle()
Comment 6 Bryan Tong Minh 2010-11-06 14:23:51 UTC
I was looking into this, and it appears that the main culprit is wfMsgExt( $msg, 'parsemag' ), which calls MessageCache::transform and in turn Parser::transformMsg. The way to fix this is to pass a $title object along the entire wfMsg chain. 

I used the following code to find out what is calling $wgTitle:

class wgTitleStub extends StubObject {
	function __construct( $title ) {
		$this->title = $title;
		parent::__construct( 'wgTitle' );
	function _newObject() {
		return $this->title;
	function _unstub( $name = '_unstub', $level = 2 ) {
		parent::_unstub( $name, $level );

		$bt = array();
		foreach ( wfDebugBacktrace() as $line ) {
			if ( isset( $line['class'] ) ) {
				$bt[] = "{$line['class']}::{$line['function']}";
			} else {
				$bt[] = $line['function'];
		wfDebug('Full $wgTitle unstub backtrace: ' . implode( ', ', $bt ) . "\n" );

Then in Wiki::performRequestForTitle() remove the pass by reference from the function arguments and set $GLOBALS['wgTitle'] = new wgTitleStub( $title );
Comment 7 Antoine "hashar" Musso (WMF) 2010-11-06 14:24:55 UTC
changed bug title to be less offending.
Comment 8 Roan Kattouw 2010-11-06 15:26:12 UTC
(In reply to comment #7)
> changed bug title to be less offending.

$wgTitle deserves every bit of it, IMO :)
Comment 9 Chad H. 2012-01-04 23:43:29 UTC
(In reply to comment #8)
> (In reply to comment #7)
> > changed bug title to be less offending.
> $wgTitle deserves every bit of it, IMO :)

Adjusted again.
Comment 10 Sam Reed (reedy) 2012-01-05 00:06:50 UTC
116 usages in phase3...

Quite a few seem to be back compat setting a value, and/or documentation

LanguageConverter probably wants contextsourcing
Comment 11 Jesús Martínez Novo (Ciencia Al Poder) 2013-10-07 20:00:27 UTC
See bug 53498 comment 10 for a very nasty bug caused by the usage of $wgTitle in AbuseFilter code
Comment 12 Jesús Martínez Novo (Ciencia Al Poder) 2014-02-05 20:51:05 UTC
Chad is doing a good job in fixing some of them lately ;),n,z

Note You need to log in before you can comment on or make changes to this bug.