(bug 10985) Special:DoubleRedirects was omitting "fixed" results when cached, leading...
[lhc/web/wiklou.git] / includes / SpecialDoubleRedirects.php
1 <?php
2 /**
3 *
4 * @addtogroup SpecialPage
5 */
6
7 /**
8 * A special page listing redirects to redirecting page.
9 * The software will automatically not follow double redirects, to prevent loops.
10 * @addtogroup SpecialPage
11 */
12 class DoubleRedirectsPage extends PageQueryPage {
13
14 function getName() {
15 return 'DoubleRedirects';
16 }
17
18 function isExpensive( ) { return true; }
19 function isSyndicated() { return false; }
20
21 function getPageHeader( ) {
22 return wfMsgExt( 'doubleredirectstext', array( 'parse' ) );
23 }
24
25 function getSql() {
26 $dbr = wfGetDB( DB_SLAVE );
27 list( $page, $redirect ) = $dbr->tableNamesN( 'page', 'redirect' );
28 return "
29 SELECT
30 'DoubleRedirects' as type,
31 pa.page_namespace as namespace, pa.page_title as title,
32 pb.page_namespace as nsb, pb.page_title as tb,
33 pc.page_namespace as nsc, pc.page_title as tc
34 FROM
35 $redirect AS ra,
36 $redirect AS rb,
37 $page AS pa,
38 $page AS pb,
39 $page AS pc
40 WHERE
41 ra.rd_from = pa.page_id
42 AND ra.rd_namespace = pb.page_namespace
43 AND ra.rd_title = pb.page_title
44 AND rb.rd_from = pb.page_id
45 AND rb.rd_namespace = pc.page_namespace
46 AND rb.rd_title = pc.page_title";
47 }
48
49 function getOrder() {
50 return '';
51 }
52
53 function formatResult( $skin, $result ) {
54 global $wgContLang;
55 $parts = array();
56
57 $titleA = Title::makeTitle( $result->namespace, $result->title );
58 $parts[] = $skin->makeKnownLinkObj( $titleA, '', 'redirect=no' );
59 $parts[] = '(' . $skin->makeKnownLinkObj(
60 $titleA,
61 wfMsgHtml( 'qbedit' ),
62 'action=edit&redirect=no'
63 ) . ')';
64
65 // If the report isn't cached, generate some useful additional
66 // links to the target page, and *that* page's redirect target
67 if( isset( $result->nsb ) ) {
68 $parts[] = $wgContLang->getArrow() . $wgContLang->getDirMark();
69 $parts[] = $skin->makeKnownLinkObj(
70 Title::makeTitle( $result->nsb, $result->tb ),
71 '',
72 'redirect=no'
73 );
74 $parts[] = $wgContLang->getArrow() . $wgContLang->getDirMark();
75 $parts[] = $skin->makeKnownLinkObj( Title::makeTitle( $result->nsc, $result->tc ) );
76 }
77
78 return implode( ' ', $parts );
79 }
80 }
81
82 /**
83 * constructor
84 */
85 function wfSpecialDoubleRedirects() {
86 list( $limit, $offset ) = wfCheckLimits();
87 $sdr = new DoubleRedirectsPage();
88 return $sdr->doQuery( $offset, $limit );
89 }