From mediawiki.org
Jump to navigation Jump to search
MediaWiki extensions manual
OOjs UI icon advanced-invert.svg
Release status: unmaintained
Implementation Skin
Description Patch the HTML representation of a page.
Author(s) (RV1971talk)
Latest version 0.2.2 (2013-10-31)
MediaWiki 1.20+
PHP 5.3+
License GNU General Public License 3.0
Download #Source
#Change Log

Check usage and version matrix.


This extension applies some patches to the HTML code of a page before it is displayed. It can be seen as a demo for using the OutputPageBeforeHTML hook. You're likely to customize it for your needs.

The current version achieves the following:


  • The result is achieved via crude string search-and-replace on the html code. The search patterns are likely to be subject to change in future MediaWiki versions.


  • Copy the #Source to a file PatchOutput/PatchOutput.php in your extensions/ folder.
  • Add the following code at the bottom of your LocalSettings.php:
require_once "$IP/extensions/PatchOutput/PatchOutput.php";
  • Yes Done – Navigate to "Special:Version" on your wiki to verify that the extension is successfully installed.

Even though this extension has been tested on MediaWiki 1.20, it should work on earlier versions as well.


The search-and-replace patterns are stored in a global variable $wgPatchOutputTable. It contains an array where keys are the terms to search and values the corresponding replacements. You can redefine this array or add entries in your LocalSettings.php.



if ( !defined( 'MEDIAWIKI' ) ) {
	echo( "This file is an extension to the MediaWiki software and cannot be used standalone.\n" );
	die( 1 );

$wgPatchOutputTable = array(
	/* do not show mailto: in mailto links */
	'">mailto:' => '">'

$wgExtensionCredits['skin'][] = array(
	'path' => __FILE__,
	'name' => 'PatchOutput',
	'description' => 'Allows to patch the HTML representation of a page.',
	'version' => '0.2.2',
	'author' => '[https://www.mediawiki.org/wiki/User:RV1971 RV1971]',
	'url' => 'https://www.mediawiki.org/wiki/Extension:PatchOutput'

$wgPatchOutput = new PatchOutput();

$wgHooks['OutputPageBeforeHTML'][] = $wgPatchOutput;

class PatchOutput
	public function onOutputPageBeforeHTML( OutputPage &$out, &$text ) {
		global $wgPatchOutputTable;

		$text = strtr( $text, $wgPatchOutputTable );

		return $out;

Change Log[edit]

  • Use strtr, thus avoiding an explicit loop.
  • Removed the replacement pair used to open links in a new browser window. This is now achieved better with the configuration parameter $wgExternalLinkTarget .
  • Removed the replacement pair used to translate "localhost" with the current server. It is better to use the magic word {{SERVERNAME}} instead.
  • The code has been reviewed in order to comply better with the guidelines on mediawiki.org.
  • The configuration parameter now a class member.
  • First version published.

See also[edit]