diff --git a/showbacklinks.body.php b/showbacklinks.body.php index 3bef37f..3e16998 100644 --- a/showbacklinks.body.php +++ b/showbacklinks.body.php @@ -5,20 +5,28 @@ class ShowBackLinksHooks { public static function onSkinAfterContent( &$data, Skin $skin = null ) { global $wgOut, $wgTitle; $tMain = Title::newFromText(wfMessage("mainpage")->text()); - $backlinks = array(); + $linksTitle = "== " . wfMessage("whatlinkshere")->text() . " ==\n"; + $text = ""; foreach ($wgTitle->getLinksTo() as $t) { - if ($t == $wgTitle || $t->getText() == $tMain || !$t->exists() || ($t->getNamespace() !== NS_MAIN) || ($t->isRedirect())) { + if ($t == $wgTitle || $t->getText() == $tMain || !$t->exists() || ($t->getNamespace() !== NS_MAIN) ) { continue; } - $backlinks[] = $t; + if ($t->isRedirect()) { + $text .= "* [[".$t->getText()."]] (redirect)\n"; + foreach ($t->getLinksTo() as $st) { + if ($st == $wgTitle || $st->getText() == $tMain || !$st->exists() || ($st->getNamespace() !== NS_MAIN) || ($st->isRedirect())) { + continue; + } + $text .= "** [[".$st->getText()."]]\n"; + } + continue; + } + $text .= "* [[".$t->getText()."]]\n"; } - if (count($backlinks) > 0) { - $text = "== " . wfMessage("whatlinkshere")->text() . " ==\n"; - foreach ($backlinks as $t) { - $text .= "* [[".$t->getText()."]]\n"; - } - $data = $wgOut->parse( $text ); + if (strlen($text) == 0) { + $text = "No backlinks for this article."; } + $data = $wgOut->parse( $linksTitle . $text ); return true; }