MediaWiki 1.40.4
SpecialListRedirects.php
Go to the documentation of this file.
1<?php
34
40
42 private $linkBatchFactory;
43
45 private $wikiPageFactory;
46
48 private $redirectLookup;
49
56 public function __construct(
57 LinkBatchFactory $linkBatchFactory,
58 ILoadBalancer $loadBalancer,
59 WikiPageFactory $wikiPageFactory,
60 RedirectLookup $redirectLookup
61 ) {
62 parent::__construct( 'Listredirects' );
63 $this->linkBatchFactory = $linkBatchFactory;
64 $this->setDBLoadBalancer( $loadBalancer );
65 $this->wikiPageFactory = $wikiPageFactory;
66 $this->redirectLookup = $redirectLookup;
67 }
68
69 public function isExpensive() {
70 return true;
71 }
72
73 public function isSyndicated() {
74 return false;
75 }
76
77 protected function sortDescending() {
78 return false;
79 }
80
81 public function getQueryInfo() {
82 return [
83 'tables' => [ 'p1' => 'page', 'redirect', 'p2' => 'page' ],
84 'fields' => [ 'namespace' => 'p1.page_namespace',
85 'title' => 'p1.page_title',
86 'rd_namespace',
87 'rd_title',
88 'rd_fragment',
89 'rd_interwiki',
90 'redirid' => 'p2.page_id' ],
91 'conds' => [ 'p1.page_is_redirect' => 1 ],
92 'join_conds' => [ 'redirect' => [
93 'LEFT JOIN', 'rd_from=p1.page_id' ],
94 'p2' => [ 'LEFT JOIN', [
95 'p2.page_namespace=rd_namespace',
96 'p2.page_title=rd_title' ] ] ]
97 ];
98 }
99
100 protected function getOrderFields() {
101 return [ 'p1.page_namespace', 'p1.page_title' ];
102 }
103
110 public function preprocessResults( $db, $res ) {
111 if ( !$res->numRows() ) {
112 return;
113 }
114
115 $batch = $this->linkBatchFactory->newLinkBatch();
116 foreach ( $res as $row ) {
117 $batch->add( $row->namespace, $row->title );
118 $redirTarget = $this->getRedirectTarget( $row );
119 if ( $redirTarget ) {
120 $batch->addObj( $redirTarget );
121 }
122 }
123 $batch->execute();
124
125 // Back to start for display
126 $res->seek( 0 );
127 }
128
133 protected function getRedirectTarget( $row ) {
134 if ( isset( $row->rd_title ) ) {
135 return Title::makeTitle(
136 $row->rd_namespace,
137 $row->rd_title,
138 $row->rd_fragment ?? '',
139 $row->rd_interwiki ?? ''
140 );
141 } else {
142 $title = Title::makeTitle( $row->namespace, $row->title );
143 if ( !$title->canExist() ) {
144 return null;
145 }
146
147 return Title::castFromLinkTarget(
148 $this->redirectLookup->getRedirectTarget( $title )
149 );
150 }
151 }
152
158 public function formatResult( $skin, $result ) {
159 $linkRenderer = $this->getLinkRenderer();
160 # Make a link to the redirect itself
161 $rd_title = Title::makeTitle( $result->namespace, $result->title );
162 $rd_link = $linkRenderer->makeLink(
163 $rd_title,
164 null,
165 [],
166 [ 'redirect' => 'no' ]
167 );
168
169 # Find out where the redirect leads
170 $target = $this->getRedirectTarget( $result );
171 if ( $target ) {
172 # Make a link to the destination page
173 $lang = $this->getLanguage();
174 $arr = $lang->getArrow() . $lang->getDirMark();
175 $targetLink = $linkRenderer->makeLink( $target, $target->getFullText() );
176
177 return "$rd_link $arr $targetLink";
178 } else {
179 return "<del>$rd_link</del>";
180 }
181 }
182
183 public function execute( $par ) {
184 $this->addHelpLink( 'Help:Redirects' );
185 parent::execute( $par );
186 }
187
188 protected function getGroupName() {
189 return 'pages';
190 }
191}
Service for creating WikiPage objects.
Represents a title within MediaWiki.
Definition Title.php:82
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:45
setDBLoadBalancer(ILoadBalancer $loadBalancer)
Special:Listredirects - Lists all the redirects on the wiki.
__construct(LinkBatchFactory $linkBatchFactory, ILoadBalancer $loadBalancer, WikiPageFactory $wikiPageFactory, RedirectLookup $redirectLookup)
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
execute( $par)
This is the actual workhorse.
isSyndicated()
Sometimes 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()
Should this query page only be updated offline on large wikis?
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.
Service for resolving a wiki page redirect.
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:36
This class is a delegate to ILBFactory for a given database cluster.
Result wrapper for grabbing data queried from an IDatabase object.
if(!isset( $args[0])) $lang