cc5ee222e357e388e9e18dc2ee5ae821cc444387
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.
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.
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 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 * http://www.gnu.org/copyleft/gpl.html
21 * A special page listing redirects to redirecting page.
22 * The software will automatically not follow double redirects, to prevent loops.
25 * @ingroup SpecialPage
27 class DoubleRedirectsPage
extends PageQueryPage
{
30 return 'DoubleRedirects';
33 function isExpensive( ) { return true; }
34 function isSyndicated() { return false; }
36 function getPageHeader( ) {
37 return wfMsgExt( 'doubleredirectstext', array( 'parse' ) );
40 function getSQLText( &$dbr, $namespace = null, $title = null ) {
42 list( $page, $redirect ) = $dbr->tableNamesN( 'page', 'redirect' );
44 $limitToTitle = !( $namespace === null && $title === null );
45 $sql = $limitToTitle ?
"SELECT" : "SELECT 'DoubleRedirects' as type," ;
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";
59 $encTitle = $dbr->addQuotes( $title );
60 $sql .= " AND pa.page_namespace=$namespace" .
61 " AND pa.page_title=$encTitle";
68 $dbr = wfGetDB( DB_SLAVE
);
69 return $this->getSQLText( $dbr );
76 function formatResult( $skin, $result ) {
79 $fname = 'DoubleRedirectsPage::formatResult';
80 $titleA = Title
::makeTitle( $result->namespace, $result->title
);
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 );
87 $result = $dbr->fetchObject( $res );
88 $dbr->freeResult( $res );
92 return '<s>' . $skin->link( $titleA, null, array(), array( 'redirect' => 'no' ) ) . '</s>';
95 $titleB = Title
::makeTitle( $result->nsb
, $result->tb
);
96 $titleC = Title
::makeTitle( $result->nsc
, $result->tc
);
98 $linkA = $skin->linkKnown(
102 array( 'redirect' => 'no' )
104 $edit = $skin->linkKnown(
106 wfMsgExt( 'parentheses', array( 'escape' ), wfMsg( 'editlink' ) ),
113 $linkB = $skin->linkKnown(
117 array( 'redirect' => 'no' )
119 $linkC = $skin->linkKnown( $titleC );
120 $arr = $wgContLang->getArrow() . $wgContLang->getDirMark();
122 return( "{$linkA} {$edit} {$arr} {$linkB} {$arr} {$linkC}" );
129 function wfSpecialDoubleRedirects() {
130 list( $limit, $offset ) = wfCheckLimits();
132 $sdr = new DoubleRedirectsPage();
134 return $sdr->doQuery( $offset, $limit );