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”


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:

64 Replies 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. Buck Golemon

    This helped me too.

    This command does the same as your script, but can be run twice safely, and doesn’t make temporary files:

    find -name “*.php” | xargs sed -i ‘s/\<Namespace::/WikiNamespace::/g'^C

    Reply
  2. Mondelli

    Cool, have not been able to find the information I was looking for before now, thanks to the blog owners for this master piece work…

    Reply
  3. Pingback: Carra Dio

  4. Pingback: carra dio

  5. jewssjna

    I love your website! did you create this yourself or did you outsource it? I’m looking for a blog design that similar so that the only reason I’m asking. Either way keep up the nice work I was impressed πŸ™‚

    Reply
  6. jewssjna23u

    I love your website! did you create this yourself or did you outsource it? Im looking for a blog design thats similar so thats the only reason I’m asking. Either way keep up the nice work I was impressed πŸ™‚

    Reply
  7. Gilberte Lohse

    Please, can you PM me and tell me few more thinks about this, I am really fan of your blog…

    Reply
  8. Uwe Brauer

    Thanks a lot. Now my mediawiki 1.9 works with one exception, the google calendar!
    I obtain
    {{#widget:Google Calendar |[email protected] |color=B1440E |height=400 |width=80% |title=Seminarios de Cadedif }}

    do you have any idea what that could be?

    Uwe Brauer

    Reply
  9. Pingback: Wordpresswindow » Ugly bug in mediawiki after php 5.3 upgrade

  10. Greg Miller

    Thanks for this information, came in very handy as I was moving a site from a Linux server into a local windows setup. I had to use notepad++’s “find in files” capability to accomplish the same thing. However, you might want to make clearer that the replace functionality has to be run on the wiki root directory, not just in the includes directory. I got that wrong on the first try and had to backtrack and try it again. It works now, thanks again.

    Reply
    • Derrick Post author

      Hi Greg,

      I only ran the script in the “include” directory and everything worked fine. I didn’t run the script in the root directory.

      –Derrick

      Reply
  11. mediawikiwave

    Terrific work! This is the kind of info that are supposed to be shared across the web. Disgrace on the search engines for no longer positioning this submit upper! Come on over and discuss with my website . Thanks =)

    Reply
  12. Ross

    TextCrawler which is freeware will let you do the “Namespace::” to “MWNamespace::” search and replace over all the PHP files under Windows.

    Great article, saved me a lot of time!!!

    Reply
  13. Pingback: MAMP und MediaWiki laufen endlich nach Update auf Mac OS X Lion Β» Pottblog

  14. hanker

    Thanks a lot!!! Safed me from jumping out of the window after upgrading my little server. πŸ˜‰

    Formerly:
    MediaWiki: 1.5.8
    PHP: 5.2.14 (apache2handler)
    MySQL: 5.0.90-community

    Now:
    MediaWiki: 1.5.8
    PHP: 5.3.10 (apache2handler)
    MySQL: 5.1.61

    Reply
  15. Pingback: Altes MediaWiki und PHP 5.3

  16. Nasir

    I must say Thank you.

    I didn’t have access to the terminal but I have manually replaced all Namespace:: to MWNamespace:: in all files under include folder.

    I have also replaced

    class Namespace {
    to
    class MWNamespace {

    Thanks again

    Reply
  17. Ian Tresman

    Thanks for this, solved the problem with my MediaWiki 1.6.8 after upgrading to PHP 5.3.18. For those that are not using a script, the following description helps:

    1. In the file Namespace.php, change “class Namespace” to “class MWNamespace”

    2. Then change all occurrences of “Namespace::” to “MWNamespace::” in these files:

    includes\Export.php
    includes\ImageGallery.php
    includes\Namespace.php
    includes\Parser.php
    includes\RecentChange.php
    includes\SkinTemplate.php
    includes\SpecialWatchlist.php
    includes\Title.php
    maintenance\generateSitemap.php

    Reply
  18. Terry

    After making your suggested changes the error is gone, but when I try to access the wiki, I get a message “Waiting for byc.org…” and it never loads the page. This site is not yet live so if you try it you will be directed to our old site where the wiki is working. I had to include the ip address of our new provider in my hosts file in order to test my new site. Any ideas as to why this might be happening?

    Reply

Leave a Reply

Your email address will not be published.