| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
namespace MediaWiki\Specials; |
| 22 |
|
| 23 |
use MediaWiki\Cache\LinkBatchFactory; |
| 24 |
use MediaWiki\Content\IContentHandlerFactory; |
| 25 |
use MediaWiki\Page\RedirectLookup; |
| 26 |
use MediaWiki\SpecialPage\QueryPage; |
| 27 |
use MediaWiki\Title\Title; |
| 28 |
use Skin; |
| 29 |
use Wikimedia\Rdbms\IConnectionProvider; |
| 30 |
use Wikimedia\Rdbms\IDatabase; |
| 31 |
use Wikimedia\Rdbms\IResultWrapper; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
class SpecialBrokenRedirects extends QueryPage { |
| 42 |
|
| 43 |
private IContentHandlerFactory $contentHandlerFactory; |
| 44 |
private RedirectLookup $redirectLookup; |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
public function __construct( |
| 52 |
IContentHandlerFactory $contentHandlerFactory, |
| 53 |
IConnectionProvider $dbProvider, |
| 54 |
LinkBatchFactory $linkBatchFactory, |
| 55 |
RedirectLookup $redirectLookup |
| 56 |
) { |
| 57 |
parent::__construct( 'BrokenRedirects' ); |
| 58 |
$this->contentHandlerFactory = $contentHandlerFactory; |
| 59 |
$this->setDatabaseProvider( $dbProvider ); |
| 60 |
$this->setLinkBatchFactory( $linkBatchFactory ); |
| 61 |
$this->redirectLookup = $redirectLookup; |
| 62 |
} |
| 63 |
|
| 64 |
public function isExpensive() { |
| 65 |
return true; |
| 66 |
} |
| 67 |
|
| 68 |
public function isSyndicated() { |
| 69 |
return false; |
| 70 |
} |
| 71 |
|
| 72 |
protected function sortDescending() { |
| 73 |
return false; |
| 74 |
} |
| 75 |
|
| 76 |
protected function getPageHeader() { |
| 77 |
return $this->msg( 'brokenredirectstext' )->parseAsBlock(); |
| 78 |
} |
| 79 |
|
| 80 |
public function getQueryInfo() { |
| 81 |
$dbr = $this->getDatabaseProvider()->getReplicaDatabase(); |
| 82 |
|
| 83 |
return [ |
| 84 |
'tables' => [ |
| 85 |
'redirect', |
| 86 |
'p1' => 'page', |
| 87 |
'p2' => 'page', |
| 88 |
], |
| 89 |
'fields' => [ |
| 90 |
'namespace' => 'p1.page_namespace', |
| 91 |
'title' => 'p1.page_title', |
| 92 |
'rd_namespace', |
| 93 |
'rd_title', |
| 94 |
'rd_fragment', |
| 95 |
], |
| 96 |
'conds' => [ |
| 97 |
|
| 98 |
|
| 99 |
$dbr->expr( 'rd_namespace', '>=', 0 ), |
| 100 |
'rd_interwiki' => '', |
| 101 |
'p2.page_namespace' => null, |
| 102 |
], |
| 103 |
'join_conds' => [ |
| 104 |
'p1' => [ 'JOIN', [ |
| 105 |
'rd_from=p1.page_id', |
| 106 |
] ], |
| 107 |
'p2' => [ 'LEFT JOIN', [ |
| 108 |
'rd_namespace=p2.page_namespace', |
| 109 |
'rd_title=p2.page_title' |
| 110 |
] ], |
| 111 |
], |
| 112 |
]; |
| 113 |
} |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
protected function getOrderFields() { |
| 119 |
return [ 'rd_namespace', 'rd_title', 'rd_from' ]; |
| 120 |
} |
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
public function formatResult( $skin, $result ) { |
| 128 |
$fromObj = Title::makeTitle( $result->namespace, $result->title ); |
| 129 |
if ( isset( $result->rd_title ) ) { |
| 130 |
$toObj = Title::makeTitle( |
| 131 |
$result->rd_namespace, |
| 132 |
$result->rd_title, |
| 133 |
$result->rd_fragment |
| 134 |
); |
| 135 |
} else { |
| 136 |
$toObj = Title::castFromLinkTarget( |
| 137 |
$this->redirectLookup->getRedirectTarget( $fromObj ) |
| 138 |
); |
| 139 |
} |
| 140 |
|
| 141 |
$linkRenderer = $this->getLinkRenderer(); |
| 142 |
|
| 143 |
if ( !is_object( $toObj ) || $toObj->exists() ) { |
| 144 |
return '<del>' . $linkRenderer->makeLink( $fromObj ) . '</del>'; |
| 145 |
} |
| 146 |
|
| 147 |
$from = $linkRenderer->makeKnownLink( |
| 148 |
$fromObj, |
| 149 |
null, |
| 150 |
[], |
| 151 |
[ 'redirect' => 'no' ] |
| 152 |
); |
| 153 |
$links = []; |
| 154 |
|
| 155 |
if ( |
| 156 |
|
| 157 |
$this->getAuthority()->isAllowed( 'edit' ) && |
| 158 |
|
| 159 |
$this->contentHandlerFactory->getContentHandler( $fromObj->getContentModel() ) |
| 160 |
->supportsDirectEditing() |
| 161 |
) { |
| 162 |
$links[] = $linkRenderer->makeKnownLink( |
| 163 |
$fromObj, |
| 164 |
$this->msg( 'brokenredirects-edit' )->text(), |
| 165 |
[], |
| 166 |
[ 'action' => 'edit' ] |
| 167 |
); |
| 168 |
} |
| 169 |
$to = $linkRenderer->makeBrokenLink( $toObj, $toObj->getFullText() ); |
| 170 |
$arr = $this->getLanguage()->getArrow(); |
| 171 |
|
| 172 |
$out = $from . $this->msg( 'word-separator' )->escaped(); |
| 173 |
|
| 174 |
if ( $this->getAuthority()->isAllowed( 'delete' ) ) { |
| 175 |
$links[] = $linkRenderer->makeKnownLink( |
| 176 |
$fromObj, |
| 177 |
$this->msg( 'brokenredirects-delete' )->text(), |
| 178 |
[], |
| 179 |
[ |
| 180 |
'action' => 'delete', |
| 181 |
'wpReason' => $this->msg( 'brokenredirects-delete-reason' ) |
| 182 |
->inContentLanguage() |
| 183 |
->text() |
| 184 |
] |
| 185 |
); |
| 186 |
} |
| 187 |
|
| 188 |
if ( $links ) { |
| 189 |
$out .= $this->msg( 'parentheses' )->rawParams( $this->getLanguage() |
| 190 |
->pipeList( $links ) )->escaped(); |
| 191 |
} |
| 192 |
$out .= " {$arr} {$to}"; |
| 193 |
|
| 194 |
return $out; |
| 195 |
} |
| 196 |
|
| 197 |
public function execute( $par ) { |
| 198 |
$this->addHelpLink( 'Help:Redirects' ); |
| 199 |
parent::execute( $par ); |
| 200 |
} |
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
public function preprocessResults( $db, $res ) { |
| 209 |
$this->executeLBFromResultWrapper( $res ); |
| 210 |
} |
| 211 |
|
| 212 |
protected function getGroupName() { |
| 213 |
return 'maintenance'; |
| 214 |
} |
| 215 |
} |
| 216 |
|
| 217 |
|
| 218 |
class_alias( SpecialBrokenRedirects::class, 'SpecialBrokenRedirects' ); |