mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Nuke
synced 2024-11-24 00:05:33 +00:00
Modernize the code a little bit
For example: * Remove redundant PHPDoc blocks that just duplicate existing information and aren't needed any more with our current PHPCS rule set. * Add some very obvious type declarations. * Use ??= where it makes sense. Change-Id: I5c182cc961c6eeccead79ff49b0376eee2418acf
This commit is contained in:
parent
f667a85e04
commit
9fb95da819
|
@ -11,12 +11,8 @@ use MediaWiki\Title\Title;
|
||||||
*/
|
*/
|
||||||
class NukeHookRunner implements NukeDeletePageHook, NukeGetNewPagesHook {
|
class NukeHookRunner implements NukeDeletePageHook, NukeGetNewPagesHook {
|
||||||
|
|
||||||
/** @var HookContainer */
|
private HookContainer $hookContainer;
|
||||||
private $hookContainer;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param HookContainer $hookContainer
|
|
||||||
*/
|
|
||||||
public function __construct( HookContainer $hookContainer ) {
|
public function __construct( HookContainer $hookContainer ) {
|
||||||
$this->hookContainer = $hookContainer;
|
$this->hookContainer = $hookContainer;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,36 +32,14 @@ class SpecialNuke extends SpecialPage {
|
||||||
/** @var NukeHookRunner|null */
|
/** @var NukeHookRunner|null */
|
||||||
private $hookRunner;
|
private $hookRunner;
|
||||||
|
|
||||||
/** @var JobQueueGroup */
|
private JobQueueGroup $jobQueueGroup;
|
||||||
private $jobQueueGroup;
|
private IConnectionProvider $dbProvider;
|
||||||
|
private PermissionManager $permissionManager;
|
||||||
|
private RepoGroup $repoGroup;
|
||||||
|
private UserFactory $userFactory;
|
||||||
|
private UserNamePrefixSearch $userNamePrefixSearch;
|
||||||
|
private UserNameUtils $userNameUtils;
|
||||||
|
|
||||||
/** @var IConnectionProvider */
|
|
||||||
private $dbProvider;
|
|
||||||
|
|
||||||
/** @var PermissionManager */
|
|
||||||
private $permissionManager;
|
|
||||||
|
|
||||||
/** @var RepoGroup */
|
|
||||||
private $repoGroup;
|
|
||||||
|
|
||||||
/** @var UserFactory */
|
|
||||||
private $userFactory;
|
|
||||||
|
|
||||||
/** @var UserNamePrefixSearch */
|
|
||||||
private $userNamePrefixSearch;
|
|
||||||
|
|
||||||
/** @var UserNameUtils */
|
|
||||||
private $userNameUtils;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param JobQueueGroup $jobQueueGroup
|
|
||||||
* @param IConnectionProvider $dbProvider
|
|
||||||
* @param PermissionManager $permissionManager
|
|
||||||
* @param RepoGroup $repoGroup
|
|
||||||
* @param UserFactory $userFactory
|
|
||||||
* @param UserNamePrefixSearch $userNamePrefixSearch
|
|
||||||
* @param UserNameUtils $userNameUtils
|
|
||||||
*/
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
JobQueueGroup $jobQueueGroup,
|
JobQueueGroup $jobQueueGroup,
|
||||||
IConnectionProvider $dbProvider,
|
IConnectionProvider $dbProvider,
|
||||||
|
@ -131,7 +109,6 @@ class SpecialNuke extends SpecialPage {
|
||||||
|
|
||||||
if ( $pages ) {
|
if ( $pages ) {
|
||||||
$this->doDelete( $pages, $reason );
|
$this->doDelete( $pages, $reason );
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} elseif ( $req->getRawVal( 'action' ) === 'submit' ) {
|
} elseif ( $req->getRawVal( 'action' ) === 'submit' ) {
|
||||||
|
@ -151,7 +128,7 @@ class SpecialNuke extends SpecialPage {
|
||||||
*
|
*
|
||||||
* @param string $userName
|
* @param string $userName
|
||||||
*/
|
*/
|
||||||
protected function promptForm( $userName = '' ) {
|
protected function promptForm( $userName = '' ): void {
|
||||||
$out = $this->getOutput();
|
$out = $this->getOutput();
|
||||||
|
|
||||||
$out->addWikiMsg( 'nuke-tools' );
|
$out->addWikiMsg( 'nuke-tools' );
|
||||||
|
@ -208,12 +185,12 @@ class SpecialNuke extends SpecialPage {
|
||||||
* @param int $limit
|
* @param int $limit
|
||||||
* @param int|null $namespace
|
* @param int|null $namespace
|
||||||
*/
|
*/
|
||||||
protected function listForm( $username, $reason, $limit, $namespace = null ) {
|
protected function listForm( $username, $reason, $limit, $namespace = null ): void {
|
||||||
$out = $this->getOutput();
|
$out = $this->getOutput();
|
||||||
|
|
||||||
$pages = $this->getNewPages( $username, $limit, $namespace );
|
$pages = $this->getNewPages( $username, $limit, $namespace );
|
||||||
|
|
||||||
if ( count( $pages ) === 0 ) {
|
if ( !$pages ) {
|
||||||
if ( $username === '' ) {
|
if ( $username === '' ) {
|
||||||
$out->addWikiMsg( 'nuke-nopages-global' );
|
$out->addWikiMsg( 'nuke-nopages-global' );
|
||||||
} else {
|
} else {
|
||||||
|
@ -221,7 +198,6 @@ class SpecialNuke extends SpecialPage {
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->promptForm( $username );
|
$this->promptForm( $username );
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -278,15 +254,10 @@ class SpecialNuke extends SpecialPage {
|
||||||
'name' => 'nukelist' ]
|
'name' => 'nukelist' ]
|
||||||
) .
|
) .
|
||||||
Html::hidden( 'wpEditToken', $this->getUser()->getEditToken() ) .
|
Html::hidden( 'wpEditToken', $this->getUser()->getEditToken() ) .
|
||||||
$dropdown . $reasonField
|
$dropdown .
|
||||||
);
|
$reasonField .
|
||||||
|
|
||||||
// Select: All, None, Invert
|
// Select: All, None, Invert
|
||||||
$listToggle = new ListToggle( $this->getOutput() );
|
( new ListToggle( $this->getOutput() ) )->getHTML() .
|
||||||
$selectLinks = $listToggle->getHTML();
|
|
||||||
|
|
||||||
$out->addHTML(
|
|
||||||
$selectLinks .
|
|
||||||
'<ul>'
|
'<ul>'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -295,11 +266,10 @@ class SpecialNuke extends SpecialPage {
|
||||||
|
|
||||||
$linkRenderer = $this->getLinkRenderer();
|
$linkRenderer = $this->getLinkRenderer();
|
||||||
$localRepo = $this->repoGroup->getLocalRepo();
|
$localRepo = $this->repoGroup->getLocalRepo();
|
||||||
foreach ( $pages as $info ) {
|
foreach ( $pages as [ $title, $userName ] ) {
|
||||||
/**
|
/**
|
||||||
* @var $title Title
|
* @var $title Title
|
||||||
*/
|
*/
|
||||||
[ $title, $userName ] = $info;
|
|
||||||
|
|
||||||
$image = $title->inNamespace( NS_FILE ) ? $localRepo->newFile( $title ) : false;
|
$image = $title->inNamespace( NS_FILE ) ? $localRepo->newFile( $title ) : false;
|
||||||
$thumb = $image && $image->exists() ?
|
$thumb = $image && $image->exists() ?
|
||||||
|
@ -315,8 +285,7 @@ class SpecialNuke extends SpecialPage {
|
||||||
[],
|
[],
|
||||||
[ 'action' => 'history' ]
|
[ 'action' => 'history' ]
|
||||||
);
|
);
|
||||||
$isRedirect = $title->isRedirect();
|
$query = $title->isRedirect() ? [ 'redirect' => 'no' ] : [];
|
||||||
$query = $isRedirect ? [ 'redirect' => 'no' ] : [];
|
|
||||||
$out->addHTML( '<li>' .
|
$out->addHTML( '<li>' .
|
||||||
Xml::check(
|
Xml::check(
|
||||||
'pages[]',
|
'pages[]',
|
||||||
|
@ -343,9 +312,9 @@ class SpecialNuke extends SpecialPage {
|
||||||
* @param int $limit
|
* @param int $limit
|
||||||
* @param int|null $namespace
|
* @param int|null $namespace
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array{0:Title,1:string|false}[]
|
||||||
*/
|
*/
|
||||||
protected function getNewPages( $username, $limit, $namespace = null ) {
|
protected function getNewPages( $username, $limit, $namespace = null ): array {
|
||||||
$dbr = $this->dbProvider->getReplicaDatabase();
|
$dbr = $this->dbProvider->getReplicaDatabase();
|
||||||
$queryBuilder = $dbr->newSelectQueryBuilder()
|
$queryBuilder = $dbr->newSelectQueryBuilder()
|
||||||
->select( [ 'rc_namespace', 'rc_title' ] )
|
->select( [ 'rc_namespace', 'rc_title' ] )
|
||||||
|
@ -378,6 +347,7 @@ class SpecialNuke extends SpecialPage {
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = $queryBuilder->caller( __METHOD__ )->fetchResultSet();
|
$result = $queryBuilder->caller( __METHOD__ )->fetchResultSet();
|
||||||
|
/** @var array{0:Title,1:string|false}[] $pages */
|
||||||
$pages = [];
|
$pages = [];
|
||||||
foreach ( $result as $row ) {
|
foreach ( $result as $row ) {
|
||||||
$pages[] = [
|
$pages[] = [
|
||||||
|
@ -407,7 +377,7 @@ class SpecialNuke extends SpecialPage {
|
||||||
* @param string $reason
|
* @param string $reason
|
||||||
* @throws PermissionsError
|
* @throws PermissionsError
|
||||||
*/
|
*/
|
||||||
protected function doDelete( array $pages, $reason ) {
|
protected function doDelete( array $pages, $reason ): void {
|
||||||
$res = [];
|
$res = [];
|
||||||
$jobs = [];
|
$jobs = [];
|
||||||
$user = $this->getUser();
|
$user = $this->getUser();
|
||||||
|
@ -512,11 +482,6 @@ class SpecialNuke extends SpecialPage {
|
||||||
return 'pagetools';
|
return 'pagetools';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param WebRequest $request
|
|
||||||
* @param string $target
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
private function getDeleteReason( WebRequest $request, string $target ): string {
|
private function getDeleteReason( WebRequest $request, string $target ): string {
|
||||||
$defaultReason = $target === ''
|
$defaultReason = $target === ''
|
||||||
? $this->msg( 'nuke-multiplepeople' )->inContentLanguage()->text()
|
? $this->msg( 'nuke-multiplepeople' )->inContentLanguage()->text()
|
||||||
|
@ -536,14 +501,8 @@ class SpecialNuke extends SpecialPage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private function getNukeHookRunner(): NukeHookRunner {
|
||||||
* @return NukeHookRunner
|
$this->hookRunner ??= new NukeHookRunner( $this->getHookContainer() );
|
||||||
*/
|
|
||||||
private function getNukeHookRunner() {
|
|
||||||
if ( !$this->hookRunner ) {
|
|
||||||
$this->hookRunner = new NukeHookRunner( $this->getHookContainer() );
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->hookRunner;
|
return $this->hookRunner;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue