Extension talk:ShowHide

MediaWiki 1.8.2
The 'UNIQ' issue seems to exist for any ShowHide content now (tested in Firefox 2.x and IE 6.x).

There is some "Other" patch code posted here that is claimed to work with 1.8.2. I haven't been able to find the code that v1.0patch3 is supposed to patch. There was a version jump from v0.1/v0.1.1 to v1.0patch3. This might have been a typo or the v1.0 code may have been mistakenly left unposted. The patch3 and patch4 versions both seem to have been contributed by "210.253.93.243" Jasonbrewer 15:45, 8 January 2007 (UTC)

Sorry my typo in version number. This should be corrected v0.1+patch3. Please apply these pathces as patch ShowHide.php ShowHide.php.v0.1+patch3 patch ShowHide.php ShowHide.php.v0.1+patch4 or by hand where ShowHide.php is version 0.1. These patches are still work on mediawiki 1.9.0 -- a.i.

patch and patch2 (Though this file is not exists in content page) are not needed. -- a.i.

On display some symbols are automatically changed from original source code by wiki. Please edit content page to copy the patches as other extention's source code. --a.i.

How exactly do I patch?
Here are the md5sums I'm getting before I try the first patch: ShowHide.php (original v0.1): 14ae799c863dfe4412e1907e3ae13dd7 ShowHide.php.v0.1+patch3: 48ea43296c1966d5e98bf4424af97f55

Here is my output from the first patch commmand: #patch ShowHide.php ShowHide.php.v0.1+patch3 patching file ShowHide.php Hunk #2 FAILED at 36. Hunk #3 FAILED at 91. 2 out of 3 hunks FAILED -- saving rejects to file ShowHide.php.rej

What am I doing wrong?

Jasonbrewer 20:51, 19 January 2007 (UTC)

a.i., can you post your final/patched code somewhere or email it to me? My email address is in my profile.

Jasonbrewer 20:59, 19 January 2007 (UTC)

OK, here is my patched (patch3 and patch4) code in running. -- a.i.


 * 6) This program is free software; you can redistribute it and/or modify
 * 7) it under the terms of the GNU General Public License as published by
 * 8) the Free Software Foundation; either version 2 of the License, or
 * 9) (at your option) any later version.
 * 10) To install, copy the extension to your extensions directory and add line
 * 11) include("extensions/ShowHide.php");
 * 12) to the bottom of your LocalSettings.php
 * 13) Example syntax:
 * 14) Some text (usually title) which will not be hidden
 * 15) Text which will be hidden
 * 16) If  tags are used instead of , the text will be
 * 17) shown by default
 * 18) For more information see its page at
 * 19) http://meta.wikimedia.org/wiki/ShowHide_Extension
 * 1) Some text (usually title) which will not be hidden
 * 2) Text which will be hidden
 * 3) If  tags are used instead of , the text will be
 * 4) shown by default
 * 5) For more information see its page at
 * 6) http://meta.wikimedia.org/wiki/ShowHide_Extension
 * 1) shown by default
 * 2) For more information see its page at
 * 3) http://meta.wikimedia.org/wiki/ShowHide_Extension
 * 1) http://meta.wikimedia.org/wiki/ShowHide_Extension

$wgExtensionFunctions[]="wfShowHideExtension";

function wfShowHideExtension {	$GLOBALS['wgParser']->setHook("showhide","ShowHideExtension"); }

function ShowHideExtension($in,$params,&$parser) {	static $numrun=0;

$out = $parser->unstrip($parser->recursiveTagParse($in),$parser->mStripState); if(		( ($s=strpos($out,"&lt;show&gt;"))!==FALSE && strpos($out,"&lt;/show&gt;")>$s ) || (			($h=strpos($out,"&lt;hide&gt;"))!==FALSE && strpos($out,"&lt;/hide&gt;")>$h )	) {		if($numrun==0) { $out= " ".$out; }		$numrun++;

if($s!==FALSE) $act="show"; else $act="hide";

if (isset($params['showbuttontext'])) $showbuttontext = $params['showbuttontext']; else $showbuttontext = wfMsg('showtoc');

if (isset($params['hidebuttontext'])) $hidebuttontext = $params['hidebuttontext']; else $hidebuttontext = wfMsg('hidetoc');

$hideline = ' showSHToggle("' . addslashes($showbuttontext) . '","' . addslashes($hidebuttontext) . '",' . $numrun . ') ';

$out=rtrim(substr($out,0,strpos($out,"&lt;$act&gt;")),"\n\r"). $hideline. substr($out,strpos($out,"&lt;$act&gt;")); $out=str_replace(			array("&lt;$act&gt;",               "&lt;/$act&gt;"),			array(""," "),			$out		); $out="$out "; if($act=="hide") $out.="toggleSH($numrun) "; }	return $out; } ?>

MediaWiki 1.7.1
All TeX--Pngs before the -section look like "�UNIQ2b16b3743d2879b7-math-5522ebf95c92a91700000012-QINU" All -sections in and after the -section work. All What to do?

it gives me the same UNIQ-QINU, with a few different extensions that use tags and but some simple tags still work for example. And only if showhide occurs after them, not if it is before or in, just like above. The problem is more general. I would use template:hidden instead but i can't get it to work on my skin (anyone crack that one either?)65.96.127.125 19:34, 2 November 2006 (UTC)

MediaWiki 1.5.4
It does work with MediaWiki 1.5.4. too, but i wasnt able to get the parameters work i use in the template together with the ShowHide-function :( Any ideas (except of not working with parameters)? 11 January 2006 (UTC)

MediaWiki 1.5.3
Does this extension work with MediaWiki 1.5.3?


 * I made it on 1.4.8, so I can't really tell. But it probably does, crash wiki runs on 1.5.2 and it works. I can test it in a week or so. Nikola 13:03, 20 December 2005 (UTC)

with templates
The extension, at this time, cannot be used inside a template that expects one or more parameters. Eg I created the template and put the following inside the template

secret:__HIDER__

and when I pass the parameter, like, the output generated by the template displayes everything except the passed parameter. Instead of the parameter it shows/hides. No value is substituted!

Can this be fixed? --202.1.192.199 13:50, 28 January 2006 (UTC)

Same problem here... would be nice to use it like this --84.154.160.1 20:55, 28 February 2006 (UTC)

This problem is fixed to apply next patch (mediawiki 1.8.2). But if you use dangerous HTML tags, it treatment is changed (reference are lines of patch in Parser.php and removeHTMLtags method of Sanitizer.php) --a.i.

--- Parser.php +++ Parser.php.new @@ -3096,6 +3096,7 @@ 				$text = preg_replace( '/ .*?<\/noinclude>/s', '', $text ); $text = strtr( $text, array( ' ' => , ' ' =>  ) ); +				$text = $this->replaceVariables( $text, $assocArgs ); if( $this->ot['html'] || $this->ot['pre'] ) { # Strip, , etc. 					$text = $this->strip( $text, $this->mStripState ); @@ -3105,7 +3106,7 @@ 						$text = Sanitizer::removeHTMLcomments( $text ); } 				} -				$text = $this->replaceVariables( $text, $assocArgs ); +//				$text = $this->replaceVariables( $text, $assocArgs ); # If the template begins with a table or block-level # element, it should be treated as beginning a new line.

Another Problem: on 1.5.4 v0.1 is not working...not even parsed i think...the __HIDER__ and all the tags are still there. v0.1.1 works at first attempt, but then this caching-bug comes again... :-/ does it work with 1.5.6 ? --84.154.165.109 18:59, 1 March 2006 (UTC)

Can I change the show/hide text dynamically?
For example, instead of a show/hide, what if the button was the name of the thing that was being shown and hidden? --69.250.40.75 19:06, 20 May 2006 (UTC)

Nesting
Is it possible to nest multiple layers of show-hide? I tried doing this at ChainsOfReason.org, but couldn't work it out. Also, the test page didn't work for me.

Anyway, I tried something like this:

::*Objection1 __HIDER__ :::*CounterObjection1 :::*CounterObjection2 ::*Objection2

What I want, is to click the Hider next to the statement to reveal the objections to that statement, and the Hider next to the first objection to reveal the counter-objections to that objection. Is it possible? It seems that the two hiders are linked--so either both are shown or both are hidden. Any thoughts? Thanks. AdamRetchless 15:30, 28 February 2007 (UTC)

I think that mediawiki is not support nesting tags. But to use below, tag nesting is possible. To use this, Open the Parser.php in the include directory of mediawiki. Then replace the extractTagsAndParams function with below. And use new ShowHide.php in below for this. I checked these programs in 1.9.3. -- a.i.

function extractTagsAndParams( $elements, $text, &$matches, $uniq_prefix = '' ) { static $n = 1; $stripped = ''; $matches = array;

$taglist = implode( '|', $elements ); $start = "/<($taglist)(\\s+[^>]*?|\\s*?)(\/?>)|<(!--)/i";

while ( '' != $text ) { $p = preg_split( $start, $text, 2, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_OFFSET_CAPTURE ); $stripped .= $p[0][0]; if( count( $p ) < 5 ) break;

if( count( $p ) > 5 ) { // comment $element   = $p[4][0]; $attributes = ''; $close     = ''; $inside    = $p[5][0]; } else { // tag $element   = $p[1][0]; $attributes = $p[2][0]; $close     = $p[3][0]; $inside    = $p[4][0]; }

$marker = "$uniq_prefix-$element-". sprintf('%08X', $n++). '-QINU'; $stripped .= $marker;

if ( $close === '/>' ) { // Empty element tag, $content = null; $text = $inside; $tail = null; } else { if( $element == '!--' ) $q = preg_split( '/(-->)/', $inside, 2, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_OFFSET_CAPTURE ); else { $nest = 1; $length = 0; do { // search end tag if ( count( $q = preg_split( "/()/i", $inside, 2, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_OFFSET_CAPTURE ) ) < 3 ) break;

// search start tag $r = preg_split( "/(<$element(\\s+[^>]*?|\\s*?)(\/?)>)|/', $r[5][0], 2, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_OFFSET_CAPTURE ) ) < 3 )								break;

$inside = $q[2][0]; $length += $q[2][1]; } else if ( count( $r ) < 5 or $q[1][1] < $r[1][1] ) {	// the next tag is an end tag $nest--; $inside = $q[2][0]; $length += $q[1][1]; if ( $nest > 0 )	// the last tag is not content $length += $q[2][1] - $q[1][1]; } else {	// the next tag is a start tag $nest++; $inside = $r[4][0]; $length += $r[4][1]; }					} while ( $nest > 0 );

$content = count( $q ) < 3 ? $p[4][0] : substr( $text, $p[4][1], $length ); }

if( count( $q ) < 3 ) { # No end tag -- let it run out to the end of the text. $tail = ''; $text = ''; } else { $tail = $q[1][0]; $text = $q[2][0]; }			}

$matches[$marker] = array( $element,				$content,				Sanitizer::decodeTagAttributes( $attributes ),				"<$element$attributes$close$content$tail" ); }		return $stripped; }


 * 6) This program is free software; you can redistribute it and/or modify
 * 7) it under the terms of the GNU General Public License as published by
 * 8) the Free Software Foundation; either version 2 of the License, or
 * 9) (at your option) any later version.
 * 10) To install, copy the extension to your extensions directory and add line
 * 11) include("extensions/ShowHide.php");
 * 12) to the bottom of your LocalSettings.php
 * 13) Example syntax:
 * 14) Some text (usually title) which will not be hidden
 * 15) Text which will be hidden
 * 16) If  tags are used instead of , the text will be
 * 17) shown by default
 * 18) For more information see its page at
 * 19) http://meta.wikimedia.org/wiki/ShowHide_Extension
 * 1) Some text (usually title) which will not be hidden
 * 2) Text which will be hidden
 * 3) If  tags are used instead of , the text will be
 * 4) shown by default
 * 5) For more information see its page at
 * 6) http://meta.wikimedia.org/wiki/ShowHide_Extension
 * 1) shown by default
 * 2) For more information see its page at
 * 3) http://meta.wikimedia.org/wiki/ShowHide_Extension
 * 1) http://meta.wikimedia.org/wiki/ShowHide_Extension

$wgExtensionFunctions[]="wfShowHideExtension";

function wfShowHideExtension {	$GLOBALS['wgParser']->setHook("showhide","ShowHideExtension"); }

function ShowHideExtension($in,$params,&$parser) {	static $numrun=0;

$out=''; if($numrun==0) { $out= " "; }	$run = $numrun++;

$out .= $parser->unstrip($parser->recursiveTagParse($in),$parser->mStripState); if(		( ($s=strpos($out,"&lt;show&gt;"))!==FALSE && strpos($out,"&lt;/show&gt;")>$s ) || (			($h=strpos($out,"&lt;hide&gt;"))!==FALSE && strpos($out,"&lt;/hide&gt;")>$h )	) {		if($s!==FALSE) $act="show"; else $act="hide";

if (isset($params['showbuttontext'])) $showbuttontext = $params['showbuttontext']; else $showbuttontext = wfMsg('showtoc');

if (isset($params['hidebuttontext'])) $hidebuttontext = $params['hidebuttontext']; else $hidebuttontext = wfMsg('hidetoc');

$hideline = 'showSHToggle("' . addslashes($showbuttontext) . '","' . addslashes($hidebuttontext) . '",' . $run . ') ';

$out=rtrim(substr($out,0,strpos($out,"&lt;$act&gt;")),"\n\r"). $hideline. substr($out,strpos($out,"&lt;$act&gt;")); $out=str_replace(			array("&lt;$act&gt;","&lt;/$act&gt;"),			array(""," "),			$out		); $out="".trim($out)." "; if($act=="hide") $out.="toggleSH($run) "; }	return $out; } ?>

An example is A B C D E