Last modified: 2014-07-01 20:23:54 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.
Mmmm 172 usages in phase3 including comments? :(
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.
ParserBeforeStrip is passed a $parser parameter, so you can grab the title with $parser->getTitle() . Similarly, you can use $ep->getArticle()->getTitle() in AlternateEdit.
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
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()
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 );
changed bug title to be less offending.
(In reply to comment #7) > changed bug title to be less offending. $wgTitle deserves every bit of it, IMO :)
(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.
116 usages in phase3... Quite a few seem to be back compat setting a value, and/or documentation LanguageConverter probably wants contextsourcing
See bug 53498 comment 10 for a very nasty bug caused by the usage of $wgTitle in AbuseFilter code
Chad is doing a good job in fixing some of them lately ;) https://gerrit.wikimedia.org/r/#/q/status:open+topic:wgTitle-ugh,n,z