User:DaSch/WeCoWi.php
Appearance
This Code does not work with MW-1.16 at the moment, other version were not tested. If you know what to change to make it work please do it. |
A attempt to put
together into one
Source
[edit]<?php
$wgExtensionCredits['other'][] = array (
'path'=> __FILE__ ,
'name'=>'Web Community Wiki Mod',
'url'=>'https://sourceforge.net/apps/trac/wecowi/wiki/WeCoWi-Mod',
'description'=>'Spezielle Modifikationen der MediaWiki-Software und ihrer Erweiterungen zur besseren Nutzbarkeit. Integriert sind [http://www.mediawiki.org/wiki/Extension:NoTitle Extension:NoTitle] und [http://www.mediawiki.org/wiki/Extension:MagicNoCache Extension:MagicNoCache].',
'author'=>'[http://www.dasch-tour.de DaSch]',
'version'=>'0.4',
);
$Magic = new Magic();
$wgCustomVariables = array ('CURRENTUSER', 'LOGO', 'THUMBSIZE', 'THUMBPX', 'THUMBWIDTH');
$wgCustomMagic = array ('NOCACHE', 'NOTITLE');
$wgHooks['MagicWordMagicWords'][] = array ($Magic, 'wfAddCustomVariable');
$wgHooks['MagicWordwgVariableIDs'][] = array ($Magic, 'wfAddCustomVariableID');
$wgHooks['LanguageGetMagic'][] = array ($Magic, 'wfAddCustomVariableLang');
$wgHooks['ParserGetVariableValueSwitch'][] = array ($Magic, 'wfGetCustomVariable');
#$wgHooks['ParserBeforeTidy'][] = array($Magic, 'wfCheckForMagicWord');
class Magic
{
function Magic()
{
}
function wfAddCustomVariable( & $magicWords)
{
foreach ($GLOBALS['wgCustomVariables'] as $var)$magicWords[] = "MAG_$var";
foreach ($GLOBALS['$wgCustomMagic'] as $var)$magicWords[] = "MAG_$var";
return true;
}
function wfAddCustomVariableID( & $variables)
{
foreach ($GLOBALS['wgCustomVariables'] as $var)$variables[] = constant("MAG_$var");
foreach ($GLOBALS['$wgCustomMagic'] as $var)$variables[] = constant("MAG_$var");
return true;
}
function wfAddCustomVariableLang( & $langMagic, $langCode = 0)
{
foreach ($GLOBALS['wgCustomVariables'] as $var)
{
$magic = "MAG_$var";
$magicWords[$magic] = array (0, $var);
# $langMagic[defined($magic)?constant($magic):
# $magic] = array (0, $var);
}
foreach ($GLOBALS['$wgCustomMagic'] as $var)
{
$magic = "MAG_$var";
$magicWords[$magic] = array (0, '__'.$var.'__');
}
return true;
}
function wfGetCustomVariable( & $parser, & $cache, & $index, & $ret)
{
global $wgUser, $wgOut, $wgAction;
switch($index)
{
case MAG_CURRENTUSER:
$parser->disableCache(); # Mark this content as uncacheable
$ret = $wgUser->mName;
break;
case MAG_THUMBSIZE:
global $wgThumbLimits;
$parser->disableCache(); # Mark this content as uncacheable
$wopt = $wgUser->getOption('thumbsize');
$ret = $wgThumbLimits[$wopt];
break;
case MAG_THUMBPX:
global $wgThumbLimits;
$parser->disableCache(); # Mark this content as uncacheable
$wopt = $wgUser->getOption('thumbsize');
$ret = $wgThumbLimits[$wopt]."px";
break;
case MAG_THUMBWIDTH:
global $wgThumbLimits;
$parser->disableCache(); # Mark this content as uncacheable
$wopt = $wgUser->getOption('thumbsize');
$size = intval($wgThumbLimits[$wopt])+10;
$strsize = strval($size);
$ret = $strsize."px";
break;
case MAG_LOGO:
$ret = $GLOBALS['wgLogo'];
break;
case MAG_NOCACHE:
$mw = MagicWord::get('MAG_NOCACHE');
if (!in_array($wgAction, array('submit','edit')) && $mw->matchAndRemove($text)) {
$parser->disableCache();
$wgOut->enableClientCache(false);
}
break;
case MAG_NOTITLE:
$mw = MagicWord::get('MAG_NOTITLE');
if (!in_array($wgAction, array('submit','edit')) && $mw->matchAndRemove($text)) {
$parser->addHeadItem("<style type='text/css'>h1.firstHeading { display:none; } </style>");
}
break;
}
return true;
}
}