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 ).

It also adds the normalizedfullpagename parser function (see below).

Usage
This will return  page content.

This will return namespace:pagetitle for , with namespace translated to english (for instance, "Modèle" namespace from a french wiki will be translated to "Template). It is useful, for instance, if you have to synchronize technical templates (like Template:Ambox of wikipedia) having the same name between several wikis in different languages.

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 (mainly) the rawcontent parser function. It returns a page content unmodified (unlike msgnw wich transforms among others "---" symbols, includeonly sections or bulleted lists).',        'version' => 0.2  );

$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' ); $wgParser->setFunctionHook( 'normalizedfullpagename', 'wfRawContentParserFunctionNormalizedPageName_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' ); $magicWords['normalizedfullpagename'] = array( 0, 'normalizedfullpagename' ); # 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 wfRawContentParserFunctionNormalizedPageName_Render(&$parser,$param1 = ''){ $title = Title::newFromText( $param1 ); $namespace = ''; $pagename = ''; if($title){ $namespace = Language::factory( 'en' )->getNsText($title->mNamespace); $pagename = $title->getText; }       if($namespace != ''){ $pagename = "$namespace:$pagename"; }       return $pagename; }

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; }