__FILE__,
'name' => 'SGPack',
'version' => '1.2.96',
'url' => 'http://www.stargate-wiki.de/wiki/Benutzer:Rene/SGPack',
'author' => '[http://www.stargate-wiki.de/wiki/Benutzer:Rene René Raule]',
);
$sgpCreditsDescription = array(); // place where classes put their description
// register extensions
$wgExtensionFunctions[] = 'sgpSetup'; // install classes
$wgHooks['LanguageGetMagic'][] = 'sgpMagic'; // define parser words
$wgExtensionMessagesFiles['sgpMessages'] = dirname(__FILE__) . '/SGPack.i18n.php'; // messages
// which classes are aktivated
$wgSgpBlockSpammer = true;
$wgSgpPageProtection = true;
$wgSgpDDInsert = true;
$wgSgpNewArticle = true;
$wgSgpParserAdds = true;
$wgSgpCacheArray = true;
$wgSgpSGHTML = false;
$wgSgpAddWhosOnline = true;
$wgSgpJWPlayer = true;
// Register parser-extension
function sgpSetup() {
global $wgExtensionCredits,$wgExtensionMessagesFiles,$sgpCredits,$sgpCreditsDescription;
global $wgSgpBlockSpammer,$wgSgpPageProtection,$wgSgpDDInsert,$wgSgpNewArticle,$wgSgpParserAdds,$wgSgpCacheArray,$wgSgpSGHTML,$wgSgpAddWhosOnline,$wgSgpJWPlayer;
// create all used extensions-classes
if($wgSgpBlockSpammer) new BlockSpammer();
if($wgSgpPageProtection) new PageProtection();
if($wgSgpDDInsert) new DDInsert();
if($wgSgpNewArticle) new NewArticle();
if($wgSgpParserAdds) new ParserAdds();
if($wgSgpCacheArray) new CacheArray();
if($wgSgpSGHTML) new SGHTML();
if($wgSgpJWPlayer) new JWPlayer();
if($wgSgpAddWhosOnline and function_exists('wfWhosOnline_update_data')) new AddWhosOnline();
// create wgExtensionsCredits for all classes
foreach($sgpCreditsDescription as $key => $value) { // loop all keys
$credits = $sgpCredits; // most parts are the same
$credits['description'] = wfMessage('sgpack-desc')->text(); // title for the description
$credits['description'] .= "
".implode("
",$value)."
"; // create list of descriptions
$wgExtensionCredits[$key][] = $credits; // set
}
// if($wgSgpAddWhosOnline) $wgExtensionAliasesFiles['WhosOnline'] = dirname(__FILE__) . '/WhosOnline.alias.php';
// wfLoadExtensionMessages( 'sgpMessages' ); - nicht mehr nötig
}
/* Define magic words */
function sgpMagic( &$magicWords, $langCode ) {
global $wgSgpParserAdds,$wgSgpCacheArray;
if($wgSgpCacheArray) { // CacheArray commands
$magicWords['carray'] = array( 0, 'carray' );
$magicWords['keys'] = array( 0, 'keys' );
}
if($wgSgpParserAdds) { // ParserAdds commands
$magicWords['trim'] = array( 0, 'trim' );
$magicWords['tocmod'] = array( 0, 'tocmod' );
$magicWords['userinfo'] = array( 0, 'userinfo' );
$magicWords['recursiv'] = array( 0, 'recursiv' );
$magicWords['in'] = array(0, 'in');
$magicWords['link'] = array(0, 'link');
}
return true;
}
/* Extensions-Classes
*
* Importent information how to add new classes.
* Each class must set its own hook (wgHook, wgParser->setHook or ...).
* The description must put in $sgpCreditsDescription[][].
* Set the used globalparameter $wgXYZ to default
* All this must be done in the class-constructor
*/
/* Simple Spam Blocker */
class BlockSpammer {
function __construct() {
global $wgBlockSpammerPatterns,$wgHooks,$sgpCreditsDescription,$wgBlockSpammerStayEdit;
$wgHooks['EditFilter'][] = array($this,'CheckBlockSpammer'); // register
$sgpCreditsDescription['antispam'][] = wfMessage('blockspammer-desc')->text(); // description
// Default Parameter
if(!is_array($wgBlockSpammerPatterns)) $wgBlockSpammerPatterns = explode(',',wfMessage('blockspammer-regex')->text()); // searchexpression (default no external links)
if(!isset($wgBlockSpammerStayEdit)) $wgBlockSpammerStayEdit = false; // Close Edit on Spam
}
/* Text-diff
* http://paulbutler.org/archives/a-simple-diff-algorithm-in-php/
*/
function _diff($old, $new) {
$maxlen = 0;
foreach($old as $oindex => $ovalue) {
$nkeys = array_keys($new, $ovalue);
foreach($nkeys as $nindex) {
$matrix[$oindex][$nindex] = isset($matrix[$oindex - 1][$nindex - 1]) ? $matrix[$oindex - 1][$nindex - 1] + 1 : 1;
if($matrix[$oindex][$nindex] > $maxlen) {
$maxlen = $matrix[$oindex][$nindex];
$omax = $oindex + 1 - $maxlen;
$nmax = $nindex + 1 - $maxlen;
}
}
}
if($maxlen == 0) return array(array('d'=>$old, 'i'=>$new));
return array_merge(
$this->_diff(array_slice($old, 0, $omax), array_slice($new, 0, $nmax)),
array_slice($new, $nmax, $maxlen),
$this->_diff(array_slice($old, $omax + $maxlen), array_slice($new, $nmax + $maxlen)));
}
function diff($old, $new) {
$old = str_replace(array("\r","\n"),'',$old);
$new = str_replace(array("\r","\n"),'',$new);
$aold = explode(' ',$old);
$anew = explode(' ',$new);
$d = $this->_diff($aold,$anew);
$iText = $dText = $oText = '';
foreach($d as $k) {
if(is_array($k)) {
if(!empty($k['d'])) { $dText .= implode(' ',$k['d']); }
if(!empty($k['i'])) { $iText .= implode(' ',$k['i']); }
} else {
$oText .= $k . ' ';
}
}
return array('o' => $oText,'d' => $dText,'i' => $iText);
}
function CheckBlockSpammer ($editpage,$text,$section,&$error,$sumary) {
global $wgBlockSpammerPatterns, $wgBlockSpammerStayEdit, $wgOut, $wgUser;
if($wgUser->mId == 0) {
// Only test new text = diff( content (=old) and textbox1 (=new) )
$diffs = $this->diff($editpage->getArticle()->getContent(),$editpage->textbox1);
foreach ($wgBlockSpammerPatterns as $re) { // loop all spampatterns
if (preg_match($re, $sumary.$diffs['i'],$s_matches)===1) { // test for pattern
// show error page
$wgOut->setPageTitle( wfMsg( 'spamprotectiontitle' ) );
$wgOut->setRobotPolicy( 'noindex,nofollow' );
$wgOut->setArticleRelated( false );
$wgOut->addWikiMsg( 'spamprotectiontext' );
$wgOut->addWikiMsg( 'spamprotectionmatch', "{$s_matches[0]}" );
if($wgBlockSpammerStayEdit) { // if want to stay in editor
$error = wfMessage('blockspammer-stayedit')->text(); // need to set $error
return true; // and return true
}
$wgOut->returnToMain( false, $editpage->mTitle );
return false;
}
}
}
return true;
}
}
/* Page Protection */
class PageProtection {
// buffer results from fnSGPageProtection to speed up program
private $lastResult = array();
function __construct() {
global $wgHooks,$wgParser,$sgpCreditsDescription,$wgAvailableRights;
global $wgPageProtectBlockNamespaces,$wgPageProtectOpenNamespaces,$wgPageProtectOwnerAlways,$wgGroupPermissions;
$wgHooks['userCan'][] = array($this, 'permissionTest'); // check the page permissions
$wgParser->setHook('user',array($this, 'userTag'));
$sgpCreditsDescription['parserhook'][] = wfMessage('pageprotection-desc')->text(); // description
// Default values for PageProtection
$wgAvailableRights[] = 'pageprotection';
if(!isset($wgPageProtectBlockNamespaces)) { $wgPageProtectBlockNamespaces = array(NS_USER); }
if(!isset($wgPageProtectOpenNamespaces)) { $wgPageProtectOpenNamespaces = array(NS_USER_TALK); }
if(!isset($wgPageProtectOwnerAlways)) { $wgPageProtectOwnerAlways = true; }
if(!isset($wgGroupPermissions['sysop']['pageprotection'])) { $wgGroupPermissions['sysop']['pageprotection'] = true; }
}
// Handel user-tags, just drop them
function userTag($input,$argv,$parser) {
return '';
}
function permissionTest( $title, $user, $action, &$result ) {
global $wgPageProtectBlockNamespaces,$wgPageProtectOpenNamespaces,$wgPageProtectOwnerAlways,$wgGroupPermissions;
// if this article was already testet for this action just give the result
if(isset($this->lastResult[$title->getText()][$action])) { return $this->lastResult[$title->getText()][$action]; }
// Name of actual user
$username = $user->getName();
/* do nothing if ...
... usergroup is free */
if( $user->isAllowed('pageprotection') ) {
$this->lastResult[$title->getText()][$action] = true;
return true;
}
// ... wrong namespace
if( !in_array($title->mNamespace,array_merge($wgPageProtectBlockNamespaces,$wgPageProtectOpenNamespaces)) ) {
$this->lastResult[$title->getText()][$action] = true;
return true;
}
// ... action not edit or move
if( !($action == 'edit' || $action == 'move') ) {
$this->lastResult[$title->getText()][$action] = true;
return true;
}
// ... user is owner of article and ownerflag is set (only in USER & USER_TALK namespaces)
if( ($title->mNamespace == NS_USER) || ($title->mNamespace == NS_USER_TALK) ) {
// get user name, title and get user part out of title
$fulltitle = $title->getText();
list($usertitle,$subtitle) = explode('/',$fulltitle,2);
if( $wgPageProtectOwnerAlways && ($usertitle == $username) ) {
$this->lastResult[$title->getText()][$action] = true;
return true;
}
}
/* simple checks are over now, look for user-tags in article content */
// get article (? can we find it already somewhere ?)
$article = new Article($title);
$text = $article->fetchContent(0);
// drop xxx parts
$expr = '/(.*?)<\s*nowiki\s*>(?s).*?<\/\s*nowiki\s*>(.*?)/i';;
$replace = '$1';
$text = preg_replace($expr,$replace,$text);
// look for **
if( preg_match("/<\s*user\s*>\s*\*\*\s*<\/\s*user\s*>/",$text) > 0 ) {
$this->lastResult[$title->getText()][$action] = true;
return true;
}
if( $user->mId != 0 ) { // normal user
// look for $username
if( preg_match("/<\s*user\s*>\s*$username\s*<\/\s*user\s*>/",$text) > 0 ) {
$this->lastResult[$title->getText()][$action] = true;
return true;
}
// look for *
if( preg_match("/<\s*user\s*>\s*\*\s*<\/\s*user\s*>/",$text) > 0 ) {
$this->lastResult[$title->getText()][$action] = true;
return true;
}
}
// if open namespaces and no user-tag is defined
if( in_array($title->mNamespace,$wgPageProtectOpenNamespaces) && preg_match("/<\s*user\s*>.*<\/\s*user\s*>/",$text) == 0 ) {
$this->lastResult[$title->getText()][$action] = true;
return true;
}
/* Nothing matched so the result ist NOT ALLOWED */
$this->lastResult[$title->getText()][$action] = false;
$result = false;
return false;
}
}
/* DropDownInsert */
class DDInsert {
private $ddIBlock = array();
private $ie9_start = "sgp_x = window.pageXOffset; sgp_y = window.pageYOffset;";
private $ie9_ende = "window.scrollTo(sgp_x,sgp_y);";
function __construct() {
global $wgParser,$sgpCreditsDescription,$wgSgpUseIE9Hack;
$wgParser->setHook('jsbutton',array($this,'JSButton'));
$wgParser->setHook('ddselect',array($this,'ddISelect'));
$wgParser->setHook('ddvalue',array($this,'ddIValue'));
$wgParser->setHook('ddbutton',array($this,'ddIButton'));
$sgpCreditsDescription['parserhook'][] = wfMessage('ddinsert-desc')->text(); // description
if(!isset($wgSgpUseIE9Hack)) $wgSgpUseIE9Hack = false;
}
// JSButton
function JSButton($input,$argv,$parser,$frame) {
global $wgVersion;
$param = 'type="button"';
$param .= isset($argv['name']) ? ' name = "'.$argv['name'].'"' : 'name = "jsbutton"';
$param .= isset($argv['id']) ? ' id = "'.$argv['id'].'"' : '';
$param .= isset($argv['value']) ? ' value = "'.$argv['value'].'"' : '';
$param .= isset($argv['class']) ? ' class = "'.$argv['class'].'"' : 'class = "jsbutton"';
$param .= isset($argv['style']) ? ' style = "'.$argv['style'].'"' : '';
$param .= isset($argv['click']) ? ' onclick = "'.$argv['click'].'"' : '';
$param .= isset($argv['mover']) ? ' onmouseover = "'.$argv['mover'].'"' : '';
$param .= isset($argv['mout']) ? ' onmouseout = "'.$argv['mout'].'"' : '';
return '';
}
// button
function ddIButton($input,$argv,$parser) {
global $wgSgpUseIE9Hack;
// if no show parameter is given use input also as showText
$show = isset($argv['show']) ? htmlspecialchars($argv['show']) : $input;
// get sampleText if given
$sample = isset($argv['sample']) ? $argv['sample'] : '';
// picture
if(isset($argv['picture'])) {
$image = wfFindFile($argv['picture']);
if($image) {
$iwidth = $image->getWidth();
$iheight = $image->getHeight();
$show = '';
}
}
$einput = explode('+',htmlspecialchars($input,ENT_QUOTES,'UTF-8')); // split parameter
$einput[] = ''; $einput[] = ''; // default set parameter to empty
$output = 'ie9_start;
$output .= 'insertTags(\''.$einput[0].'\',\''.$einput[1].'\',\''.$sample.'\');';
if($wgSgpUseIE9Hack) $output .= $this->ie9_ende;
$output .= 'return false;"';
$output .= '>'.$show.'';
return $output;
}
// Create Output
function ddIOutput() {
global $wgSgpUseIE9Hack;
$cssimage = '';
$output = '';
$output .= '";
return $output;
}
// ...
function ddISelect($input,$argv,$parser) {
$this->ddIBlock = array('size'=>1,'name'=>'Auswahl','title'=>wfMessage('ddinsert-selecttitle'),'pwidth'=>0,'pheight'=>1,'values'=>array());
if(isset($argv['title'])) {
$this->ddIBlock['title'] = $argv['title'];
}
if(isset($argv['size'])) {
$this->ddIBlock['size'] = $argv['size'];
}
if(isset($argv['name'])) {
$this->ddIBlock['name'] = $argv['name'];
}
$parser->recursiveTagParse($input);
return $this->ddIOutput();
}
// value
function ddIValue($input,$argv,$paser) {
// if no show parameter is given use input also as showText
$show = isset($argv['show']) ? $argv['show'] : $input;
// get sampleText if given
$sample = isset($argv['sample']) ? $argv['sample'] : '';
// add + to input if not set - need for javascript-split
if(strpos($input,"+") === false) {
$input .= "+";
}
// picture
$iURL = '';
if(isset($argv['picture'])) {
$image = wfFindFile($argv['picture']);
if($image) {
$iURL = $image->getURL();
$iwidth = $image->getWidth();
$iheight = $image->getHeight();
if($iwidth > ($this->ddIBlock['pwidth']-5)) {
$this->ddIBlock['pwidth'] = $iwidth+5;
}
if($iheight > ($this->ddIBlock['pheight'])) {
$this->ddIBlock['pheight'] = $iheight;
}
}
}
// save parameter to global array
$this->ddIBlock['values'][] = array('value'=>$input.'+'.$sample,'text'=>$show,'image'=>$iURL);
return '';
}
// create option line
function ddILine($text,$value,$image) {
if($this->ddIBlock['pwidth'] > 0) {
if(!empty($image)) {
$css = 'style="height: '.$this->ddIBlock['pheight'].'px; padding-left: '.$this->ddIBlock['pwidth'].'px; padding-right: 5px; background-repeat: no-repeat; background-image: url('.$image.');"';
} else {
$css = 'style="padding-left: '.$this->ddIBlock['pwidth'].'px; padding-right: 5px;"';
}
} else {
$css = '';
}
$output = ''."\n";
// $output = ''."\n";
return $output;
}
}
/* Template for new Article */
class NewArticle {
private $ie9_start = "sgp_x = window.pageXOffset; sgp_y = window.pageYOffset;";
private $ie9_ende = "window.scrollTo(sgp_x,sgp_y);";
function __construct() {
global $wgHooks,$sgpCreditsDescription,$wgSgpUseIE9Hack;
$wgHooks['AlternateEdit'][] = array($this,'NewArticle');
$sgpCreditsDescription['other'][] = wfMessage('newarticle-desc')->text(); // description
if(!isset($wgSgpUseIE9Hack)) $wgSgpUseIE9Hack = false;
}
// Umwandeln einer Zeichenkette fuer die JS Funktion unescape()
function JSencode($text) {
// return rawurlencode(utf8_decode($text));
$revert = array('%21'=>'!','%2A'=>'*','%27'=>"'",'%28'=>'(','%29'=>')');
return strtr(rawurlencode($text),$revert);
//return rawurlencode(html_entity_decode(htmlentities($text,ENT_QUOTES,'UTF-8')));
}
/* Filter des Artikels, noinclude Bereiche entfernen */
function FilterPage($text) {
// Bereiche komplett entfernen
$expr = '/(.*)(?s).*<\/noinclude>(.*)/';
$replace = '$1$2';
$text = preg_replace($expr,$replace,$text);
// , einfach entfernen
$expr = '/(.*)|<\/includeonly>(.*)/';
$replace = '$1$2';
$text = preg_replace($expr,$replace,$text);
return $text;
}
function NewArticle($seite) {
global $wgOut,$wgParser,$wgSgpUseIE9Hack;
// Pruefen ob der Artikel neu ist
if( !$seite->mArticle->exists() ) {
// Steuerseite einlesen "MediaWiki:NewArticle-NS"
$steuer = new Article(Title::makeTitle(8,'NewArticle-'.$seite->mTitle->mNamespace));
$steuer->getContent();
// Pruefen ob Steuerseite vorhanden
if( $steuer->mContentLoaded ) {
// Ausgabe Puffer Variablen anlegen
$html = ''; $jscript = ''; $idNr = 0;
// Seite parsen
$text = $wgParser->parse($steuer->fetchContent(),$steuer->mTitle,new ParserOptions());
// Definition der Auswahlliste(n) herrauslösen
$teile = preg_split('/(\[\[\[.*?\]\]\])/s',$text->mText,-1,PREG_SPLIT_NO_EMPTY|PREG_SPLIT_DELIM_CAPTURE);
foreach($teile as $teil) {
// Wenn Auswahlliste [[[...]]]
if(substr($teil,0,3) == '[[[' and substr($teil,-3,3) == ']]]') {
$teil = substr($teil,3,count($teil)-4); // Klammern entfernen
$tarray = explode(',',$teil);
// Nur ein Argument -> Button statt Liste
if(count($tarray) == 1) {
$idNr += 1;
$zeile = explode('|',$tarray[0]); $zeile[] = ''; $zeile[] = '';
// Artikel einlesen umwandeln und im HTML Code ablegen
$artikel = new Article(Title::makeTitle(10,trim($zeile[0])));
$artikel->getContent();
if($artikel->mContentLoaded) {
$onclick = '';
if($wgSgpUseIE9Hack) $onclick .= $this->ie9_start;
$onclick .= "insertTags('',decodeURIComponent('".$this->JSencode($this->FilterPage($artikel->fetchContent()))."'),'');";
if($wgSgpUseIE9Hack) $onclick .= $this->ie9_ende;
$html .= '\n";
}
unset($artikel);
}
if(count($tarray) > 1) {
$idNr += 1;
// Das JS zum einfügen
$jscript = '\n";
$html .= '';
}
} else { // Sonstigen Text nur übernehmen
$html .= $teil;
}
}
// Ergebniss in die Ausgabe einfuegen
$wgOut->addHTML($jscript.$html);
}
}
return true;
}
}
/* Addon for WhosOnline */
class AddWhosOnline {
function __construct() {
global $wgHooks,$sgpCreditsDescription,$wgSpecialPageGroups;
$wgSpecialPageGroups['WhosOnline'] = 'users';
$wgHooks['UserLogout'][] = array($this,'logOut');
$wgHooks['PersonalUrls'][] = array($this,'PersonalUrls');
$sgpCreditsDescription['other'][] = wfMessage('addwhosonline-desc')->text(); // description
}
// New Personal Tabs
function PersonalUrls(&$personal_urls, &$title) {
$sp = Title::makeTitle(NS_SPECIAL,'WhosOnline'); // title of the whosonline specialpage
if( $title->mNamespace != NS_SPECIAL or SpecialPage::getTitleFor('WhosOnline',false)->mTextform != $title->mTextform ) { // be sure we are not on the specialpage
$a['online'] = array('text' => wfMessage('addwhosonline-pmenu')->text(),'href' => $sp->getLocalURL());
array_splice($personal_urls,-1,0,$a); // place new item(s) on second last position
}
return true;
}
function logOut( &$user ) {
global $wgDBname;
$db = wfGetDB( DB_MASTER );
$db->selectDB( $wgDBname );
$db->delete('online', array('userid = '.$user->mId),__METHOD__);
return true;
}
}
/* ParserAdds */
class ParserAdds {
function __construct() {
global $wgParser,$sgpCreditsDescription;
$wgParser->setFunctionHook( 'trim', array($this,'trim') , SFH_NO_HASH );
$wgParser->setFunctionHook( 'userinfo', array($this,'userinfo') , SFH_NO_HASH );
$wgParser->setFunctionHook( 'in', array($this,'in') );
$wgParser->setFunctionHook( 'tocmod', array($this,'tocmod') );
$wgParser->setFunctionHook( 'recursiv', array($this,'recursiv') );
$wgParser->setFunctionHook( 'link', array($this,'link') );
$sgpCreditsDescription['parserhook'][] = wfMessage('parseradds-desc'); // description
}
function link( &$parser, $rel = '', $page = '', $title = '') {
global $wgOut;
if( empty($rel) ) return ''.wfMsgForContent('parseradds_link_norel').'';
if( empty($page) ) return ''.wfMsgForContent('parseradds_link_nopage').'';
if( empty($title) ) $title = $page;
if( !($pt = Title::newFromText($page)) ) return ''.wfMsgForContent('parseradds_link_illegalpage').'';
if( $pt->exists() ) $wgOut->addLink(array('rel' => $rel, 'title' => $title, 'href' => $pt->getFullURL()));
return '';
}
/* in - ermittelt ob ein oder mehrere Werte in einer Menge enthalten sind
* $element: Wert(e) die gesucht werden. Mehrere Werte müssen durch $trenn getrennt werden
* $menge: Menge von Elementen, getrennt durch $trenn
* $trenn: Trennzeichen, default = ','
* $modus: Art der Suche. 'a' - Alle Elemente, 'e' - Ein Element
* $result: Rückgabe bei Erfolg bzw. Misserfolg durch $trenn getrennt
* Rückgabe: Gefundene Elemente oder Leer
*/
function in( &$parser, $element = '', $menge = '',$trenn = ',',$modus = 'a', $result = '' ) {
// Parameter prüfen
if( empty($trenn) ) { $trenn = ','; }
if( empty($modus) ) { $modus = 'a'; }
// Variablen vorbereiten
$back = '';
// Listen in Arrays umwandeln
$result = explode($trenn,$result);
$aelement = explode($trenn,$element);
$amenge = explode($trenn,$menge);
// Prüfen ob alle Elemente in der Menge
if( $modus == 'a' ) {
$count = count($aelement);
foreach( $aelement as $wert ) {
if( in_array($wert,$amenge) ) {
$count -= 1;
}
}
// Alle Elemente gefunden wenn Zähler auf Null
if( $count == 0 ) {
$back = $element;
}
}
// Prüfen ob ein Element in der Menge
if( $modus == 'e' or $modus == 's' ) {
foreach( $aelement as $wert) {
if( in_array($wert,$amenge) ) {
$back .= (empty($back) ? '' : $trenn).$wert;
}
}
}
// Prüfen ob spezielle Rückgabe erforderlich
if( empty($back) ) {
if( isset($result[1]) ) {
$back = $result[1];
}
} else {
if( !empty($result[0]) ) {
$back = $result[0];
}
}
return array($back, 'noparse' => true);
}
// trim
function trim( &$parser, $inStr='') {
return array(trim($inStr),'noparse'=>true);
}
function tocmod( &$parser, $inPara='', $Default='set') {
global $wgOut;
//$parser->disableCache();
$back = '';
if(empty($inPara)) $inPara = $Default;
$arPara = explode(',',$inPara);
foreach($arPara as $para) {
switch(strtolower($para)) {
case 'no' : $back .= '__NOTOC__';
break;
case 'set' : $back .= '__TOC__';
break;
case 'hide' :
// $wgOut->addInlineScript("function tocHide() { if(document.getElementById('toc')) { var toc = document.getElementById('toc').getElementsByTagName('ul')[0]; var toggleLink = document.getElementById('togglelink'); if(toc.style.display != 'none') { changeText(toggleLink, tocShowText); toc.style.display = 'none'; }}} addOnloadHook(tocHide);");
/*$wgOut->addInlineScript("$(function() {
var $tocList = $('#toc ul:first');
if($tocList.length()) {
if(!$tocList.is(':hidden')) {
util.toggleToc($('#togglelink'));
}
}
});");*/
break;
case 'show' :
// $wgOut->addInlineScript("function tocShow() { if(document.getElementById('toc')) { var toc = document.getElementById('toc').getElementsByTagName('ul')[0]; var toggleLink = document.getElementById('togglelink'); if(toc.style.display != 'block') { changeText(toggleLink, tocHideText); toc.style.display = 'block'; }}} addOnloadHook(tocShow);");
break;
case 'force' : $back .= '__FORCETOC__';
break;
}
}
return array($back,'found'=>true);
}
//
function userinfo( &$parser, $inStr='name', $inPara='') {
global $wgUser,$wgDBname;
$parser->disableCache();
$back = '';
$user = $wgUser;
switch(strtolower($inStr)) {
case 'name' : $back = $user->mName;
break;
case 'id' : $back = $user->mId;
break;
case 'realname' : $back = $user->mRealName;
break;
case 'email' :
if( !empty($inPara) ) {
$user = User::NewFromName($inPara);
if( $user === false ) return ''.wfMsgForContent('parseradds_userinfo_illegal').'';
}
$back = $user->mEmail;
break;
case 'skin' : $back = $user->getSkin()->skinname;
break;
case 'home' :
if( !empty($inPara) ) {
$user = User::NewFromName($inPara);
if( $user === false ) return ''.wfMsgForContent('parseradds_userinfo_illegal').'';
}
$back = '[['.$user->getUserPage()->getFullText().']]';
break;
case 'talk' :
if( !empty($inPara) ) {
$user = User::NewFromName($inPara);
if( $user === false ) return ''.wfMsgForContent('parseradds_userinfo_illegal').'';
}
$back = '[['.$user->getUserPage()->getTalkNsText().$wgUser->mName.']]';
break;
case 'groups' : $back = implode(",",$wgUser->mGroups);
break;
case 'group' : $back = in_array($inPara,$wgUser->mGroups) ? $inPara : '';
break;
case 'browser' :
$back = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : "undefined";
if( !empty($inPara) ) {
if( FALSE === strpos($back,$inPara) ) {
$back = '';
} else {
$back = $inPara;
}
}
break;
case 'online' :
if(function_exists('wfWhosOnline_update_data')) {
$db = wfGetDB( DB_SLAVE );
$db->selectDB( $wgDBname );
$res = $db->selectField('online',array('count(*)'),array('username' => $inPara));
$back = $res == '1' ? 'online' : 'offline';
} else {
$back = 'unknown';
}
break;
}
return array($back,'noparse'=>true);
}
/* Vorlage mehrfach aufrufen
* Alle Ausdrücke in () werden an die Vorlage "calltemplate" übergeben.
* Weitere Parameter "callparameter" werden ebenfalls übergeben.
* Ausdrücke in [[]] werden nicht beachtet
*/
function recursiv( &$parser, $calltemplate = '', $parstext = '', $callparameter = '' ) {
// Weitere Übergabeparameter vorbereiten
if(!empty($callparameter)) { $callparameter = '|'.$callparameter; }
$output = '';
// Text aufspalten in geklammerte und nicht geklammerte Teile, Elemente in [[]] werden nicht beachtet
$split = preg_split('/(\[\[.*?\]\]|\(.*?\))/i',$parstext,-1,PREG_SPLIT_NO_EMPTY|PREG_SPLIT_DELIM_CAPTURE);
// Sonderfall ein Element
if(count($split) == 1) {
$para = $parstext;
if($para[0] == '(' and $para[strlen($para)-1] == ')') {
$para = substr($para,1,strlen($para)-2); // "Ausklammern"
}
$output = '{{'.$calltemplate.'|'.$para.$callparameter.'}}'; // Erzeuge Anfrage
} else {
// Alle Elemente parsen
foreach($split as $para) {
if($para[0] == '(' and $para[strlen($para)-1] == ')') {
$sub = substr($para,1,strlen($para)-2); // "Ausklammern"
$ask = '{{'.$calltemplate.'|'.$sub.$callparameter.'}}'; // Erzeuge Anfrage
$result = $parser->recursiveTagParse($ask);
// Wenn Ergebniss == leer oder == Anfrage dann kennt die Vorlage den Paranmeter nicht
if(empty($result) or $result == $sub) {
$output .= $para; // Eingabe 1:1 in Ausgabe einfügen
} else {
$output .= $ask; // Ersetze Ausdruck durch Vorlage
}
} else { // Kein Klammerausdruck
$output .= $para; // Eingabe 1:1 in Ausgabe einfügen
}
}
}
return array($output,'noparse'=>false);
}
}
/* Cache Array */
class CacheArray {
private $Cache = array();
private $Key_Delimiter = '_';
function __construct() {
global $wgParser,$sgpCreditsDescription;
$wgParser->setFunctionHook( 'carray', array($this,'carray'), SFH_NO_HASH);
$wgParser->setFunctionHook( 'keys', array($this,'keys'), SFH_NO_HASH );
$sgpCreditsDescription['parserhook'][] = wfMessage('cachearray-desc'); // description
}
// combinate keys
function keys() {
// get the parser parameter
$param = func_get_args();
$parser = current($param);
// get the parts for the key
$key = '';
while($value = next($param)) {
// get key-modifier(s) m:key
$mod = explode(':',$value,2);
// if count(mod[]) == 2 means we also have modifier
if(count($mod) == 2) {
$value = $mod[1];
if(strpos($mod[0],'u')!==false) { // uppercase
$value = strtoupper($value);
}
if(strpos($mod[0],'l')!==false) { // lowercase
$value = strtolower($value);
}
} else {
$value = $mod[0];
}
// keys always trim
$value = trim($value);
// drop empty mw-variables
$value = preg_replace('/\{\{\{.*?\}\}\}/','',$value);
// if value is not empty add to key
if(!empty($value)) {
if(!empty($key)) {
$key .= $this->Key_Delimiter;
}
$key .= $value;
}
}
return $key;
}
// carray main part
function carray() {
// minimum parser, cachenumber and action are needed
if(func_num_args() < 3) {
return array('','noparse'=>true);
}
// get the parser parameter
$param = func_get_args();
$parser = current($param);
// get the first two wiki-parameters (chachenumber, action)
$cnumber = trim(next($param));
$action = strtolower(trim(next($param)));
// default output is empty
$output = '';
// action
switch($action) {
case 'f' :
case 'file' :
case 'fr' :
case 'fileread' :
// read array out of "file"
$file = next($param);
// if carray is already set do not read it again (cache!)
if(!isset($this->Cache[$cnumber])) {
$fh = new Article(Title::newFromText($file));
$content = $fh->fetchContent();
if($fh->mContentLoaded) {
$cont = explode('|',$content);
foreach($cont as $line) {
$sp = explode('=',$line,2);
if(count($sp) == 2) {
$this->Cache[$cnumber][trim($sp[0])] = trim($sp[1]);
}
}
}
}
// leave switch (only if file)
if(($action === 'f') or ($action === 'file')) {
break;
}
// read key
$key = trim(next($param));
// read cache, if no value, look for default
if(isset($this->Cache[$cnumber][$key])) {
$output = $this->Cache[$cnumber][$key];
} else {
if(isset($this->Cache[$cnumber]['#default'])) {
$output = str_replace('{{K}}',$key,$this->Cache[$cnumber]['#default']);
}
}
break;
case 'w' : // only create new carray
case 'write' :
case 'rw' : // write new carray and read one value
case 'readwrite' :
// read key (only if readwrite)
if(($action === 'rw') or ($action === 'readwrite')) {
$key = trim(next($param));
}
// if carray is already set do not read it again (cache!)
if(!isset($this->Cache[$cnumber])) {
// read the keys and values and save in carray
while($values = next($param)) {
$sp = explode('=',$values,2);
if(count($sp) == 2) {
$this->Cache[$cnumber][trim($sp[0])] = trim($sp[1]);
}
}
}
// leave switch (only if write)
if(($action === 'w') or ($action === 'write')) {
break;
}
case 'r' : // read value out of carray
case 'read' :
// read key, if not already set by action readwrite
if(!isset($key)) {
$key = trim(next($param));
}
// read cache, if no value, look for default
if(isset($this->Cache[$cnumber][$key])) {
$output = $this->Cache[$cnumber][$key];
} else {
if(isset($this->Cache[$cnumber]['#default'])) {
$output = str_replace('{{K}}',$key,$this->Cache[$cnumber]['#default']);
}
}
break;
case 'd' : // delete carray
case 'delete' :
unset($this->Cache[$cnumber]);
break;
case 'c' : // count elements in carray
case 'count' :
$output = count($this->Cache[$cnumber]);
break;
case 'u' : // test if cache is used
case 'used' :
// if carray is used give size
if(isset($this->Cache[$cnumber])) {
$output = count($this->Cache[$cnumber]);
}
break;
}
return array($output,'noparse'=>false);
}
}
class JWPlayer {
function __construct() {
global $wgParser,$sgpCreditsDescription;
$wgParser->setHook('vplayer',array($this,'VideoPlayer'));
$wgParser->setHook('aplayer',array($this,'AudioPlayer'));
$sgpCreditsDescription['parserhook'][] = 'JWPlayer: Video-/Audio-Player - neue Version noch nicht freigegeben!'; // description
}
// Audioplayer jPlayer
function AudioPlayer( $file, $args, $parser, $frame ) {
}
// Videoplayer
function VideoPlayer($file, $args, $parser, $frame ) {
//var_dump($frame->numberedExpansionCache);
$frame->numberedExpansionCache[1] = 'Neuer Wert';
$frame->numberedExpansionCache[2] = 'Neue Variable';
//var_dump($frame->namedExpansionCache);
//return "";
// $file = $parser->recursiveTagParse( $file, $frame );
$args['width'] = isset($args['width']) ? $args['width'] : 250;
$args['height'] = isset($args['height']) ? $args['height'] : 200;
return array($this->CreateOutput($file, $args),'noparse'=>true,'isHTML'=>true);
}
function CreateOutput($file,$args) {
global $wgOut;
$width = $args['width'];
$height = $args['height'];
/* $out = "";
$out .= '';
$wgOut->addInlineScript("");
*/
$wgOut->addInlineStyle("#container_wrapper {display: inline-block;}");
$out="";
$wgOut->addInlineScript("
jwplayer('container').setup({ flashplayer: '/mw/extensions/SGPack/jwplayer/player.swf',
file: 'http://www.stargate-wiki.de/w/images/0/05/Captain_Samantha_Carter.mp3',
height: 12,
width: 400,
controlbar: 'bottom',
onplay: function(event) { jwplayer('container').resize(300,12); jwplayer('container').getPlugin('controlbar').hide(); },
}); jwplayer('container').getPlugin('controlbar').show(); jwplayer('container').resize(24,12);
"); // 'http://www.youtube.com/watch?v=aDO0rlwEjnQ',
/* $out = "\n";
$out .= "
This text will be replaced
\n";
$out .= "\n";*/
return $out;
}
}
/* Modify HTML page */
class SGHTML {
private $isSpoiler = false;
function __construct() {
global $wgHooks,$sgpCreditsDescription;
$wgHooks['OutputPageBeforeHTML'][] = array($this,'SGHtml');
$wgHooks['BeforePageDisplay'][] = array($this,'fnSGHtmlBPD');
$sgpCreditsDescription['other'][] = wfMessage('sghtml-desc');; // description
}
// Last updates before page display
function fnSGHtmlBPD(&$out) {
$keywords = wfMessage('sghtml-keywords'); // get keywords
if( $keywords != '' ) { // test if keywords are defined
$out->addMeta('keywords',$keywords);
// foreach($keywords as $word) $out->addKeyword($word); // put keywords
}
return true;
}
function SGHtml( &$out, &$text ) {
global $wgSGHTMLImageTop,$wgSGHTMLImageEdit;
// Jump to Top, Edit-Image
$suchen = array('