You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.5 KiB
PHP
46 lines
1.5 KiB
PHP
<?php
|
|
namespace Isekai\Widgets;
|
|
|
|
use MediaWiki\Parser\Parser;
|
|
use MediaWiki\Html\Html;
|
|
use PPFrame;
|
|
|
|
class ExtraFontWidget {
|
|
public static function create($text, $params, Parser $parser, PPFrame $frame) {
|
|
/** @var \MediaWiki\Parser\ParserOutput */
|
|
$out = $parser->getOutput();
|
|
$existsFonts = $out->getExtensionData('IsekaiWidgets.extraFonts');
|
|
if (!$existsFonts) {
|
|
$existsFonts = [];
|
|
}
|
|
|
|
$content = $text = $parser->recursiveTagParseFully($text, $frame);
|
|
if (empty($params['name'])) {
|
|
return '<span class="error">' . wfMessage('isekai-font-error-invalid-params')->parse() . '</span>' . $content;
|
|
}
|
|
|
|
$fontName = 'extra-' . $params['name'];
|
|
if (preg_match('/[`~!@#$%^&*()+=<>?:"{}|,.\/;\'\\\\\[\]]\r\n/', $fontName)) {
|
|
return '<span class="error">' .
|
|
wfMessage('isekai-font-error-font-name-invalid')->parse() .
|
|
'</span>' .
|
|
$content;
|
|
}
|
|
|
|
if (!isset($existsFonts[$fontName])) {
|
|
return '<span class="error">' .
|
|
wfMessage('isekai-font-error-font-not-imported', $params['name'])->parse() .
|
|
'</span>' .
|
|
$content;
|
|
}
|
|
$fontId = $existsFonts[$fontName];
|
|
|
|
return [
|
|
Html::rawElement('span', [
|
|
'class' => 'isekai-extra-font font-' . $fontId,
|
|
], $content),
|
|
"markerType" => 'nowiki'
|
|
];
|
|
}
|
|
}
|