Merge "Add a parent class for special pages"

This commit is contained in:
jenkins-bot 2019-08-06 18:32:29 +00:00 committed by Gerrit Code Review
commit 097b2da0ed
5 changed files with 92 additions and 91 deletions

View file

@ -116,6 +116,7 @@
"AbuseFilterHooks": "includes/AbuseFilterHooks.php",
"AbuseFilterPreAuthenticationProvider": "includes/AbuseFilterPreAuthenticationProvider.php",
"AbuseFilterRunner": "includes/AbuseFilterRunner.php",
"AbuseFilterSpecialPage": "includes/special/AbuseFilterSpecialPage.php",
"SpecialAbuseLog": "includes/special/SpecialAbuseLog.php",
"AbuseLogPager": "includes/pagers/AbuseLogPager.php",
"SpecialAbuseFilter": "includes/special/SpecialAbuseFilter.php",

View file

@ -1,6 +1,5 @@
<?php
use MediaWiki\Linker\LinkRenderer;
use MediaWiki\Logger\LoggerFactory;
use MediaWiki\Revision\RevisionRecord;
use MediaWiki\MediaWikiServices;
@ -233,70 +232,6 @@ class AbuseFilter {
'moved_to_articleid' => 'moved_to_id',
];
/**
* @param IContextSource $context
* @param string $pageType
* @param LinkRenderer $linkRenderer
*/
public static function addNavigationLinks(
IContextSource $context,
$pageType,
LinkRenderer $linkRenderer
) {
$linkDefs = [
'home' => 'Special:AbuseFilter',
'recentchanges' => 'Special:AbuseFilter/history',
'examine' => 'Special:AbuseFilter/examine',
];
if ( $context->getUser()->isAllowed( 'abusefilter-log' ) ) {
$linkDefs = array_merge( $linkDefs, [
'log' => 'Special:AbuseLog'
] );
}
if ( $context->getUser()->isAllowedAny( 'abusefilter-modify', 'abusefilter-view-private' ) ) {
$linkDefs = array_merge( $linkDefs, [
'test' => 'Special:AbuseFilter/test',
'tools' => 'Special:AbuseFilter/tools'
] );
}
if ( $context->getUser()->isAllowed( 'abusefilter-modify' ) ) {
$linkDefs = array_merge( $linkDefs, [
'import' => 'Special:AbuseFilter/import'
] );
}
$links = [];
foreach ( $linkDefs as $name => $page ) {
// Give grep a chance to find the usages:
// abusefilter-topnav-home, abusefilter-topnav-recentchanges, abusefilter-topnav-test,
// abusefilter-topnav-log, abusefilter-topnav-tools, abusefilter-topnav-import
// abusefilter-topnav-examine
$msgName = "abusefilter-topnav-$name";
$msg = $context->msg( $msgName )->parse();
$title = Title::newFromText( $page );
if ( $name === $pageType ) {
$links[] = Xml::tags( 'strong', null, $msg );
} else {
$links[] = $linkRenderer->makeLink( $title, new HtmlArmor( $msg ) );
}
}
$linkStr = $context->msg( 'parentheses' )
->rawParams( $context->getLanguage()->pipeList( $links ) )
->text();
$linkStr = $context->msg( 'abusefilter-topnav' )->parse() . " $linkStr";
$linkStr = Xml::tags( 'div', [ 'class' => 'mw-abusefilter-navigation' ], $linkStr );
$context->getOutput()->setSubtitle( $linkStr );
}
/**
* @param User $user
* @param null|stdClass $rcRow If the variables should be generated for an RC row, this is the row.

View file

@ -0,0 +1,66 @@
<?php
/**
* Parent class for AbuseFilter special pages.
*/
abstract class AbuseFilterSpecialPage extends SpecialPage {
/**
* Add topbar navigation links
*
* @param string $pageType
*/
protected function addNavigationLinks( $pageType ) {
$linkDefs = [
'home' => 'Special:AbuseFilter',
'recentchanges' => 'Special:AbuseFilter/history',
'examine' => 'Special:AbuseFilter/examine',
];
if ( $this->getUser()->isAllowed( 'abusefilter-log' ) ) {
$linkDefs = array_merge( $linkDefs, [
'log' => 'Special:AbuseLog'
] );
}
if ( $this->getUser()->isAllowedAny( 'abusefilter-modify', 'abusefilter-view-private' ) ) {
$linkDefs = array_merge( $linkDefs, [
'test' => 'Special:AbuseFilter/test',
'tools' => 'Special:AbuseFilter/tools'
] );
}
if ( $this->getUser()->isAllowed( 'abusefilter-modify' ) ) {
$linkDefs = array_merge( $linkDefs, [
'import' => 'Special:AbuseFilter/import'
] );
}
$links = [];
foreach ( $linkDefs as $name => $page ) {
// Give grep a chance to find the usages:
// abusefilter-topnav-home, abusefilter-topnav-recentchanges, abusefilter-topnav-test,
// abusefilter-topnav-log, abusefilter-topnav-tools, abusefilter-topnav-import
// abusefilter-topnav-examine
$msgName = "abusefilter-topnav-$name";
$msg = $this->msg( $msgName )->parse();
$title = Title::newFromText( $page );
if ( $name === $pageType ) {
$links[] = Xml::tags( 'strong', null, $msg );
} else {
$links[] = $this->getLinkRenderer()->makeLink( $title, new HtmlArmor( $msg ) );
}
}
$linkStr = $this->msg( 'parentheses' )
->rawParams( $this->getLanguage()->pipeList( $links ) )
->text();
$linkStr = $this->msg( 'abusefilter-topnav' )->parse() . " $linkStr";
$linkStr = Xml::tags( 'div', [ 'class' => 'mw-abusefilter-navigation' ], $linkStr );
$this->getOutput()->setSubtitle( $linkStr );
}
}

View file

@ -1,6 +1,6 @@
<?php
class SpecialAbuseFilter extends SpecialPage {
class SpecialAbuseFilter extends AbuseFilterSpecialPage {
/**
* @var int|string|null The current filter
*/
@ -10,17 +10,27 @@ class SpecialAbuseFilter extends SpecialPage {
*/
public $mHistoryID;
/**
* @inheritDoc
*/
public function __construct() {
parent::__construct( 'AbuseFilter', 'abusefilter-view' );
}
/**
* @return bool
* @inheritDoc
*/
public function doesWrites() {
return true;
}
/**
* @inheritDoc
*/
protected function getGroupName() {
return 'wiki';
}
/**
* @param string|null $subpage
*/
@ -122,8 +132,7 @@ class SpecialAbuseFilter extends SpecialPage {
}
// Links at the top
AbuseFilter::addNavigationLinks(
$this->getContext(), $pageType, $this->getLinkRenderer() );
$this->addNavigationLinks( $pageType );
/** @var AbuseFilterView $v */
$v = new $view( $this, $params );
@ -131,21 +140,12 @@ class SpecialAbuseFilter extends SpecialPage {
}
/**
* @param string|null $subpage
* @param string|null $filter
*/
public function loadParameters( $subpage ) {
$filter = $subpage;
public function loadParameters( $filter ) {
if ( !is_numeric( $filter ) && $filter !== 'new' ) {
$filter = $this->getRequest()->getIntOrNull( 'wpFilter' );
}
$this->mFilter = $filter;
}
/**
* @return string
*/
protected function getGroupName() {
return 'wiki';
}
}

View file

@ -1,6 +1,6 @@
<?php
class SpecialAbuseLog extends SpecialPage {
class SpecialAbuseLog extends AbuseFilterSpecialPage {
/**
* @var User The user whose AbuseLog entries are being searched
*/
@ -62,12 +62,19 @@ class SpecialAbuseLog extends SpecialPage {
}
/**
* @return bool
* @inheritDoc
*/
public function doesWrites() {
return true;
}
/**
* @inheritDoc
*/
protected function getGroupName() {
return 'changes';
}
/**
* Main routine
*
@ -96,8 +103,7 @@ class SpecialAbuseLog extends SpecialPage {
$out = $this->getOutput();
$request = $this->getRequest();
AbuseFilter::addNavigationLinks(
$this->getContext(), 'log', $this->getLinkRenderer() );
$this->addNavigationLinks( 'log' );
$this->setHeaders();
$this->addHelpLink( 'Extension:AbuseFilter' );
@ -1183,11 +1189,4 @@ class SpecialAbuseLog extends SpecialPage {
return false;
}
/**
* @return string
*/
protected function getGroupName() {
return 'changes';
}
}