Separate language generation from outputPage
[lhc/web/wiklou.git] / includes / specials / SpecialDoubleRedirects.php
1 <?php
2 /**
3 * Implements Special:DoubleRedirects
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 redirecting page.
26 * The software will automatically not follow double redirects, to prevent loops.
27 *
28 * @ingroup SpecialPage
29 */
30 class DoubleRedirectsPage extends QueryPage {
31
32 function __construct( $name = 'DoubleRedirects' ) {
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( 'doubleredirectstext' )->parseAsBlock();
50 }
51
52 function reallyGetQueryInfo( $namespace = null, $title = null ) {
53 $limitToTitle = !( $namespace === null && $title === null );
54 $dbr = wfGetDB( DB_SLAVE );
55 $retval = array (
56 'tables' => array (
57 'ra' => 'redirect',
58 'rb' => 'redirect',
59 'pa' => 'page',
60 'pb' => 'page'
61 ),
62 'fields' => array(
63 'namespace' => 'pa.page_namespace',
64 'title' => 'pa.page_title',
65 'value' => 'pa.page_title',
66
67 'nsb' => 'pb.page_namespace',
68 'tb' => 'pb.page_title',
69
70 // Select fields from redirect instead of page. Because there may
71 // not actually be a page table row for this target (e.g. for interwiki redirects)
72 'nsc' => 'rb.rd_namespace',
73 'tc' => 'rb.rd_title',
74 'iwc' => 'rb.rd_interwiki',
75 ),
76 'conds' => array(
77 'ra.rd_from = pa.page_id',
78
79 // Filter out redirects where the target goes interwiki (bug 40353).
80 // This isn't an optimization, it is required for correct results,
81 // otherwise a non-double redirect like Bar -> w:Foo will show up
82 // like "Bar -> Foo -> w:Foo".
83
84 // Need to check both NULL and "" for some reason,
85 // apparently either can be stored for non-iw entries.
86 'ra.rd_interwiki IS NULL OR ra.rd_interwiki = ' . $dbr->addQuotes( '' ),
87
88 'pb.page_namespace = ra.rd_namespace',
89 'pb.page_title = ra.rd_title',
90
91 'rb.rd_from = pb.page_id',
92 )
93 );
94 if ( $limitToTitle ) {
95 $retval['conds']['pa.page_namespace'] = $namespace;
96 $retval['conds']['pa.page_title'] = $title;
97 }
98 return $retval;
99 }
100
101 function getQueryInfo() {
102 return $this->reallyGetQueryInfo();
103 }
104
105 function getOrderFields() {
106 return array ( 'ra.rd_namespace', 'ra.rd_title' );
107 }
108
109 function formatResult( $skin, $result ) {
110 $titleA = Title::makeTitle( $result->namespace, $result->title );
111
112 // If only titleA is in the query, it means this came from
113 // querycache (which only saves 3 columns).
114 // That does save the bulk of the query cost, but now we need to
115 // get a little more detail about each individual entry quickly
116 // using the filter of reallyGetQueryInfo.
117 if ( $result && !isset( $result->nsb ) ) {
118 $dbr = wfGetDB( DB_SLAVE );
119 $qi = $this->reallyGetQueryInfo( $result->namespace,
120 $result->title );
121 $res = $dbr->select( $qi['tables'], $qi['fields'],
122 $qi['conds'], __METHOD__ );
123 if ( $res ) {
124 $result = $dbr->fetchObject( $res );
125 }
126 }
127 if ( !$result ) {
128 return '<del>' . Linker::link( $titleA, null, array(), array( 'redirect' => 'no' ) ) . '</del>';
129 }
130
131 $titleB = Title::makeTitle( $result->nsb, $result->tb );
132 $titleC = Title::makeTitle( $result->nsc, $result->tc, '', $result->iwc );
133
134 $linkA = Linker::linkKnown(
135 $titleA,
136 null,
137 array(),
138 array( 'redirect' => 'no' )
139 );
140
141 $edit = Linker::linkKnown(
142 $titleA,
143 $this->msg( 'parentheses', $this->msg( 'editlink' )->text() )->escaped(),
144 array(),
145 array(
146 'redirect' => 'no',
147 'action' => 'edit'
148 )
149 );
150
151 $linkB = Linker::linkKnown(
152 $titleB,
153 null,
154 array(),
155 array( 'redirect' => 'no' )
156 );
157
158 $linkC = Linker::linkKnown( $titleC );
159
160 $lang = $this->getLanguage();
161 $arr = $lang->getArrow() . $lang->getDirMark();
162
163 return( "{$linkA} {$edit} {$arr} {$linkB} {$arr} {$linkC}" );
164 }
165
166 protected function getGroupName() {
167 return 'maintenance';
168 }
169 }