MediaWiki  master
SpecialListRedirects.php
Go to the documentation of this file.
1 <?php
32 
38 
41 
44 
50  public function __construct(
54  ) {
55  parent::__construct( 'Listredirects' );
56  $this->linkBatchFactory = $linkBatchFactory;
57  $this->setDBLoadBalancer( $loadBalancer );
58  $this->wikiPageFactory = $wikiPageFactory;
59  }
60 
61  public function isExpensive() {
62  return true;
63  }
64 
65  public function isSyndicated() {
66  return false;
67  }
68 
69  protected function sortDescending() {
70  return false;
71  }
72 
73  public function getQueryInfo() {
74  return [
75  'tables' => [ 'p1' => 'page', 'redirect', 'p2' => 'page' ],
76  'fields' => [ 'namespace' => 'p1.page_namespace',
77  'title' => 'p1.page_title',
78  'rd_namespace',
79  'rd_title',
80  'rd_fragment',
81  'rd_interwiki',
82  'redirid' => 'p2.page_id' ],
83  'conds' => [ 'p1.page_is_redirect' => 1 ],
84  'join_conds' => [ 'redirect' => [
85  'LEFT JOIN', 'rd_from=p1.page_id' ],
86  'p2' => [ 'LEFT JOIN', [
87  'p2.page_namespace=rd_namespace',
88  'p2.page_title=rd_title' ] ] ]
89  ];
90  }
91 
92  protected function getOrderFields() {
93  return [ 'p1.page_namespace', 'p1.page_title' ];
94  }
95 
102  public function preprocessResults( $db, $res ) {
103  if ( !$res->numRows() ) {
104  return;
105  }
106 
107  $batch = $this->linkBatchFactory->newLinkBatch();
108  foreach ( $res as $row ) {
109  $batch->add( $row->namespace, $row->title );
110  $redirTarget = $this->getRedirectTarget( $row );
111  if ( $redirTarget ) {
112  $batch->addObj( $redirTarget );
113  }
114  }
115  $batch->execute();
116 
117  // Back to start for display
118  $res->seek( 0 );
119  }
120 
125  protected function getRedirectTarget( $row ) {
126  if ( isset( $row->rd_title ) ) {
127  return Title::makeTitle(
128  $row->rd_namespace,
129  $row->rd_title,
130  $row->rd_fragment ?? '',
131  $row->rd_interwiki ?? ''
132  );
133  } else {
134  $title = Title::makeTitle( $row->namespace, $row->title );
135  if ( !$title->canExist() ) {
136  return null;
137  }
138  $page = $this->wikiPageFactory->newFromTitle( $title );
139 
140  return $page->getRedirectTarget();
141  }
142  }
143 
149  public function formatResult( $skin, $result ) {
150  $linkRenderer = $this->getLinkRenderer();
151  # Make a link to the redirect itself
152  $rd_title = Title::makeTitle( $result->namespace, $result->title );
153  $rd_link = $linkRenderer->makeLink(
154  $rd_title,
155  null,
156  [],
157  [ 'redirect' => 'no' ]
158  );
159 
160  # Find out where the redirect leads
161  $target = $this->getRedirectTarget( $result );
162  if ( $target ) {
163  # Make a link to the destination page
164  $lang = $this->getLanguage();
165  $arr = $lang->getArrow() . $lang->getDirMark();
166  $targetLink = $linkRenderer->makeLink( $target, $target->getFullText() );
167 
168  return "$rd_link $arr $targetLink";
169  } else {
170  return "<del>$rd_link</del>";
171  }
172  }
173 
174  public function execute( $par ) {
175  $this->addHelpLink( 'Help:Redirects' );
176  parent::execute( $par );
177  }
178 
179  protected function getGroupName() {
180  return 'pages';
181  }
182 }
SpecialPage\$linkRenderer
LinkRenderer null $linkRenderer
Definition: SpecialPage.php:80
SpecialListRedirects\__construct
__construct(LinkBatchFactory $linkBatchFactory, ILoadBalancer $loadBalancer, WikiPageFactory $wikiPageFactory)
Definition: SpecialListRedirects.php:50
SpecialListRedirects\getOrderFields
getOrderFields()
Subclasses return an array of fields to order by here.
Definition: SpecialListRedirects.php:92
SpecialListRedirects\getRedirectTarget
getRedirectTarget( $row)
Definition: SpecialListRedirects.php:125
SpecialListRedirects\getQueryInfo
getQueryInfo()
Subclasses return an SQL query here, formatted as an array with the following keys: tables => Table(s...
Definition: SpecialListRedirects.php:73
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:37
SpecialListRedirects\isSyndicated
isSyndicated()
Sometimes we don't want to build rss / atom feeds.
Definition: SpecialListRedirects.php:65
SpecialListRedirects\$linkBatchFactory
LinkBatchFactory $linkBatchFactory
Definition: SpecialListRedirects.php:40
SpecialPage\getLanguage
getLanguage()
Shortcut to get user's language.
Definition: SpecialPage.php:830
SpecialListRedirects\isExpensive
isExpensive()
Is this query expensive (for some definition of expensive)? Then we don't let it run in miser mode.
Definition: SpecialListRedirects.php:61
$res
$res
Definition: testCompression.php:57
SpecialListRedirects\execute
execute( $par)
This is the actual workhorse.
Definition: SpecialListRedirects.php:174
QueryPage
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:41
SpecialListRedirects
Special:Listredirects - Lists all the redirects on the wiki.
Definition: SpecialListRedirects.php:37
Wikimedia\Rdbms\IDatabase
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:38
SpecialPage\addHelpLink
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
Definition: SpecialPage.php:948
Wikimedia\Rdbms\IResultWrapper
Result wrapper for grabbing data queried from an IDatabase object.
Definition: IResultWrapper.php:26
MediaWiki\Cache\LinkBatchFactory
Definition: LinkBatchFactory.php:39
SpecialListRedirects\$wikiPageFactory
WikiPageFactory $wikiPageFactory
Definition: SpecialListRedirects.php:43
Page\WikiPageFactory
Definition: WikiPageFactory.php:19
$title
$title
Definition: testCompression.php:38
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:663
SpecialListRedirects\sortDescending
sortDescending()
Override to sort by increasing values.
Definition: SpecialListRedirects.php:69
SpecialListRedirects\formatResult
formatResult( $skin, $result)
Definition: SpecialListRedirects.php:149
SpecialListRedirects\preprocessResults
preprocessResults( $db, $res)
Cache page existence for performance.
Definition: SpecialListRedirects.php:102
QueryPage\setDBLoadBalancer
setDBLoadBalancer(ILoadBalancer $loadBalancer)
Definition: QueryPage.php:892
SpecialListRedirects\getGroupName
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Definition: SpecialListRedirects.php:179
SpecialPage\getLinkRenderer
getLinkRenderer()
Definition: SpecialPage.php:1028
QueryPage\$loadBalancer
ILoadBalancer null $loadBalancer
Definition: QueryPage.php:71
Wikimedia\Rdbms\ILoadBalancer
Database cluster connection, tracking, load balancing, and transaction manager interface.
Definition: ILoadBalancer.php:81