Benutzer:Martin Lemke/Extensions/autor
Aus Wiki der Arachnologischen Gesellschaft e. V.
Zur Navigation springenZur Suche springen
Extension autor
Die Extension autor formatiert einen übergebenen Namen in Versalien und berücksichtig dabei bestimmt Begriffe nicht.
Voreingestellt sind folgende:
- Koordinator
- Koord.
- et. al
Die Auswahl der zu ignorirenden Begriffe ist beliebig einstellbar in der Variabeln $wgExtensionAutorPreventFormattingSmappCaps, welche inder zentralen Konfigurationsdatei LocalSetting.php zu definieren ist.
Der Voreinstelleung entspricht:
$wgExtensionAutorPreventFormattingSmallCaps=array('Koord.','Koordinator','et. al');Hinweise:
- Mit dem Setzen der Variablen werden die Vorgabewerte überschrieben. Soll also beispielsweise 'et. al' erhalten bleiben, muss es mit der neuen Definition ebenfalls definiert sein.
- Groß- und Kleinschreibung wird berücksichtigt. 'et. al' und 'et. Al' ist damit nicht das selbe.
Source
<?php
/* Extension macht folgendes:
Formatieren von Autorangabe als small-caps
Geschützute Worte sind avon ausgenommen. Welche das sind, werden in sder Variablen
$wgExtensionAutorPreventFormattingSmallCaps=array() festgelegt
*/
$wgExtensionsCredits['validextensionclass'][]=
array(
'name'=>'Autor-Formatierung',
'author'=>'Martin Lemke',
//'url'=>'',
'description'=>'Formatieren von Autorangabe als small-caps mit Ausnahme bestimmter Worte'
);
if (defined('MW_SUPPORTS_PARSERFIRSTCALLINIT'))
{
$wgHooks['ParserFirstCallInit'][]='runAutor';
}
else $wgExtensionsFunctions[]='runAutor';
function runAutor() {
global $wgParser;
$wgParser->setHook('autor','FormatiereAutor');
return true;
}
function FormatiereAutor($input, $args, $parser, $frame)
{
global $wgExtensionAutorPreventFormattingSmallCaps;
if (!is_array($wgExtensionAutorPreventFormattingSmallCaps) || count($wgExtensionAutorPreventFormattingSmallCaps)==0)
$wgExtensionAutorPreventFormattingSmallCaps=array('et al.','Koord.','Koordinator');// SET DEFAULT VALUES
if (isset($args['zitat']))
$autor=$args['zitat'];
elseif (isset($args['parsein']))
$autor=$parser->recursiveTagParse($args['parsein']);
else return "<p style='color:red;'>FEHLER! <autor zitat=''/> Zitat nicht angegeben!</p>";
foreach($wgExtensionAutorPreventFormattingSmallCaps as $wort)
{
$autor=str_replace($wort, "<span style='font-variant: normal;'>$wort</span>", $autor);
}
return sprintf("<span style='font-variant: small-caps;'>%s</span>", $autor);
} # ENDE #####################