Extension:PatchOutput
From MediaWiki.org
| 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: beta |
|||
|---|---|---|---|
| Implementation | Extended syntax | ||
| Description | patch MediaWiki output before displaying | ||
| Author(s) | RV1971talk | ||
| Last version | 0.2 (2007-07-19) | ||
| MediaWiki | >=1.10.0 | ||
| License | No license specified | ||
| Download | #Source #Change Log |
||
|
|||
| Check usage and version matrix; stats | |||
Contents |
Purpose[edit]
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:
- External links are automatically opened in a new browser window.
- The server name "localhost" is translated to the current server. This is useful if your MediaWiki site can be addressed by different IP addresses or names, and you want to comfortably access other resources on the same webserver. The normal meaning of "localhost" (the machine where the client is running) would not have any sense on a MediaWiki page, anyway.
- A link like mailto:test@test.org is shown as test@test.org (while the link behind is still a mailto: link).
Warnings[edit]
- 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]
- Save the #Source to a file extensions/PatchOutput/PatchOutput.php.
- Add the following line to your LocalSettings.php:
require_once( "extensions/PatchOutput/PatchOutput.php" );
- The search-and-replace patterns are stored in a static class member ExtPatchOutput::$mTable. 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.
Even though this extension has been tested on MediaWiki 1.10, it should work on MediaWiki >= 1.6.0.
Source[edit]
<?php $wgExtensionCredits['other'][] = array( 'name' => 'PatchOutput', 'version' => ExtPatchOutput::VERSION, 'author' => '[http://www.mediawiki.org/wiki/User:RV1971 RV1971]', 'url' => 'http://www.mediawiki.org/wiki/Extension:PatchOutput', 'description' => 'patch html output' ); // default settings ExtPatchOutput::$mTable = array( /* open external links in new window */ 'class="external' => 'target="_blank" class="external', /* translate localhost to MediaWiki server */ '://localhost' => '://' . $_SERVER[ 'SERVER_NAME' ], /* do not show mailto: in mailto links */ 'rel="nofollow">mailto:' => '>' ); $wgExtPatchOutput = new ExtPatchOutput(); $wgHooks['OutputPageBeforeHTML'][] = array( &$wgExtPatchOutput, 'onOutputPageBeforeHTML' ); class ExtPatchOutput { const VERSION = '0.2'; public static $mTable; public function onOutputPageBeforeHTML( &$out, &$text ) { foreach( self::$mTable as $from => $to ) $text =& str_replace( $from, $to, $text ); return true; } }
Change Log[edit]
- 0.2
- The configuration parameter now a class member.
- 0.1
- First version published.