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( $result->rd_namespace, $result->rd_title, $result->rd_fragment );
125  } else {
126  $blinks = $fromObj->getBrokenLinksFrom(); # TODO: check for redirect, not for links
127  if ( $blinks ) {
128  $toObj = $blinks[0];
129  } else {
130  $toObj = false;
131  }
132  }
133 
134  $linkRenderer = $this->getLinkRenderer();
135 
136  // $toObj may very easily be false if the $result list is cached
137  if ( !is_object( $toObj ) ) {
138  return '<del>' . $linkRenderer->makeLink( $fromObj ) . '</del>';
139  }
140 
141  $from = $linkRenderer->makeKnownLink(
142  $fromObj,
143  null,
144  [],
145  [ 'redirect' => 'no' ]
146  );
147  $links = [];
148  // if the page is editable, add an edit link
149  if (
150  // check user permissions
151  $this->getAuthority()->isAllowed( 'edit' ) &&
152  // check, if the content model is editable through action=edit
153  $this->contentHandlerFactory->getContentHandler( $fromObj->getContentModel() )
154  ->supportsDirectEditing()
155  ) {
156  $links[] = $linkRenderer->makeKnownLink(
157  $fromObj,
158  $this->msg( 'brokenredirects-edit' )->text(),
159  [],
160  [ 'action' => 'edit' ]
161  );
162  }
163  $to = $linkRenderer->makeBrokenLink( $toObj, $toObj->getFullText() );
164  $arr = $this->getLanguage()->getArrow();
165 
166  $out = $from . $this->msg( 'word-separator' )->escaped();
167 
168  if ( $this->getAuthority()->isAllowed( 'delete' ) ) {
169  $links[] = $linkRenderer->makeKnownLink(
170  $fromObj,
171  $this->msg( 'brokenredirects-delete' )->text(),
172  [],
173  [
174  'action' => 'delete',
175  'wpReason' => $this->msg( 'brokenredirects-delete-reason' )
176  ->inContentLanguage()
177  ->text()
178  ]
179  );
180  }
181 
182  if ( $links ) {
183  $out .= $this->msg( 'parentheses' )->rawParams( $this->getLanguage()
184  ->pipeList( $links ) )->escaped();
185  }
186  $out .= " {$arr} {$to}";
187 
188  return $out;
189  }
190 
191  public function execute( $par ) {
192  $this->addHelpLink( 'Help:Redirects' );
193  parent::execute( $par );
194  }
195 
202  public function preprocessResults( $db, $res ) {
204  }
205 
206  protected function getGroupName() {
207  return 'maintenance';
208  }
209 }
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:202
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:651
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:191
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:206
SpecialBrokenRedirects\isSyndicated
isSyndicated()
Sometime 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