Extension:PatchOutput
![]() |
This extension stores its source code on a wiki page. Please be aware that this code may be unreviewed or maliciously altered. They may contain security holes, outdated interfaces that are no longer compatible etc. Note: No localisation updates are provided for this extension by translatewiki.net. |
PatchOutput Release status: stable |
|||
---|---|---|---|
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 | GPL v3 | ||
Download | #Source #Change Log |
||
|
|||
|
|||
Translate the PatchOutput extension if it is available at translatewiki.net |
|||
Check usage and version matrix; code metrics |
Purpose[edit | edit source]
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:
- A link like
mailto:[email protected]
is shown as [email protected] (while the link behind is still a mailto: link).
Warnings[edit | edit source]
- 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.
- As stated on OutputPageBeforeHTML#Warning, the hook may have bugs.
Installation[edit | edit source]
- Copy the #Source to a file
PatchOutput/PatchOutput.php
in yourextensions/
folder. - Add the following code at the bottom of your LocalSettings.php:
require_once "$IP/extensions/PatchOutput/PatchOutput.php";
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.
Configuration[edit | edit source]
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
.
Source[edit | edit source]
<?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 | edit source]
- 0.2.2
- Use
strtr
, thus avoiding an explicit loop.
- 0.2.1
- Removed the replacement pair used to open links in a new browser windwo. 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.
- 0.2
- The configuration parameter now a class member.
- 0.1
- First version published.