]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - includes/specials/SpecialListredirects.php
MediaWiki 1.30.2 renames
[autoinstallsdev/mediawiki.git] / includes / specials / SpecialListredirects.php
1 <?php
2 /**
3  * Implements Special:Listredirects
4  *
5  * Copyright © 2006 Rob Church
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  * http://www.gnu.org/copyleft/gpl.html
21  *
22  * @file
23  * @ingroup SpecialPage
24  * @author Rob Church <robchur@gmail.com>
25  */
26
27 use Wikimedia\Rdbms\ResultWrapper;
28 use Wikimedia\Rdbms\IDatabase;
29
30 /**
31  * Special:Listredirects - Lists all the redirects on the wiki.
32  * @ingroup SpecialPage
33  */
34 class ListredirectsPage extends QueryPage {
35         function __construct( $name = 'Listredirects' ) {
36                 parent::__construct( $name );
37         }
38
39         public function isExpensive() {
40                 return true;
41         }
42
43         function isSyndicated() {
44                 return false;
45         }
46
47         function sortDescending() {
48                 return false;
49         }
50
51         public function getQueryInfo() {
52                 return [
53                         'tables' => [ 'p1' => 'page', 'redirect', 'p2' => 'page' ],
54                         'fields' => [ 'namespace' => 'p1.page_namespace',
55                                 'title' => 'p1.page_title',
56                                 'value' => 'p1.page_title',
57                                 'rd_namespace',
58                                 'rd_title',
59                                 'rd_fragment',
60                                 'rd_interwiki',
61                                 'redirid' => 'p2.page_id' ],
62                         'conds' => [ 'p1.page_is_redirect' => 1 ],
63                         'join_conds' => [ 'redirect' => [
64                                 'LEFT JOIN', 'rd_from=p1.page_id' ],
65                                 'p2' => [ 'LEFT JOIN', [
66                                         'p2.page_namespace=rd_namespace',
67                                         'p2.page_title=rd_title' ] ] ]
68                 ];
69         }
70
71         function getOrderFields() {
72                 return [ 'p1.page_namespace', 'p1.page_title' ];
73         }
74
75         /**
76          * Cache page existence for performance
77          *
78          * @param IDatabase $db
79          * @param ResultWrapper $res
80          */
81         function preprocessResults( $db, $res ) {
82                 if ( !$res->numRows() ) {
83                         return;
84                 }
85
86                 $batch = new LinkBatch;
87                 foreach ( $res as $row ) {
88                         $batch->add( $row->namespace, $row->title );
89                         $redirTarget = $this->getRedirectTarget( $row );
90                         if ( $redirTarget ) {
91                                 $batch->addObj( $redirTarget );
92                         }
93                 }
94                 $batch->execute();
95
96                 // Back to start for display
97                 $res->seek( 0 );
98         }
99
100         /**
101          * @param stdClass $row
102          * @return Title|null
103          */
104         protected function getRedirectTarget( $row ) {
105                 if ( isset( $row->rd_title ) ) {
106                         return Title::makeTitle( $row->rd_namespace,
107                                 $row->rd_title, $row->rd_fragment,
108                                 $row->rd_interwiki
109                         );
110                 } else {
111                         $title = Title::makeTitle( $row->namespace, $row->title );
112                         $article = WikiPage::factory( $title );
113
114                         return $article->getRedirectTarget();
115                 }
116         }
117
118         /**
119          * @param Skin $skin
120          * @param object $result Result row
121          * @return string
122          */
123         function formatResult( $skin, $result ) {
124                 $linkRenderer = $this->getLinkRenderer();
125                 # Make a link to the redirect itself
126                 $rd_title = Title::makeTitle( $result->namespace, $result->title );
127                 $rd_link = $linkRenderer->makeLink(
128                         $rd_title,
129                         null,
130                         [],
131                         [ 'redirect' => 'no' ]
132                 );
133
134                 # Find out where the redirect leads
135                 $target = $this->getRedirectTarget( $result );
136                 if ( $target ) {
137                         # Make a link to the destination page
138                         $lang = $this->getLanguage();
139                         $arr = $lang->getArrow() . $lang->getDirMark();
140                         $targetLink = $linkRenderer->makeLink( $target, $target->getFullText() );
141
142                         return "$rd_link $arr $targetLink";
143                 } else {
144                         return "<del>$rd_link</del>";
145                 }
146         }
147
148         protected function getGroupName() {
149                 return 'pages';
150         }
151 }