Merge "Fix HTML output of TablePager"
[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() {
38 return true;
39 }
40
41 function isSyndicated() {
42 return false;
43 }
44
45 function sortDescending() {
46 return false;
47 }
48
49 function getQueryInfo() {
50 return array(
51 'tables' => array( 'p1' => 'page', 'redirect', 'p2' => 'page' ),
52 'fields' => array( 'namespace' => 'p1.page_namespace',
53 'title' => 'p1.page_title',
54 'value' => 'p1.page_title',
55 'rd_namespace',
56 'rd_title',
57 'rd_fragment',
58 'rd_interwiki',
59 'redirid' => 'p2.page_id' ),
60 'conds' => array( 'p1.page_is_redirect' => 1 ),
61 'join_conds' => array( 'redirect' => array(
62 'LEFT JOIN', 'rd_from=p1.page_id' ),
63 'p2' => array( 'LEFT JOIN', array(
64 'p2.page_namespace=rd_namespace',
65 'p2.page_title=rd_title' ) ) )
66 );
67 }
68
69 function getOrderFields() {
70 return array( 'p1.page_namespace', 'p1.page_title' );
71 }
72
73 /**
74 * Cache page existence for performance
75 *
76 * @param DatabaseBase $db
77 * @param ResultWrapper $res
78 */
79 function preprocessResults( $db, $res ) {
80 $batch = new LinkBatch;
81 foreach ( $res as $row ) {
82 $batch->add( $row->namespace, $row->title );
83 $batch->addObj( $this->getRedirectTarget( $row ) );
84 }
85 $batch->execute();
86
87 // Back to start for display
88 if ( $res->numRows() > 0 ) {
89 // If there are no rows we get an error seeking.
90 $db->dataSeek( $res, 0 );
91 }
92 }
93
94 protected function getRedirectTarget( $row ) {
95 if ( isset( $row->rd_title ) ) {
96 return Title::makeTitle( $row->rd_namespace,
97 $row->rd_title, $row->rd_fragment,
98 $row->rd_interwiki
99 );
100 } else {
101 $title = Title::makeTitle( $row->namespace, $row->title );
102 $article = WikiPage::factory( $title );
103 return $article->getRedirectTarget();
104 }
105 }
106
107 /**
108 * @param Skin $skin
109 * @param object $result Result row
110 * @return string
111 */
112 function formatResult( $skin, $result ) {
113 # Make a link to the redirect itself
114 $rd_title = Title::makeTitle( $result->namespace, $result->title );
115 $rd_link = Linker::link(
116 $rd_title,
117 null,
118 array(),
119 array( 'redirect' => 'no' )
120 );
121
122 # Find out where the redirect leads
123 $target = $this->getRedirectTarget( $result );
124 if( $target ) {
125 # Make a link to the destination page
126 $lang = $this->getLanguage();
127 $arr = $lang->getArrow() . $lang->getDirMark();
128 $targetLink = Linker::link( $target );
129 return "$rd_link $arr $targetLink";
130 } else {
131 return "<del>$rd_link</del>";
132 }
133 }
134
135 protected function getGroupName() {
136 return 'pages';
137 }
138 }