更改链接按钮的实现方式

master
落雨楓 1 year ago
parent 5437b4f062
commit f47a0f245f

@ -175,9 +175,7 @@
] ]
}, },
"ext.isekai.buttonLink": { "ext.isekai.buttonLink": {
"scripts": [ "scripts": [],
"buttonLink/ext.isekai.buttonLink.js"
],
"dependencies": [ "dependencies": [
"oojs-ui-core" "oojs-ui-core"
], ],

@ -12,6 +12,33 @@ use Title;
class PreviewPageListWidget { class PreviewPageListWidget {
public const CONTAINER_CLASS_NAME = 'isekai-card isekai-preview-page-list-card'; 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) { public static function create($text, $params, \Parser $parser, \PPFrame $frame) {
$parser->getOutput()->addModules(['ext.isekai.previewPageList']); $parser->getOutput()->addModules(['ext.isekai.previewPageList']);
@ -41,13 +68,6 @@ class PreviewPageListWidget {
return trim($page); return trim($page);
}, $pageList); }, $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', [ return Html::openElement('div', [
'class' => self::CONTAINER_CLASS_NAME, 'class' => self::CONTAINER_CLASS_NAME,
'data-loader' => $loader, 'data-loader' => $loader,
@ -58,12 +78,7 @@ class PreviewPageListWidget {
'type' => 'application/json', 'type' => 'application/json',
'data-pages' => true, 'data-pages' => true,
], json_encode($pageList)) . ], json_encode($pageList)) .
Html::openElement('div', [ self::buildFallbackPageList($pageList) .
'class' => 'fallback-page-list'
]) . Html::openElement('ul', []) .
implode("\n", $pageListHtml) .
Html::closeElement('ul') .
Html::closeElement('div') .
Html::closeElement('div'); Html::closeElement('div');
case 'category': case 'category':
$category = $params['category'] ?? null; $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', [ return Html::openElement('div', [
'class' => self::CONTAINER_CLASS_NAME, 'class' => self::CONTAINER_CLASS_NAME,
'data-loader' => $loader, 'data-loader' => $loader,
'data-category' => $categoryTitleText, 'data-category' => $categoryTitleText,
'data-autofocus' => $autoFocus, 'data-autofocus' => $autoFocus,
'data-lazyload' => $lazyLoad, 'data-lazyload' => $lazyLoad,
]) . Html::openElement('div', [ ]) .
'class' => 'fallback-page-list' self::buildFallbackPageList($pageList) .
]) . Html::openElement('ul', []) .
implode("\n", $pageListHtml) .
Html::closeElement('ul') .
Html::closeElement('div') .
Html::closeElement('div'); Html::closeElement('div');
} }

Loading…
Cancel
Save