MediaWiki  master
SpecialBrokenRedirects.php
Go to the documentation of this file.
1 <?php
27 
35  public function __construct( $name = 'BrokenRedirects' ) {
36  parent::__construct( $name );
37  }
38 
39  public function isExpensive() {
40  return true;
41  }
42 
43  public function isSyndicated() {
44  return false;
45  }
46 
47  protected function sortDescending() {
48  return false;
49  }
50 
51  protected function getPageHeader() {
52  return $this->msg( 'brokenredirectstext' )->parseAsBlock();
53  }
54 
55  public function getQueryInfo() {
56  $dbr = wfGetDB( DB_REPLICA );
57 
58  return [
59  'tables' => [
60  'redirect',
61  'p1' => 'page',
62  'p2' => 'page',
63  ],
64  'fields' => [
65  'namespace' => 'p1.page_namespace',
66  'title' => 'p1.page_title',
67  'rd_namespace',
68  'rd_title',
69  'rd_fragment',
70  ],
71  'conds' => [
72  // Exclude pages that don't exist locally as wiki pages,
73  // but aren't "broken" either.
74  // Special pages and interwiki links
75  'rd_namespace >= 0',
76  'rd_interwiki IS NULL OR rd_interwiki = ' . $dbr->addQuotes( '' ),
77  'p2.page_namespace IS NULL',
78  ],
79  'join_conds' => [
80  'p1' => [ 'JOIN', [
81  'rd_from=p1.page_id',
82  ] ],
83  'p2' => [ 'LEFT JOIN', [
84  'rd_namespace=p2.page_namespace',
85  'rd_title=p2.page_title'
86  ] ],
87  ],
88  ];
89  }
90 
94  protected function getOrderFields() {
95  return [ 'rd_namespace', 'rd_title', 'rd_from' ];
96  }
97 
103  public function formatResult( $skin, $result ) {
104  $fromObj = Title::makeTitle( $result->namespace, $result->title );
105  if ( isset( $result->rd_title ) ) {
106  $toObj = Title::makeTitle( $result->rd_namespace, $result->rd_title, $result->rd_fragment );
107  } else {
108  $blinks = $fromObj->getBrokenLinksFrom(); # TODO: check for redirect, not for links
109  if ( $blinks ) {
110  $toObj = $blinks[0];
111  } else {
112  $toObj = false;
113  }
114  }
115 
116  $linkRenderer = $this->getLinkRenderer();
117  $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
118 
119  // $toObj may very easily be false if the $result list is cached
120  if ( !is_object( $toObj ) ) {
121  return '<del>' . $linkRenderer->makeLink( $fromObj ) . '</del>';
122  }
123 
124  $from = $linkRenderer->makeKnownLink(
125  $fromObj,
126  null,
127  [],
128  [ 'redirect' => 'no' ]
129  );
130  $links = [];
131  // if the page is editable, add an edit link
132  if (
133  // check user permissions
134  $permissionManager->userHasRight( $this->getUser(), 'edit' ) &&
135  // check, if the content model is editable through action=edit
136  MediaWikiServices::getInstance()
137  ->getContentHandlerFactory()
138  ->getContentHandler( $fromObj->getContentModel() )
139  ->supportsDirectEditing()
140  ) {
141  $links[] = $linkRenderer->makeKnownLink(
142  $fromObj,
143  $this->msg( 'brokenredirects-edit' )->text(),
144  [],
145  [ 'action' => 'edit' ]
146  );
147  }
148  $to = $linkRenderer->makeBrokenLink( $toObj, $toObj->getFullText() );
149  $arr = $this->getLanguage()->getArrow();
150 
151  $out = $from . $this->msg( 'word-separator' )->escaped();
152 
153  if ( $permissionManager->userHasRight( $this->getUser(), 'delete' ) ) {
154  $links[] = $linkRenderer->makeKnownLink(
155  $fromObj,
156  $this->msg( 'brokenredirects-delete' )->text(),
157  [],
158  [
159  'action' => 'delete',
160  'wpReason' => $this->msg( 'brokenredirects-delete-reason' )
161  ->inContentLanguage()
162  ->text()
163  ]
164  );
165  }
166 
167  if ( $links ) {
168  $out .= $this->msg( 'parentheses' )->rawParams( $this->getLanguage()
169  ->pipeList( $links ) )->escaped();
170  }
171  $out .= " {$arr} {$to}";
172 
173  return $out;
174  }
175 
176  public function execute( $par ) {
177  $this->addHelpLink( 'Help:Redirects' );
178  parent::execute( $par );
179  }
180 
187  public function preprocessResults( $db, $res ) {
189  }
190 
191  protected function getGroupName() {
192  return 'maintenance';
193  }
194 }
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:39
SpecialPage\msg
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
Definition: SpecialPage.php:800
SpecialBrokenRedirects\getPageHeader
getPageHeader()
The content returned by this function will be output before any result.
Definition: SpecialBrokenRedirects.php:51
SpecialBrokenRedirects\formatResult
formatResult( $skin, $result)
Definition: SpecialBrokenRedirects.php:103
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:152
SpecialBrokenRedirects\__construct
__construct( $name='BrokenRedirects')
Definition: SpecialBrokenRedirects.php:35
SpecialBrokenRedirects\getQueryInfo
getQueryInfo()
Subclasses return an SQL query here, formatted as an array with the following keys: tables => Table(s...
Definition: SpecialBrokenRedirects.php:55
SpecialBrokenRedirects\preprocessResults
preprocessResults( $db, $res)
Cache page content model for performance.
Definition: SpecialBrokenRedirects.php:187
SpecialPage\getLanguage
getLanguage()
Shortcut to get user's language.
Definition: SpecialPage.php:746
$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:36
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:798
Wikimedia\Rdbms\IDatabase
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:38
$dbr
$dbr
Definition: testCompression.php:54
SpecialPage\addHelpLink
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
Definition: SpecialPage.php:836
Wikimedia\Rdbms\IResultWrapper
Result wrapper for grabbing data queried from an IDatabase object.
Definition: IResultWrapper.php:24
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2461
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:592
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
SpecialBrokenRedirects\sortDescending
sortDescending()
Override to sort by increasing values.
Definition: SpecialBrokenRedirects.php:47
SpecialBrokenRedirects
A special page listing redirects to non existent page.
Definition: SpecialBrokenRedirects.php:34
SpecialPage\getLinkRenderer
getLinkRenderer()
Definition: SpecialPage.php:912
SpecialBrokenRedirects\execute
execute( $par)
This is the actual workhorse.
Definition: SpecialBrokenRedirects.php:176
SpecialPage\$linkRenderer
MediaWiki Linker LinkRenderer null $linkRenderer
Definition: SpecialPage.php:69
SpecialBrokenRedirects\getGroupName
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Definition: SpecialBrokenRedirects.php:191
SpecialBrokenRedirects\isSyndicated
isSyndicated()
Sometime we don't want to build rss / atom feeds.
Definition: SpecialBrokenRedirects.php:43
SpecialBrokenRedirects\getOrderFields
getOrderFields()
Definition: SpecialBrokenRedirects.php:94