fixed bugs added recently
[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 = $_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 $wgOut->addHTML("&lt; ".$sk->makeKnownLinkObj($nt, "", "redirect=no" )."<br>\n");
30
31 if ( 0 == $id ) {
32 $sql = "SELECT cur_id,cur_namespace,cur_title,cur_is_redirect FROM brokenlinks,cur WHERE bl_to='" .
33 wfStrencode( $nt->getPrefixedDBkey() ) . "' AND bl_from=cur_id LIMIT 500";
34 $res = wfQuery( $sql, DB_READ, $fname );
35
36 if ( 0 == wfNumRows( $res ) ) {
37 $wgOut->addHTML( wfMsg( "nolinkshere" ) );
38 } else {
39 $wgOut->addHTML( wfMsg( "linkshere" ) );
40 $wgOut->addHTML( "\n<ul>" );
41
42 while ( $row = wfFetchObject( $res ) ) {
43 $nt = Title::makeTitle( $row->cur_namespace, $row->cur_title );
44 if( !$nt ) {
45 continue;
46 }
47 $link = $sk->makeKnownLinkObj( $nt, "", "redirect=no" );
48 $wgOut->addHTML( "<li>{$link}" );
49
50 if ( $row->cur_is_redirect ) {
51 $wgOut->addHTML( $isredir );
52 wfShowIndirectLinks( 1, $row->cur_id );
53 }
54 $wgOut->addHTML( "</li>\n" );
55 }
56 $wgOut->addHTML( "</ul>\n" );
57 wfFreeResult( $res );
58 }
59 } else {
60 wfShowIndirectLinks( 0, $id );
61 }
62 }
63
64 function wfShowIndirectLinks( $level, $lid )
65 {
66 global $wgOut, $wgUser;
67 $fname = "wfShowIndirectLinks";
68
69 $sql = "SELECT cur_id,cur_namespace,cur_title,cur_is_redirect FROM links,cur WHERE l_to={$lid} AND l_from=cur_id LIMIT 500";
70 $res = wfQuery( $sql, DB_READ, $fname );
71
72 if ( 0 == wfNumRows( $res ) ) {
73 if ( 0 == $level ) {
74 $wgOut->addHTML( wfMsg( "nolinkshere" ) );
75 }
76 return;
77 }
78 if ( 0 == $level ) {
79 $wgOut->addHTML( wfMsg( "linkshere" ) );
80 }
81 $sk = $wgUser->getSkin();
82 $isredir = " (" . wfMsg( "isredirect" ) . ")\n";
83
84 $wgOut->addHTML( "<ul>" );
85 while ( $row = wfFetchObject( $res ) ) {
86 $nt = Title::makeTitle( $row->cur_namespace, $row->cur_title );
87 if( !$nt ) {
88 $wgOut->addHTML( "<!-- bad backlink: " . htmlspecialchars( $row->l_from ) . " -->\n" );
89 continue;
90 }
91
92 if ( $row->cur_is_redirect ) {
93 $extra = "redirect=no";
94 } else {
95 $extra = "";
96 }
97
98 $link = $sk->makeKnownLinkObj( $nt, "", $extra );
99 $wgOut->addHTML( "<li>{$link}" );
100
101 if ( $row->cur_is_redirect ) {
102 $wgOut->addHTML( $isredir );
103 if ( $level < 2 ) {
104 wfShowIndirectLinks( $level + 1, $row->cur_id );
105 }
106 }
107 $wgOut->addHTML( "</li>\n" );
108 }
109 $wgOut->addHTML( "</ul>\n" );
110 }
111
112 ?>