tag * * @package TabberNeue * @author alistair3149, Eric Fortin, Alexia E. Smith, Ciencia Al Poder * @license GPL-3.0-or-later * @link https://www.mediawiki.org/wiki/Extension:TabberNeue */ declare( strict_types=1 ); namespace MediaWiki\Extension\TabberNeue; use MediaWiki\MediaWikiServices; use Parser; use PPFrame; class Tabber { /** * Parser callback for tag * * @param string $input * @param array $args * @param Parser $parser Mediawiki Parser Object * @param PPFrame $frame Mediawiki PPFrame Object * * @return string HTML */ public static function parserHook( string $input, array $args, Parser $parser, PPFrame $frame ) { $tabber = new Tabber(); $html = $tabber->render( $input, $parser, $frame ); if ( $input === null ) { return; } $useCodex = MediaWikiServices::getInstance()->getMainConfig()->get( 'TabberNeueUseCodex' ); if ( $useCodex === true ) { $parser->getOutput()->addModules( [ 'ext.tabberNeue.codex' ] ); } else { // Critial rendering styles // See ext.tabberNeue.inline.less $style = sprintf( '', '.client-js .tabber__header{height:2.6em;box-shadow:inset 0 -1px 0 0;opacity:.1}.client-js .tabber__header:after{position:absolute;width:16ch;height:.5em;border-radius:40px;margin-top:1em;margin-left:.75em;background:#000;content:""}.client-js .tabber__noscript,.client-js .tabber__panel:not( :first-child ){display:none}' ); $parser->getOutput()->addHeadItem( $style, true ); $parser->getOutput()->addModules( [ 'ext.tabberNeue.legacy' ] ); } $parser->addTrackingCategory( 'tabberneue-tabber-category' ); return $html; } /** * Renders the necessary HTML for a tag. * * @param string $input The input URL between the beginning and ending tags. * @param Parser $parser Mediawiki Parser Object * @param PPFrame $frame Mediawiki PPFrame Object * * @return string HTML */ public static function render( $input, Parser $parser, PPFrame $frame ) { $arr = explode( "|-|", $input ); $htmlTabs = ''; foreach ( $arr as $tab ) { $htmlTabs .= self::buildTab( $tab, $parser, $frame ); } $html = '
' . '
' . '
' . $htmlTabs . '
'; return $html; } /** * Build individual tab. * * @param string $tab Tab information * @param Parser $parser Mediawiki Parser Object * @param PPFrame $frame Mediawiki PPFrame Object * * @return string HTML */ private static function buildTab( $tab, Parser $parser, PPFrame $frame ) { if ( empty( trim( $tab ) ) ) { return ''; } // Use array_pad to make sure at least 2 array values are always returned list( $tabName, $tabBody ) = array_pad( explode( '=', $tab, 2 ), 2, '' ); // Use language converter to get variant title and also escape html $tabName = $parser->getTargetLanguageConverter()->convertHtml( trim( $tabName ) ); $tabBody = $parser->recursiveTagParse( trim( $tabBody ), $frame ); // If $tabBody does not have any HTML element (i.e. just a text node), wrap it in

if ( substr( $tabBody, 0, 1 ) !== '<' ) { $tabBody = '

' . $tabBody . '

'; } $tab = '
' . $tabBody . '
'; return $tab; } }