Follow-up r84814: revert redundant summary message addition.
[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 PageQueryPage {
31
32 function __construct( $name = 'DoubleRedirects' ) {
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( 'doubleredirectstext', array( 'parse' ) );
42 }
43
44 function reallyGetQueryInfo( $namespace = null, $title = null ) {
45 $limitToTitle = !( $namespace === null && $title === null );
46 $retval = array (
47 'tables' => array ( 'ra' => 'redirect',
48 'rb' => 'redirect', 'pa' => 'page',
49 'pb' => 'page', 'pc' => 'page' ),
50 'fields' => array ( 'pa.page_namespace AS namespace',
51 'pa.page_title AS title',
52 'pb.page_namespace AS nsb',
53 'pb.page_title AS tb',
54 'pc.page_namespace AS nsc',
55 'pc.page_title AS tc' ),
56 'conds' => array ( 'ra.rd_from = pa.page_id',
57 'pb.page_namespace = ra.rd_namespace',
58 'pb.page_title = ra.rd_title',
59 'rb.rd_from = pb.page_id',
60 'pc.page_namespace = rb.rd_namespace',
61 'pc.page_title = rb.rd_title' )
62 );
63 if ( $limitToTitle ) {
64 $retval['conds']['pa.page_namespace'] = $namespace;
65 $retval['conds']['pa.page_title'] = $title;
66 }
67 return $retval;
68 }
69
70 function getQueryInfo() {
71 return $this->reallyGetQueryInfo();
72 }
73
74 function getOrderFields() {
75 return array ( 'ra.rd_namespace', 'ra.rd_title' );
76 }
77
78 function formatResult( $skin, $result ) {
79 global $wgContLang;
80
81 $titleA = Title::makeTitle( $result->namespace, $result->title );
82
83 if ( $result && !isset( $result->nsb ) ) {
84 $dbr = wfGetDB( DB_SLAVE );
85 $qi = $this->reallyGetQueryInfo( $result->namespace,
86 $result->title );
87 $res = $dbr->select($qi['tables'], $qi['fields'],
88 $qi['conds'], __METHOD__ );
89 if ( $res ) {
90 $result = $dbr->fetchObject( $res );
91 }
92 }
93 if ( !$result ) {
94 return '<del>' . $skin->link( $titleA, null, array(), array( 'redirect' => 'no' ) ) . '</del>';
95 }
96
97 $titleB = Title::makeTitle( $result->nsb, $result->tb );
98 $titleC = Title::makeTitle( $result->nsc, $result->tc );
99
100 $linkA = $skin->linkKnown(
101 $titleA,
102 null,
103 array(),
104 array( 'redirect' => 'no' )
105 );
106 $edit = $skin->linkKnown(
107 $titleA,
108 wfMsgExt( 'parentheses', array( 'escape' ), wfMsg( 'editlink' ) ),
109 array(),
110 array(
111 'redirect' => 'no',
112 'action' => 'edit'
113 )
114 );
115 $linkB = $skin->linkKnown(
116 $titleB,
117 null,
118 array(),
119 array( 'redirect' => 'no' )
120 );
121 $linkC = $skin->linkKnown( $titleC );
122 $arr = $wgContLang->getArrow() . $wgContLang->getDirMark();
123
124 return( "{$linkA} {$edit} {$arr} {$linkB} {$arr} {$linkC}" );
125 }
126 }