only get the title string if action is not empty
[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(!empty($par)) {
9 $target = $par;
10 } else if (!empty($_REQUEST['target'])) {
11 $target = $_REQUEST['target'] ;
12 } else {
13 $wgOut->errorpage( "notargettitle", "notargettext" );
14 return;
15 }
16 $nt = Title::newFromURL( $target );
17 if( !$nt ) {
18 $wgOut->errorpage( "notargettitle", "notargettext" );
19 return;
20 }
21 $wgOut->setPagetitle( $nt->getPrefixedText() );
22 $wgOut->setSubtitle( wfMsg( "linklistsub" ) );
23
24 $id = $nt->getArticleID();
25 $sk = $wgUser->getSkin();
26 $isredir = " (" . wfMsg( "isredirect" ) . ")\n";
27
28 $wgOut->addHTML("&lt; ".$sk->makeKnownLinkObj($nt, "", "redirect=no" )."<br/>\n");
29
30 if ( 0 == $id ) {
31 $sql = "SELECT cur_id,cur_namespace,cur_title,cur_is_redirect FROM brokenlinks,cur WHERE bl_to='" .
32 wfStrencode( $nt->getPrefixedDBkey() ) . "' AND bl_from=cur_id LIMIT 500";
33 $res = wfQuery( $sql, DB_READ, $fname );
34
35 if ( 0 == wfNumRows( $res ) ) {
36 $wgOut->addHTML( wfMsg( "nolinkshere" ) );
37 } else {
38 $wgOut->addHTML( wfMsg( "linkshere" ) );
39 $wgOut->addHTML( "\n<ul>" );
40
41 while ( $row = wfFetchObject( $res ) ) {
42 $nt = Title::makeTitle( $row->cur_namespace, $row->cur_title );
43 if( !$nt ) {
44 continue;
45 }
46 $link = $sk->makeKnownLinkObj( $nt, "", "redirect=no" );
47 $wgOut->addHTML( "<li>{$link}" );
48
49 if ( $row->cur_is_redirect ) {
50 $wgOut->addHTML( $isredir );
51 wfShowIndirectLinks( 1, $row->cur_id );
52 }
53 $wgOut->addHTML( "</li>\n" );
54 }
55 $wgOut->addHTML( "</ul>\n" );
56 wfFreeResult( $res );
57 }
58 } else {
59 wfShowIndirectLinks( 0, $id );
60 }
61 }
62
63 function wfShowIndirectLinks( $level, $lid )
64 {
65 global $wgOut, $wgUser;
66 $fname = "wfShowIndirectLinks";
67
68 $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";
69 $res = wfQuery( $sql, DB_READ, $fname );
70
71 if ( 0 == wfNumRows( $res ) ) {
72 if ( 0 == $level ) {
73 $wgOut->addHTML( wfMsg( "nolinkshere" ) );
74 }
75 return;
76 }
77 if ( 0 == $level ) {
78 $wgOut->addHTML( wfMsg( "linkshere" ) );
79 }
80 $sk = $wgUser->getSkin();
81 $isredir = " (" . wfMsg( "isredirect" ) . ")\n";
82
83 $wgOut->addHTML( "<ul>" );
84 while ( $row = wfFetchObject( $res ) ) {
85 $nt = Title::makeTitle( $row->cur_namespace, $row->cur_title );
86 if( !$nt ) {
87 $wgOut->addHTML( "<!-- bad backlink: " . htmlspecialchars( $row->l_from ) . " -->\n" );
88 continue;
89 }
90
91 if ( $row->cur_is_redirect ) {
92 $extra = "redirect=no";
93 } else {
94 $extra = "";
95 }
96
97 $link = $sk->makeKnownLinkObj( $nt, "", $extra );
98 $wgOut->addHTML( "<li>{$link}" );
99
100 if ( $row->cur_is_redirect ) {
101 $wgOut->addHTML( $isredir );
102 if ( $level < 2 ) {
103 wfShowIndirectLinks( $level + 1, $row->cur_id );
104 }
105 }
106 $wgOut->addHTML( "</li>\n" );
107 }
108 $wgOut->addHTML( "</ul>\n" );
109 }
110
111 ?>