MediaWiki REL1_39
SpecialBrokenRedirects.php
Go to the documentation of this file.
1<?php
29
37
39 private $contentHandlerFactory;
40
46 public function __construct(
47 IContentHandlerFactory $contentHandlerFactory,
48 ILoadBalancer $loadBalancer,
49 LinkBatchFactory $linkBatchFactory
50 ) {
51 parent::__construct( 'BrokenRedirects' );
52 $this->contentHandlerFactory = $contentHandlerFactory;
53 $this->setDBLoadBalancer( $loadBalancer );
54 $this->setLinkBatchFactory( $linkBatchFactory );
55 }
56
57 public function isExpensive() {
58 return true;
59 }
60
61 public function isSyndicated() {
62 return false;
63 }
64
65 protected function sortDescending() {
66 return false;
67 }
68
69 protected function getPageHeader() {
70 return $this->msg( 'brokenredirectstext' )->parseAsBlock();
71 }
72
73 public function getQueryInfo() {
74 $dbr = $this->getDBLoadBalancer()->getConnectionRef( ILoadBalancer::DB_REPLICA );
75
76 return [
77 'tables' => [
78 'redirect',
79 'p1' => 'page',
80 'p2' => 'page',
81 ],
82 'fields' => [
83 'namespace' => 'p1.page_namespace',
84 'title' => 'p1.page_title',
85 'rd_namespace',
86 'rd_title',
87 'rd_fragment',
88 ],
89 'conds' => [
90 // Exclude pages that don't exist locally as wiki pages,
91 // but aren't "broken" either.
92 // Special pages and interwiki links
93 'rd_namespace >= 0',
94 'rd_interwiki IS NULL OR rd_interwiki = ' . $dbr->addQuotes( '' ),
95 'p2.page_namespace IS NULL',
96 ],
97 'join_conds' => [
98 'p1' => [ 'JOIN', [
99 'rd_from=p1.page_id',
100 ] ],
101 'p2' => [ 'LEFT JOIN', [
102 'rd_namespace=p2.page_namespace',
103 'rd_title=p2.page_title'
104 ] ],
105 ],
106 ];
107 }
108
112 protected function getOrderFields() {
113 return [ 'rd_namespace', 'rd_title', 'rd_from' ];
114 }
115
121 public function formatResult( $skin, $result ) {
122 $fromObj = Title::makeTitle( $result->namespace, $result->title );
123 if ( isset( $result->rd_title ) ) {
124 $toObj = Title::makeTitle(
125 $result->rd_namespace,
126 $result->rd_title,
127 $result->rd_fragment ?? ''
128 );
129 } else {
130 $blinks = $fromObj->getBrokenLinksFrom(); # TODO: check for redirect, not for links
131 if ( $blinks ) {
132 $toObj = $blinks[0];
133 } else {
134 $toObj = false;
135 }
136 }
137
138 $linkRenderer = $this->getLinkRenderer();
139
140 // $toObj may very easily be false if the $result list is cached
141 if ( !is_object( $toObj ) ) {
142 return '<del>' . $linkRenderer->makeLink( $fromObj ) . '</del>';
143 }
144
145 $from = $linkRenderer->makeKnownLink(
146 $fromObj,
147 null,
148 [],
149 [ 'redirect' => 'no' ]
150 );
151 $links = [];
152 // if the page is editable, add an edit link
153 if (
154 // check user permissions
155 $this->getAuthority()->isAllowed( 'edit' ) &&
156 // check, if the content model is editable through action=edit
157 $this->contentHandlerFactory->getContentHandler( $fromObj->getContentModel() )
158 ->supportsDirectEditing()
159 ) {
160 $links[] = $linkRenderer->makeKnownLink(
161 $fromObj,
162 $this->msg( 'brokenredirects-edit' )->text(),
163 [],
164 [ 'action' => 'edit' ]
165 );
166 }
167 $to = $linkRenderer->makeBrokenLink( $toObj, $toObj->getFullText() );
168 $arr = $this->getLanguage()->getArrow();
169
170 $out = $from . $this->msg( 'word-separator' )->escaped();
171
172 if ( $this->getAuthority()->isAllowed( 'delete' ) ) {
173 $links[] = $linkRenderer->makeKnownLink(
174 $fromObj,
175 $this->msg( 'brokenredirects-delete' )->text(),
176 [],
177 [
178 'action' => 'delete',
179 'wpReason' => $this->msg( 'brokenredirects-delete-reason' )
180 ->inContentLanguage()
181 ->text()
182 ]
183 );
184 }
185
186 if ( $links ) {
187 $out .= $this->msg( 'parentheses' )->rawParams( $this->getLanguage()
188 ->pipeList( $links ) )->escaped();
189 }
190 $out .= " {$arr} {$to}";
191
192 return $out;
193 }
194
195 public function execute( $par ) {
196 $this->addHelpLink( 'Help:Redirects' );
197 parent::execute( $par );
198 }
199
206 public function preprocessResults( $db, $res ) {
208 }
209
210 protected function getGroupName() {
211 return 'maintenance';
212 }
213}
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:42
executeLBFromResultWrapper(IResultWrapper $res, $ns=null)
Creates a new LinkBatch object, adds all pages from the passed result wrapper (MUST include title and...
setDBLoadBalancer(ILoadBalancer $loadBalancer)
setLinkBatchFactory(LinkBatchFactory $linkBatchFactory)
getDBLoadBalancer()
A special page listing redirects to non existent page.
preprocessResults( $db, $res)
Cache page content model for performance.
isSyndicated()
Sometimes we don't want to build rss / atom feeds.
getQueryInfo()
Subclasses return an SQL query here, formatted as an array with the following keys: tables => Table(s...
execute( $par)
This is the actual workhorse.
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
sortDescending()
Override to sort by increasing values.
isExpensive()
Should this query page only be updated offline on large wikis?
__construct(IContentHandlerFactory $contentHandlerFactory, ILoadBalancer $loadBalancer, LinkBatchFactory $linkBatchFactory)
getPageHeader()
The content returned by this function will be output before any result.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getAuthority()
Shortcut to get the Authority executing this instance.
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:39
Create and track the database connections and transactions for a given database cluster.
Result wrapper for grabbing data queried from an IDatabase object.