* Reorganised the includes directory, creating subdirectories db, parser and specials
[lhc/web/wiklou.git] / includes / specials / DoubleRedirects.php
1 <?php
2 /**
3 * @file
4 * @ingroup 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 * @ingroup 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 getSQLText( &$dbr, $namespace = null, $title = null ) {
26
27 list( $page, $redirect ) = $dbr->tableNamesN( 'page', 'redirect' );
28
29 $limitToTitle = !( $namespace === null && $title === null );
30 $sql = $limitToTitle ? "SELECT" : "SELECT 'DoubleRedirects' as type," ;
31 $sql .=
32 " pa.page_namespace as namespace, pa.page_title as title," .
33 " pb.page_namespace as nsb, pb.page_title as tb," .
34 " pc.page_namespace as nsc, pc.page_title as tc" .
35 " FROM $redirect AS ra, $redirect AS rb, $page AS pa, $page AS pb, $page AS pc" .
36 " WHERE ra.rd_from=pa.page_id" .
37 " AND ra.rd_namespace=pb.page_namespace" .
38 " AND ra.rd_title=pb.page_title" .
39 " AND rb.rd_from=pb.page_id" .
40 " AND rb.rd_namespace=pc.page_namespace" .
41 " AND rb.rd_title=pc.page_title";
42
43 if( $limitToTitle ) {
44 $encTitle = $dbr->addQuotes( $title );
45 $sql .= " AND pa.page_namespace=$namespace" .
46 " AND pa.page_title=$encTitle";
47 }
48
49 return $sql;
50 }
51
52 function getSQL() {
53 $dbr = wfGetDB( DB_SLAVE );
54 return $this->getSQLText( $dbr );
55 }
56
57 function getOrder() {
58 return '';
59 }
60
61 function formatResult( $skin, $result ) {
62 global $wgContLang;
63
64 $fname = 'DoubleRedirectsPage::formatResult';
65 $titleA = Title::makeTitle( $result->namespace, $result->title );
66
67 if ( $result && !isset( $result->nsb ) ) {
68 $dbr = wfGetDB( DB_SLAVE );
69 $sql = $this->getSQLText( $dbr, $result->namespace, $result->title );
70 $res = $dbr->query( $sql, $fname );
71 if ( $res ) {
72 $result = $dbr->fetchObject( $res );
73 $dbr->freeResult( $res );
74 }
75 }
76 if ( !$result ) {
77 return '<s>' . $skin->makeLinkObj( $titleA, '', 'redirect=no' ) . '</s>';
78 }
79
80 $titleB = Title::makeTitle( $result->nsb, $result->tb );
81 $titleC = Title::makeTitle( $result->nsc, $result->tc );
82
83 $linkA = $skin->makeKnownLinkObj( $titleA, '', 'redirect=no' );
84 $edit = $skin->makeBrokenLinkObj( $titleA, "(".wfMsg("qbedit").")" , 'redirect=no');
85 $linkB = $skin->makeKnownLinkObj( $titleB, '', 'redirect=no' );
86 $linkC = $skin->makeKnownLinkObj( $titleC );
87 $arr = $wgContLang->getArrow() . $wgContLang->getDirMark();
88
89 return( "{$linkA} {$edit} {$arr} {$linkB} {$arr} {$linkC}" );
90 }
91 }
92
93 /**
94 * constructor
95 */
96 function wfSpecialDoubleRedirects() {
97 list( $limit, $offset ) = wfCheckLimits();
98
99 $sdr = new DoubleRedirectsPage();
100
101 return $sdr->doQuery( $offset, $limit );
102
103 }