MediaWiki  master
SpecialBrokenRedirects.php
Go to the documentation of this file.
1 <?php
29 
37 
40 
46  public function __construct(
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 }
SpecialPage\$linkRenderer
LinkRenderer null $linkRenderer
Definition: SpecialPage.php:80
SpecialBrokenRedirects\isExpensive
isExpensive()
Is this query expensive (for some definition of expensive)? Then we don't let it run in miser mode.
Definition: SpecialBrokenRedirects.php:57
SpecialPage\msg
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
Definition: SpecialPage.php:912
QueryPage\getDBLoadBalancer
getDBLoadBalancer()
Definition: QueryPage.php:900
SpecialBrokenRedirects\getPageHeader
getPageHeader()
The content returned by this function will be output before any result.
Definition: SpecialBrokenRedirects.php:69
SpecialBrokenRedirects\formatResult
formatResult( $skin, $result)
Definition: SpecialBrokenRedirects.php:121
SpecialBrokenRedirects\getQueryInfo
getQueryInfo()
Subclasses return an SQL query here, formatted as an array with the following keys: tables => Table(s...
Definition: SpecialBrokenRedirects.php:73
SpecialBrokenRedirects\preprocessResults
preprocessResults( $db, $res)
Cache page content model for performance.
Definition: SpecialBrokenRedirects.php:206
SpecialBrokenRedirects\__construct
__construct(IContentHandlerFactory $contentHandlerFactory, ILoadBalancer $loadBalancer, LinkBatchFactory $linkBatchFactory)
Definition: SpecialBrokenRedirects.php:46
SpecialPage\getAuthority
getAuthority()
Shortcut to get the Authority executing this instance.
Definition: SpecialPage.php:810
SpecialPage\getLanguage
getLanguage()
Shortcut to get user's language.
Definition: SpecialPage.php:830
$res
$res
Definition: testCompression.php:57
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
QueryPage\executeLBFromResultWrapper
executeLBFromResultWrapper(IResultWrapper $res, $ns=null)
Creates a new LinkBatch object, adds all pages from the passed result wrapper (MUST include title and...
Definition: QueryPage.php:874
SpecialBrokenRedirects\$contentHandlerFactory
IContentHandlerFactory $contentHandlerFactory
Definition: SpecialBrokenRedirects.php:39
Wikimedia\Rdbms\IDatabase
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:38
$dbr
$dbr
Definition: testCompression.php:54
QueryPage\setLinkBatchFactory
setLinkBatchFactory(LinkBatchFactory $linkBatchFactory)
Definition: QueryPage.php:135
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
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:666
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
SpecialBrokenRedirects\sortDescending
sortDescending()
Override to sort by increasing values.
Definition: SpecialBrokenRedirects.php:65
SpecialBrokenRedirects
A special page listing redirects to non existent page.
Definition: SpecialBrokenRedirects.php:36
MediaWiki\Content\IContentHandlerFactory
Definition: IContentHandlerFactory.php:10
QueryPage\setDBLoadBalancer
setDBLoadBalancer(ILoadBalancer $loadBalancer)
Definition: QueryPage.php:892
QueryPage\$linkBatchFactory
LinkBatchFactory null $linkBatchFactory
Definition: QueryPage.php:74
SpecialPage\getLinkRenderer
getLinkRenderer()
Definition: SpecialPage.php:1028
SpecialBrokenRedirects\execute
execute( $par)
This is the actual workhorse.
Definition: SpecialBrokenRedirects.php:195
QueryPage\$loadBalancer
ILoadBalancer null $loadBalancer
Definition: QueryPage.php:71
SpecialBrokenRedirects\getGroupName
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Definition: SpecialBrokenRedirects.php:210
SpecialBrokenRedirects\isSyndicated
isSyndicated()
Sometimes we don't want to build rss / atom feeds.
Definition: SpecialBrokenRedirects.php:61
Wikimedia\Rdbms\ILoadBalancer
Database cluster connection, tracking, load balancing, and transaction manager interface.
Definition: ILoadBalancer.php:81
SpecialBrokenRedirects\getOrderFields
getOrderFields()
Definition: SpecialBrokenRedirects.php:112