@ -41,7 +41,7 @@ class Isekai {
$outputPage->addModuleStyles('ext.isekai.styles');
$outputPage->addModuleStyles('ext.isekai.styles');
$outputPage->addModules('ext.isekai');
$outputPage->addModules('ext.isekai');
$outputPage->addModules('ext.fontawesome');
// $outputPage->addModules('ext.fontawesome');
//$outputPage->addModules('ext.treeview');
//$outputPage->addModules('ext.treeview');
// 加载动画,三秒内未加载完成则强制显示
// 加载动画,三秒内未加载完成则强制显示
@ -84,6 +84,10 @@ var _hmt = _hmt || [];
HTML
HTML
);
);
if ($outputPage->getUser() & & $outputPage->getUser()->isRegistered()) {
$outputPage->addBodyClasses(['logged-in']);
}
self::showAds($outputPage);
self::showAds($outputPage);
}
}
@ -114,6 +118,7 @@ HTML
$outputPage->addHTML(
$outputPage->addHTML(
< < < HTML
< < < HTML
< script type = "text/javascript" >
< script type = "text/javascript" >
window.addEventListener('load', function () {
if (window.innerWidth >= 1100) {
if (window.innerWidth >= 1100) {
var adElem = document.createElement('div');
var adElem = document.createElement('div');
adElem.className = 'googlead-container googlead-container-sidebar';
adElem.className = 'googlead-container googlead-container-sidebar';
@ -124,6 +129,7 @@ HTML
(adsbygoogle = window.adsbygoogle || []).push({});
(adsbygoogle = window.adsbygoogle || []).push({});
}
}
}
}
})
< / script >
< / script >
HTML
HTML
);
);
@ -176,44 +182,76 @@ HTML
if (!$outputPage->isArticle()) return;
if (!$outputPage->isArticle()) return;
$title = $outputPage->getTitle();
$title = $outputPage->getTitle();
if ($title & & $title->isSubpage()) {
if ($title) {
//更改显示的标题
if ($title->isSubpage()) {
$titleText = $title->getPrefixedText();
//更改显示的标题
$titleText = $title->getPrefixedText();
$baseTitleText = basename($titleText);
$htmlTitle = $outputPage->getHTMLTitle();
$currentDisplayTitle = $outputPage->getDisplayTitle();
if (strpos($htmlTitle, $baseTitleText) === 0) {
$htmlTitle = $outputPage->getHTMLTitle();
// 将HTML标题替换为完整标题
if (strpos($htmlTitle, $currentDisplayTitle) === 0) {
$outputPage->setHTMLTitle($titleText . substr($htmlTitle, strlen($baseTitleText)));
// 将HTML标题替换为完整标题
}
$htmlTitleText = $currentDisplayTitle . ' (' . dirname($titleText) . ')';
$outputPage->setHTMLTitle($htmlTitleText . substr($htmlTitle, strlen($currentDisplayTitle)));
$outputPage->addMeta('title', $htmlTitleText);
}
//面包屑
//面包屑
$titlePathList = explode('/', $titleText);
$titlePathList = explode('/', $titleText);
$titlePathLen = count($titlePathList);
$titlePathLen = count($titlePathList);
$breadcrumbsHtml = [
$breadcrumbsHtml = [
Html::openElement('ol', ['class' => 'breadcrumb']),
Html::openElement('ol', ['class' => 'breadcrumb']),
];
];
$linkRender = MediaWikiServices::getInstance()->getLinkRenderer();
$linkRender = MediaWikiServices::getInstance()->getLinkRenderer();
foreach ($titlePathList as $key => $titleName) {
foreach ($titlePathList as $key => $titleName) {
if ($key === $titlePathLen - 1) {
if ($key === $titlePathLen - 1) {
$breadcrumbsHtml[] = Html::element('li', ['class' => 'active'], $titleName);
$breadcrumbsHtml[] = Html::element('li', ['class' => 'active'], $titleName);
} else {
$titleSubPath = implode('/', array_slice($titlePathList, 0, $key + 1));
$currentTitle = Title::newFromText($titleSubPath);
if ($currentTitle) {
$link = $linkRender->makeLink(Title::newFromText($titleSubPath), $titleName);
} else {
} else {
$link = $titleSubPath;
$titleSubPath = implode('/', array_slice($titlePathList, 0, $key + 1));
$currentTitle = Title::newFromText($titleSubPath);
if ($currentTitle) {
$link = $linkRender->makeLink(Title::newFromText($titleSubPath), $titleName);
} else {
$link = $titleSubPath;
}
if ($key === 0) {
$breadcrumbsHtml[] = Html::openElement('li', ['class' => 'root']) . $link . Html::closeElement('li');
} else {
$breadcrumbsHtml[] = Html::openElement('li') . $link . Html::closeElement('li');
}
$breadcrumbsHtml[] = Html::openElement('span', ['class' => 'breadcrumb-divider']) . '/' . Html::closeElement('span');
}
}
$breadcrumbsHtml[] = Html::openElement('li') . $link . Html::closeElement('li');
}
}
}
$breadcrumbsHtml[] = Html::closeElement('ol');
$breadcrumbsHtml[] = Html::closeElement('ol');
$html = implode($breadcrumbsHtml);
$html = implode($breadcrumbsHtml);
// 阻止出现subtitle空行
// 阻止出现subtitle空行
$subtitle = $outputPage->getSubtitle();
$subtitle = $outputPage->getSubtitle();
$outputPage->setSubtitle($subtitle . $html);
$outputPage->setSubtitle($subtitle . $html);
} else {
$currentDisplayTitle = $outputPage->getDisplayTitle();
if ($currentDisplayTitle) {
$currentDisplayTitle = strip_tags($currentDisplayTitle);
$outputPage->addMeta('title', $currentDisplayTitle);
if ($currentDisplayTitle !== $title->getPrefixedText()) {
// 输出原标题
$breadcrumbsHtml = [
Html::openElement('ol', ['class' => 'breadcrumb']),
Html::element('li', ['class' => 'root active'], $title->getPrefixedText()),
Html::closeElement('ol'),
];
$html = implode($breadcrumbsHtml);
$subtitle = $outputPage->getSubtitle();
$outputPage->setSubtitle($subtitle . $html);
}
} else {
$outputPage->addMeta('title', $title->getPrefixedText());
}
}
}
}
}
}
@ -224,7 +262,7 @@ HTML
//更改显示的标题
//更改显示的标题
$titleText = $title->getPrefixedText();
$titleText = $title->getPrefixedText();
if ($titleText) {
if ($titleText) {
$parser->getOutput()->setTitleText('< span class = "mw-page-title-main" > ' . basename($titleText) . '< / span > ' );
$parser->getOutput()->setTitleText(basename($titleText));
}
}
}
}
}
}
@ -296,4 +334,31 @@ HTML
'section' => 'misc/isekai-ads',
'section' => 'misc/isekai-ads',
];
];
}
}
public static function onCirrusSearchAnalysisConfig(array & $config, $builder) {
if (isset($config['filter']['smartcn_stop'])) { // 处理中文Analysis Config
}
}
public static function onMugenAppGetAvatar(& $avatarUrl, $size, $user) {
if (!$user) {
$avatarUrl = "https://account.isekai.cn/realms/isekai/avatar/default";
return;
}
$userName = $user->getName();
$avatarBase = 'https://account.isekai.cn/realms/isekai/avatar/by-username/' . $userName;
if ($size < = 64) {
$avatarUrl = "$avatarBase?size=md";
} else if ($size < = 128) {
$avatarUrl = "$avatarBase?size=lg";
} else if ($size < = 256) {
$avatarUrl = "$avatarBase?size=xl";
} else {
$avatarUrl = "$avatarBase?size=xxl";
}
}
}
}