설치한 확장기능

From XFwiki
(Difference between revisions)
Jump to: navigation, search
(# 오늘의 명언)
Line 1: Line 1:
  
  
 +
== 엑파위키에 설치한 확장기능 모음 ==
  
=== 엑파위키에 설치한 확장기능 모음 ===
 
  
 
+
=== # 오늘의 명언 (문장이 무작위로 나옴) ===
==== # 오늘의 명언 (문장이 무작위로 나옴) ====
+
  
 
http://www.mediawiki.org/wiki/Extension:RandomSelection
 
http://www.mediawiki.org/wiki/Extension:RandomSelection
Line 118: Line 117:
 
</pre>
 
</pre>
  
==== # ShowHide (글 접었다 펴기) ====
+
 
 +
 
 +
 
 +
=== # ShowHide (글 접었다 펴기) ===
  
 
http://www.mediawiki.org/wiki/Extension:ShowHide
 
http://www.mediawiki.org/wiki/Extension:ShowHide

Revision as of 11:56, 17 October 2009


엑파위키에 설치한 확장기능 모음

# 오늘의 명언 (문장이 무작위로 나옴)

http://www.mediawiki.org/wiki/Extension:RandomSelection


<choose>
<option>"차는 미안해요." - 멀더 ([[XFeature02|극장판 2]])</option>
<option>핸드폰은 필요할 때면 안 터진다.</option>
<option>세기말이란 또다른 쓰레기같은 천년이 시작하는 것. - 호세 청([[mlm209]])</option>
<option>배우는 한 역을 하고 나면 다른 역을 위해 자신을 비워야 한다. - 서혜정</option>
<option>도겟: 키는 180 정도... (다들: 정말?)</option>
<option>우리는 우리가 아니다. ([[1X07]])</option>
<option>우선은 가장 많이 찍을 장소를 결정합니다. - 우린 이걸 이물(船首, 뱃머리)과 고물(船尾, 뱃꼬리)라고 부르는데 - 주 촬영장소를 발견하고 나서 꼬리 부분을 마저 결정하는 거죠. - 일트 존스 (장소섭외자)</option>
<option>"멀더는 나의 등대에요." - 스컬리 ([[7X04]])</option>
</choose>

Code

The code in this page will only work in MediaWiki 1.7 and above. (Alternate version for 1.5 and above)

<?php
/**
 * RandomSelection -- randomly displays one of the given options.
 * Usage: <choose><option>A</option><option>B</option></choose>
 * Optional parameter: <option weight="3"> == 3x weight given
 *
 * @file
 * @ingroup Extensions
 * @version 2.1.4
 * @date 30 September 2009
 * @author Ross McClure <http://www.mediawiki.org/wiki/User:Algorithm>
 * @link http://www.mediawiki.org/wiki/Extension:RandomSelection Documentation
 */
 
if( !defined( 'MEDIAWIKI' ) ) {
	die( "This is not a valid entry point to MediaWiki.\n" );
}
 
// Avoid unstubbing $wgParser on setHook() too early on modern (1.12+) MW versions, as per r35980
if( defined( 'MW_SUPPORTS_PARSERFIRSTCALLINIT' ) ) {
	$wgHooks['ParserFirstCallInit'][] = 'wfRandomSelection';
} else {
	$wgExtensionFunctions[] = 'wfRandomSelection';
}
 
$wgExtensionCredits['parserhook'][] = array(
	'name' => 'RandomSelection',
	'version' => '2.1.4',
	'author' => 'Ross McClure',
	'description' => 'Displays a random option from the given set.',
	'url' => 'http://www.mediawiki.org/wiki/Extension:RandomSelection',
);
 
function wfRandomSelection() {
	global $wgParser;
	$wgParser->setHook( 'choose', 'renderChosen' );
	return true;
}
 
function renderChosen( $input, $argv, &$parser ) {
	# Prevent caching
	$parser->disableCache();
 
	# Parse the options and calculate total weight
	$len = preg_match_all( "/<option(?:(?:\\s[^>]*?)?\\sweight=[\"']?([^\\s>]+))?"
		. "(?:\\s[^>]*)?>([\\s\\S]*?)<\\/option>/", $input, $out );
	$r = 0;
	for( $i = 0; $i < $len; $i++ ) {
		if( strlen( $out[1][$i] ) == 0 )
			$out[1][$i] = 1;
		else
			$out[1][$i] = intval( $out[1][$i] );
		$r += $out[1][$i];
	}
 
	# Choose an option at random
	if( $r <= 0 )
		return '';
	$r = mt_rand( 1, $r );
	for( $i = 0; $i < $len; $i++ ) {
		$r -= $out[1][$i];
		if( $r <= 0 ) {
			$input = $out[2][$i];
			break;
		}
	}
 
	# If running new parser, take the easy way out
	if( defined( 'Parser::VERSION' ) && version_compare( Parser::VERSION, '1.6.1', '>' ) ) {
		return $parser->recursiveTagParse( $input );
	}
 
	# Otherwise, create new parser to handle rendering
	$localParser = new Parser();
 
	# Initialize defaults, then copy info from parent parser
	$localParser->clearState();
	$localParser->mTagHooks         = $parser->mTagHooks;
	$localParser->mTemplates        = $parser->mTemplates;
	$localParser->mTemplatePath     = $parser->mTemplatePath;
	$localParser->mFunctionHooks    = $parser->mFunctionHooks;
	$localParser->mFunctionSynonyms = $parser->mFunctionSynonyms;
 
	# Render the chosen option
	$output = $localParser->parse( $input, $parser->mTitle,
					$parser->mOptions, false, false );
	return $output->getText();
}



# ShowHide (글 접었다 펴기)

http://www.mediawiki.org/wiki/Extension:ShowHide

Source

Helpful hint: the copyright symbol and the script tags are messing up the display. Edit this page to copy the code! --Bytesmiths 03:14, 20 December 2005 (UTC)

v 0.1.1

PHP5 version with corrections according to Smerf's comments.

   Note the following version does not work correctly for me on MediaWiki 1.5. The following will work correctly on the first load, but after loading from cache, the one-time Javascript code inserted by $wgOut->addHtml does not get added leading to problems. v.0.1 above works fine for me.

<?php
# MediaWiki 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://www.mediawiki.org/wiki/Extension:ShowHide

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


Personal tools
Namespaces

Variants
Actions
원전
팬활동
1013 Production
기타
그리고
Toolbox