mirror of
https://github.com/StarCitizenTools/mediawiki-extensions-TabberNeue.git
synced 2024-11-23 16:06:45 +00:00
feat: throw exception when duplicated label is found under legacy ID mode
This commit is contained in:
parent
df9897441a
commit
ab8e306fc6
|
@ -43,9 +43,7 @@
|
|||
"name": "ext.tabberNeue/config.json",
|
||||
"config": {
|
||||
"enableAnimation": "TabberNeueEnableAnimation",
|
||||
"parseTabName": "TabberNeueParseTabName",
|
||||
"updateLocationOnTabChange": "TabberNeueUpdateLocationOnTabChange",
|
||||
"useLegacyTabIds": "TabberNeueUseLegacyTabIds"
|
||||
"updateLocationOnTabChange": "TabberNeueUpdateLocationOnTabChange"
|
||||
}
|
||||
},
|
||||
"ext.tabberNeue/Transclude.js",
|
||||
|
|
|
@ -17,6 +17,7 @@ namespace MediaWiki\Extension\TabberNeue;
|
|||
use Html;
|
||||
use JsonException;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use InvalidArgumentException;
|
||||
use Parser;
|
||||
use PPFrame;
|
||||
use Sanitizer;
|
||||
|
@ -27,11 +28,14 @@ class Tabber {
|
|||
/** @var bool Flag that checks if this is a nested tabber */
|
||||
private static $isNested = false;
|
||||
|
||||
/** @var bool */
|
||||
private static $parseTabName = false;
|
||||
|
||||
/** @var bool */
|
||||
private static $useCodex = false;
|
||||
|
||||
/** @var bool */
|
||||
private static $parseTabName = false;
|
||||
private static $useLegacyId = false;
|
||||
|
||||
/**
|
||||
* Parser callback for <tabber> tag
|
||||
|
@ -49,6 +53,8 @@ class Tabber {
|
|||
|
||||
self::$parseTabName = $config->get( 'TabberNeueParseTabName' );
|
||||
self::$useCodex = $config->get( 'TabberNeueUseCodex' );
|
||||
self::$useLegacyId = $config->get( 'TabberNeueUseLegacyTabIds' );
|
||||
|
||||
$count = count( $parserOutput->getExtensionData( 'tabber-count' ) ?? [] );
|
||||
|
||||
$html = self::render( $input ?? '', $count, $parser, $frame );
|
||||
|
@ -189,6 +195,7 @@ class Tabber {
|
|||
* @param PPFrame $frame Mediawiki PPFrame Object
|
||||
*
|
||||
* @return array<string, string>
|
||||
* @throws MWException
|
||||
*/
|
||||
private static function getTabData( string $tab, int $count, Parser $parser, PPFrame $frame ): array {
|
||||
$data = [];
|
||||
|
@ -206,7 +213,20 @@ class Tabber {
|
|||
|
||||
$data['content'] = self::getTabContent( $content, $parser, $frame );
|
||||
|
||||
$id = Sanitizer::escapeIdForAttribute( htmlspecialchars( $data['label'] ) ) . '-' . $count;
|
||||
$id = Sanitizer::escapeIdForAttribute( htmlspecialchars( $data['label'] ) );
|
||||
if ( self::$useLegacyId === true ) {
|
||||
$parserOutput = $parser->getOutput();
|
||||
$existingIds = $parserOutput->getExtensionData( 'tabber-ids' ) ?? [];
|
||||
if ( in_array( $id, $existingIds ) ) {
|
||||
throw new InvalidArgumentException(
|
||||
'Duplicated Tabber labels is not allowed with $wgTabberNeueUseLegacyTabIds = true.' .
|
||||
'Label was: ' . $label
|
||||
);
|
||||
}
|
||||
$parserOutput->appendExtensionData( 'tabber-ids', $id );
|
||||
} else {
|
||||
$id = "$id-$count";
|
||||
}
|
||||
$data['id'] = $id;
|
||||
return $data;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue