Standardised file description headers; first path
[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 getName() {
33 return 'DoubleRedirects';
34 }
35
36 function isExpensive( ) { return true; }
37 function isSyndicated() { return false; }
38
39 function getPageHeader( ) {
40 return wfMsgExt( 'doubleredirectstext', array( 'parse' ) );
41 }
42
43 function getSQLText( &$dbr, $namespace = null, $title = null ) {
44
45 list( $page, $redirect ) = $dbr->tableNamesN( 'page', 'redirect' );
46
47 $limitToTitle = !( $namespace === null && $title === null );
48 $sql = $limitToTitle ? "SELECT" : "SELECT 'DoubleRedirects' as type," ;
49 $sql .=
50 " pa.page_namespace as namespace, pa.page_title as title," .
51 " pb.page_namespace as nsb, pb.page_title as tb," .
52 " pc.page_namespace as nsc, pc.page_title as tc" .
53 " FROM $redirect AS ra, $redirect AS rb, $page AS pa, $page AS pb, $page AS pc" .
54 " WHERE ra.rd_from=pa.page_id" .
55 " AND ra.rd_namespace=pb.page_namespace" .
56 " AND ra.rd_title=pb.page_title" .
57 " AND rb.rd_from=pb.page_id" .
58 " AND rb.rd_namespace=pc.page_namespace" .
59 " AND rb.rd_title=pc.page_title";
60
61 if( $limitToTitle ) {
62 $encTitle = $dbr->addQuotes( $title );
63 $sql .= " AND pa.page_namespace=$namespace" .
64 " AND pa.page_title=$encTitle";
65 }
66
67 return $sql;
68 }
69
70 function getSQL() {
71 $dbr = wfGetDB( DB_SLAVE );
72 return $this->getSQLText( $dbr );
73 }
74
75 function getOrder() {
76 return '';
77 }
78
79 function formatResult( $skin, $result ) {
80 global $wgContLang;
81
82 $fname = 'DoubleRedirectsPage::formatResult';
83 $titleA = Title::makeTitle( $result->namespace, $result->title );
84
85 if ( $result && !isset( $result->nsb ) ) {
86 $dbr = wfGetDB( DB_SLAVE );
87 $sql = $this->getSQLText( $dbr, $result->namespace, $result->title );
88 $res = $dbr->query( $sql, $fname );
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 }
127
128 /**
129 * constructor
130 */
131 function wfSpecialDoubleRedirects() {
132 list( $limit, $offset ) = wfCheckLimits();
133
134 $sdr = new DoubleRedirectsPage();
135
136 return $sdr->doQuery( $offset, $limit );
137
138 }