add Last-Modified header
[lhc/web/wiklou.git] / includes / SpecialWhatlinkshere.php
1 <?php
2
3 function wfSpecialWhatlinkshere($par = NULL)
4 {
5 global $wgUser, $wgOut, $wgRequest;
6 $fname = "wfSpecialWhatlinkshere";
7
8 $target = $wgRequest->getVal( 'target' );
9 $limit = $wgRequest->getInt( 'limit', 500 );
10
11 if(!empty($par)) {
12 $target = $par;
13 } else if ( is_null( $target ) ) {
14 $wgOut->errorpage( "notargettitle", "notargettext" );
15 return;
16 }
17
18 $nt = Title::newFromURL( $target );
19 if( !$nt ) {
20 $wgOut->errorpage( "notargettitle", "notargettext" );
21 return;
22 }
23 $wgOut->setPagetitle( $nt->getPrefixedText() );
24 $wgOut->setSubtitle( wfMsg( "linklistsub" ) );
25
26 $id = $nt->getArticleID();
27 $sk = $wgUser->getSkin();
28 $isredir = " (" . wfMsg( "isredirect" ) . ")\n";
29
30 $wgOut->addHTML("&lt; ".$sk->makeKnownLinkObj($nt, "", "redirect=no" )."<br />\n");
31
32 if ( 0 == $id ) {
33 $sql = "SELECT cur_id,cur_namespace,cur_title,cur_is_redirect FROM brokenlinks,cur WHERE bl_to='" .
34 wfStrencode( $nt->getPrefixedDBkey() ) . "' AND bl_from=cur_id LIMIT $limit";
35 $res = wfQuery( $sql, DB_READ, $fname );
36
37 if ( 0 == wfNumRows( $res ) ) {
38 $wgOut->addHTML( wfMsg( "nolinkshere" ) );
39 } else {
40 $wgOut->addHTML( wfMsg( "linkshere" ) );
41 $wgOut->addHTML( "\n<ul>" );
42
43 while ( $row = wfFetchObject( $res ) ) {
44 $nt = Title::makeTitle( $row->cur_namespace, $row->cur_title );
45 if( !$nt ) {
46 continue;
47 }
48 $link = $sk->makeKnownLinkObj( $nt, "", "redirect=no" );
49 $wgOut->addHTML( "<li>{$link}" );
50
51 if ( $row->cur_is_redirect ) {
52 $wgOut->addHTML( $isredir );
53 wfShowIndirectLinks( 1, $row->cur_id, $limit );
54 }
55 $wgOut->addHTML( "</li>\n" );
56 }
57 $wgOut->addHTML( "</ul>\n" );
58 wfFreeResult( $res );
59 }
60 } else {
61 wfShowIndirectLinks( 0, $id, $limit );
62 }
63 }
64
65 function wfShowIndirectLinks( $level, $lid, $limit )
66 {
67 global $wgOut, $wgUser;
68 $fname = "wfShowIndirectLinks";
69
70 $sql = "SELECT cur_id,cur_namespace,cur_title,cur_is_redirect FROM links,cur WHERE l_to={$lid} AND l_from=cur_id LIMIT $limit";
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::makeTitle( $row->cur_namespace, $row->cur_title );
88 if( !$nt ) {
89 $wgOut->addHTML( "<!-- bad backlink: " . htmlspecialchars( $row->l_from ) . " -->\n" );
90 continue;
91 }
92
93 if ( $row->cur_is_redirect ) {
94 $extra = "redirect=no";
95 } else {
96 $extra = "";
97 }
98
99 $link = $sk->makeKnownLinkObj( $nt, "", $extra );
100 $wgOut->addHTML( "<li>{$link}" );
101
102 if ( $row->cur_is_redirect ) {
103 $wgOut->addHTML( $isredir );
104 if ( $level < 2 ) {
105 wfShowIndirectLinks( $level + 1, $row->cur_id, $limit );
106 }
107 }
108 $wgOut->addHTML( "</li>\n" );
109 }
110 $wgOut->addHTML( "</ul>\n" );
111 }
112
113 ?>