forked from automatist/showbacklinks
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathshowbacklinks.body.php
33 lines (30 loc) · 1.2 KB
/
showbacklinks.body.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
class ShowBackLinksHooks {
public static function onSkinAfterContent( &$data, Skin $skin = null ) {
global $wgOut, $wgTitle;
$tMain = Title::newFromText(wfMessage("mainpage")->text());
$linksTitle = "== " . wfMessage("whatlinkshere")->text() . " ==\n";
$text = "";
foreach ($wgTitle->getLinksTo() as $t) {
if ($t == $wgTitle || $t->getText() == $tMain || !$t->exists() || ($t->getNamespace() !== NS_MAIN) ) {
continue;
}
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 (strlen($text) == 0) {
$text = "No backlinks for this article.";
}
$data = $wgOut->parse( $linksTitle . $text );
return true;
}
}