Merge "(bug 38556) Add header and footer messages to MediaWiki's info action"
[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( 'namespace' => 'p1.page_namespace',
45 'title' => 'p1.page_title',
46 'value' => 'p1.page_title',
47 'rd_namespace',
48 'rd_title',
49 'rd_fragment',
50 'rd_interwiki',
51 'redirid' => 'p2.page_id' ),
52 'conds' => array( 'p1.page_is_redirect' => 1 ),
53 'join_conds' => array( 'redirect' => array(
54 'LEFT JOIN', 'rd_from=p1.page_id' ),
55 'p2' => array( 'LEFT JOIN', array(
56 'p2.page_namespace=rd_namespace',
57 'p2.page_title=rd_title' ) ) )
58 );
59 }
60
61 function getOrderFields() {
62 return array ( 'p1.page_namespace', 'p1.page_title' );
63 }
64
65 /**
66 * Cache page existence for performance
67 *
68 * @param $db DatabaseBase
69 * @param $res ResultWrapper
70 */
71 function preprocessResults( $db, $res ) {
72 $batch = new LinkBatch;
73 foreach ( $res as $row ) {
74 $batch->add( $row->namespace, $row->title );
75 $batch->addObj( $this->getRedirectTarget( $row ) );
76 }
77 $batch->execute();
78
79 // Back to start for display
80 if ( $db->numRows( $res ) > 0 ) {
81 // If there are no rows we get an error seeking.
82 $db->dataSeek( $res, 0 );
83 }
84 }
85
86 protected function getRedirectTarget( $row ) {
87 if ( isset( $row->rd_title ) ) {
88 return Title::makeTitle( $row->rd_namespace,
89 $row->rd_title, $row->rd_fragment,
90 $row->rd_interwiki
91 );
92 } else {
93 $title = Title::makeTitle( $row->namespace, $row->title );
94 $article = WikiPage::factory( $title );
95 return $article->getRedirectTarget();
96 }
97 }
98
99 function formatResult( $skin, $result ) {
100 # Make a link to the redirect itself
101 $rd_title = Title::makeTitle( $result->namespace, $result->title );
102 $rd_link = Linker::link(
103 $rd_title,
104 null,
105 array(),
106 array( 'redirect' => 'no' )
107 );
108
109 # Find out where the redirect leads
110 $target = $this->getRedirectTarget( $result );
111 if( $target ) {
112 # Make a link to the destination page
113 $lang = $this->getLanguage();
114 $arr = $lang->getArrow() . $lang->getDirMark();
115 $targetLink = Linker::link( $target );
116 return "$rd_link $arr $targetLink";
117 } else {
118 return "<del>$rd_link</del>";
119 }
120 }
121 }