3 * Implements Special:Listredirects
5 * Copyright © 2006 Rob Church
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.
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.
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
23 * @ingroup SpecialPage
24 * @author Rob Church <robchur@gmail.com>
27 use Wikimedia\Rdbms\ResultWrapper
;
28 use Wikimedia\Rdbms\IDatabase
;
31 * Special:Listredirects - Lists all the redirects on the wiki.
32 * @ingroup SpecialPage
34 class ListredirectsPage
extends QueryPage
{
35 function __construct( $name = 'Listredirects' ) {
36 parent
::__construct( $name );
39 public function isExpensive() {
43 function isSyndicated() {
47 function sortDescending() {
51 public function getQueryInfo() {
53 'tables' => [ 'p1' => 'page', 'redirect', 'p2' => 'page' ],
54 'fields' => [ 'namespace' => 'p1.page_namespace',
55 'title' => 'p1.page_title',
56 'value' => 'p1.page_title',
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' ] ] ]
71 function getOrderFields() {
72 return [ 'p1.page_namespace', 'p1.page_title' ];
76 * Cache page existence for performance
78 * @param IDatabase $db
79 * @param ResultWrapper $res
81 function preprocessResults( $db, $res ) {
82 if ( !$res->numRows() ) {
86 $batch = new LinkBatch
;
87 foreach ( $res as $row ) {
88 $batch->add( $row->namespace, $row->title
);
89 $redirTarget = $this->getRedirectTarget( $row );
91 $batch->addObj( $redirTarget );
96 // Back to start for display
101 * @param stdClass $row
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
,
111 $title = Title
::makeTitle( $row->namespace, $row->title
);
112 $article = WikiPage
::factory( $title );
114 return $article->getRedirectTarget();
120 * @param object $result Result row
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(
131 [ 'redirect' => 'no' ]
134 # Find out where the redirect leads
135 $target = $this->getRedirectTarget( $result );
137 # Make a link to the destination page
138 $lang = $this->getLanguage();
139 $arr = $lang->getArrow() . $lang->getDirMark();
140 $targetLink = $linkRenderer->makeLink( $target );
142 return "$rd_link $arr $targetLink";
144 return "<del>$rd_link</del>";
148 protected function getGroupName() {