User:Gizmhail/RawContent

Purpose
This extension adds the rawcontent parser function. It returns a page content unmodified (unlike msgnw wich transforms "---" symbols or bulleted lists). It can be seen as an improved (or fixed) msgnw.

It can be used, for instance, to include the true content of a page in a textarea form, using an extension like SimpleForm (trying to do this with msgnw parser function works, until the included page contains lists, includeonly sections or "" symbols ).

Code
<? /* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * @author Sebastien Poivre  * @copyright Copyright (C) 2008 Sebastien Poivre * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later */

$wgExtensionCredits['parserhook'][] = array(       'name' => 'RawContent',        'author' =>  'Orange Labs (Sebastien Poivre)',        'url' => 'http://www.mediawiki.org/wiki/User:Gizmhail/RawContent',        'description' => 'Add the rawcontent parser function. It returns a page content unmodified (unlike msgnw wich transforms among others "---" symbols, includeonly sections or bulleted lists).',        'version' => 0.1  );

$wgExtensionFunctions[] = 'wfRawContentParserFunction_Setup'; $wgHooks['LanguageGetMagic'][]      = 'wfRawContentParserFunction_Magic'; $wgHooks['ParserAfterTidy'][] = 'wfRawContentParserAfterTidy';
 * 1) Define a setup function
 * 1) Add a hook to initialise the magic word

function wfRawContentParserFunction_Setup { global $wgParser; # Set a function hook associating the "rawcontent" magic word with our function $wgParser->setFunctionHook( 'rawcontent', 'wfRawContentParserFunction_Render' ); }

function wfRawContentParserFunction_Magic( &$magicWords, $langCode ) { # Add the magic word # The first array element is case sensitive, in this case it is not case sensitive # All remaining elements are synonyms for our parser function $magicWords['rawcontent'] = array( 0, 'rawcontent' ); # unless we return true, other parser functions extensions won't get loaded. return true; }

function wfRawContentParserFunction_Render( &$parser, $param1 = , $param2 =  ) { # The parser function itself # The input parameters are wikitext with templates expanded # The output should be wikitext too global $rawContentMarkerList; $title = Title::newFromText( $param1 ); list($articleContent,$title) = $parser->fetchTemplateAndtitle( $title ); $makercount = count($rawContentMarkerList); $marker = "xx-start-raw-content---".$makercount."-raw-content-end-xx"; $rawContentMarkerList[$makercount] = $articleContent; return $marker; }

function wfRawContentParserAfterTidy(&$parser, &$text){ global $rawContentMarkerList; for ($i=0;$i<count($rawContentMarkerList);$i++) $text = preg_replace(                       '/xx-start-raw-content---'.$i.'-raw-content-end-xx/',                        $rawContentMarkerList[$i],                        $text); return true; }