Split files and classes in different packages for phpdocumentor. I probably changed...
[lhc/web/wiklou.git] / includes / SpecialWhatlinkshere.php
1 <?php
2 /**
3 *
4 * @package MediaWiki
5 * @subpackage SpecialPage
6 */
7
8 /**
9 *
10 */
11 function wfSpecialWhatlinkshere($par = NULL) {
12 global $wgUser, $wgOut, $wgRequest;
13 $fname = "wfSpecialWhatlinkshere";
14
15 $target = $wgRequest->getVal( 'target' );
16 $limit = $wgRequest->getInt( 'limit', 500 );
17
18 if(!empty($par)) {
19 $target = $par;
20 } else if ( is_null( $target ) ) {
21 $wgOut->errorpage( "notargettitle", "notargettext" );
22 return;
23 }
24
25 $nt = Title::newFromURL( $target );
26 if( !$nt ) {
27 $wgOut->errorpage( "notargettitle", "notargettext" );
28 return;
29 }
30 $wgOut->setPagetitle( $nt->getPrefixedText() );
31 $wgOut->setSubtitle( wfMsg( "linklistsub" ) );
32
33 $id = $nt->getArticleID();
34 $sk = $wgUser->getSkin();
35 $isredir = " (" . wfMsg( "isredirect" ) . ")\n";
36
37 $wgOut->addHTML("&lt; ".$sk->makeKnownLinkObj($nt, "", "redirect=no" )."<br />\n");
38 $dbr =& wfGetDB( DB_SLAVE );
39 extract( $dbr->tableNames( 'cur', 'brokenlinks', 'links' ) );
40
41 if ( 0 == $id ) {
42 $sql = "SELECT cur_id,cur_namespace,cur_title,cur_is_redirect FROM $brokenlinks,$cur WHERE bl_to='" .
43 $dbr->strencode( $nt->getPrefixedDBkey() ) . "' AND bl_from=cur_id LIMIT $limit";
44 $res = $dbr->query( $sql, $fname );
45
46 if ( 0 == $dbr->numRows( $res ) ) {
47 $wgOut->addHTML( wfMsg( "nolinkshere" ) );
48 } else {
49 $wgOut->addHTML( wfMsg( "linkshere" ) );
50 $wgOut->addHTML( "\n<ul>" );
51
52 while ( $row = $dbr->fetchObject( $res ) ) {
53 $nt = Title::makeTitle( $row->cur_namespace, $row->cur_title );
54 if( !$nt ) {
55 continue;
56 }
57 $link = $sk->makeKnownLinkObj( $nt, "", "redirect=no" );
58 $wgOut->addHTML( "<li>{$link}" );
59
60 if ( $row->cur_is_redirect ) {
61 $wgOut->addHTML( $isredir );
62 wfShowIndirectLinks( 1, $row->cur_id, $limit );
63 }
64 $wgOut->addHTML( "</li>\n" );
65 }
66 $wgOut->addHTML( "</ul>\n" );
67 $dbr->freeResult( $res );
68 }
69 } else {
70 wfShowIndirectLinks( 0, $id, $limit );
71 }
72 }
73
74 /**
75 *
76 */
77 function wfShowIndirectLinks( $level, $lid, $limit ) {
78 global $wgOut, $wgUser;
79 $fname = "wfShowIndirectLinks";
80
81 $dbr =& wfGetDB( DB_READ );
82 extract( $dbr->tableNames( 'links','cur' ) );
83
84 $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";
85 $res = $dbr->query( $sql, $fname );
86
87 if ( 0 == $dbr->numRows( $res ) ) {
88 if ( 0 == $level ) {
89 $wgOut->addHTML( wfMsg( "nolinkshere" ) );
90 }
91 return;
92 }
93 if ( 0 == $level ) {
94 $wgOut->addHTML( wfMsg( "linkshere" ) );
95 }
96 $sk = $wgUser->getSkin();
97 $isredir = " (" . wfMsg( "isredirect" ) . ")\n";
98
99 $wgOut->addHTML( "<ul>" );
100 while ( $row = $dbr->fetchObject( $res ) ) {
101 $nt = Title::makeTitle( $row->cur_namespace, $row->cur_title );
102 if( !$nt ) {
103 $wgOut->addHTML( "<!-- bad backlink: " . htmlspecialchars( $row->l_from ) . " -->\n" );
104 continue;
105 }
106
107 if ( $row->cur_is_redirect ) {
108 $extra = "redirect=no";
109 } else {
110 $extra = "";
111 }
112
113 $link = $sk->makeKnownLinkObj( $nt, "", $extra );
114 $wgOut->addHTML( "<li>{$link}" );
115
116 if ( $row->cur_is_redirect ) {
117 $wgOut->addHTML( $isredir );
118 if ( $level < 2 ) {
119 wfShowIndirectLinks( $level + 1, $row->cur_id, $limit );
120 }
121 }
122 $wgOut->addHTML( "</li>\n" );
123 }
124 $wgOut->addHTML( "</ul>\n" );
125 }
126
127 ?>