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