Fix for compatibility with short_open_tag = Off
[lhc/web/wiklou.git] / includes / SpecialWhatlinkshere.php
1 <?php
2
3 function wfSpecialWhatlinkshere($par = NULL)
4 {
5 global $wgUser, $wgOut, $target;
6 $fname = "wfSpecialWhatlinkshere";
7
8 if($par) {
9 $target = $par;
10 } else {
11 $target = wfCleanQueryVar( $_REQUEST['target'] );
12 }
13 if ( "" == $target ) {
14 $wgOut->errorpage( "notargettitle", "notargettext" );
15 return;
16 }
17 $nt = Title::newFromURL( $target );
18 if( !$nt ) {
19 $wgOut->errorpage( "notargettitle", "notargettext" );
20 return;
21 }
22 $wgOut->setPagetitle( $nt->getPrefixedText() );
23 $wgOut->setSubtitle( wfMsg( "linklistsub" ) );
24
25 $id = $nt->getArticleID();
26 $sk = $wgUser->getSkin();
27 $isredir = " (" . wfMsg( "isredirect" ) . ")\n";
28
29 if ( 0 == $id ) {
30 $sql = "SELECT bl_from FROM brokenlinks WHERE bl_to='" .
31 wfStrencode( $nt->getPrefixedDBkey() ) . "' LIMIT 500";
32 $res = wfQuery( $sql, DB_READ, $fname );
33
34 if ( 0 == wfNumRows( $res ) ) {
35 $wgOut->addHTML( wfMsg( "nolinkshere" ) );
36 } else {
37 $wgOut->addHTML( wfMsg( "linkshere" ) );
38 $wgOut->addHTML( "\n<ul>" );
39
40 while ( $row = wfFetchObject( $res ) ) {
41 $lid = $row->bl_from;
42 $sql = "SELECT cur_namespace,cur_title,cur_is_redirect " .
43 "FROM cur WHERE cur_id={$lid}";
44 $res2 = wfQuery( $sql, DB_READ, $fname );
45 $s = wfFetchObject( $res2 );
46
47 $n = Title::makeName( $s->cur_namespace, $s->cur_title );
48 $link = $sk->makeKnownLink( $n, "", "redirect=no" );
49 $wgOut->addHTML( "<li>{$link}" );
50
51 if ( 1 == $s->cur_is_redirect ) {
52 $wgOut->addHTML( $isredir );
53 wfShowIndirectLinks( 1, $lid );
54 }
55 $wgOut->addHTML( "</li>\n" );
56 }
57 $wgOut->addHTML( "</ul>\n" );
58 wfFreeResult( $res );
59 }
60 } else {
61 wfShowIndirectLinks( 0, $id );
62 }
63 }
64
65 function wfShowIndirectLinks( $level, $lid )
66 {
67 global $wgOut, $wgUser;
68 $fname = "wfShowIndirectLinks";
69
70 $sql = "SELECT l_from FROM links WHERE l_to={$lid} LIMIT 500";
71 $res = wfQuery( $sql, DB_READ, $fname );
72
73 if ( 0 == wfNumRows( $res ) ) {
74 if ( 0 == $level ) {
75 $wgOut->addHTML( wfMsg( "nolinkshere" ) );
76 }
77 return;
78 }
79 if ( 0 == $level ) {
80 $wgOut->addHTML( wfMsg( "linkshere" ) );
81 }
82 $sk = $wgUser->getSkin();
83 $isredir = " (" . wfMsg( "isredirect" ) . ")\n";
84
85 $wgOut->addHTML( "<ul>" );
86 while ( $row = wfFetchObject( $res ) ) {
87 $nt = Title::newFromDBkey( $row->l_from );
88 if( !$nt ) {
89 $wgOut->addHTML( "<!-- bad backlink: " . htmlspecialchars( $row->l_from ) . " -->\n" );
90 continue;
91 }
92 $ns = $nt->getNamespace();
93 $t = wfStrencode( $nt->getDBkey() );
94
95 # FIXME: this should be in a join above, or cached in the links table
96
97 $sql = "SELECT cur_id,cur_is_redirect FROM cur " .
98 "WHERE cur_namespace={$ns} AND cur_title='{$t}'";
99 $res2 = wfQuery( $sql, DB_READ, $fname );
100 $s = wfFetchObject( $res2 );
101
102 if ( 1 == $s->cur_is_redirect ) {
103 $extra = "redirect=no";
104 } else {
105 $extra = "";
106 }
107
108 $link = $sk->makeKnownLink( $row->l_from, "", $extra );
109 $wgOut->addHTML( "<li>{$link}" );
110
111 if ( 1 == $s->cur_is_redirect ) {
112 $wgOut->addHTML( $isredir );
113 if ( $level < 2 ) {
114 wfShowIndirectLinks( $level + 1, $s->cur_id );
115 }
116 }
117 $wgOut->addHTML( "</li>\n" );
118 }
119 $wgOut->addHTML( "</ul>\n" );
120 }
121
122 ?>