MediaWiki  master
SpecialBrokenRedirects.php
Go to the documentation of this file.
1 <?php
27 
35  function __construct( $name = 'BrokenRedirects' ) {
36  parent::__construct( $name );
37  }
38 
39  public function isExpensive() {
40  return true;
41  }
42 
43  function isSyndicated() {
44  return false;
45  }
46 
47  function sortDescending() {
48  return false;
49  }
50 
51  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  'value' => 'p1.page_title',
68  'rd_namespace',
69  'rd_title',
70  'rd_fragment',
71  ],
72  'conds' => [
73  // Exclude pages that don't exist locally as wiki pages,
74  // but aren't "broken" either.
75  // Special pages and interwiki links
76  'rd_namespace >= 0',
77  'rd_interwiki IS NULL OR rd_interwiki = ' . $dbr->addQuotes( '' ),
78  'p2.page_namespace IS NULL',
79  ],
80  'join_conds' => [
81  'p1' => [ 'JOIN', [
82  'rd_from=p1.page_id',
83  ] ],
84  'p2' => [ 'LEFT JOIN', [
85  'rd_namespace=p2.page_namespace',
86  'rd_title=p2.page_title'
87  ] ],
88  ],
89  ];
90  }
91 
95  function getOrderFields() {
96  return [ 'rd_namespace', 'rd_title', 'rd_from' ];
97  }
98 
104  function formatResult( $skin, $result ) {
105  $fromObj = Title::makeTitle( $result->namespace, $result->title );
106  if ( isset( $result->rd_title ) ) {
107  $toObj = Title::makeTitle( $result->rd_namespace, $result->rd_title, $result->rd_fragment );
108  } else {
109  $blinks = $fromObj->getBrokenLinksFrom(); # TODO: check for redirect, not for links
110  if ( $blinks ) {
111  $toObj = $blinks[0];
112  } else {
113  $toObj = false;
114  }
115  }
116 
117  $linkRenderer = $this->getLinkRenderer();
118  $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
119 
120  // $toObj may very easily be false if the $result list is cached
121  if ( !is_object( $toObj ) ) {
122  return '<del>' . $linkRenderer->makeLink( $fromObj ) . '</del>';
123  }
124 
125  $from = $linkRenderer->makeKnownLink(
126  $fromObj,
127  null,
128  [],
129  [ 'redirect' => 'no' ]
130  );
131  $links = [];
132  // if the page is editable, add an edit link
133  if (
134  // check user permissions
135  $permissionManager->userHasRight( $this->getUser(), 'edit' ) &&
136  // check, if the content model is editable through action=edit
137  ContentHandler::getForTitle( $fromObj )->supportsDirectEditing()
138  ) {
139  $links[] = $linkRenderer->makeKnownLink(
140  $fromObj,
141  $this->msg( 'brokenredirects-edit' )->text(),
142  [],
143  [ 'action' => 'edit' ]
144  );
145  }
146  $to = $linkRenderer->makeBrokenLink( $toObj, $toObj->getFullText() );
147  $arr = $this->getLanguage()->getArrow();
148 
149  $out = $from . $this->msg( 'word-separator' )->escaped();
150 
151  if ( $permissionManager->userHasRight( $this->getUser(), 'delete' ) ) {
152  $links[] = $linkRenderer->makeKnownLink(
153  $fromObj,
154  $this->msg( 'brokenredirects-delete' )->text(),
155  [],
156  [ 'action' => 'delete' ]
157  );
158  }
159 
160  if ( $links ) {
161  $out .= $this->msg( 'parentheses' )->rawParams( $this->getLanguage()
162  ->pipeList( $links ) )->escaped();
163  }
164  $out .= " {$arr} {$to}";
165 
166  return $out;
167  }
168 
169  public function execute( $par ) {
170  $this->addHelpLink( 'Help:Redirects' );
171  parent::execute( $par );
172  }
173 
180  function preprocessResults( $db, $res ) {
182  }
183 
184  protected function getGroupName() {
185  return 'maintenance';
186  }
187 }
preprocessResults( $db, $res)
Cache page content model for performance.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
This is a class for doing query pages; since they&#39;re almost all the same, we factor out some of the f...
Definition: QueryPage.php:36
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
A special page listing redirects to non existent page.
static getForTitle(Title $title)
Returns the appropriate ContentHandler singleton for the given title.
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:586
getLanguage()
Shortcut to get user&#39;s language.
__construct( $name='BrokenRedirects')
const DB_REPLICA
Definition: defines.php:25
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:800
MediaWiki Linker LinkRenderer null $linkRenderer
Definition: SpecialPage.php:67