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