MediaWiki REL1_37
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( $row->rd_namespace,
128 $row->rd_title, $row->rd_fragment,
129 $row->rd_interwiki
130 );
131 } else {
132 $title = Title::makeTitle( $row->namespace, $row->title );
133 $page = $this->wikiPageFactory->newFromTitle( $title );
134
135 return $page->getRedirectTarget();
136 }
137 }
138
144 public function formatResult( $skin, $result ) {
146 # Make a link to the redirect itself
147 $rd_title = Title::makeTitle( $result->namespace, $result->title );
148 $rd_link = $linkRenderer->makeLink(
149 $rd_title,
150 null,
151 [],
152 [ 'redirect' => 'no' ]
153 );
154
155 # Find out where the redirect leads
156 $target = $this->getRedirectTarget( $result );
157 if ( $target ) {
158 # Make a link to the destination page
159 $lang = $this->getLanguage();
160 $arr = $lang->getArrow() . $lang->getDirMark();
161 $targetLink = $linkRenderer->makeLink( $target, $target->getFullText() );
162
163 return "$rd_link $arr $targetLink";
164 } else {
165 return "<del>$rd_link</del>";
166 }
167 }
168
169 public function execute( $par ) {
170 $this->addHelpLink( 'Help:Redirects' );
171 parent::execute( $par );
172 }
173
174 protected function getGroupName() {
175 return 'pages';
176 }
177}
makeLink( $target, $text=null, array $extraAttribs=[], array $query=[])
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
setDBLoadBalancer(ILoadBalancer $loadBalancer)
ILoadBalancer null $loadBalancer
Definition QueryPage.php:71
Special:Listredirects - Lists all the redirects on the wiki.
WikiPageFactory $wikiPageFactory
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
execute( $par)
This is the actual workhorse.
__construct(LinkBatchFactory $linkBatchFactory, ILoadBalancer $loadBalancer, WikiPageFactory $wikiPageFactory)
isSyndicated()
Sometime we don't want to build rss / atom feeds.
preprocessResults( $db, $res)
Cache page existence for performance.
LinkBatchFactory $linkBatchFactory
getQueryInfo()
Subclasses return an SQL query here, formatted as an array with the following keys: tables => Table(s...
isExpensive()
Is this query expensive (for some definition of expensive)? Then we don't let it run in miser mode.
getOrderFields()
Subclasses return an array of fields to order by here.
sortDescending()
Override to sort by increasing values.
LinkRenderer null $linkRenderer
getLanguage()
Shortcut to get user's language.
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:38
Database cluster connection, tracking, load balancing, and transaction manager interface.
Result wrapper for grabbing data queried from an IDatabase object.
if(!isset( $args[0])) $lang