allwiki首页  
天下维客 你可以修改的网络知识库
首页最近更改优秀条目专题展示电脑科技词典软件学习网络知识电脑安全明星时尚天下百科
 

MediaWiki扩展:内容折叠隐藏

天下维客,你可以修改的网络知识库

Jump to: navigation, search
MediaWiki扩展简明教程 Inputbox帮助文档 使用Spam黑名单 内容折叠隐藏 动态文章列表 指定图片链接
代码高亮处理 预置初始编辑文本 页面访问限制 所见即所得编辑器 QQ在线信息
交流:扩展使用 投票与评分 内容随机展示 wikitex 改进设想 ...更多
加入google地图和51地图标注功能 Ajax五颗星评分插件

<showhide> 部分不需要隐藏的文本(通常为标题) __HIDER__ <hide>隐现文本内容</hide> </showhide>

这个折叠隐藏扩展可以制作通过开关进行显示/隐藏的内容元素,表现方式如同表格。

本扩展的创意来自Avala因创建了一系列非对其的国家列表(类似于NATO列表)而受到的指责。一方面,这种列表非常合理,但另一方面又完全不常用。本扩展使得这种列表合理化。

本扩展可以在ShowHide Wikimedia SCG的crash wiki看到实地应用。由于并非mediawiki的内置功能,所以其他wiki网站并不一定能见到本功能;你可以访问测试页面来观察实际例子,以了解和测试其工作表现。

注意,本扩展并未经过深入的测试,并可能存有小错误。目前,它正在Veggie Van Gogh wiki站点上使用。

在Mediawiki中增加本特性的请求参见bug #1257.

目录

语法

本扩展的语法如下:

<showhide>
部分不需要隐藏的文本(通常为标题) __HIDER__
<hide>隐现文本内容</hide>
</showhide>

__HIDER__ 是放置隐现开关链接的地方。用户通过点击隐现开关,可显示/隐藏位于<hide></hide>标签之间的内容。 在上面的例子里,可被隐现的内容是“隐现文本内容”,

如果使用<show></show>标签,隐现文本内容将默认处于显示状态,通过点击隐现开关可以把它折叠隐藏起来。

源代码

v 0.1

当忘记html_entity_decode()以及 $wgOut->addHTML(),而仅仅把JS粘贴到$out时,有时可能不能正常工作(在PHP 5.x下测试) --Smerf

请注意,这个扩展有违反XHTML 1.0 Transitional兼容性的地方!! --Smerf

<?php
# WikiMedia ShowHide extension v0.1
#
# Based on example code from
# http://meta.wikimedia.org/wiki/Write_your_own_MediaWiki_extension
# Contains code from MediaWiki's Skin.php and wikibits.js
#
# All other code is copyright © 2005 Nikola Smolenski <smolensk@eunet.yu>
#
# 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:
#
# <showhide>
# Some text (usually title) which will not be hidden __HIDER__
# <hide>Text which will be hidden</hide>
# </showhide>
#
# If <show></show> tags are used instead of <hide></hide>, the text will be
# shown by default
#
# For more information see its page at
# http://meta.wikimedia.org/wiki/ShowHide_Extension

$wgExtensionFunctions[]="wfShowHideExtension";

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

function ShowHideExtension($in)
{
	global $wgOut;
	static $numrun=0;

	$out=$wgOut->parse($in);
	if(
		strpos($out,"__HIDER__")!==FALSE &&
		((
			($s=strpos($out,"<show>"))!==FALSE &&
			strpos($out,"</show>")>$s
		) || (
			($h=strpos($out,"<hide>"))!==FALSE &&
			strpos($out,"</hide>")>$h
		))
	) {
		if($numrun==0) {
			$out=
"<script type=\"text/javascript\"><!--
shWas=new Array();
function showSHToggle(show,hide,num) {
	if(document.getElementById) {
		document.writeln('<span class=\'toctoggle\'>[<a href=\"javascript:toggleSH('+num+')\" class=\"internal\">' +
		'<span id=\"showlink'+num+'\" style=\"display:none;\">' + show + '</span>' +
		'<span id=\"hidelink'+num+'\">' + hide + '</span>' +
		'</a>]</span>');
	}
}
function toggleSH(num) {
	var shmain = document.getElementById('showhide'+num);
	var sh = document.getElementById('shinside'+num);
	var showlink=document.getElementById('showlink'+num);
	var hidelink=document.getElementById('hidelink'+num);
	if(sh.style.display == 'none') {
		sh.style.display = shWas[num];
		hidelink.style.display='';
		showlink.style.display='none';
		shmain.className = '';
	} else {
		shWas[num] = sh.style.display;
		sh.style.display = 'none';
		hidelink.style.display='none';
		showlink.style.display='';
		shmain.className = 'tochidden';
	}
} // --></script>
".$out;
		}
		$numrun++;

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

		$hideline = ' <script type="text/javascript">showSHToggle("' . addslashes( wfMsg('showtoc') ) . '","' . addslashes( wfMsg('hidetoc') ) . '",' . $numrun . ')</script>';

		$out=str_replace("__HIDER__","$hideline",$out);
		$out=str_replace(
			array("<$act>",                "</$act>"),
			array("<div id=\"shinside$numrun\">","</div>"),
			$out
		);
		$out="<span id=\"showhide$numrun\">$out</span>";
		if($act=="hide")
			$out.="<script type=\"text/javascript\">toggleSH($numrun)</script>";
	}
	return $out;
}
?>

v 0.1.1

PHP5 version with corrections according to 根据Smerf's的意见.

注意:我无法让下面这个版本在MediaWiki 1.5版本上正确运行。下面的内容可以在首次加载时正确工作,但经过cache加载,由$wgOut->addHtml插入的一次性Javascript代码无法加进去导致了这个问题。前面的v.0.1则在我这里能正常工作。
<?php
# WikiMedia ShowHide extension v0.1.1
#
# Based on example code from
# http://meta.wikimedia.org/wiki/Write_your_own_MediaWiki_extension
# Contains code from MediaWiki's Skin.php and wikibits.js
#
# All other code is copyright © 2005 Nikola Smolenski <smolensk@eunet.yu>
#
# 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:
#
# <showhide>
# Some text (usually title) which will not be hidden __HIDER__
# <hide>Text which will be hidden</hide>
# </showhide>
#
# If <show></show> tags are used instead of <hide></hide>, the text will be
# shown by default
#
# For more information see its page at
# http://meta.wikimedia.org/wiki/ShowHide_Extension

$wgExtensionFunctions[]="wfShowHideExtension";

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

function ShowHideExtension($in)
{
	global $wgOut;
	static $numrun=0;

	$out=$wgOut->parse($in);
	if(
                strpos($out,"__HIDER__")!==FALSE &&
                ((
                        ($s=strpos($out,htmlentities("<show>")))!==FALSE &&
                        strpos($out,htmlentities("</show>"))>$s
                ) || (
                        ($h=strpos($out,htmlentities("<hide>")))!==FALSE &&
                        strpos($out,htmlentities("</hide>"))>$h
                ))
        ) {
                if($numrun==0) {
                        $wgOut->addHTML(
"<script type=\"text/javascript\"><!--
shWas=new Array();
function showSHToggle(show,hide,num) {
        if(document.getElementById) {
                document.writeln('<span class=\'toctoggle\'>[<a href=\"javascript:toggleSH('+num+')\" class=\"internal\">' +
                '<span id=\"showlink'+num+'\" style=\"display:none;\">' + show + '</span>' +
                '<span id=\"hidelink'+num+'\">' + hide + '</span>' +
                '</a>]</span>');
        }
}
function toggleSH(num) {
        var shmain = document.getElementById('showhide'+num);
        var sh = document.getElementById('shinside'+num);
        var showlink=document.getElementById('showlink'+num);
        var hidelink=document.getElementById('hidelink'+num);
        if(sh.style.display == 'none') {
                sh.style.display = shWas[num];
                hidelink.style.display='';
                showlink.style.display='none';
                shmain.className = '';
        } else {
                shWas[num] = sh.style.display;
                sh.style.display = 'none';
                hidelink.style.display='none';
                showlink.style.display='';
                shmain.className = 'tochidden';
        }
} // --></script>
");
                }
                $numrun++;

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

                $hideline = ' <script type="text/javascript">showSHToggle("' . addslashes( wfMsg('showtoc') ) . '","' . addslashes( wfMsg('hidetoc') ) . '",' . $numrun . ')</script>';

                $out=str_replace("__HIDER__","$hideline",$out);
                $out=str_replace(
                        array(htmlentities("<$act>"),                htmlentities("</$act>")),
                        array("<div id=\"shinside$numrun\">","</div>"),
                        $out
                );
		$out="<span id=\"showhide$numrun\">$out</span>";
		if($act=="hide")
			$out.="<script type=\"text/javascript\">toggleSH($numrun)</script>";
	}
	return $out;
}
?>

其他

还有其他的版本,由Austin Che编写。参见 http://austin.mit.edu/mediawiki/showhide.php.txt

原文参见: ShowHide Extension[1]

MediaWiki扩展简明教程 Inputbox帮助文档 使用Spam黑名单 内容折叠隐藏 动态文章列表 指定图片链接
代码高亮处理 预置初始编辑文本 页面访问限制 所见即所得编辑器 QQ在线信息
交流:扩展使用 投票与评分 内容随机展示 wikitex 改进设想 ...更多
加入google地图和51地图标注功能 Ajax五颗星评分插件
mediawiki图标

MediaWiki是全球最著名和最流行的开源wiki程序,运行于PHP+MySQL环境。MediaWiki从2002年2月25日被维基百科全书选用,并有大量其他应用实例。

MediaWiki功能齐备,中文支持良好,且学习资源丰富,是建立wiki网站的首选后台程序。目前国内的天下维客等站点都采用这套系统。

MediaWiki的开发得到维基媒体基金会的支持,一直保值着持续更新。目前最新版本为1.12.x。

mediawiki知识


mediawiki建站

mediawiki资源

国外站需代理访问

→ 更多mediawiki资料  相关资源:wiki知识 wiki文摘  QQ群:22134343 / 3680101-wiki建站与应用 5903157-电脑使用

Personal tools
工具
金银币拍卖 金币拍卖预展  金银币网店 熊猫金银币 生肖金银币