2019-05-14 18:59:33 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2021-06-21 23:48:07 +00:00
|
|
|
* TabberNeue
|
|
|
|
* TabberNeue Hooks Class
|
2019-05-14 18:59:33 +00:00
|
|
|
*
|
2021-06-21 23:48:07 +00:00
|
|
|
* @package TabberNeue
|
2021-06-21 23:55:06 +00:00
|
|
|
* @author alistair3149, Eric Fortin, Alexia E. Smith
|
2021-06-21 23:48:07 +00:00
|
|
|
* @license GPL-3.0-or-later
|
|
|
|
* @link https://www.mediawiki.org/wiki/Extension:TabberNeue
|
2021-06-21 23:56:28 +00:00
|
|
|
*/
|
2019-05-14 18:59:33 +00:00
|
|
|
|
2021-10-01 16:20:00 +00:00
|
|
|
declare( strict_types=1 );
|
|
|
|
|
2021-06-21 17:49:47 +00:00
|
|
|
namespace TabberNeue;
|
2019-05-14 18:59:33 +00:00
|
|
|
|
|
|
|
use Parser;
|
|
|
|
use PPFrame;
|
|
|
|
|
2021-06-21 17:49:47 +00:00
|
|
|
class TabberNeueHooks {
|
2019-05-14 18:59:33 +00:00
|
|
|
/**
|
|
|
|
* Sets up this extension's parser functions.
|
|
|
|
*
|
2021-06-22 19:23:39 +00:00
|
|
|
* @param Parser $parser Parser object passed as a reference.
|
2019-05-14 18:59:33 +00:00
|
|
|
*/
|
2021-06-22 19:23:39 +00:00
|
|
|
public static function onParserFirstCallInit( Parser $parser ) {
|
|
|
|
$parser->setHook( 'tabber', [ __CLASS__, 'renderTabber' ] );
|
2019-05-14 18:59:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders the necessary HTML for a <tabber> tag.
|
|
|
|
*
|
2021-06-21 23:56:28 +00:00
|
|
|
* @param string $input The input URL between the beginning and ending tags.
|
|
|
|
* @param array $args Array of attribute arguments on that beginning tag.
|
2021-06-22 00:01:05 +00:00
|
|
|
* @param Parser $parser Mediawiki Parser Object
|
|
|
|
* @param PPFrame $frame Mediawiki PPFrame Object
|
2019-05-14 18:59:33 +00:00
|
|
|
*
|
2021-06-21 23:56:28 +00:00
|
|
|
* @return string HTML
|
2019-05-14 18:59:33 +00:00
|
|
|
*/
|
2021-06-21 23:56:28 +00:00
|
|
|
public static function renderTabber( $input, array $args, Parser $parser, PPFrame $frame ) {
|
|
|
|
$parser->getOutput()->addModules( 'ext.tabberNeue' );
|
|
|
|
$arr = explode( "|-|", $input );
|
2019-05-14 18:59:33 +00:00
|
|
|
$htmlTabs = '';
|
2021-06-21 23:56:28 +00:00
|
|
|
foreach ( $arr as $tab ) {
|
|
|
|
$htmlTabs .= self::buildTab( $tab, $parser, $frame );
|
2019-05-14 18:59:33 +00:00
|
|
|
}
|
|
|
|
|
2021-10-23 04:47:49 +00:00
|
|
|
$html = '<div class="tabber">' .
|
2021-06-21 17:49:47 +00:00
|
|
|
'<section class="tabber__section">' . $htmlTabs . "</section></div>";
|
2019-05-14 18:59:33 +00:00
|
|
|
|
2021-06-21 17:49:47 +00:00
|
|
|
return $html;
|
2019-05-14 18:59:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Build individual tab.
|
|
|
|
*
|
2021-06-21 23:56:28 +00:00
|
|
|
* @param string $tab Tab information
|
2021-06-22 00:01:05 +00:00
|
|
|
* @param Parser $parser Mediawiki Parser Object
|
|
|
|
* @param PPFrame $frame Mediawiki PPFrame Object
|
2019-05-14 18:59:33 +00:00
|
|
|
*
|
2021-06-21 23:56:28 +00:00
|
|
|
* @return string HTML
|
2019-05-14 18:59:33 +00:00
|
|
|
*/
|
2021-06-21 23:56:28 +00:00
|
|
|
private static function buildTab( $tab, Parser $parser, PPFrame $frame ) {
|
|
|
|
$tab = trim( $tab );
|
|
|
|
if ( empty( $tab ) ) {
|
2019-05-14 18:59:33 +00:00
|
|
|
return $tab;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Use array_pad to make sure at least 2 array values are always returned
|
2021-06-21 23:56:28 +00:00
|
|
|
list( $tabName, $tabBody ) = array_pad( explode( '=', $tab, 2 ), 2, '' );
|
2019-05-14 18:59:33 +00:00
|
|
|
|
2021-10-01 04:11:04 +00:00
|
|
|
$tabBody = $parser->recursiveTagParseFully( $tabBody, $frame );
|
2019-05-14 18:59:33 +00:00
|
|
|
|
2021-06-21 23:56:28 +00:00
|
|
|
$tab = '<article class="tabber__panel" title="' . htmlspecialchars( $tabName ) .
|
2021-10-01 04:11:04 +00:00
|
|
|
'">' . $tabBody . '</article>';
|
2021-06-21 17:49:47 +00:00
|
|
|
|
2019-05-14 18:59:33 +00:00
|
|
|
return $tab;
|
|
|
|
}
|
|
|
|
}
|