User:Paxed/SimpleTabs
Jump to navigation
Jump to search
SimpleTabs extension
Adds <simpletabs> -tag, which allows creating CSS-only tabs in an article.
<simpletabs> Tab 1 name|Contents for tab 1 |-| Tab 2 name|Contents for tab 2 |-| Tab 3 name|Contents for tab 3 </simpletabs> |
Contents for tab 1 Contents for tab 2 Contents for tab 3
|
- Tab data is separated by |-| alone in a line.
- Tab name and contents are separated by |
- Tab contents can span multiple lines and can contain wiki markup.
- Requires CSS (hiding input buttons, etc), see simpletabs in MediaWiki:Common.css.
- First tab is active by default.
Code for SimpleTabs.php
<?php
if( !defined( 'MEDIAWIKI' ) ) {
die( "This is not a valid entry point to MediaWiki.\n" );
}
$wgHooks['ParserFirstCallInit'][] = 'wfSimpleTabs';
$wgExtensionCredits['parserhook'][] = array(
'name' => 'SimpleTabs',
'version' => '0.1',
'author' => array(
'[http://nethackwiki.com/wiki/User:Paxed Pasi Kallinen]',
),
'url' => 'http://nethackwiki.com/wiki/User:Paxed/SimpleTabs',
'description' => 'Allow creating simple CSS-only tabs.',
);
function wfSimpleTabs( &$parser ) {
$parser->setHook( 'simpletabs', 'renderSimpleTabs' );
return true;
}
function renderSimpleTabs( $input, $argv, $parser, $frame ) {
/*$parser->disableCache();*/
$key = md5($input);
$tabdefs = preg_split('/\n\|-\|\s*\n/', $input);
$inputs = '';
$labels = '';
$contents = '';
$tabidx = 1;
foreach ($tabdefs as $t) {
list($tname, $tcont) = array_pad(preg_split('/\|/', $t, 2), 2, '');
$inputs .= '<input type="radio" id="tab-' . $tabidx . '" name="tab-group-' . $key . '"' . ($tabidx == 1 ? ' checked' : '') . '>';
$labels .= '<li class="tab"><label for="tab-' . $tabidx . '">' . htmlspecialchars($tname) . '</label></li>';
$contents .= '<div class="tab-content">' . $parser->recursiveTagParse($tcont, $frame) . '</div>';
$tabidx++;
}
$text = '<div id="simpletab-' . $key . '" class="simpletabs">' . $inputs .
'<ul class="tabs">' . $labels . '</ul>' .
'<div class="tabs-content">' . $contents . '</div>' .
'</div>';
return $text;
}