Merge "Removed useless begin()/commit() calls as DBO_TRX is not on in cli mode."
[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 to non existent page. Those should be
26 * fixed to point to an existing page.
27 *
28 * @ingroup SpecialPage
29 */
30 class BrokenRedirectsPage extends QueryPage {
31
32 function __construct( $name = 'BrokenRedirects' ) {
33 parent::__construct( $name );
34 }
35
36 function isExpensive() {
37 return true;
38 }
39
40 function isSyndicated() {
41 return false;
42 }
43
44 function sortDescending() {
45 return false;
46 }
47
48 function getPageHeader() {
49 return $this->msg( 'brokenredirectstext' )->parseAsBlock();
50 }
51
52 function getQueryInfo() {
53 return array(
54 'tables' => array(
55 'redirect',
56 'p1' => 'page',
57 'p2' => 'page',
58 ),
59 'fields' => array(
60 'namespace' => 'p1.page_namespace',
61 'title' => 'p1.page_title',
62 'value' => 'p1.page_title',
63 'rd_namespace',
64 'rd_title',
65 ),
66 'conds' => array(
67 // Exclude pages that don't exist locally as wiki pages,
68 // but aren't "broken" either.
69 // Special pages and interwiki links
70 'rd_namespace >= 0',
71 '(rd_interwiki IS NULL OR rd_interwiki = "")',
72 'p2.page_namespace IS NULL',
73 ),
74 'join_conds' => array(
75 'p1' => array( 'JOIN', array(
76 'rd_from=p1.page_id',
77 ) ),
78 'p2' => array( 'LEFT JOIN', array(
79 'rd_namespace=p2.page_namespace',
80 'rd_title=p2.page_title'
81 ) ),
82 ),
83 );
84 }
85
86 /**
87 * @return array
88 */
89 function getOrderFields() {
90 return array ( 'rd_namespace', 'rd_title', 'rd_from' );
91 }
92
93 /**
94 * @param $skin Skin
95 * @param $result
96 * @return String
97 */
98 function formatResult( $skin, $result ) {
99 $fromObj = Title::makeTitle( $result->namespace, $result->title );
100 if ( isset( $result->rd_title ) ) {
101 $toObj = Title::makeTitle( $result->rd_namespace, $result->rd_title );
102 } else {
103 $blinks = $fromObj->getBrokenLinksFrom(); # TODO: check for redirect, not for links
104 if ( $blinks ) {
105 $toObj = $blinks[0];
106 } else {
107 $toObj = false;
108 }
109 }
110
111 // $toObj may very easily be false if the $result list is cached
112 if ( !is_object( $toObj ) ) {
113 return '<del>' . Linker::link( $fromObj ) . '</del>';
114 }
115
116 $from = Linker::linkKnown(
117 $fromObj,
118 null,
119 array(),
120 array( 'redirect' => 'no' )
121 );
122 $links = array();
123 $links[] = Linker::linkKnown(
124 $fromObj,
125 $this->msg( 'brokenredirects-edit' )->escaped(),
126 array(),
127 array( 'action' => 'edit' )
128 );
129 $to = Linker::link(
130 $toObj,
131 null,
132 array(),
133 array(),
134 array( 'broken' )
135 );
136 $arr = $this->getLanguage()->getArrow();
137
138 $out = $from . $this->msg( 'word-separator' )->escaped();
139
140 if( $this->getUser()->isAllowed( 'delete' ) ) {
141 $links[] = Linker::linkKnown(
142 $fromObj,
143 $this->msg( 'brokenredirects-delete' )->escaped(),
144 array(),
145 array( 'action' => 'delete' )
146 );
147 }
148
149 $out .= $this->msg( 'parentheses' )->rawParams( $this->getLanguage()->pipeList( $links ) )->escaped();
150 $out .= " {$arr} {$to}";
151 return $out;
152 }
153 }