Cms/mediawiki/h1タイトルをパンクズ化
ナビゲーションに移動
検索に移動
バージョン1.45の場合
LocalSettings.php
$wgHooks['BeforePageDisplay'][] = function ( $out, $skin ) {
$out->addScriptFile( '/resources/custom-title.js' );
return true;
};
resources/custom-title.js
"resources/custom-title.js" 20L, 470B
// パンくずリンク
document.addEventListener("DOMContentLoaded", function () {
const h1 = document.querySelector("#firstHeading");
if (!h1) return;
const text = h1.textContent;
const parts = text.split("/");
let path = [];
const html = parts.map(part => {
path.push(part);
const encoded = path.join("/");
return `<a href="/index.php/${encoded}">${part}</a>`;
});
h1.innerHTML = html.join("/");
});
バージョン1.24の場合
スラッシュ(/)で区切られたページごとにリンクを貼ります。
- skins/Vector/VectorTemplate.php
変更前
?>"><span dir="auto"><?php $this->html( 'title' ) ?></span></h1>
変更後
<span dir="auto">
<?php if ($_GET['action']): ?>
<?php $this->html( 'title' ) ?>
<?php else: ?>
<?php $name = $this->get( 'title' ); $names = explode('/', $name); $path = ""; ?>
<?php foreach ($names as $key => $name): ?><?php $path .= $name; ?><a href="/index.php/<?php echo htmlspecialchars($path); ?>"><?php echo htmlspecialchars($name); ?></a><?php if ($key + 1 < count($names)): ?>/<?php endif; ?><?php $path .= "/"; ?><?php endforeach; ?>
<?php endif; ?>
</span></h1>