Page MenuHomePhabricator

Web updater throws exceptions if installed extensions are using explicit globals ($GLOBALS['wgHooks']) for hooks like 'ParserFirstCallInit'
Closed, DeclinedPublic

Description

When you go to the web installer of an existing wiki which has Babel extension enabled, after setting the installation language, it throws an exception.

This happens on current master with Extension:Babel, also tested on MediaWiki 1.23. I'm not sure if the problem is with Babel extension or with the installer, although I also have ParserFunctions installed and they don't throw that error.

[edddcc91] /mw-config/?page=ExistingWiki Exception from line 341 of /home/jesus/git/mediawiki/core/includes/MagicWord.php: Error: invalid magic word 'babel'

Backtrace:

#0 /home/jesus/git/mediawiki/core/includes/MagicWord.php(264): MagicWord->load(string)
#1 /home/jesus/git/mediawiki/core/includes/parser/Parser.php(5121): MagicWord::get(string)
#2 /home/www/lib/mediawiki-git/extensions/Babel/BabelStatic.class.php(22): Parser->setFunctionHook(string, array)
#3 [internal function]: BabelStatic::onParserFirstCallInit(Parser)
#4 /home/jesus/git/mediawiki/core/includes/Hooks.php(206): call_user_func_array(string, array)
#5 /home/jesus/git/mediawiki/core/includes/GlobalFunctions.php(4042): Hooks::run(string, array, NULL)
#6 /home/jesus/git/mediawiki/core/includes/parser/Parser.php(279): wfRunHooks(string, array)
#7 /home/jesus/git/mediawiki/core/includes/parser/Parser.php(291): Parser->firstCallInit()
#8 /home/jesus/git/mediawiki/core/includes/parser/Parser.php(4962): Parser->clearState()
#9 /home/jesus/git/mediawiki/core/includes/parser/Parser.php(377): Parser->startParse(Title, ParserOptions, integer, boolean)
#10 /home/jesus/git/mediawiki/core/includes/installer/Installer.php(596): Parser->parse(string, Title, ParserOptions, boolean)
#11 /home/jesus/git/mediawiki/core/includes/installer/WebInstaller.php(676): Installer->parse(string, boolean)
#12 /home/jesus/git/mediawiki/core/includes/installer/WebInstallerPage.php(391): WebInstaller->getInfoBox(string)
#13 /home/jesus/git/mediawiki/core/includes/installer/WebInstallerPage.php(379): WebInstallerExistingWiki->showKeyForm()
#14 /home/jesus/git/mediawiki/core/includes/installer/WebInstaller.php(280): WebInstallerExistingWiki->execute()
#15 /home/jesus/git/mediawiki/core/mw-config/index.php(79): WebInstaller->execute(array)
#16 /home/jesus/git/mediawiki/core/mw-config/index.php(38): wfInstallerMain()
#17 {main}


Version: master
Severity: normal

Details

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 22 2014, 3:39 AM
bzimport set Reference to bz67877.
bzimport added a subscriber: Unknown Object (MLST).

This error is still current as of MediaWiki 1.25. I've added a warning at the top of Extension:Babel telling people to disable this extension when using the web updater. This doesn't happen when using the update.php maintenance script.

I think the web updater is loading part of this extension on the parser, but not all what's needed. causing this problem. That, or Babel is loading itself when that's not needed.

Ciencia_Al_Poder set Security to None.
Ciencia_Al_Poder removed a subscriber: Unknown Object (MLST).

This is happening also for CreatePage extension:

´´´
[84ac3d71] /mw-config/?page=ExistingWiki MWException from line 337 of /home/www/lib/mediawiki-1.25.1/includes/MagicWord.php: Error: invalid magic word 'createpage'

Backtrace:

#0 /home/www/lib/mediawiki-1.25.1/includes/MagicWord.php(262): MagicWord->load(string)
#1 /home/www/lib/mediawiki-1.25.1/includes/parser/Parser.php(5182): MagicWord::get(string)
#2 /home/www/lib/mediawiki-1.25.1/extensions/CreatePage/CreatePage.php(112): Parser->setFunctionHook(string, Closure, integer)
#3 [internal function]: Installer::{closure}(Parser)
#4 /home/www/lib/mediawiki-1.25.1/includes/Hooks.php(209): call_user_func_array(Closure, array)
#5 /home/www/lib/mediawiki-1.25.1/includes/parser/Parser.php(310): Hooks::run(string, array)
#6 /home/www/lib/mediawiki-1.25.1/includes/parser/Parser.php(320): Parser->firstCallInit()
#7 /home/www/lib/mediawiki-1.25.1/includes/parser/Parser.php(5025): Parser->clearState()
#8 /home/www/lib/mediawiki-1.25.1/includes/parser/Parser.php(405): Parser->startParse(Title, ParserOptions, integer, boolean)
#9 /home/www/lib/mediawiki-1.25.1/includes/installer/Installer.php(630): Parser->parse(string, Title, ParserOptions, boolean)
#10 /home/www/lib/mediawiki-1.25.1/includes/installer/WebInstaller.php(676): Installer->parse(string, boolean)
#11 /home/www/lib/mediawiki-1.25.1/includes/installer/WebInstallerPage.php(392): WebInstaller->getInfoBox(string)
#12 /home/www/lib/mediawiki-1.25.1/includes/installer/WebInstallerPage.php(380): WebInstallerExistingWiki->showKeyForm()
#13 /home/www/lib/mediawiki-1.25.1/includes/installer/WebInstaller.php(280): WebInstallerExistingWiki->execute()
#14 /home/www/lib/mediawiki-1.25.1/mw-config/index.php(77): WebInstaller->execute(array)
#15 /home/www/lib/mediawiki-1.25.1/mw-config/index.php(36): wfInstallerMain()
#16 {main}
´´´

The problem seems to be the ParserFirstCallInit hook. If I comment out the registration of that hook in the extension, it doesn't crash

The problem seems to be the ParserFirstCallInit hook. If I comment out the registration of that hook in the extension, it doesn't crash

Does it happen without ParserFunctions? Do we have idea if anyone else is experiencing the same problem?

The problem seems to be the ParserFirstCallInit hook. If I comment out the registration of that hook in the extension, it doesn't crash

Does it happen without ParserFunctions? Do we have idea if anyone else is experiencing the same problem?

Well, this issue seems rather common.

A fresh example: Bug in MediaWiki Language Extension Bundle

This is because Babel, CreatePage and others are using explicit global variables and not implicit ones that the installer depends upon. The installer tries to read extension entry points to get schema updates (which is also broken due to explicit globals), but the explicit globals register hooks which should not be registered.

Only Translate Extension than MediaWiki Language Extension Bundle need update table so me disable Babel,cldr,CleanChanges,LocalisationUpdate,UniversalLanguageSelector and only add require_once "$EXT/Translate/Translate.php"; in LocalSettings.php in end go to /mw-config but this error see:

[60961cae] /mediawiki/mw-config/?page=ExistingWiki MWException from line 337 of /home/...../domains/wikimech.org/public_html/mediawiki/includes/MagicWord.php: Error: invalid magic word 'translation'
Backtrace:
#0 /home/...../domains/wikimech.org/public_html/mediawiki/includes/MagicWord.php(262): MagicWord->load(string)
#1 /home/...../domains/wikimech.org/public_html/mediawiki/includes/parser/Parser.php(5182): MagicWord::get(string)
#2 /home/...../domains/wikimech.org/public_html/mediawiki/extensions/Translate/TranslateHooks.php(656): Parser->setFunctionHook(string, string)
#3 [internal function]: TranslateHooks::setupTranslateParserFunction(Parser)
#4 /home/...../domains/wikimech.org/public_html/mediawiki/includes/Hooks.php(209): call_user_func_array(string, array)
#5 /home/...../domains/wikimech.org/public_html/mediawiki/includes/parser/Parser.php(310): Hooks::run(string, array)
#6 /home/...../domains/wikimech.org/public_html/mediawiki/includes/parser/Parser.php(320): Parser->firstCallInit()
#7 /home/...../domains/wikimech.org/public_html/mediawiki/includes/parser/Parser.php(5025): Parser->clearState()
#8 /home/...../domains/wikimech.org/public_html/mediawiki/includes/parser/Parser.php(405): Parser->startParse(Title, ParserOptions, integer, boolean)
#9 /home/...../domains/wikimech.org/public_html/mediawiki/includes/installer/Installer.php(630): Parser->parse(string, Title, ParserOptions, boolean)
#10 /home/...../domains/wikimech.org/public_html/mediawiki/includes/installer/WebInstaller.php(676): Installer->parse(string, boolean)
#11 /home/...../domains/wikimech.org/public_html/mediawiki/includes/installer/WebInstallerPage.php(392): WebInstaller->getInfoBox(string)
#12 /home/...../domains/wikimech.org/public_html/mediawiki/includes/installer/WebInstallerPage.php(380): WebInstallerExistingWiki->showKeyForm()
#13 /home/...../domains/wikimech.org/public_html/mediawiki/includes/installer/WebInstaller.php(280): WebInstallerExistingWiki->execute()
#14 /home/...../domains/wikimech.org/public_html/mediawiki/mw-config/index.php(77): WebInstaller->execute(array)
#15 /home/...../domains/wikimech.org/public_html/mediawiki/mw-config/index.php(36): wfInstallerMain()

Help Help Help

Nemo_bis raised the priority of this task from Medium to High.Jun 13 2015, 11:26 PM

This is because Babel, CreatePage and others are using explicit global variables and not implicit ones that the installer depends upon. The installer tries to read extension entry points to get schema updates (which is also broken due to explicit globals), but the explicit globals register hooks which should not be registered.

Will extension.json when added take a precedence? The explicit globals are for composer support. Maybe skipping most of the registration if MW_INSTALLER is defined, is there such a thing?

Another instance, this time for MediaWiki-extensions-Validator

https://www.mediawiki.org/wiki/Thread:Project:Support_desk/Upgrading

[3b19e340] /mw-config/ Exception from line 318 of /home/trouse/domains/..../public_html/wiki/includes/MagicWord.php: Error: invalid magic word 'listerrors'

Backtrace:

0 /home/trouse/domains/..../public_html/wiki/includes/MagicWord.php(241): MagicWord->load(string)
1 /home/trouse/domains/..../public_html/wiki/includes/parser/Parser.php(4984): MagicWord::get(string)
2 /home/trouse/domains/..../public_html/wiki/extensions/Validator/src/legacy/ParserHook.php(208): Parser->setFunctionHook(string, array, integer)
3 /home/trouse/domains/..../public_html/wiki/extensions/Validator/src/legacy/ListErrors.php(37): ParserHook->init(Parser)
4 [internal function]: ValidatorListErrors::staticInit(Parser)
5 /home/trouse/domains/..../public_html/wiki/includes/Hooks.php(206): call_user_func_array(string, array)
6 /home/trouse/domains/..../public_html/wiki/includes/GlobalFunctions.php(4013): Hooks::run(string, array, NULL)
7 /home/trouse/domains/..../public_html/wiki/includes/parser/Parser.php(275): wfRunHooks(string, array)
8 /home/trouse/domains/..../public_html/wiki/includes/parser/Parser.php(287): Parser->firstCallInit()
9 /home/trouse/domains/..../public_html/wiki/includes/parser/Parser.php(4825): Parser->clearState()
10 /home/trouse/domains/..../public_html/wiki/includes/parser/Parser.php(367): Parser->startParse(Title, ParserOptions, integer, boolean)
11 /home/trouse/domains/..../public_html/wiki/includes/installer/Installer.php(612): Parser->parse(string, Title, ParserOptions, boolean)
12 /home/trouse/domains/..../public_html/wiki/includes/installer/WebInstaller.php(681): Installer->parse(string, boolean)
13 /home/trouse/domains/..../public_html/wiki/includes/installer/WebInstallerPage.php(391): WebInstaller->getInfoBox(string)
14 /home/trouse/domains/..../public_html/wiki/includes/installer/WebInstallerPage.php(379): WebInstaller_ExistingWiki->showKeyForm()
15 /home/trouse/domains/..../public_html/wiki/includes/installer/WebInstaller.php(283): WebInstaller_ExistingWiki->execute()
16 /home/trouse/domains/..../public_html/wiki/mw-config/index.php(63): WebInstaller->execute(array)
17 /home/trouse/domains/..../public_html/wiki/mw-config/index.php(31): wfInstallerMain()
18 {main}

Will extension.json when added take a precedence? The explicit globals are for composer support. Maybe skipping most of the registration if MW_INSTALLER is defined, is there such a thing?

It uses whatever is in LocalSettings, so if wfLoadExtension() is being used, then extension.json will be read from. Otherwise it'll use the PHP file.

There is a MEDIAWIKI_INSTALL constant, but that seems like a hack.

Legoktm renamed this task from Installer: MagicWord.php: Error: invalid magic word 'babel' when upgrading an existing wiki to Web updater throws exceptions if installed extensions are using explicit globals ($GLOBALS['wgHooks']) for hooks like 'ParserFirstCallInit'.Sep 3 2015, 7:04 PM
Legoktm added subscribers: Paladox, MarkAHershberger.

For what it is word I am removing $GLOBALS from the setup file of my extensions and stopping using composer autoloading.

Currently $GLOBALS is not support in the web updater but I have a patch for that fixes it and allows to use both $GLOBALS and non $GLOBALS by doing $example or $prefixexample and you can use extension registration. But extension registration is fixed and support web updater but not everything yet I doint think.

Change 227238 had a related patch set uploaded (by Paladox):
Fix using $GLOBALS in database updater

https://gerrit.wikimedia.org/r/227238

Can someone explain in user talk how to solve this? I'm trying to install MLEB using this
https://www.mediawiki.org/wiki/MediaWiki_Language_Extension_Bundle#Installation
Guide and getting the same error.
We are using mediawiki as an information system but I'm not really familiar with its intrinsics nor do I want to be :)
I've tried running some scripts, namely

maintenance/update.php
maintenance/rebuildLocalisationCache.php --force

But that yielded nothing unfortunately :(

Due to $GLOBALS not being supported yet in the web updater and has never been supported in the web updater there is currently a patch that fixes the problem. please try the patch with mediawiki 1.25 or 1.26 alpha. or just take out $GLOBALS and replace it with $ so it it would be $wg not $GLOBALS['wg'] but that would be editing the main php file for that extension which is not recommended since if you update your extension you will loose the changes. but testing with that patch should help fix and give feedback that it works.

Please test this patch https://gerrit.wikimedia.org/r/#/c/227238/

Okay thanks, will try to do that. But how can I download the patch as a set of files? Unfortunately, our wikimedia is not a git clone from the main wikimedia repository so I cannot git pull in the patch?

Hi heres link https://git.wikimedia.org/tree/mediawiki%2Fcore/a2880f534f01a2b35aaa989259d66320a787f0d6 where you can download it. you can download zip or gz file. or if you look at the diff of file and go into your file in the same file as that one and go to line and copying what it shows in the diff.

Thanks. It did not work unfortunately, our mediawiki was not up to date so the line numbers differed. However I was able to find the same piece of code and I added the green lines (those that were added in the patch). I restarted the mediawiki web installer but I got the same error.

Our wikimedia version is 1.24.1.
Under Installed extensions it does list all the extensions installed by MLEB... weird?

Hi try please try updating to mediawiki 1.25 and see if that fixes the problem please. please make a backup before you do including a backup of the database.

After spending more then half the day updating mediawiki (!) I'm getting exactly the same error:

[3bc6d419] /mw-config/?page=ExistingWiki MWException from line 337 of /var/www/vhosts/wiki.vastgoedmaps.nl/httpdocs/mediawiki-1.25.2/includes/MagicWord.php: Error: invalid magic word 'babel'

Will now try the patch....

After applying the 4 changed lines manually, still the same error:

[208d8937] /mw-config/?page=ExistingWiki MWException from line 337 of /var/www/vhosts/wiki.vastgoedmaps.nl/httpdocs/mediawiki-1.25.2/includes/MagicWord.php: Error: invalid magic word 'babel'

Rebuilding the localisation cache now to see if that makes any difference, but it doesn't seem related at all. Will uncomment the babel extension in LocalSettings.php after and retry...

Both rebuilding the cache and excluding only the require_once line for Babel did not work...

I've commented them before running the webinstaller, then continued, uncommented the require_once lines and everything 'seems' to work. Still very confusing to get this message.

Ok thanks hope the patch fixes the problem. Could you report back saying if it did pass or didn't so that the patch can move along and probably get reviewed sooner if it works and fixes the problem here.

Maybe extension.json may help fix the problem.

I could probably do the extension.json conversion now and get you to try it since it may fix the problem since it wont use $GLOBALS instead it will use code that is in the core of mediawiki to get the configs.

It will be just a few mins to convert it then I have to sort out which bits go where.

Yeah that would be great!
The Translate extension from the MLEB extension bundle is working, I can translate pages, however when I switch from Dutch to English for example, the translations do not show up. I'm not getting errors either... weird.

Hmm, the translations ARE done correctly. However, the language chooser doesn't change the current page to the language that is selected. I added
<languages /> to the top of the dutch original page. Now I see that I can select English at the top of the page. When I click that, the page is translated to English using my previously given translations. However, switching to the English language does not automatically 'switch' to the english version of the page. Is this intended behaviour? because, that seems like a bad default (as opposed to the mantra of 'good defaults'). Ah well, this is already a lot better then it used to be..

Hi please try this patch https://gerrit.wikimedia.org/r/#/c/213300/ or to download it in full please go to https://git.wikimedia.org/tree/mediawiki%2Fextensions%2FBabel/8d0ec6e1c9b2254f874f8c370e7d981a92f15ee0 and please report back and tell us if it fixes the problem please.

Oh never mind! the 'available translations' bar DOES show up when I switch to English. So the only question that remains is, why doesn't the mediawiki switch to the available English translated version by default?

The patch I describe above should work In the web updater. and should work in MW 1.25+.

michahell, this report is not a suitable venue to discuss Translate functionality. I'll reply on https://www.mediawiki.org/wiki/User_talk:Michael_Trouw

Translate is no longer using $GLOBALS so I removed it from the tags. Expected to be released in MLEB 2015.10.

Does translate still support composer since it doesn't use $GLOBALS any more. If so composer should be kept as it is and convert to using extension.jspn and keeping the main php as back compat.

Translate is still installable via composer. It just wont automatically load for MediaWiki.

If the extension uses the extension.json file the web updater will work for it.

The linked patch doesn't address this bug, and I remain unconvinced that this should be fixed based on the ugliness/hackiness of the code, and when migrating to extension.json will resolve the issue. or doing what Translate does and not autoload via composer.

This has also been an issue for a pretty long time, so I don't think it should block 1.26.

Change 227238 abandoned by Paladox:
Fix using $GLOBALS in database updater

https://gerrit.wikimedia.org/r/227238

At this point this is not really an issue in practice given that most extensions have moved to extension.json, or no longer autoload entry points in composer.json, so using an explicit $GLOBALS isn't needed.