* Removed mysql5 SQL files, obviously we're collectively incapable of keeping them...
[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 not procede double redirects automaticly 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 #FIXME : probably need to add a backlink to the maintenance page.
23 return '<p>'.wfMsg("doubleredirectstext")."</p><br />\n";
24 }
25
26 function getSQLText( &$dbr, $namespace = null, $title = null ) {
27
28 list( $page, $redirect ) = $dbr->tableNamesN( 'page', 'redirect' );
29
30 $limitToTitle = !( $namespace === null && $title === null );
31 $sql = $limitToTitle ? "SELECT" : "SELECT 'DoubleRedirects' as type," ;
32 $sql .=
33 " pa.page_namespace as namespace, pa.page_title as title," .
34 " pb.page_namespace as nsb, pb.page_title as tb," .
35 " pc.page_namespace as nsc, pc.page_title as tc" .
36 " FROM $redirect AS ra, $redirect AS rb, $page AS pa, $page AS pb, $page AS pc" .
37 " WHERE ra.rd_from=pa.page_id" .
38 " AND ra.rd_namespace=pb.page_namespace" .
39 " AND ra.rd_title=pb.page_title" .
40 " AND rb.rd_from=pb.page_id" .
41 " AND rb.rd_namespace=pc.page_namespace" .
42 " AND rb.rd_title=pc.page_title";
43
44 if( $limitToTitle ) {
45 $encTitle = $dbr->addQuotes( $title );
46 $sql .= " AND pa.page_namespace=$namespace" .
47 " AND pa.page_title=$encTitle";
48 }
49
50 return $sql;
51 }
52
53 function getSQL() {
54 $dbr = wfGetDB( DB_SLAVE );
55 return $this->getSQLText( $dbr );
56 }
57
58 function getOrder() {
59 return '';
60 }
61
62 function formatResult( $skin, $result ) {
63 global $wgContLang;
64
65 $fname = 'DoubleRedirectsPage::formatResult';
66 $titleA = Title::makeTitle( $result->namespace, $result->title );
67
68 if ( $result && !isset( $result->nsb ) ) {
69 $dbr = wfGetDB( DB_SLAVE );
70 $sql = $this->getSQLText( $dbr, $result->namespace, $result->title );
71 $res = $dbr->query( $sql, $fname );
72 if ( $res ) {
73 $result = $dbr->fetchObject( $res );
74 $dbr->freeResult( $res );
75 }
76 }
77 if ( !$result ) {
78 return '';
79 }
80
81 $titleB = Title::makeTitle( $result->nsb, $result->tb );
82 $titleC = Title::makeTitle( $result->nsc, $result->tc );
83
84 $linkA = $skin->makeKnownLinkObj( $titleA,'', 'redirect=no' );
85 $edit = $skin->makeBrokenLinkObj( $titleA, "(".wfMsg("qbedit").")" , 'redirect=no');
86 $linkB = $skin->makeKnownLinkObj( $titleB, '', 'redirect=no' );
87 $linkC = $skin->makeKnownLinkObj( $titleC );
88 $arr = $wgContLang->getArrow() . $wgContLang->getDirMark();
89
90 return( "{$linkA} {$edit} {$arr} {$linkB} {$arr} {$linkC}" );
91 }
92 }
93
94 /**
95 * constructor
96 */
97 function wfSpecialDoubleRedirects() {
98 list( $limit, $offset ) = wfCheckLimits();
99
100 $sdr = new DoubleRedirectsPage();
101
102 return $sdr->doQuery( $offset, $limit );
103
104 }
105 ?>