5acc262d46a7b8720dbf3a92c0835d2b0222a31d
[lhc/web/wiklou.git] / includes / SpecialDoubleRedirects.php
1 <?php
2 /**
3 *
4 * @addtogroup SpecialPage
5 */
6
7 /**
8 *
9 * @addtogroup SpecialPage
10 */
11 class DoubleRedirectsPage extends PageQueryPage {
12
13 function getName() {
14 return 'DoubleRedirects';
15 }
16
17 function isExpensive( ) { return true; }
18 function isSyndicated() { return false; }
19
20 function getPageHeader( ) {
21 #FIXME : probably need to add a backlink to the maintenance page.
22 return '<p>'.wfMsg("doubleredirectstext")."</p><br />\n";
23 }
24
25 function getSQLText( &$dbr, $namespace = null, $title = null ) {
26
27 list( $page, $pagelinks ) = $dbr->tableNamesN( 'page', 'pagelinks' );
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 $pagelinks AS la, $pagelinks AS lb, $page AS pa, $page AS pb, $page AS pc" .
36 " WHERE pa.page_is_redirect=1 AND pb.page_is_redirect=1" .
37 " AND la.pl_from=pa.page_id" .
38 " AND la.pl_namespace=pb.page_namespace" .
39 " AND la.pl_title=pb.page_title" .
40 " AND lb.pl_from=pb.page_id" .
41 " AND lb.pl_namespace=pc.page_namespace" .
42 " AND lb.pl_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 ?>