Bug 1761: Cleanup of Recent Changes indicator flags
[lhc/web/wiklou.git] / includes / SpecialWhatlinkshere.php
1 <?php
2 /**
3 *
4 * @package MediaWiki
5 * @subpackage SpecialPage
6 */
7
8 /**
9 * Entry point
10 * @param string $par An article name ??
11 */
12 function wfSpecialWhatlinkshere($par = NULL) {
13 global $wgUser, $wgOut, $wgRequest;
14 $fname = 'wfSpecialWhatlinkshere';
15
16 $target = $wgRequest->getVal( 'target' );
17 list( $limit, $offset ) = $wgRequest->getLimitOffset();
18
19 if(!empty($par)) {
20 $target = $par;
21 } else if ( is_null( $target ) ) {
22 $wgOut->errorpage( 'notargettitle', 'notargettext' );
23 return;
24 }
25
26 $nt = Title::newFromURL( $target );
27 if( !$nt ) {
28 $wgOut->errorpage( 'notargettitle', 'notargettext' );
29 return;
30 }
31 $wgOut->setPagetitle( $nt->getPrefixedText() );
32 $wgOut->setSubtitle( wfMsg( 'linklistsub' ) );
33
34 $id = $nt->getArticleID();
35 $sk = $wgUser->getSkin();
36 $isredir = ' (' . wfMsg( 'isredirect' ) . ")\n";
37
38 $wgOut->addHTML('&lt; '.$sk->makeKnownLinkObj($nt, '', 'redirect=no' )."<br />\n");
39
40 $specialTitle = Title::makeTitle( NS_SPECIAL, 'Whatlinkshere' );
41 $wgOut->addHTML( wfViewPrevNext( $offset, $limit, $specialTitle, 'target=' . urlencode( $target ) ) );
42
43 $dbr =& wfGetDB( DB_SLAVE );
44 extract( $dbr->tableNames( 'page', 'brokenlinks', 'links' ) );
45
46 if ( 0 == $id ) {
47 print $dbr->limitResult( $limit, $offset );
48 exit;
49
50 $sql = "SELECT page_id,page_namespace,page_title,page_is_redirect FROM $brokenlinks,$page WHERE bl_to='" .
51 $dbr->strencode( $nt->getPrefixedDBkey() ) . "' AND bl_from=page_id " .
52 $dbr->limitResult( $limit, $offset );
53 $res = $dbr->query( $sql, $fname );
54
55 if ( 0 == $dbr->numRows( $res ) ) {
56 $wgOut->addHTML( wfMsg( 'nolinkshere' ) );
57 } else {
58 $wgOut->addHTML( wfMsg( 'linkshere' ) );
59 $wgOut->addHTML( "\n<ul>" );
60
61 while ( $row = $dbr->fetchObject( $res ) ) {
62 $nt = Title::makeTitle( $row->page_namespace, $row->page_title );
63 if( !$nt ) {
64 continue;
65 }
66 $link = $sk->makeKnownLinkObj( $nt, '', 'redirect=no' );
67 $wgOut->addHTML( "<li>{$link}" );
68
69 if ( $row->page_is_redirect ) {
70 $wgOut->addHTML( $isredir );
71 wfShowIndirectLinks( 1, $row->page_id, 500 );
72 }
73 $wgOut->addHTML( "</li>\n" );
74 }
75 $wgOut->addHTML( "</ul>\n" );
76 $dbr->freeResult( $res );
77 }
78 } else {
79 wfShowIndirectLinks( 0, $id, $limit, $offset );
80 }
81 $wgOut->addHTML( wfViewPrevNext( $offset, $limit, $specialTitle, 'target=' . urlencode( $target ) ) );
82 }
83
84 /**
85 *
86 */
87 function wfShowIndirectLinks( $level, $lid, $limit, $offset = 0 ) {
88 global $wgOut, $wgUser;
89 $fname = 'wfShowIndirectLinks';
90
91 $dbr =& wfGetDB( DB_READ );
92 extract( $dbr->tableNames( 'links','page' ) );
93
94 if ( $level == 0 ) {
95 $limitSql = $dbr->limitResult( $limit, $offset );
96 } else {
97 $limitSql = "LIMIT $limit";
98 }
99
100 $sql = "SELECT page_id,page_namespace,page_title,page_is_redirect FROM $links,$page WHERE l_to={$lid} AND l_from=page_id $limitSql";
101 $res = $dbr->query( $sql, $fname );
102
103 if ( 0 == $dbr->numRows( $res ) ) {
104 if ( 0 == $level ) {
105 $wgOut->addHTML( wfMsg( 'nolinkshere' ) );
106 }
107 return;
108 }
109 if ( 0 == $level ) {
110 $wgOut->addHTML( wfMsg( 'linkshere' ) );
111 }
112 $sk = $wgUser->getSkin();
113 $isredir = ' (' . wfMsg( 'isredirect' ) . ")\n";
114
115 $wgOut->addHTML( '<ul>' );
116 while ( $row = $dbr->fetchObject( $res ) ) {
117 $nt = Title::makeTitle( $row->page_namespace, $row->page_title );
118 if( !$nt ) {
119 $wgOut->addHTML( '<!-- bad backlink: ' . htmlspecialchars( $row->l_from ) . " -->\n" );
120 continue;
121 }
122
123 if ( $row->page_is_redirect ) {
124 $extra = 'redirect=no';
125 } else {
126 $extra = '';
127 }
128
129 $link = $sk->makeKnownLinkObj( $nt, '', $extra );
130 $wgOut->addHTML( '<li>'.$link );
131
132 if ( $row->page_is_redirect ) {
133 $wgOut->addHTML( $isredir );
134 if ( $level < 2 ) {
135 wfShowIndirectLinks( $level + 1, $row->page_id, 500 );
136 }
137 }
138 $wgOut->addHTML( "</li>\n" );
139 }
140 $wgOut->addHTML( "</ul>\n" );
141 }
142
143 ?>