Merge "Revert "Setting up a way to have uploading by URL, but not on Special:Upload""
[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() { return true; }
37 function isSyndicated() { return false; }
38 function sortDescending() { return false; }
39
40 function getPageHeader() {
41 return $this->msg( 'brokenredirectstext' )->parseAsBlock();
42 }
43
44 function getQueryInfo() {
45 return array(
46 'tables' => array( 'redirect', 'p1' => 'page',
47 'p2' => 'page' ),
48 'fields' => array( 'namespace' => 'p1.page_namespace',
49 'title' => 'p1.page_title',
50 'value' => 'p1.page_title',
51 'rd_namespace',
52 'rd_title'
53 ),
54 'conds' => array( 'rd_namespace >= 0',
55 'p2.page_namespace IS NULL'
56 ),
57 'join_conds' => array( 'p1' => array( 'JOIN', array(
58 'rd_from=p1.page_id',
59 ) ),
60 'p2' => array( 'LEFT JOIN', array(
61 'rd_namespace=p2.page_namespace',
62 'rd_title=p2.page_title'
63 ) )
64 )
65 );
66 }
67
68 /**
69 * @return array
70 */
71 function getOrderFields() {
72 return array ( 'rd_namespace', 'rd_title', 'rd_from' );
73 }
74
75 /**
76 * @param $skin Skin
77 * @param $result
78 * @return String
79 */
80 function formatResult( $skin, $result ) {
81 $fromObj = Title::makeTitle( $result->namespace, $result->title );
82 if ( isset( $result->rd_title ) ) {
83 $toObj = Title::makeTitle( $result->rd_namespace, $result->rd_title );
84 } else {
85 $blinks = $fromObj->getBrokenLinksFrom(); # TODO: check for redirect, not for links
86 if ( $blinks ) {
87 $toObj = $blinks[0];
88 } else {
89 $toObj = false;
90 }
91 }
92
93 // $toObj may very easily be false if the $result list is cached
94 if ( !is_object( $toObj ) ) {
95 return '<del>' . Linker::link( $fromObj ) . '</del>';
96 }
97
98 $from = Linker::linkKnown(
99 $fromObj,
100 null,
101 array(),
102 array( 'redirect' => 'no' )
103 );
104 $links = array();
105 $links[] = Linker::linkKnown(
106 $fromObj,
107 $this->msg( 'brokenredirects-edit' )->escaped(),
108 array(),
109 array( 'action' => 'edit' )
110 );
111 $to = Linker::link(
112 $toObj,
113 null,
114 array(),
115 array(),
116 array( 'broken' )
117 );
118 $arr = $this->getLanguage()->getArrow();
119
120 $out = $from . $this->msg( 'word-separator' )->escaped();
121
122 if( $this->getUser()->isAllowed( 'delete' ) ) {
123 $links[] = Linker::linkKnown(
124 $fromObj,
125 $this->msg( 'brokenredirects-delete' )->escaped(),
126 array(),
127 array( 'action' => 'delete' )
128 );
129 }
130
131 $out .= $this->msg( 'parentheses' )->rawParams( $this->getLanguage()->pipeList( $links ) )->escaped();
132 $out .= " {$arr} {$to}";
133 return $out;
134 }
135 }