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