Page MenuHomePhabricator

Moving Pages in PHP 4.1.2 gives fatal error
Closed, ResolvedPublic

Description

Author: nickpj

Description:
Setup:
Debian Woody r3.0 (a.k.a. "Brion's mortal enemy") running PHP 4.1.2 with
MediaWiki 1.5.0

Background:
Trying to modify MediaWiki to make it suitable for use for running my personal
homepage.

To repo:
0) To LocalSettings.php add "$wgUseDatabaseMessages = false;", so as to allow
the UI to be customized.

  1. Edit languages/LanguageEn.php, and add this line:

$wgAllMessagesEn['mainpage'] = "Nick's Homepage";

  1. Login as Wikisysop.
  2. Move the "Main Page", to "Nick's Homepage".

Expected results:
The move succeeds.

Actual Results:

Gives this error:

Warning: Wrong datatype for first argument in call to array_key_exists in
/var/www/hosts/wiki-homepage/wiki/includes/Hooks.php on line 42

Fatal error: Call to a member function on a non-object in

/var/www/hosts/wiki-homepage/wiki/includes/Title.php on line 664

Should this work, or have I done something dumb? Also despite the error it seems
to have moved the page successfully, so setting the severity to "minor".


Version: 1.5.x
Severity: normal
OS: Windows 2000
Platform: PC

Details

Reference
bz3667

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 8:52 PM
bzimport set Reference to bz3667.
bzimport added a subscriber: Unknown Object (MLST).

robchur wrote:

If the page moved, then I wouldn't worry. However, you don't need to make
changes to the code to change the interface any more. Going into
MediaWiki:Mainpage and changing the text there to "Nick's Homepage" would have
set up the default page easily; moving the page from "Main Page" to "Nick's
Homepage" is a trifling matter.

Then again, you seem to be more worried about the error message, and rightly so.
Can you reproduce the error - does moving any other page throw up the same results?

nickpj wrote:

Thank you for the tip about "MediaWiki:Mainpage" - that's a much easier way of
doing it.

With the error, I can reproduce the error on the current wiki.

Created an article called "Test", and then moved it to "Test's test".

Gives this error:

Warning: Wrong datatype for first argument in call to array_key_exists in
/var/www/hosts/wiki-homepage/wiki/includes/Hooks.php on line 42

Fatal error: Call to a member function on a non-object in

/var/www/hosts/wiki-homepage/wiki/includes/Title.php on line 664

So as to eliminate any changes or customizations that I may have made being the
cause of the problem, I made a new virtual host, with an unmodified copy of
MediaWiki 1.5.0, and recorded all the steps I followed starting right at
installation through to getting the error message. Steps are shown below in the
hope that it may be of assistance:

ludo:/var/www/# cd /var/www/hosts/
ludo:/var/www/hosts# mkdir mediawiki-test
ludo:/var/www/hosts# cd mediawiki-test
ludo:/var/www/hosts/mediawiki-test# tar xfz ~/tmp/mediawiki-1.5.0.tar.gz
ludo:/var/www/hosts/mediawiki-test# mv mediawiki-1.5.0/ wiki
ludo:/var/www/hosts/mediawiki-test# chown -R www-data.www-data /var/www/hosts
ludo:/var/www/hosts/mediawiki-test#

Then the browser steps:

Please include all of the lines below when reporting installation problems.

Checking environment...

  • WARNING: PHP 4.3.2 or higher is recommended. Older versions from 4.1.x up

may work but are not actively supported. PHP 4.1.2: ok

  • Warning: PHP's register_globals option is enabled. MediaWiki will work

correctly, but this setting increases your exposure to potential security
vulnerabilities in PHP-based software running on your server. You should disable
it if you are able.

  • PHP server API is apache; ok, using pretty URLs (index.php/Page_Title)
  • Have XML / Latin1-UTF-8 conversion support.
  • PHP's memory_limit is 16M. If this is too low, installation may fail!

Attempting to raise limit to 20M... ok.

  • Have zlib support; enabling output compression.
  • Neither Turck MMCache nor eAccelerator are installed, can't use object

caching functions

  • GNU diff3 not found.
  • Found GD graphics library built-in, image thumbnailing will be enabled if

you enable uploads.

  • Installation directory: /var/www/hosts/mediawiki-test/wiki
  • Script URI path: /wiki
  • Configure as follows:

Site name: mediawiki-test
Contact e-mail: <I'm omitting this to limit spam>
Language: en- English
no license metadata
Sysop account name: Nickj
password: test
pwd again: test
no caching
email: enabled
User-to-user e-mail: enabled
E-mail notification: enabled for changes of watch-listed and user_talk pages
E-mail address authentication: disabled
MySQL server: localhost
Database name: wikitest
db user: wikiuser
DB password: test
DB wd again: test
Database table prefix: <blank/none/not specified>
DB root password: <blank/none/not specified>

  • click "Install"
  • Output as follows:

MediaWiki 1.5.0 installation

Please include all of the lines below when reporting installation problems.
Checking environment...

  • WARNING: PHP 4.3.2 or higher is recommended. Older versions from 4.1.x up

may work but are not actively supported. PHP 4.1.2: ok

  • Warning: PHP's register_globals option is enabled. MediaWiki will work

correctly, but this setting increases your exposure to potential security
vulnerabilities in PHP-based software running on your server. You should disable
it if you are able.

  • PHP server API is apache; ok, using pretty URLs (index.php/Page_Title)
  • Have XML / Latin1-UTF-8 conversion support.
  • PHP's memory_limit is 16M. If this is too low, installation may fail!

Attempting to raise limit to 20M... ok.

  • Have zlib support; enabling output compression.
  • Neither Turck MMCache nor eAccelerator are installed, can't use object

caching functions

  • GNU diff3 not found.
  • Found GD graphics library built-in, image thumbnailing will be enabled if

you enable uploads.

  • Installation directory: /var/www/hosts/mediawiki-test/wiki
  • Script URI path: /wiki
  • PHP is linked with old MySQL client libraries. If you are using a MySQL

4.1 server and have problems connecting to the database, see
http://dev.mysql.com/doc/mysql/en/old-client.html for help.

  • Trying to connect to MySQL on localhost as root... o Connected as root (automatic)
  • Connected to 3.23.49
  • Created database wikitest
  • Creating tables... done.
  • Initializing data...
  • Granting user permissions...
  • Created sysop account Nickj. *

Initialising "MediaWiki" namespace...
Clearing message cache...Done.

Creating LocalSettings.php...

Installation successful! Move the config/LocalSettings.php file into the

parent directory, then follow this link to your wiki.

  • Moved config/LocalSettings.php:

ludo:/var/www/hosts/mediawiki-test# mv wiki/config/LocalSettings.php wiki/
ludo:/var/www/hosts/mediawiki-test#

  • Click the link ( http://mediawiki-test/wiki/index.php ) to open the wiki
  • Looks normal.
  • Go to http://mediawiki-test/wiki/index.php/test
  • Click "edit"
  • Type "this is a test"
  • save page
  • Click "create an account or login" (as anons cannot move page)
  • Enter username "Nickj", pwd "test", tick "Remember me", click "login".
  • Click "return the test" link
  • click move
  • Enter new title as "Test's test", click "Move page".
  • get a white screen with this error message: --------------------------------

Warning: Wrong datatype for first argument in call to array_key_exists in
/var/www/hosts/mediawiki-test/wiki/includes/Hooks.php on line 42

Fatal error: Call to a member function on a non-object in

/var/www/hosts/mediawiki-test/wiki/includes/Title.php on line 664

  • Then if I press the browser's back button (to go to

http://wiki-homepage/wiki/index.php/Test ) I get this error message:

Fatal error: Call to a member function on a non-object in

/var/www/hosts/wiki-homepage/wiki/includes/Database.php on line 1667

the error above:

Fatal error: Call to a member function on a non-object in

/var/www/hosts/wiki-homepage/wiki/includes/Database.php on line 1667

  • Pressing reload, and shift-reload, gives the same error. In MS Internet

Explorer 5 I tried to clear the cache by going tools -> internet options ->
general tab -> delete files -> ticked box to also delete offline content (just
in case) -> click OK -> click OK. Then closed IE, and then restarted it (just to
be safe again), and then went to http://wiki-homepage/wiki/ again. Same error
message: "Fatal error: Call to a member function on a non-object in
/var/www/hosts/wiki-homepage/wiki/includes/Database.php on line 1667".

At this point, I think I've basically hosed my mediawiki-test wiki ... So, in
answer to your question, yes, the error worries me a bit :-) Also I'm thinking
now the severity might be higher than minor.

  • All the best, Nick.

nickpj wrote:

Please disregard from "Then if I press the browser's back button" onwards in the
above message (before this about the move-error is still correct, but after this
point about the database-error it is wrong). The reason is (and I should have
seen this in the URLs) is that for some reason pressing back in IE went back to
the original (non-test) wiki.

When the test wiki was installed, I used the same DB username but a different
password for the new wiki, and the setup configures the DB user's password as
specified. So, the setup of the new wiki meant the original wiki could not
access the database, which caused it to give an error.

Strangely, it gives different messages in IE and Firefox - Firefox says:

Sorry! The wiki is experiencing some technical difficulties, and cannot contact
the database server.

Access denied for user: 'wikiuser@localhost' (Using password: YES) (localhost)

(which is a far more informative error)

whilst IE keeps showing :

Fatal error: Call to a member function on a non-object in

/var/www/hosts/wiki-homepage/wiki/includes/Database.php on line 1667

However after changing both wikis to use the same password, then both sites can
be accessed in both browsers.

Can you reproduce this with PHP 4.3.x/4.4.0/5.x?

nickpj wrote:

Don't know, and I don't currently have a PHP 4.3.x/4.4.0/5.x install with which
I can test this.

I've also since tried moving pages without any apostrophes or any spaces in the
name in case that was the problem (for example I tried moving "T2" to "T3"), and
this generates the error too.

On further investigation, it looks like it's this PHP bug:
http://bugs.php.net/bug.php?id=20865 [array_key_exists() fails to find NULL
key]. When I run the test script from that bug in PHP 4.1.2, it generates an

error which says:

ludo:~# ~/tmp/test.php
<br />
<b>Warning</b>: Wrong datatype for first argument in call to array_key_exists
in <b>/root/tmp/test.php</b> on line <b>16</b><br />

ludo:~#

Looks pretty similar.

I then edited Hooks.php as follows:

  • includes/Hooks.php.bak Tue Oct 11 17:15:11 2005

+++ includes/Hooks.php Tue Oct 11 17:21:56 2005
@@ -39,6 +39,11 @@

        return false;
}

+ if (is_null($event)) {
+ //#### wfDieDebugBacktrace("Event was null!\n");
+ return false;
+ }
+

if (!array_key_exists($event, $wgHooks)) {
        return true;
}

This stopped the first of the messages I see, so that now the only error message

is like this:

Fatal error: Call to a member function on a non-object in

/var/www/hosts/mediawiki-test/wiki/includes/Title.php on line 664

By the way, the wfDieDebugBacktrace call is commented out because if it's not, I

get this error:

Fatal error: Call to undefined function: wfdiedebugbacktrace() in

/var/www/hosts/mediawiki-test/wiki/includes/Hooks.php on line 44

... which suggests to me that it's fairly likely that none of the other calls to
wfDieDebugBacktrace (located both above and below the one I inserted) are going
to work either.

nickpj wrote:

includes/Title.php patch for MediaWiki 1.5.0

Visual inspection of the code lead me to suspect that includes/Title.php was
the problem, and specifically that it might be something to do with reference
abuse (which in PHP < 4.4 can corrupt memory), plus one or more null values
being used somewhere. So, I modified includes/Title.php to remove the cruft
that stood out the most (namely: unused vars + one un-initialized var that
should be global + unused globals + the use of references that seemed worst).
Patch against MediaWiki 1.5.0 is attached. With this applied, page moves are
now working successfully again in PHP 4.1.2.

Attached:

nickpj wrote:

Hi, If the above patch is going to take a while to review, can I please request
that a one-line subset of the above patch be applied? Namely the line adding the
"global $wgUser;" around line 1659. This type of fix would qualify for inclusion
in a Linux 2.6.x.y point release (i.e. it's a trivial and simple and short fix,
it helps fix a definite problem, which has affected real users), and for these
reasons I think it would be good to apply this to MediaWiki sooner rather than
later. I have not tested whether this line alone will fix page moves in PHP
4.1.2, but it is definitely a significant part of the problem.

Added the global, not touching the other bits if there's not any clear reason for it.
PHP 4.1.2 is no longer supported, so don't really care if it works or not, but it's
incorrect to be missing the global. :)