]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - includes/specials/SpecialDoubleRedirects.php
MediaWiki 1.16.1-scripts
[autoinstallsdev/mediawiki.git] / includes / specials / SpecialDoubleRedirects.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->link( $titleA, null, array(), array( '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->linkKnown(
84                         $titleA,
85                         null,
86                         array(),
87                         array( 'redirect' => 'no' )
88                 );
89                 $edit = $skin->linkKnown(
90                         $titleA,
91                         wfMsgExt( 'parentheses', array( 'escape' ), wfMsg( 'editlink' ) ),
92                         array(),
93                         array(
94                                 'redirect' => 'no',
95                                 'action' => 'edit'
96                         )
97                 );
98                 $linkB = $skin->linkKnown(
99                         $titleB,
100                         null,
101                         array(),
102                         array( 'redirect' => 'no' )
103                 );
104                 $linkC = $skin->linkKnown( $titleC );
105                 $arr = $wgContLang->getArrow() . $wgContLang->getDirMark();
106
107                 return( "{$linkA} {$edit} {$arr} {$linkB} {$arr} {$linkC}" );
108         }
109 }
110
111 /**
112  * constructor
113  */
114 function wfSpecialDoubleRedirects() {
115         list( $limit, $offset ) = wfCheckLimits();
116
117         $sdr = new DoubleRedirectsPage();
118
119         return $sdr->doQuery( $offset, $limit );
120
121 }