User:RV1971/PatchOutput

Extension
 * name     = PatchOutput
 * status   = beta
 * type     = hook
 * author   = RV1971
 * image    =
 * version  = 0.1
 * update   = 2007-05-30
 * mediawiki = >=1.10.0
 * download =
 * readme   =
 * changelog =
 * description = patch MediaWiki output before displaying
 * parameters= $wgExtPatchOutputTable
 * rights   =
 * example  =

Purpose
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 [mailto:test@test.org test@test.org] (while the link behind is still a mailto: link).

Warnings

 * 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 has bugs. In particular, it is not applied to the page preview.

Installation

 * Save the to a file extensions/PatchOutput/PatchOutput.php.

require_once( "extensions/PatchOutput/PatchOutput.php" );
 * Add the following line to your LocalSettings.php:


 * The search-and-replace patterns are stored in a global variable $wgExtPatchOutputTable. 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
 'PatchOutput',  'version' => ExtPatchOutput::$mVersion,  'author' => 'RV1971',  'url' => '',  'description' => 'patch html output' );

$wgExtPatchOutputTable = 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 { public static $mVersion = "0.1";

public function onOutputPageBeforeHTML( &$out, &$text ) { global $wgExtPatchOutputTable;

foreach( $wgExtPatchOutputTable as $from => $to ) $text =& str_replace( $from, $to, $text );

return true; } } ?>

Change Log

 * 0.1 :
 * First version published.