#
# 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.
#
# To install, copy the extension to your extensions directory and add line
# include("extensions/ShowHide.php");
# to the bottom of your LocalSettings.php
#
# Example syntax:
#
#
# Some text (usually title) which will not be hidden __HIDER__
# Text which will be hidden
#
#
# If tags are used instead of , the text will be
# shown by default
#
# For more information see its page at
# http://meta.wikimedia.org/wiki/ShowHide_Extension
$wgExtensionFunctions[]="wfShowHideExtension";
$wgExtensionCredits['parserhook'][] = array(
'name' => 'ShowHide',
'version' => '2007/02/12',
'author' => 'Austin Che',
'url' => 'http://openwetware.org/wiki/User:Austin/Extensions/ShowHide',
'description' => 'Enable showing/hiding parts of a page',
);
function wfShowHideExtension()
{
global $wgMessageCache, $wgParser;
$wgParser->setHook("showhide", "ShowHideExtension");
$wgMessageCache->addMessages(array('showall' => 'show all', 'hideall' => 'hide all'));
wfShowHideAddJs();
}
function wfShowHideAddJs()
{
global $wgOut;
$wgOut->addScript("
");
}
function ShowHideExtension($in, $argv, &$parser)
{
global $wgOut;
static $numrun=0;
// fix for when including a template that uses this extension
// cannot use current parser as we're in middle of a parse so we create another one
$localParser = new Parser();
$parserOutput = $localParser->parse( $in, $parser->mTitle, $parser->mOptions );
$out = $parserOutput->getText();
if(
strpos($out,"__HIDER__")!==FALSE &&
((
($s=strpos($out,"<show>"))!==FALSE &&
strpos($out,"</show>")>$s
) || (
($h=strpos($out,"<hide>"))!==FALSE &&
strpos($out,"</hide>")>$h
))
) {
$numrun++;
if($s!==FALSE)
$act="show";
else
$act="hide";
$hideline = '';
$out=str_replace("__HIDER__","$hideline",$out);
$out=str_replace(
array("<$act>", "</$act>"),
array("
","
"),
$out
);
$out="$out";
if($act=="hide")
$out.="";
}
$out=str_replace("__HIDEALL__", '', $out);
$out=str_replace("__SHOWALL__", '', $out);
return $out;
}
?>