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 or "" symbols .

Limitation
There is a difference between the page content and the output result : and tags filter as expected the content. Preventing this might be an option included later in the extension, if needed.

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' =>  'Gizmhail(Sebastien Poivre)',        'url' => 'http://www.mediawiki.org/wiki/Extension:RawContent',        'description' => 'Add the rawcontent parser function. It returns a page content unmodified (unlike msgnw wich transforms "---" symbols or bulleted lists).',        'version' => 0.1  );

$wgExtensionFunctions[] = 'wfRawContentParserFunction_Setup'; $wgHooks['LanguageGetMagic'][]      = 'wfRawContentParserFunction_Magic';
 * 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 $title = Title::newFromText( $param1 ); list($articleContent,$title) = $parser->fetchTemplateAndtitle( $title ); return "<"."nowiki>$articleContent"; }