From f47a0f245fe84f8579aad052f3f2a36c9850f518 Mon Sep 17 00:00:00 2001 From: Lex Lim Date: Fri, 18 Aug 2023 14:18:41 +0000 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E9=93=BE=E6=8E=A5=E6=8C=89?= =?UTF-8?q?=E9=92=AE=E7=9A=84=E5=AE=9E=E7=8E=B0=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extension.json | 4 +-- includes/PreviewPageListWidget.php | 56 ++++++++++++++++-------------- 2 files changed, 31 insertions(+), 29 deletions(-) diff --git a/extension.json b/extension.json index a1baa34..4e60535 100644 --- a/extension.json +++ b/extension.json @@ -175,9 +175,7 @@ ] }, "ext.isekai.buttonLink": { - "scripts": [ - "buttonLink/ext.isekai.buttonLink.js" - ], + "scripts": [], "dependencies": [ "oojs-ui-core" ], diff --git a/includes/PreviewPageListWidget.php b/includes/PreviewPageListWidget.php index 27434f1..02a5c85 100644 --- a/includes/PreviewPageListWidget.php +++ b/includes/PreviewPageListWidget.php @@ -12,6 +12,33 @@ use Title; class PreviewPageListWidget { public const CONTAINER_CLASS_NAME = 'isekai-card isekai-preview-page-list-card'; + /** + * Build fallback list for browsers that don't support JS and for SEO + * @param string[] $pageList + * @return string + */ + public static function buildFallbackPageList($pageList) { + $pageListHtml = []; + foreach ($pageList as $pageTitle) { + $title = Title::newFromText($pageTitle); + $pageListHtml[] = Html::rawElement('a', ['class' => 'isekai-list-item', 'href' => $title->getLocalURL()], + Html::rawElement('div', ['class' => 'isekai-list-item-content'], + Html::element('div', ['class' => 'isekai-list-item-title'], $title->getPrefixedText()) + ) + ); + } + + return + Html::openElement('div', [ + 'class' => 'fallback-page-list' + ]) . Html::openElement('ul', [ + 'class' => 'isekai-list' + ]) . + implode("\n", $pageListHtml) . + Html::closeElement('ul') . + Html::closeElement('div'); + } + public static function create($text, $params, \Parser $parser, \PPFrame $frame) { $parser->getOutput()->addModules(['ext.isekai.previewPageList']); @@ -41,13 +68,6 @@ class PreviewPageListWidget { return trim($page); }, $pageList); - $pageListHtml = []; - $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer(); - foreach ($pageList as $pageTitle) { - $title = Title::newFromText($pageTitle); - $pageListHtml[] = Html::rawElement('li', [], $linkRenderer->makeLink($title)); - } - return Html::openElement('div', [ 'class' => self::CONTAINER_CLASS_NAME, 'data-loader' => $loader, @@ -58,12 +78,7 @@ class PreviewPageListWidget { 'type' => 'application/json', 'data-pages' => true, ], json_encode($pageList)) . - Html::openElement('div', [ - 'class' => 'fallback-page-list' - ]) . Html::openElement('ul', []) . - implode("\n", $pageListHtml) . - Html::closeElement('ul') . - Html::closeElement('div') . + self::buildFallbackPageList($pageList) . Html::closeElement('div'); case 'category': $category = $params['category'] ?? null; @@ -103,25 +118,14 @@ class PreviewPageListWidget { ]); } - $pageListHtml = []; - $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer(); - foreach ($pageList as $pageTitle) { - $title = Title::newFromText($pageTitle); - $pageListHtml[] = Html::rawElement('li', [], $linkRenderer->makeLink($title)); - } - return Html::openElement('div', [ 'class' => self::CONTAINER_CLASS_NAME, 'data-loader' => $loader, 'data-category' => $categoryTitleText, 'data-autofocus' => $autoFocus, 'data-lazyload' => $lazyLoad, - ]) . Html::openElement('div', [ - 'class' => 'fallback-page-list' - ]) . Html::openElement('ul', []) . - implode("\n", $pageListHtml) . - Html::closeElement('ul') . - Html::closeElement('div') . + ]) . + self::buildFallbackPageList($pageList) . Html::closeElement('div'); }