Introduce Language::getMessageKeysFor() and use it in ApiQueryAllmessages
[lhc/web/wiklou.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 /**
28 * Special:Listredirects - Lists all the redirects on the wiki.
29 * @ingroup SpecialPage
30 */
31 class ListredirectsPage extends QueryPage {
32
33 function __construct( $name = 'Listredirects' ) {
34 parent::__construct( $name );
35 }
36
37 function isExpensive() { return true; }
38 function isSyndicated() { return false; }
39 function sortDescending() { return false; }
40
41 function getQueryInfo() {
42 return array(
43 'tables' => array( 'p1' => 'page', 'redirect', 'p2' => 'page' ),
44 'fields' => array( 'p1.page_namespace AS namespace',
45 'p1.page_title AS title',
46 'rd_namespace',
47 'rd_title',
48 'rd_fragment',
49 'rd_interwiki',
50 'p2.page_id AS redirid' ),
51 'conds' => array( 'p1.page_is_redirect' => 1 ),
52 'join_conds' => array( 'redirect' => array(
53 'LEFT JOIN', 'rd_from=p1.page_id' ),
54 'p2' => array( 'LEFT JOIN', array(
55 'p2.page_namespace=rd_namespace',
56 'p2.page_title=rd_title' ) ) )
57 );
58 }
59
60 function getOrderFields() {
61 return array ( 'p1.page_namespace', 'p1.page_title' );
62 }
63
64 /**
65 * Cache page existence for performance
66 *
67 * @param $db DatabaseBase
68 * @param $res ResultWrapper
69 */
70 function preprocessResults( $db, $res ) {
71 $batch = new LinkBatch;
72 foreach ( $res as $row ) {
73 $batch->add( $row->namespace, $row->title );
74 $batch->addObj( $this->getRedirectTarget( $row ) );
75 }
76 $batch->execute();
77
78 // Back to start for display
79 if ( $db->numRows( $res ) > 0 ) {
80 // If there are no rows we get an error seeking.
81 $db->dataSeek( $res, 0 );
82 }
83 }
84
85 protected function getRedirectTarget( $row ) {
86 if ( isset( $row->rd_title ) ) {
87 return Title::makeTitle( $row->rd_namespace,
88 $row->rd_title, $row->rd_fragment,
89 $row->rd_interwiki
90 );
91 } else {
92 $title = Title::makeTitle( $row->namespace, $row->title );
93 $article = new Article( $title );
94 return $article->getRedirectTarget();
95 }
96 }
97
98 function formatResult( $skin, $result ) {
99 # Make a link to the redirect itself
100 $rd_title = Title::makeTitle( $result->namespace, $result->title );
101 $rd_link = $skin->link(
102 $rd_title,
103 null,
104 array(),
105 array( 'redirect' => 'no' )
106 );
107
108 # Find out where the redirect leads
109 $target = $this->getRedirectTarget( $result );
110 if( $target ) {
111 global $wgLang;
112 # Make a link to the destination page
113 $arr = $wgLang->getArrow() . $wgLang->getDirMark();
114 $targetLink = $skin->link( $target );
115 return "$rd_link $arr $targetLink";
116 } else {
117 return "<del>$rd_link</del>";
118 }
119 }
120 }