MediaWiki master
SpecialListRedirects.php
Go to the documentation of this file.
1<?php
23namespace MediaWiki\Specials;
24
31use Skin;
32use stdClass;
36
44
45 private LinkBatchFactory $linkBatchFactory;
46 private WikiPageFactory $wikiPageFactory;
47 private RedirectLookup $redirectLookup;
48
55 public function __construct(
56 LinkBatchFactory $linkBatchFactory,
57 IConnectionProvider $dbProvider,
58 WikiPageFactory $wikiPageFactory,
59 RedirectLookup $redirectLookup
60 ) {
61 parent::__construct( 'Listredirects' );
62 $this->linkBatchFactory = $linkBatchFactory;
63 $this->setDatabaseProvider( $dbProvider );
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' => [ 'page', 'redirect' ],
83 'fields' => [ 'namespace' => 'page_namespace',
84 'title' => 'page_title',
85 'rd_namespace',
86 'rd_title',
87 'rd_fragment',
88 'rd_interwiki',
89 ],
90 'conds' => [ 'page_is_redirect' => 1 ],
91 'join_conds' => [ 'redirect' => [
92 'LEFT JOIN', 'rd_from=page_id' ],
93 ]
94 ];
95 }
96
97 protected function getOrderFields() {
98 return [ 'page_namespace', 'page_title' ];
99 }
100
107 public function preprocessResults( $db, $res ) {
108 if ( !$res->numRows() ) {
109 return;
110 }
111
112 $batch = $this->linkBatchFactory->newLinkBatch();
113 foreach ( $res as $row ) {
114 $batch->add( $row->namespace, $row->title );
115 $redirTarget = $this->getRedirectTarget( $row );
116 if ( $redirTarget ) {
117 $batch->addObj( $redirTarget );
118 }
119 }
120 $batch->execute();
121
122 // Back to start for display
123 $res->seek( 0 );
124 }
125
130 protected function getRedirectTarget( $row ) {
131 if ( isset( $row->rd_title ) ) {
132 return Title::makeTitle(
133 $row->rd_namespace,
134 $row->rd_title,
135 $row->rd_fragment,
136 $row->rd_interwiki
137 );
138 } else {
139 $title = Title::makeTitle( $row->namespace, $row->title );
140 if ( !$title->canExist() ) {
141 return null;
142 }
143
144 return Title::castFromLinkTarget(
145 $this->redirectLookup->getRedirectTarget( $title )
146 );
147 }
148 }
149
155 public function formatResult( $skin, $result ) {
156 $linkRenderer = $this->getLinkRenderer();
157 # Make a link to the redirect itself
158 $rd_title = Title::makeTitle( $result->namespace, $result->title );
159 $rd_link = $linkRenderer->makeLink(
160 $rd_title,
161 null,
162 [],
163 [ 'redirect' => 'no' ]
164 );
165
166 # Find out where the redirect leads
167 $target = $this->getRedirectTarget( $result );
168 if ( $target ) {
169 # Make a link to the destination page
170 $lang = $this->getLanguage();
171 $arr = $lang->getArrow();
172 $rd_link = Html::rawElement( 'bdi', [ 'dir' => $lang->getDir() ], $rd_link );
173 $targetLink = $linkRenderer->makeLink( $target, $target->getFullText() );
174 $targetLink = Html::rawElement( 'bdi', [ 'dir' => $lang->getDir() ], $targetLink );
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}
191
193class_alias( SpecialListRedirects::class, 'SpecialListRedirects' );
This class is a collection of static functions that serve two purposes:
Definition Html.php:56
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:87
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:64
Service for resolving a wiki page redirect.
Provide primary and replica IDatabase connections.
Interface to a relational database.
Definition IDatabase.php:48
Result wrapper for grabbing data queried from an IDatabase object.