2014-06-17 21:37:56 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2015-04-08 10:07:01 +00:00
|
|
|
* Tabber Hooks
|
2014-06-17 21:37:56 +00:00
|
|
|
*
|
2015-04-08 10:07:01 +00:00
|
|
|
* @author Eric Fortin, Alexia E. Smith, Kris Blair
|
2014-06-17 21:37:56 +00:00
|
|
|
* @license GPL
|
|
|
|
* @package Tabber
|
|
|
|
* @link https://www.mediawiki.org/wiki/Extension:Tabber
|
2015-04-08 10:07:01 +00:00
|
|
|
*/
|
2014-06-17 21:37:56 +00:00
|
|
|
|
|
|
|
class TabberHooks {
|
|
|
|
/**
|
2015-04-08 10:07:01 +00:00
|
|
|
* Sets up this extension's parser functions
|
2014-06-17 21:37:56 +00:00
|
|
|
*
|
|
|
|
* @access public
|
2015-04-08 10:07:01 +00:00
|
|
|
* @param object Parser object passed as a reference
|
|
|
|
* @return boolean True
|
2014-06-17 21:37:56 +00:00
|
|
|
*/
|
|
|
|
static public function onParserFirstCallInit(Parser &$parser) {
|
2015-04-08 10:07:01 +00:00
|
|
|
$parser->setHook('tabber', 'TabberHooks::renderTabber');
|
2014-06-17 21:37:56 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-04-08 10:07:01 +00:00
|
|
|
* Renders the necessary HTML for a <tabber> tag
|
2014-06-17 21:37:56 +00:00
|
|
|
*
|
|
|
|
* @access public
|
2015-04-08 10:07:01 +00:00
|
|
|
* @param string The input URL between the beginning and ending tags
|
|
|
|
* @param array Array of attribute arguments on that beginning tag
|
2014-06-17 21:37:56 +00:00
|
|
|
* @param object Mediawiki Parser Object
|
|
|
|
* @param object Mediawiki PPFrame Object
|
|
|
|
* @return string HTML
|
|
|
|
*/
|
|
|
|
static public function renderTabber($input, array $args, Parser $parser, PPFrame $frame) {
|
2014-07-23 21:42:05 +00:00
|
|
|
$parser->getOutput()->addModules('ext.Tabber');
|
2014-06-17 21:37:56 +00:00
|
|
|
|
2015-04-08 10:07:01 +00:00
|
|
|
$arr = explode('|-|', $input);
|
2014-06-17 21:37:56 +00:00
|
|
|
foreach ($arr as $tab) {
|
|
|
|
$htmlTabs .= self::buildTab($tab, $parser);
|
|
|
|
}
|
|
|
|
|
2015-04-08 10:07:01 +00:00
|
|
|
$HTML = "<div class='tabber'>{$htmlTabs}</div>";
|
2014-06-17 21:37:56 +00:00
|
|
|
|
|
|
|
return $HTML;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-04-08 10:07:01 +00:00
|
|
|
* Build individual tab
|
2014-06-17 21:37:56 +00:00
|
|
|
*
|
|
|
|
* @access private
|
|
|
|
* @param string Tab information
|
|
|
|
* @param object Mediawiki Parser Object
|
|
|
|
* @return string HTML
|
|
|
|
*/
|
|
|
|
static private function buildTab($tab = '', Parser $parser) {
|
|
|
|
$tab = trim($tab);
|
|
|
|
if (empty($tab)) {
|
|
|
|
return $tab;
|
|
|
|
}
|
|
|
|
|
|
|
|
$args = explode('=', $tab);
|
|
|
|
$tabName = array_shift($args);
|
|
|
|
$tabBody = $parser->recursiveTagParse(implode('=', $args));
|
|
|
|
|
2015-04-08 10:07:01 +00:00
|
|
|
$tab = "<div class='tabbertab' title='" . htmlspecialchars($tabName) . "'>
|
|
|
|
<p>{$tabBody}</p>
|
|
|
|
</div>";
|
2014-06-17 21:37:56 +00:00
|
|
|
|
|
|
|
return $tab;
|
|
|
|
}
|
|
|
|
}
|