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