After upgrading my PHP to 5.3.2, I received the following error when accessing MediaWiki (1.6.12):

Parse error: syntax error, unexpected T_NAMESPACE, expecting T_STRING in /usr/local/www/apache22/data/wiki/includes/Namespace.php  on line 46

There are three solutions:

  1. Downgrade your PHP from 5.3 back to 5.2
  2. Upgrade your MediaWiki to a newer version.
  3. Fix the codes.

In my case, the first couple solutions do not work for me, and therefore I choose 3.

  1. Backup your wiki file first.
  2. Access your webserver and go to the MediaWiki/includes directory.
    For example:

    cd /usr/local/www/apache22/data/wiki/includes
  3. Edit Namespace.php
    nano Namespace.php
  4. Go to line 46, change the following from:
    class Namespace {

    to:

    class MWNamespace {

    Save the file.

  5. Now, let’s create a script:
    nano wikifix.sh

    Copy and paste the following:

    for fl in *.php; do
    mv $fl $fl.old
    sed 's/Namespace::/MWNamespace::/g' $fl.old > $fl
    done

    Save the file.

  6. Change the file to executable by:
    chmod u+x wikifix.sh
  7. Search the keyword Namespace:: and replace it by MWNamespace:::
    ./wikifix.sh

    Warning: Don’t run the script twice!

  8. Delete the script.
    rm wikifix.sh

Try to access the MediaWiki again and the problem should be gone.

Enjoy Wiki.

–Derrick

Our sponsors:

59 Responses to “MediaWiki Error: “Parse error: syntax error, unexpected T_NAMESPACE, expecting T_STRING in /usr/local/www/apache22/data/wiki/includes/Namespace.php on line 46″”

  1. Too quick to post that comment … solved it by adding MW to the Namespace as below:

    if( ( $ns = MWNamespace::getCanonicalIndex( $lctext ) ) !== null ) return $ns;

  2. Great solution solved error on Mediawiki 1.9.3

  3. It is worth to say that this excellent bash script should be launched in the /includes/filerepo/ folder as well

  4. This is obviously a syntax error in the source code. Can you show me the link?

Trackbacks/Pingbacks

  1. Carra Dio - It's a good blog... I will make sure and bookmark this page and be back to follow you more....
  2. carra dio - It's a good blog... I will make sure and bookmark this page and be back to follow you more....
  3. Wordpresswindow » Ugly bug in mediawiki after php 5.3 upgrade - [...] fix is described here… but another ugly bug then [...]
  4. MAMP und MediaWiki laufen endlich nach Update auf Mac OS X Lion » Pottblog - [...] icesquare.com fand ich drei mögliche Wege, das ganze zu [...]
  5. Altes MediaWiki und PHP 5.3 - [...] {} ;Es sollte aber dennoch auf die neueste MediaWiki Version 1.19 geupgraded werden.Quelle: MediaWiki Error: “Parse error: syntax error, …

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>