CologneBlue rewrite: remove hard dependency on SkinLegacy, kill Quickbar nonsense
[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( 'redirect', 'p1' => 'page',
55 'p2' => 'page' ),
56 'fields' => array( 'namespace' => 'p1.page_namespace',
57 'title' => 'p1.page_title',
58 'value' => 'p1.page_title',
59 'rd_namespace',
60 'rd_title'
61 ),
62 'conds' => array( 'rd_namespace >= 0',
63 'p2.page_namespace IS NULL'
64 ),
65 'join_conds' => array( 'p1' => array( 'JOIN', array(
66 'rd_from=p1.page_id',
67 ) ),
68 'p2' => array( 'LEFT JOIN', array(
69 'rd_namespace=p2.page_namespace',
70 'rd_title=p2.page_title'
71 ) )
72 )
73 );
74 }
75
76 /**
77 * @return array
78 */
79 function getOrderFields() {
80 return array ( 'rd_namespace', 'rd_title', 'rd_from' );
81 }
82
83 /**
84 * @param $skin Skin
85 * @param $result
86 * @return String
87 */
88 function formatResult( $skin, $result ) {
89 $fromObj = Title::makeTitle( $result->namespace, $result->title );
90 if ( isset( $result->rd_title ) ) {
91 $toObj = Title::makeTitle( $result->rd_namespace, $result->rd_title );
92 } else {
93 $blinks = $fromObj->getBrokenLinksFrom(); # TODO: check for redirect, not for links
94 if ( $blinks ) {
95 $toObj = $blinks[0];
96 } else {
97 $toObj = false;
98 }
99 }
100
101 // $toObj may very easily be false if the $result list is cached
102 if ( !is_object( $toObj ) ) {
103 return '<del>' . Linker::link( $fromObj ) . '</del>';
104 }
105
106 $from = Linker::linkKnown(
107 $fromObj,
108 null,
109 array(),
110 array( 'redirect' => 'no' )
111 );
112 $links = array();
113 $links[] = Linker::linkKnown(
114 $fromObj,
115 $this->msg( 'brokenredirects-edit' )->escaped(),
116 array(),
117 array( 'action' => 'edit' )
118 );
119 $to = Linker::link(
120 $toObj,
121 null,
122 array(),
123 array(),
124 array( 'broken' )
125 );
126 $arr = $this->getLanguage()->getArrow();
127
128 $out = $from . $this->msg( 'word-separator' )->escaped();
129
130 if( $this->getUser()->isAllowed( 'delete' ) ) {
131 $links[] = Linker::linkKnown(
132 $fromObj,
133 $this->msg( 'brokenredirects-delete' )->escaped(),
134 array(),
135 array( 'action' => 'delete' )
136 );
137 }
138
139 $out .= $this->msg( 'parentheses' )->rawParams( $this->getLanguage()->pipeList( $links ) )->escaped();
140 $out .= " {$arr} {$to}";
141 return $out;
142 }
143 }