MediaWiki master
SpecialListRedirects.php
Go to the documentation of this file.
1<?php
23namespace MediaWiki\Specials;
24
30use Skin;
31use stdClass;
35
43
44 private LinkBatchFactory $linkBatchFactory;
45 private WikiPageFactory $wikiPageFactory;
46 private RedirectLookup $redirectLookup;
47
54 public function __construct(
55 LinkBatchFactory $linkBatchFactory,
56 IConnectionProvider $dbProvider,
57 WikiPageFactory $wikiPageFactory,
58 RedirectLookup $redirectLookup
59 ) {
60 parent::__construct( 'Listredirects' );
61 $this->linkBatchFactory = $linkBatchFactory;
62 $this->setDatabaseProvider( $dbProvider );
63 $this->wikiPageFactory = $wikiPageFactory;
64 $this->redirectLookup = $redirectLookup;
65 }
66
67 public function isExpensive() {
68 return true;
69 }
70
71 public function isSyndicated() {
72 return false;
73 }
74
75 protected function sortDescending() {
76 return false;
77 }
78
79 public function getQueryInfo() {
80 return [
81 'tables' => [ 'page', 'redirect' ],
82 'fields' => [ 'namespace' => 'page_namespace',
83 'title' => 'page_title',
84 'rd_namespace',
85 'rd_title',
86 'rd_fragment',
87 'rd_interwiki',
88 ],
89 'conds' => [ 'page_is_redirect' => 1 ],
90 'join_conds' => [ 'redirect' => [
91 'LEFT JOIN', 'rd_from=page_id' ],
92 ]
93 ];
94 }
95
96 protected function getOrderFields() {
97 return [ 'page_namespace', 'page_title' ];
98 }
99
106 public function preprocessResults( $db, $res ) {
107 if ( !$res->numRows() ) {
108 return;
109 }
110
111 $batch = $this->linkBatchFactory->newLinkBatch();
112 foreach ( $res as $row ) {
113 $batch->add( $row->namespace, $row->title );
114 $redirTarget = $this->getRedirectTarget( $row );
115 if ( $redirTarget ) {
116 $batch->addObj( $redirTarget );
117 }
118 }
119 $batch->execute();
120
121 // Back to start for display
122 $res->seek( 0 );
123 }
124
129 protected function getRedirectTarget( $row ) {
130 if ( isset( $row->rd_title ) ) {
131 return Title::makeTitle(
132 $row->rd_namespace,
133 $row->rd_title,
134 $row->rd_fragment,
135 $row->rd_interwiki
136 );
137 } else {
138 $title = Title::makeTitle( $row->namespace, $row->title );
139 if ( !$title->canExist() ) {
140 return null;
141 }
142
143 return Title::castFromLinkTarget(
144 $this->redirectLookup->getRedirectTarget( $title )
145 );
146 }
147 }
148
154 public function formatResult( $skin, $result ) {
155 $linkRenderer = $this->getLinkRenderer();
156 # Make a link to the redirect itself
157 $rd_title = Title::makeTitle( $result->namespace, $result->title );
158 $rd_link = $linkRenderer->makeLink(
159 $rd_title,
160 null,
161 [],
162 [ 'redirect' => 'no' ]
163 );
164
165 # Find out where the redirect leads
166 $target = $this->getRedirectTarget( $result );
167 if ( $target ) {
168 # Make a link to the destination page
169 $lang = $this->getLanguage();
170 $arr = $lang->getArrow() . $lang->getDirMark();
171 $targetLink = $linkRenderer->makeLink( $target, $target->getFullText() );
172
173 return "$rd_link $arr $targetLink";
174 } else {
175 return "<del>$rd_link</del>";
176 }
177 }
178
179 public function execute( $par ) {
180 $this->addHelpLink( 'Help:Redirects' );
181 parent::execute( $par );
182 }
183
184 protected function getGroupName() {
185 return 'pages';
186 }
187}
188
190class_alias( SpecialListRedirects::class, 'SpecialListRedirects' );
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:89
setDatabaseProvider(IConnectionProvider $databaseProvider)
getLanguage()
Shortcut to get user's language.
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
Lists all the redirecting pages on the wiki.
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
getOrderFields()
Subclasses return an array of fields to order by here.
sortDescending()
Override to sort by increasing values.
isSyndicated()
Sometimes we don't want to build rss / atom feeds.
execute( $par)
This is the actual workhorse.
__construct(LinkBatchFactory $linkBatchFactory, IConnectionProvider $dbProvider, WikiPageFactory $wikiPageFactory, RedirectLookup $redirectLookup)
isExpensive()
Should this query page only be updated offline on large wikis?
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...
Represents a title within MediaWiki.
Definition Title.php:78
The base class for all skins.
Definition Skin.php:59
Service for resolving a wiki page redirect.
Provide primary and replica IDatabase connections.
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:39
Result wrapper for grabbing data queried from an IDatabase object.