Page MenuHomePhabricator

Autoloader regression causes errors of "undefined function" after upgrading to 1.17
Closed, InvalidPublic


In my LocalSettings.php, I have the following line to modify $wgMWSuggestTemplate to increase the number of dropdown items:

$wgMWSuggestTemplate = SearchEngine::getMWSuggestTemplate() . '&limit=20';

This works perfectly in MediaWiki 1.16.4 and earlier. In 1.17.0, however, when I run maintenance/update.php, the above line causes this error to be thrown, aborting update.php:

PHP Fatal error: Call to undefined function wfScript()
in /.../includes/search/SearchEngine.php on line 457

Version: 1.17.x
Severity: normal



Event Timeline

bzimport raised the priority of this task from to Unbreak Now!.Nov 21 2014, 11:32 PM
bzimport added a project: MediaWiki-Search.
bzimport set Reference to bz29760.
bzimport added a subscriber: Unknown Object (MLST).

Line 457 in SearchEngine.php is:

return $wgServer . wfScript( 'api' ) . '?action=opensearch&search={searchTerms}&namespace={namespaces}&suggest';

Looks like the same error is thrown by the web site, not only when running update.php.

Adding this line to LocalSettings.php fixes the problem, but should it be necessary?

require_once( "includes/GlobalFunctions.php" );

Reedy added a comment.Jul 7 2011, 6:58 PM

It's a change in the order of the AutoLoader running, with respect to the settings also.

I'm not sure if this was was "supposed" to work, or was incidental

demon added a comment.Jul 8 2011, 7:39 PM

I believe it was an accident that it worked. Moving it to $wgExtensionFunctions should do the trick.

brion added a comment.Jul 8 2011, 8:31 PM

Never try to call MediaWiki active code from LocalSettings.php main area -- *all* MW functions and classes should be assumed unsafe to use.

If you need to call into MediaWiki *after* basic platform initialization, use $wgExtensionFunctions to add a callback that runs at that time.

Brion: even static methods are considered unsafe? They are by nature designed to be called without initialization from their class.

Reedy added a comment.Jul 8 2011, 8:58 PM

The classes aren't in scope (ie haven't been loaded) so aren't accessible

Thanks. After trial and error, I rewrote our code to set $wgMWSuggestTemplate via the hook "SetupAfterCache". This seems to be the only hook early enough to change $wgMWSuggestTemplate in time.

Restricted Application added a project: Discovery. · View Herald TranscriptJan 28 2016, 6:04 PM