Standardised file description headers; first path
[lhc/web/wiklou.git] / includes / specials / SpecialBrokenRedirects.php
1 <?php
2 /**
3 * Implements Special:Brokenredirects
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @ingroup SpecialPage
22 */
23
24 /**
25 * A special page listing redirects tonon existent page. Those should be
26 * fixed to point to an existing page.
27 *
28 * @ingroup SpecialPage
29 */
30 class BrokenRedirectsPage extends PageQueryPage {
31 var $targets = array();
32
33 function getName() {
34 return 'BrokenRedirects';
35 }
36
37 function isExpensive( ) { return true; }
38 function isSyndicated() { return false; }
39
40 function getPageHeader( ) {
41 return wfMsgExt( 'brokenredirectstext', array( 'parse' ) );
42 }
43
44 function getSQL() {
45 $dbr = wfGetDB( DB_SLAVE );
46 list( $page, $redirect ) = $dbr->tableNamesN( 'page', 'redirect' );
47
48 $sql = "SELECT 'BrokenRedirects' AS type,
49 p1.page_namespace AS namespace,
50 p1.page_title AS title,
51 rd_namespace,
52 rd_title
53 FROM $redirect AS rd
54 JOIN $page p1 ON (rd.rd_from=p1.page_id)
55 LEFT JOIN $page AS p2 ON (rd_namespace=p2.page_namespace AND rd_title=p2.page_title )
56 WHERE rd_namespace >= 0
57 AND p2.page_namespace IS NULL";
58 return $sql;
59 }
60
61 function getOrder() {
62 return '';
63 }
64
65 function formatResult( $skin, $result ) {
66 global $wgUser, $wgContLang, $wgLang;
67
68 $fromObj = Title::makeTitle( $result->namespace, $result->title );
69 if ( isset( $result->rd_title ) ) {
70 $toObj = Title::makeTitle( $result->rd_namespace, $result->rd_title );
71 } else {
72 $blinks = $fromObj->getBrokenLinksFrom(); # TODO: check for redirect, not for links
73 if ( $blinks ) {
74 $toObj = $blinks[0];
75 } else {
76 $toObj = false;
77 }
78 }
79
80 // $toObj may very easily be false if the $result list is cached
81 if ( !is_object( $toObj ) ) {
82 return '<del>' . $skin->link( $fromObj ) . '</del>';
83 }
84
85 $from = $skin->linkKnown(
86 $fromObj,
87 null,
88 array(),
89 array( 'redirect' => 'no' )
90 );
91 $links = array();
92 $links[] = $skin->linkKnown(
93 $fromObj,
94 wfMsgHtml( 'brokenredirects-edit' ),
95 array(),
96 array( 'action' => 'edit' )
97 );
98 $to = $skin->link(
99 $toObj,
100 null,
101 array(),
102 array(),
103 array( 'broken' )
104 );
105 $arr = $wgContLang->getArrow();
106
107 $out = $from . wfMsg( 'word-separator' );
108
109 if( $wgUser->isAllowed( 'delete' ) ) {
110 $links[] = $skin->linkKnown(
111 $fromObj,
112 wfMsgHtml( 'brokenredirects-delete' ),
113 array(),
114 array( 'action' => 'delete' )
115 );
116 }
117
118 $out .= wfMsg( 'parentheses', $wgLang->pipeList( $links ) );
119 $out .= " {$arr} {$to}";
120 return $out;
121 }
122 }
123
124 /**
125 * constructor
126 */
127 function wfSpecialBrokenRedirects() {
128 list( $limit, $offset ) = wfCheckLimits();
129
130 $sbr = new BrokenRedirectsPage();
131
132 return $sbr->doQuery( $offset, $limit );
133 }