Initial revision
[lhc/web/wiklou.git] / includes / SpecialWhatlinkshere.php
1 <?
2
3 function wfSpecialWhatlinkshere()
4 {
5 global $wgUser, $wgOut, $target;
6 $fname = "wfSpecialWhatlinkshere";
7
8 if ( "" == $target ) {
9 $wgOut->errorpage( "notargettitle", "notargettext" );
10 return;
11 }
12 $nt = Title::newFromURL( wfCleanQueryVar( $target ) );
13 $wgOut->setPagetitle( $nt->getPrefixedText() );
14 $wgOut->setSubtitle( wfMsg( "linklistsub" ) );
15
16 $id = $nt->getArticleID();
17 $sk = $wgUser->getSkin();
18 $isredir = " (" . wfMsg( "isredirect" ) . ")\n";
19
20 if ( 0 == $id ) {
21 $sql = "SELECT DISTINCT bl_from FROM brokenlinks WHERE bl_to='" .
22 wfStrencode( $nt->getPrefixedDBkey() ) . "' LIMIT 500";
23 $res = wfQuery( $sql, $fname );
24
25 if ( 0 == wfNumRows( $res ) ) {
26 $wgOut->addHTML( wfMsg( "nolinkshere" ) );
27 } else {
28 $wgOut->addHTML( wfMsg( "linkshere" ) );
29 $wgOut->addHTML( "\n<ul>" );
30
31 while ( $row = wfFetchObject( $res ) ) {
32 $lid = $row->bl_from;
33 $sql = "SELECT cur_namespace,cur_title,cur_is_redirect " .
34 "FROM cur WHERE cur_id={$lid}";
35 $res2 = wfQuery( $sql, $fname );
36 $s = wfFetchObject( $res2 );
37
38 $n = Title::makeName( $s->cur_namespace, $s->cur_title );
39 $link = $sk->makeKnownLink( $n, "", "redirect=no" );
40 $wgOut->addHTML( "<li>{$link}" );
41
42 if ( 1 == $s->cur_is_redirect ) {
43 $wgOut->addHTML( $isredir );
44 wfShowIndirectLinks( 1, $lid );
45 }
46 $wgOut->addHTML( "</li>\n" );
47 }
48 $wgOut->addHTML( "</ul>\n" );
49 wfFreeResult( $res );
50 }
51 } else {
52 wfShowIndirectLinks( 0, $id );
53 }
54 }
55
56 function wfShowIndirectLinks( $level, $lid )
57 {
58 global $wgOut, $wgUser;
59 $fname = "wfShowIndirectLinks";
60
61 $sql = "SELECT DISTINCT l_from FROM links WHERE l_to={$lid} LIMIT 500";
62 $res = wfQuery( $sql, $fname );
63
64 if ( 0 == wfNumRows( $res ) ) {
65 if ( 0 == $level ) {
66 $wgOut->addHTML( wfMsg( "nolinkshere" ) );
67 }
68 return;
69 }
70 if ( 0 == $level ) {
71 $wgOut->addHTML( wfMsg( "linkshere" ) );
72 }
73 $sk = $wgUser->getSkin();
74 $isredir = " (" . wfMsg( "isredirect" ) . ")\n";
75
76 $wgOut->addHTML( "<ul>" );
77 while ( $row = wfFetchObject( $res ) ) {
78 $nt = Title::newFromDBkey( $row->l_from );
79 $ns = $nt->getNamespace();
80 $t = wfStrencode( $nt->getDBkey() );
81
82 $link = $sk->makeKnownLink( $row->l_from, "", "redirect=no" );
83 $wgOut->addHTML( "<li>{$link}" );
84
85 $sql = "SELECT cur_id,cur_is_redirect FROM cur " .
86 "WHERE cur_namespace={$ns} AND cur_title='{$t}'";
87 $res2 = wfQuery( $sql, $fname );
88 $s = wfFetchObject( $res2 );
89
90 if ( 1 == $s->cur_is_redirect ) {
91 $wgOut->addHTML( $isredir );
92 if ( $level < 2 ) {
93 wfShowIndirectLinks( $level + 1, $s->cur_id );
94 }
95 }
96 $wgOut->addHTML( "</il>\n" );
97 }
98 $wgOut->addHTML( "</ul>\n" );
99 }
100
101 ?>