修复MW 1.42支持

master
落雨楓 1 month ago
parent e0ac8c7da0
commit f49bd60c6a

@ -7,7 +7,12 @@ use PPFrame;
class ExtraFontWidget { class ExtraFontWidget {
public static function create($text, $params, Parser $parser, PPFrame $frame) { public static function create($text, $params, Parser $parser, PPFrame $frame) {
$existsFonts = $parser->extIsekaiWidgetsCache->get('extraFonts', INF, []); /** @var \MediaWiki\Parser\ParserOutput */
$out = $parser->getOutput();
$existsFonts = $out->getExtensionData('IsekaiWidgets.extraFonts');
if (!$existsFonts) {
$existsFonts = [];
}
$content = $text = $parser->recursiveTagParseFully($text, $frame); $content = $text = $parser->recursiveTagParseFully($text, $frame);
if (empty($params['name'])) { if (empty($params['name'])) {
@ -22,7 +27,6 @@ class ExtraFontWidget {
$content; $content;
} }
$existsFonts = $parser->extIsekaiWidgetsCache->get('extraFonts', INF, []);
if (!isset($existsFonts[$fontName])) { if (!isset($existsFonts[$fontName])) {
return '<span class="error">' . return '<span class="error">' .
wfMessage('isekai-font-error-font-not-imported', $params['name'])->parse() . wfMessage('isekai-font-error-font-not-imported', $params['name'])->parse() .

@ -20,9 +20,16 @@ class FontFaceWidget {
} }
$service = MediaWikiServices::getInstance(); $service = MediaWikiServices::getInstance();
/** @var \MediaWiki\Parser\ParserOutput */
$out = $parser->getOutput();
$fontName = 'extra-' . $params['name']; $fontName = 'extra-' . $params['name'];
$existsFonts = $parser->extIsekaiWidgetsCache->get('extraFonts', INF, []);
$existsFonts = $out->getExtensionData('IsekaiWidgets.extraFonts');
if (!$existsFonts) {
$existsFonts = [];
}
if (isset($existsFonts[$fontName])) { if (isset($existsFonts[$fontName])) {
return '<span class="error">' . return '<span class="error">' .
wfMessage('isekai-fontface-error-font-already-defined', $params['name'])->parse() . wfMessage('isekai-fontface-error-font-already-defined', $params['name'])->parse() .
@ -48,7 +55,7 @@ class FontFaceWidget {
".isekai-extra-font.font-{$fontId}{font-family:'{$fontName}'}</style></span>"; ".isekai-extra-font.font-{$fontId}{font-family:'{$fontName}'}</style></span>";
$existsFonts[$fontName] = $fontId; $existsFonts[$fontName] = $fontId;
$existsFonts = $parser->extIsekaiWidgetsCache->set('extraFonts', $existsFonts); $out->setExtensionData('IsekaiWidgets.extraFonts', $existsFonts);
return [$css, "markerType" => 'nowiki']; return [$css, "markerType" => 'nowiki'];
} }

@ -49,7 +49,7 @@ class MasonryWidget {
$maxCol = max(1, $value); $maxCol = max(1, $value);
$colWidth = round(100 / $maxCol, 6); $colWidth = round(100 / $maxCol, 6);
$css .= "@media (min-width: {$width}px) { .isekai-masonry.max-col-{$breakpoint}-${maxCol} { --masonry-col-width: {$colWidth}%; } }"; $css .= "@media (min-width: {$width}px) { .isekai-masonry.max-col-{$breakpoint}-{$maxCol} { --masonry-col-width: {$colWidth}%; } }";
} }
return Html::rawElement('style', [], $css); return Html::rawElement('style', [], $css);

@ -8,13 +8,11 @@ use MediaWiki\Output\OutputPage;
class Widgets { class Widgets {
/** /**
* @param \Parser $parser * @param Parser $parser
* @return bool * @return bool
* @throws \MWException * @throws \MWException
*/ */
public static function onParserSetup(&$parser) { public static function onParserSetup(&$parser) {
$parser->extIsekaiWidgetsCache = new MapCacheLRU( 100 ); // 100 is arbitrary
$parser->setHook('createpage', [CreatePageWidget::class, 'create']); $parser->setHook('createpage', [CreatePageWidget::class, 'create']);
$parser->setHook('discoverbox', [DiscoverWidget::class, 'create']); $parser->setHook('discoverbox', [DiscoverWidget::class, 'create']);
$parser->setHook('feedlist', [FeedListWidget::class, 'create']); $parser->setHook('feedlist', [FeedListWidget::class, 'create']);

@ -4,7 +4,7 @@
opacity: 0; opacity: 0;
top: 0; top: 0;
right: 0; right: 0;
z-index: 102; z-index: 200;
margin: 0; margin: 0;
height: 100vh; height: 100vh;
min-width: 275px; min-width: 275px;

Loading…
Cancel
Save