更改链接按钮的实现方式

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

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

@ -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');
}

Loading…
Cancel
Save