This repository was archived by the owner on Apr 12, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathTabber.hooks.php
77 lines (67 loc) · 1.79 KB
/
Tabber.hooks.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
/**
* Tabber
* Tabber Hooks Class
*
* @author Eric Fortin, Alexia E. Smith
* @license GPL
* @package Tabber
* @link https://www.mediawiki.org/wiki/Extension:Tabber
*
**/
class TabberHooks {
/**
* Sets up this extension's parser functions.
*
* @access public
* @param object Parser object passed as a reference.
* @return boolean true
*/
static public function onParserFirstCallInit(Parser &$parser) {
$parser->setHook("tabber", "TabberHooks::renderTabber");
return true;
}
/**
* Renders the necessary HTML for a <tabber> tag.
*
* @access public
* @param string The input URL between the beginning and ending tags.
* @param array Array of attribute arguments on that beginning tag.
* @param object Mediawiki Parser Object
* @param object Mediawiki PPFrame Object
* @return string HTML
*/
static public function renderTabber($input, array $args, Parser $parser, PPFrame $frame) {
$parser->getOutput()->addModules('ext.Tabber');
$key = md5($input);
$arr = explode("|-|", $input);
$htmlTabs = '';
foreach ($arr as $tab) {
$htmlTabs .= self::buildTab($tab, $parser, $frame);
}
$HTML = '<div id="tabber-'.$key.'" class="tabber">'.$htmlTabs."</div>";
return $HTML;
}
/**
* Build individual tab.
*
* @access private
* @param string Tab information
* @param object Mediawiki Parser Object
* @param object Mediawiki PPFrame Object
* @return string HTML
*/
static private function buildTab($tab = '', Parser $parser, PPFrame $frame) {
$tab = trim($tab);
if (empty($tab)) {
return $tab;
}
list($tabName, $tabBody) = explode('=', $tab, 2);
$tabBody = $parser->recursiveTagParse($tabBody, $frame);
$tab = '
<div class="tabbertab" title="'.htmlspecialchars($tabName).'">
<p>'.$tabBody.'</p>
</div>';
return $tab;
}
}