Correct the address of the FSF in some of the GPL headers
[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 $dbr->freeResult( $res );
89 }
90 }
91 if ( !$result ) {
92 return '<s>' . $skin->link( $titleA, null, array(), array( 'redirect' => 'no' ) ) . '</s>';
93 }
94
95 $titleB = Title::makeTitle( $result->nsb, $result->tb );
96 $titleC = Title::makeTitle( $result->nsc, $result->tc );
97
98 $linkA = $skin->linkKnown(
99 $titleA,
100 null,
101 array(),
102 array( 'redirect' => 'no' )
103 );
104 $edit = $skin->linkKnown(
105 $titleA,
106 wfMsgExt( 'parentheses', array( 'escape' ), wfMsg( 'editlink' ) ),
107 array(),
108 array(
109 'redirect' => 'no',
110 'action' => 'edit'
111 )
112 );
113 $linkB = $skin->linkKnown(
114 $titleB,
115 null,
116 array(),
117 array( 'redirect' => 'no' )
118 );
119 $linkC = $skin->linkKnown( $titleC );
120 $arr = $wgContLang->getArrow() . $wgContLang->getDirMark();
121
122 return( "{$linkA} {$edit} {$arr} {$linkB} {$arr} {$linkC}" );
123 }
124 }
125
126 /**
127 * constructor
128 */
129 function wfSpecialDoubleRedirects() {
130 list( $limit, $offset ) = wfCheckLimits();
131
132 $sdr = new DoubleRedirectsPage();
133
134 return $sdr->doQuery( $offset, $limit );
135
136 }