MediaWiki REL1_34
SpecialListRedirects.php
Go to the documentation of this file.
1<?php
29
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 'rd_namespace',
57 'rd_title',
58 'rd_fragment',
59 'rd_interwiki',
60 'redirid' => 'p2.page_id' ],
61 'conds' => [ 'p1.page_is_redirect' => 1 ],
62 'join_conds' => [ 'redirect' => [
63 'LEFT JOIN', 'rd_from=p1.page_id' ],
64 'p2' => [ 'LEFT JOIN', [
65 'p2.page_namespace=rd_namespace',
66 'p2.page_title=rd_title' ] ] ]
67 ];
68 }
69
70 function getOrderFields() {
71 return [ 'p1.page_namespace', 'p1.page_title' ];
72 }
73
80 function preprocessResults( $db, $res ) {
81 if ( !$res->numRows() ) {
82 return;
83 }
84
85 $batch = new LinkBatch;
86 foreach ( $res as $row ) {
87 $batch->add( $row->namespace, $row->title );
88 $redirTarget = $this->getRedirectTarget( $row );
89 if ( $redirTarget ) {
90 $batch->addObj( $redirTarget );
91 }
92 }
93 $batch->execute();
94
95 // Back to start for display
96 $res->seek( 0 );
97 }
98
103 protected function getRedirectTarget( $row ) {
104 if ( isset( $row->rd_title ) ) {
105 return Title::makeTitle( $row->rd_namespace,
106 $row->rd_title, $row->rd_fragment,
107 $row->rd_interwiki
108 );
109 } else {
110 $title = Title::makeTitle( $row->namespace, $row->title );
111 $article = WikiPage::factory( $title );
112
113 return $article->getRedirectTarget();
114 }
115 }
116
122 function formatResult( $skin, $result ) {
124 # Make a link to the redirect itself
125 $rd_title = Title::makeTitle( $result->namespace, $result->title );
126 $rd_link = $linkRenderer->makeLink(
127 $rd_title,
128 null,
129 [],
130 [ 'redirect' => 'no' ]
131 );
132
133 # Find out where the redirect leads
134 $target = $this->getRedirectTarget( $result );
135 if ( $target ) {
136 # Make a link to the destination page
137 $lang = $this->getLanguage();
138 $arr = $lang->getArrow() . $lang->getDirMark();
139 $targetLink = $linkRenderer->makeLink( $target, $target->getFullText() );
140
141 return "$rd_link $arr $targetLink";
142 } else {
143 return "<del>$rd_link</del>";
144 }
145 }
146
147 public function execute( $par ) {
148 $this->addHelpLink( 'Help:Redirects' );
149 parent::execute( $par );
150 }
151
152 protected function getGroupName() {
153 return 'pages';
154 }
155}
Class representing a list of titles The execute() method checks them all for existence and adds them ...
Definition LinkBatch.php:34
add( $ns, $dbkey)
Definition LinkBatch.php:83
This is a class for doing query pages; since they're almost all the same, we factor out some of the f...
Definition QueryPage.php:36
Special:Listredirects - Lists all the redirects on the wiki.
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
execute( $par)
This is the actual workhorse.
__construct( $name='Listredirects')
isSyndicated()
Sometime we don't want to build rss / atom feeds.
preprocessResults( $db, $res)
Cache page existence for performance.
getQueryInfo()
Subclasses return an SQL query here, formatted as an array with the following keys: tables => Table(s...
isExpensive()
Is this query expensive (for some definition of expensive)? Then we don't let it run in miser mode.
getOrderFields()
Subclasses return an array of fields to order by here.
sortDescending()
Override to sort by increasing values.
getLanguage()
Shortcut to get user's language.
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
MediaWiki Linker LinkRenderer null $linkRenderer
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:38
Result wrapper for grabbing data queried from an IDatabase object.
if(!isset( $args[0])) $lang