3 * Implements Special:DoubleRedirects
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.
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.
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
21 * @ingroup SpecialPage
25 * A special page listing redirects to redirecting page.
26 * The software will automatically not follow double redirects, to prevent loops.
28 * @ingroup SpecialPage
30 class DoubleRedirectsPage
extends QueryPage
{
32 function __construct( $name = 'DoubleRedirects' ) {
33 parent
::__construct( $name );
36 function isExpensive() {
40 function isSyndicated() {
44 function sortDescending() {
48 function getPageHeader() {
49 return $this->msg( 'doubleredirectstext' )->parseAsBlock();
52 function reallyGetQueryInfo( $namespace = null, $title = null ) {
53 $limitToTitle = !( $namespace === null && $title === null );
62 'namespace' => 'pa.page_namespace',
63 'title' => 'pa.page_title',
64 'value' => 'pa.page_title',
66 'nsb' => 'pb.page_namespace',
67 'tb' => 'pb.page_title',
69 // Select fields from redirect instead of page. Because there may
70 // not actually be a page table row for this target (e.g. for interwiki redirects)
71 'nsc' => 'rb.rd_namespace',
72 'tc' => 'rb.rd_title',
73 'iwc' => 'rb.rd_interwiki',
76 'ra.rd_from = pa.page_id',
78 // Filter out redirects where the target goes interwiki (bug 40353).
79 // This isn't an optimization, it is required for correct results,
80 // otherwise a non-double redirect like Bar -> w:Foo will show up
81 // like "Bar -> Foo -> w:Foo".
83 // Need to check both NULL and "" for some reason,
84 // apparently either can be stored for non-iw entries.
85 '(ra.rd_interwiki IS NULL OR ra.rd_interwiki = "")',
87 'pb.page_namespace = ra.rd_namespace',
88 'pb.page_title = ra.rd_title',
90 'rb.rd_from = pb.page_id',
93 if ( $limitToTitle ) {
94 $retval['conds']['pa.page_namespace'] = $namespace;
95 $retval['conds']['pa.page_title'] = $title;
100 function getQueryInfo() {
101 return $this->reallyGetQueryInfo();
104 function getOrderFields() {
105 return array ( 'ra.rd_namespace', 'ra.rd_title' );
108 function formatResult( $skin, $result ) {
109 $titleA = Title
::makeTitle( $result->namespace, $result->title
);
111 // If only titleA is in the query, it means this came from
112 // querycache (which only saves 3 columns).
113 // That does save the bulk of the query cost, but now we need to
114 // get a little more detail about each individual entry quickly
115 // using the filter of reallyGetQueryInfo.
116 if ( $result && !isset( $result->nsb
) ) {
117 $dbr = wfGetDB( DB_SLAVE
);
118 $qi = $this->reallyGetQueryInfo( $result->namespace,
120 $res = $dbr->select($qi['tables'], $qi['fields'],
121 $qi['conds'], __METHOD__
);
123 $result = $dbr->fetchObject( $res );
127 return '<del>' . Linker
::link( $titleA, null, array(), array( 'redirect' => 'no' ) ) . '</del>';
130 $titleB = Title
::makeTitle( $result->nsb
, $result->tb
);
131 $titleC = Title
::makeTitle( $result->nsc
, $result->tc
, '', $result->iwc
);
133 $linkA = Linker
::linkKnown(
137 array( 'redirect' => 'no' )
140 $edit = Linker
::linkKnown(
142 $this->msg( 'parentheses', $this->msg( 'editlink' )->text() )->escaped(),
150 $linkB = Linker
::linkKnown(
154 array( 'redirect' => 'no' )
157 $linkC = Linker
::linkKnown( $titleC );
159 $lang = $this->getLanguage();
160 $arr = $lang->getArrow() . $lang->getDirMark();
162 return( "{$linkA} {$edit} {$arr} {$linkB} {$arr} {$linkC}" );