Last modified: 2010-05-15 15:38:26 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 T5667, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 3667 - Moving Pages in PHP 4.1.2 gives fatal error
Moving Pages in PHP 4.1.2 gives fatal error
Status: RESOLVED FIXED
Product: MediaWiki
Classification: Unclassified
Interface (Other open bugs)
1.5.x
PC Windows 2000
: Normal normal (vote)
: ---
Assigned To: Nobody - You can work on this!
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2005-10-10 06:57 UTC by Nick Jenkins
Modified: 2010-05-15 15:38 UTC (History)
0 users

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


Attachments
includes/Title.php patch for MediaWiki 1.5.0 (14.46 KB, patch)
2005-10-13 02:46 UTC, Nick Jenkins
Details

Description Nick Jenkins 2005-10-10 06:57:10 UTC
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";
2) Login as Wikisysop.
3) 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".
Comment 1 Rob Church 2005-10-10 08:08:16 UTC
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?
Comment 2 Nick Jenkins 2005-10-11 03:11:17 UTC
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:
* open http://mediawiki-test/wiki
* click setup link
* gives this output:

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
--------------------------------
* Then I went to the homepage, http://wiki-homepage/wiki/ , and it keeps giving
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.
Comment 3 Nick Jenkins 2005-10-11 04:38:48 UTC
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.
Comment 4 Brion Vibber 2005-10-11 05:09:09 UTC
Can you reproduce this with PHP 4.3.x/4.4.0/5.x?
Comment 5 Nick Jenkins 2005-10-11 07:31:53 UTC
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.
Comment 6 Nick Jenkins 2005-10-13 02:46:23 UTC
Created attachment 986 [details]
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.
Comment 7 Nick Jenkins 2005-10-20 03:01:16 UTC
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.
Comment 8 Brion Vibber 2005-10-29 06:05:16 UTC
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. :)

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


Navigation
Links