Link content pages and uploaded files to AllPages and FileList respectively
[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
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 wfMsgExt( 'brokenredirectstext', array( 'parse' ) );
42 }
43
44 function getQueryInfo() {
45 return array(
46 'tables' => array( 'redirect', 'p1' => 'page',
47 'p2' => 'page' ),
48 'fields' => array( 'p1.page_namespace AS namespace',
49 'p1.page_title AS title',
50 'rd_namespace',
51 'rd_title'
52 ),
53 'conds' => array( 'rd_namespace >= 0',
54 'p2.page_namespace IS NULL'
55 ),
56 'join_conds' => array( 'p1' => array( 'LEFT JOIN', array(
57 'rd_from=p1.page_id',
58 ) ),
59 'p2' => array( 'LEFT JOIN', array(
60 'rd_namespace=p2.page_namespace',
61 'rd_title=p2.page_title'
62 ) )
63 )
64 );
65 }
66
67 /**
68 * @return array
69 */
70 function getOrderFields() {
71 return array ( 'rd_namespace', 'rd_title', 'rd_from' );
72 }
73
74 /**
75 * @param $skin Skin
76 * @param $result
77 * @return String
78 */
79 function formatResult( $skin, $result ) {
80 global $wgUser, $wgLang;
81
82 $fromObj = Title::makeTitle( $result->namespace, $result->title );
83 if ( isset( $result->rd_title ) ) {
84 $toObj = Title::makeTitle( $result->rd_namespace, $result->rd_title );
85 } else {
86 $blinks = $fromObj->getBrokenLinksFrom(); # TODO: check for redirect, not for links
87 if ( $blinks ) {
88 $toObj = $blinks[0];
89 } else {
90 $toObj = false;
91 }
92 }
93
94 // $toObj may very easily be false if the $result list is cached
95 if ( !is_object( $toObj ) ) {
96 return '<del>' . $skin->link( $fromObj ) . '</del>';
97 }
98
99 $from = $skin->linkKnown(
100 $fromObj,
101 null,
102 array(),
103 array( 'redirect' => 'no' )
104 );
105 $links = array();
106 $links[] = $skin->linkKnown(
107 $fromObj,
108 wfMsgHtml( 'brokenredirects-edit' ),
109 array(),
110 array( 'action' => 'edit' )
111 );
112 $to = $skin->link(
113 $toObj,
114 null,
115 array(),
116 array(),
117 array( 'broken' )
118 );
119 $arr = $wgLang->getArrow();
120
121 $out = $from . wfMsg( 'word-separator' );
122
123 if( $wgUser->isAllowed( 'delete' ) ) {
124 $links[] = $skin->linkKnown(
125 $fromObj,
126 wfMsgHtml( 'brokenredirects-delete' ),
127 array(),
128 array( 'action' => 'delete' )
129 );
130 }
131
132 $out .= wfMsg( 'parentheses', $wgLang->pipeList( $links ) );
133 $out .= " {$arr} {$to}";
134 return $out;
135 }
136 }