30f84f0c2025e30438d9eb2e42fdd9509f0e75e9
[lhc/web/wiklou.git] / includes / specials / SpecialDoubleRedirects.php
1 <?php
2 /**
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 * http://www.gnu.org/copyleft/gpl.html
18 */
19
20 /**
21 * A special page listing redirects to redirecting page.
22 * The software will automatically not follow double redirects, to prevent loops.
23 *
24 * @file
25 * @ingroup SpecialPage
26 */
27 class DoubleRedirectsPage extends PageQueryPage {
28
29 function getName() {
30 return 'DoubleRedirects';
31 }
32
33 function isExpensive( ) { return true; }
34 function isSyndicated() { return false; }
35
36 function getPageHeader( ) {
37 return wfMsgExt( 'doubleredirectstext', array( 'parse' ) );
38 }
39
40 function getSQLText( &$dbr, $namespace = null, $title = null ) {
41
42 list( $page, $redirect ) = $dbr->tableNamesN( 'page', 'redirect' );
43
44 $limitToTitle = !( $namespace === null && $title === null );
45 $sql = $limitToTitle ? "SELECT" : "SELECT 'DoubleRedirects' as type," ;
46 $sql .=
47 " pa.page_namespace as namespace, pa.page_title as title," .
48 " pb.page_namespace as nsb, pb.page_title as tb," .
49 " pc.page_namespace as nsc, pc.page_title as tc" .
50 " FROM $redirect AS ra, $redirect AS rb, $page AS pa, $page AS pb, $page AS pc" .
51 " WHERE ra.rd_from=pa.page_id" .
52 " AND ra.rd_namespace=pb.page_namespace" .
53 " AND ra.rd_title=pb.page_title" .
54 " AND rb.rd_from=pb.page_id" .
55 " AND rb.rd_namespace=pc.page_namespace" .
56 " AND rb.rd_title=pc.page_title";
57
58 if( $limitToTitle ) {
59 $encTitle = $dbr->addQuotes( $title );
60 $sql .= " AND pa.page_namespace=$namespace" .
61 " AND pa.page_title=$encTitle";
62 }
63
64 return $sql;
65 }
66
67 function getSQL() {
68 $dbr = wfGetDB( DB_SLAVE );
69 return $this->getSQLText( $dbr );
70 }
71
72 function getOrder() {
73 return '';
74 }
75
76 function formatResult( $skin, $result ) {
77 global $wgContLang;
78
79 $fname = 'DoubleRedirectsPage::formatResult';
80 $titleA = Title::makeTitle( $result->namespace, $result->title );
81
82 if ( $result && !isset( $result->nsb ) ) {
83 $dbr = wfGetDB( DB_SLAVE );
84 $sql = $this->getSQLText( $dbr, $result->namespace, $result->title );
85 $res = $dbr->query( $sql, $fname );
86 if ( $res ) {
87 $result = $dbr->fetchObject( $res );
88 }
89 }
90 if ( !$result ) {
91 return '<del>' . $skin->link( $titleA, null, array(), array( 'redirect' => 'no' ) ) . '</del>';
92 }
93
94 $titleB = Title::makeTitle( $result->nsb, $result->tb );
95 $titleC = Title::makeTitle( $result->nsc, $result->tc );
96
97 $linkA = $skin->linkKnown(
98 $titleA,
99 null,
100 array(),
101 array( 'redirect' => 'no' )
102 );
103 $edit = $skin->linkKnown(
104 $titleA,
105 wfMsgExt( 'parentheses', array( 'escape' ), wfMsg( 'editlink' ) ),
106 array(),
107 array(
108 'redirect' => 'no',
109 'action' => 'edit'
110 )
111 );
112 $linkB = $skin->linkKnown(
113 $titleB,
114 null,
115 array(),
116 array( 'redirect' => 'no' )
117 );
118 $linkC = $skin->linkKnown( $titleC );
119 $arr = $wgContLang->getArrow() . $wgContLang->getDirMark();
120
121 return( "{$linkA} {$edit} {$arr} {$linkB} {$arr} {$linkC}" );
122 }
123 }
124
125 /**
126 * constructor
127 */
128 function wfSpecialDoubleRedirects() {
129 list( $limit, $offset ) = wfCheckLimits();
130
131 $sdr = new DoubleRedirectsPage();
132
133 return $sdr->doQuery( $offset, $limit );
134
135 }