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