Pages with content displayed blank/empty (MediaWiki)


To totally unlock this section you need to Log-in


Login

NOTE: this is a quick tip.

In some old Mediawiki installations, especially those hosted on public hosting services, could "break" and will not display any content on every pages of the wiki even if the wiki text (by modifying the page) still exist.

This typical issue can be verified by reviewing the Apache error.log and searching for an entry similar to the following:

PHP Warning: preg_match_all(): Compilation failed: group name must start with a non-digit at offset 4 in /var/www/wiki/htdocs/includes/MagicWord.php

This issue is caused by PCRE upgrade from version 8.33 to higher versions, when $regex groups start with digit.

The PCRE library is a set of functions that implement regular expression pattern matching (regex) using the same syntax and semantics as Perl 5, with just a few differences.

Solution

The solution to this issue, if we can't or do not want to upgrade our MediaWiki installation, is to modify manually (with advanced text editor like Notepad++) the PHP code of the file (in includes folder of our MediaWiki installation) called MagicWord.php and identify the following PHP function (this is an example of MediaWiki 1.16):

	function getBaseRegex() {
		if ( is_null( $this->baseRegex ) ) {
			$this->baseRegex = array( 0 => '', 1 => '' );
			foreach ( $this->names as $name ) {
				$magic = MagicWord::get( $name );
				$case = intval( $magic->isCaseSensitive() );
				foreach ( $magic->getSynonyms() as $i => $syn ) {
					$group = "(?P<{$i}_{$name}>" . preg_quote( $syn, '/' ) . ')';
					if ( $this->baseRegex[$case] === '' ) {
						$this->baseRegex[$case] = $group;
					} else {
						$this->baseRegex[$case] .= '|' . $group;
					}
				}
			}
		}
		return $this->baseRegex;
	}

And change the bolded text to the following code (just add an underscore character):

	function getBaseRegex() {
		if ( is_null( $this->baseRegex ) ) {
			$this->baseRegex = array( 0 => '', 1 => '' );
			foreach ( $this->names as $name ) {
				$magic = MagicWord::get( $name );
				$case = intval( $magic->isCaseSensitive() );
				foreach ( $magic->getSynonyms() as $i => $syn ) {
					$group = "(?P<_{$i}_{$name}>" . preg_quote( $syn, '/' ) . ')';
					if ( $this->baseRegex[$case] === '' ) {
						$this->baseRegex[$case] = $group;
					} else {
						$this->baseRegex[$case] .= '|' . $group;
					}
				}
			}
		}
		return $this->baseRegex;
	}

After this quick modification your MediaWiki will show again all your pages correctly, without any issue about editing or saving changes.

REMEMBER: make always a backup of your PHP files before editing or overwriting them.