User:Djomla/Sandbox

To use the spoilerMla extension, simply add the following tag to any article:

...spoilerMla information goes here...

This extension is based upon the spoilerMla extension by Brian Enigma (though heavily modified). Here is the source code for this MediaWiki extension in the incarnation that is implemented on this wiki:

 some text 
 * 3) the function registered by the extension hides the text between the
 * 4) tags behind a JavaScript spoilerMla block.
 * 5) (C) Copyright 2006, Brian Enigma 
 * 6) This work is licensed under a Creative Commons Attribution-Noncommercial-Share
 * 7) Alike 2.5 License. Some rights reserved.
 * 8) http://creativecommons.org/licenses/by-nc-sa/2.5/
 * 1) http://creativecommons.org/licenses/by-nc-sa/2.5/


 * 1) Modified February 2007 by Patrick Delancy for use in TibiaWiki ( http://tibia.erig.net/ )

$wgExtensionFunctions[] = "wfspoilerMlaExtension"; $wgHooks['OutputPageBeforeHTML'][] = 'spoilerMlaParserHook' ;

function wfspoilerMlaExtension { global $wgParser; # register the extension with the WikiText parser # the first parameter is the name of the new tag. # the second parameter is the callback function for # processing the text between the tags $wgParser->setHook( "spoilerMla", "renderspoilerMla" ); }

function wfspoilerMlaJavaScript { return "\n". "\n". "function getStyleObject(objectId) {\n". "   // checkW3C DOM, then MSIE 4, then NN 4.\n". "   //\n". "   if(document.getElementById) {\n". "     if (document.getElementById(objectId)) {\n". "	    return document.getElementById(objectId).style;\n". "     }\n". "   } else if (document.all) {\n". "     if (document.all(objectId)) {\n". "	    return document.all(objectId).style;\n". "     }\n". "   } else if (document.layers) { \n". "     if (document.layers[objectId]) { \n". "	    return document.layers[objectId];\n". "     }\n". "   } else {\n". "	  return false;\n". "   }\n". "}\n". "\n". "function toggleObjectVisibility(objectId) {\n". "   // first get the object's stylesheet\n". "   var styleObject = getStyleObject(objectId);\n". "\n". "   // then if we find a stylesheet, set its visibility\n". "   // as requested\n". "   //\n". "   if (styleObject) {\n". "       if (styleObject.visibility == 'hidden') {\n". "           styleObject.visibility = 'visible';\n". "           styleObject.position = 'relative';\n". "       } else {\n". "           styleObject.visibility = 'hidden';\n". "           styleObject.position = 'absolute';\n". "       }\n". "       return true;\n". "   } else {\n". "       return false;\n". "   }\n". "}\n". " \n"; }

function spoilerMlaParserHook( &$parser, &$text ) { $text = wfspoilerMlaJavaScript. $text; }

function wfMakespoilerMlaId { $result = "spoilerMla_"; for ($i=0; $i<20; $i++) $result .= chr(rand(ord('A'), ord('Z'))); return $result; }

function renderspoilerMla( $input, $argv, &$parser ) { # $argv is an array containing any arguments passed to the # extension like .. # Put this on the sandbox page: (works in MediaWiki 1.5.5) #  Testing text **example** in between the new tags
 * 1) The callback function for converting the input text to HTML output

$localParser = new Parser; $outputObj = $localParser->parse($input, $parser->mTitle, $parser->mOptions); $spoilerMlaId = wfMakespoilerMlaId;

$output = ""; $output .= ($argv["linktext"] == '' ? 'Click Here to Show/Hide spoilerMla Information' : $argv["linktext"]). " ";   $output .= ""; if (!in_array("hidewarning", array_values($argv))) { $output .= ""; $output .= ($argv["headwarningtext"] == ? "spoilerMla warning: Quest and/or game spoiling details follow.''" : $argv["headwarningtext"]); $output .= " "; }   $output .= "". $outputObj->getText. " ";   if (!in_array("hidewarning", array_values($argv))) { $output .= ""; $output .= ($argv["footwarningtext"] == '' ? "spoilerMla ends here." : $argv["footwarningtext"]); $output .= " "; }   $output .= " "; if ($argv["collapsed"] != "false") { $output .= ""; $output .= "toggleObjectVisibility('" . $spoilerMlaId . "');"; $output .= " "; }

return $output; } ?>