MediaWiki master
SpecialListRedirects.php
Go to the documentation of this file.
1<?php
9namespace MediaWiki\Specials;
10
11use MediaWiki\Cache\LinkBatchFactory;
18use stdClass;
22
30
31 private LinkBatchFactory $linkBatchFactory;
32 private WikiPageFactory $wikiPageFactory;
33 private RedirectLookup $redirectLookup;
34
35 public function __construct(
36 LinkBatchFactory $linkBatchFactory,
37 IConnectionProvider $dbProvider,
38 WikiPageFactory $wikiPageFactory,
39 RedirectLookup $redirectLookup
40 ) {
41 parent::__construct( 'Listredirects' );
42 $this->linkBatchFactory = $linkBatchFactory;
43 $this->setDatabaseProvider( $dbProvider );
44 $this->wikiPageFactory = $wikiPageFactory;
45 $this->redirectLookup = $redirectLookup;
46 }
47
49 public function isExpensive() {
50 return true;
51 }
52
54 public function isSyndicated() {
55 return false;
56 }
57
59 protected function sortDescending() {
60 return false;
61 }
62
64 public function getQueryInfo() {
65 return [
66 'tables' => [ 'page', 'redirect' ],
67 'fields' => [ 'namespace' => 'page_namespace',
68 'title' => 'page_title',
69 'rd_namespace',
70 'rd_title',
71 'rd_fragment',
72 'rd_interwiki',
73 ],
74 'conds' => [ 'page_is_redirect' => 1 ],
75 'join_conds' => [ 'redirect' => [
76 'LEFT JOIN', 'rd_from=page_id' ],
77 ]
78 ];
79 }
80
82 protected function getOrderFields() {
83 return [ 'page_namespace', 'page_title' ];
84 }
85
92 public function preprocessResults( $db, $res ) {
93 if ( !$res->numRows() ) {
94 return;
95 }
96
97 $batch = $this->linkBatchFactory->newLinkBatch()->setCaller( __METHOD__ );
98 foreach ( $res as $row ) {
99 $batch->add( $row->namespace, $row->title );
100 $redirTarget = $this->getRedirectTarget( $row );
101 if ( $redirTarget ) {
102 $batch->addObj( $redirTarget );
103 }
104 }
105 $batch->execute();
106
107 // Back to start for display
108 $res->seek( 0 );
109 }
110
111 protected function getRedirectTarget( stdClass $row ): ?Title {
112 if ( isset( $row->rd_title ) ) {
113 return Title::makeTitle(
114 $row->rd_namespace,
115 $row->rd_title,
116 $row->rd_fragment,
117 $row->rd_interwiki
118 );
119 } else {
120 $title = Title::makeTitle( $row->namespace, $row->title );
121 if ( !$title->canExist() ) {
122 return null;
123 }
124
125 return Title::castFromLinkTarget(
126 $this->redirectLookup->getRedirectTarget( $title )
127 );
128 }
129 }
130
136 public function formatResult( $skin, $result ) {
137 $linkRenderer = $this->getLinkRenderer();
138 # Make a link to the redirect itself
139 $rd_title = Title::makeTitle( $result->namespace, $result->title );
140 $rd_link = $linkRenderer->makeLink(
141 $rd_title,
142 null,
143 [],
144 [ 'redirect' => 'no' ]
145 );
146
147 # Find out where the redirect leads
148 $target = $this->getRedirectTarget( $result );
149 if ( $target ) {
150 # Make a link to the destination page
151 $lang = $this->getLanguage();
152 $arr = $lang->getArrow();
153 $rd_link = Html::rawElement( 'bdi', [ 'dir' => $lang->getDir() ], $rd_link );
154 $targetLink = $linkRenderer->makeLink( $target, $target->getFullText() );
155 $targetLink = Html::rawElement( 'bdi', [ 'dir' => $lang->getDir() ], $targetLink );
156
157 return "$rd_link $arr $targetLink";
158 } else {
159 return "<del>$rd_link</del>";
160 }
161 }
162
164 public function execute( $par ) {
165 $this->addHelpLink( 'Help:Redirects' );
166 parent::execute( $par );
167 }
168
170 protected function getGroupName() {
171 return 'pages';
172 }
173}
174
176class_alias( SpecialListRedirects::class, 'SpecialListRedirects' );
if(!defined('MW_SETUP_CALLBACK'))
Definition WebStart.php:68
makeTitle( $linkId)
Convert a link ID to a Title.to override Title
This class is a collection of static functions that serve two purposes:
Definition Html.php:43
Service for creating WikiPage objects.
The base class for all skins.
Definition Skin.php:52
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:77
setDatabaseProvider(IConnectionProvider $databaseProvider)
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.Don't append DESC to the field names,...
sortDescending()
Override to sort by increasing values.to override bool
isSyndicated()
Sometimes we don't want to build rss / atom feeds.to override bool
execute( $par)
This is the actual workhorse.It does everything needed to make a real, honest-to-gosh query page....
__construct(LinkBatchFactory $linkBatchFactory, IConnectionProvider $dbProvider, WikiPageFactory $wikiPageFactory, RedirectLookup $redirectLookup)
isExpensive()
Should this query page only be updated offline on large wikis?If the query for this page is considere...
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:69
Service for resolving a wiki page redirect.
Provide primary and replica IDatabase connections.
A database connection without write operations.
Result wrapper for grabbing data queried from an IDatabase object.