cf1153eaccac0ef398cf14c1bb7422f62a2c3e42
[lhc/web/wiklou.git] / includes / SpecialDoubleRedirects.php
1 <?php
2 /**
3 *
4 * @package MediaWiki
5 * @subpackage SpecialPage
6 */
7
8 /**
9 *
10 * @package MediaWiki
11 * @subpackage SpecialPage
12 */
13 class DoubleRedirectsPage extends PageQueryPage {
14
15 function getName() {
16 return 'DoubleRedirects';
17 }
18
19 function isExpensive( ) { return true; }
20 function isSyndicated() { return false; }
21
22 function getPageHeader( ) {
23 #FIXME : probably need to add a backlink to the maintenance page.
24 return '<p>'.wfMsg("doubleredirectstext")."</p><br />\n";
25 }
26
27 function getSQLText( &$dbr, $namespace = null, $title = null ) {
28
29 list( $page, $pagelinks ) = $dbr->tableNamesN( 'page', 'pagelinks' );
30
31 $limitToTitle = !( $namespace === null && $title === null );
32 $sql = $limitToTitle ? "SELECT" : "SELECT 'DoubleRedirects' as type," ;
33 $sql .=
34 " pa.page_namespace as namespace, pa.page_title as title," .
35 " pb.page_namespace as nsb, pb.page_title as tb," .
36 " pc.page_namespace as nsc, pc.page_title as tc" .
37 " FROM $pagelinks AS la, $pagelinks AS lb, $page AS pa, $page AS pb, $page AS pc" .
38 " WHERE pa.page_is_redirect=1 AND pb.page_is_redirect=1" .
39 " AND la.pl_from=pa.page_id" .
40 " AND la.pl_namespace=pb.page_namespace" .
41 " AND la.pl_title=pb.page_title" .
42 " AND lb.pl_from=pb.page_id" .
43 " AND lb.pl_namespace=pc.page_namespace" .
44 " AND lb.pl_title=pc.page_title";
45
46 if( $limitToTitle ) {
47 $encTitle = $dbr->addQuotes( $title );
48 $sql .= " AND pa.page_namespace=$namespace" .
49 " AND pa.page_title=$encTitle";
50 }
51
52 return $sql;
53 }
54
55 function getSQL() {
56 $dbr =& wfGetDB( DB_SLAVE );
57 return $this->getSQLText( $dbr );
58 }
59
60 function getOrder() {
61 return '';
62 }
63
64 function formatResult( $skin, $result ) {
65 global $wgContLang;
66
67 $fname = 'DoubleRedirectsPage::formatResult';
68 $titleA = Title::makeTitle( $result->namespace, $result->title );
69
70 if ( $result && !isset( $result->nsb ) ) {
71 $dbr =& wfGetDB( DB_SLAVE );
72 $sql = $this->getSQLText( $dbr, $result->namespace, $result->title );
73 $res = $dbr->query( $sql, $fname );
74 if ( $res ) {
75 $result = $dbr->fetchObject( $res );
76 $dbr->freeResult( $res );
77 }
78 }
79 if ( !$result ) {
80 return '';
81 }
82
83 $titleB = Title::makeTitle( $result->nsb, $result->tb );
84 $titleC = Title::makeTitle( $result->nsc, $result->tc );
85
86 $linkA = $skin->makeKnownLinkObj( $titleA,'', 'redirect=no' );
87 $edit = $skin->makeBrokenLinkObj( $titleA, "(".wfMsg("qbedit").")" , 'redirect=no');
88 $linkB = $skin->makeKnownLinkObj( $titleB, '', 'redirect=no' );
89 $linkC = $skin->makeKnownLinkObj( $titleC );
90 $arr = $wgContLang->getArrow() . $wgContLang->getDirMark();
91
92 return( "{$linkA} {$edit} {$arr} {$linkB} {$arr} {$linkC}" );
93 }
94 }
95
96 /**
97 * constructor
98 */
99 function wfSpecialDoubleRedirects() {
100 list( $limit, $offset ) = wfCheckLimits();
101
102 $sdr = new DoubleRedirectsPage();
103
104 return $sdr->doQuery( $offset, $limit );
105
106 }
107 ?>