jenkins-bot has submitted this change and it was merged.
Change subject: Refactor AbuseFilterView::canEdit* functions
......................................................................
Refactor AbuseFilterView::canEdit* functions
Don't use global state in here, centralize
the logic for global filters and avoid static
functions.
This also makes the UI for global filters nicer
in case the user can't edit them (as all fields
are disabled then).
Change-Id: Ica4e77536d315d8ef39a45666c6b8834315bee77
---
M Views/AbuseFilterView.php
M Views/AbuseFilterViewEdit.php
2 files changed, 23 insertions(+), 27 deletions(-)
Approvals:
CSteipp: Looks good to me, approved
jenkins-bot: Verified
diff --git a/Views/AbuseFilterView.php b/Views/AbuseFilterView.php
index c874760..db53d6d 100644
--- a/Views/AbuseFilterView.php
+++ b/Views/AbuseFilterView.php
@@ -22,33 +22,31 @@
abstract function show();
/**
- * @static
* @return bool
*/
- static function canEdit() {
- global $wgUser;
- static $canEdit = null;
-
- if ( is_null( $canEdit ) ) {
- $canEdit = $wgUser->isAllowed( 'abusefilter-modify' );
- }
-
- return $canEdit;
+ public function canEdit() {
+ return $this->getUser()->isAllowed( 'abusefilter-modify' );
}
/**
- * @static
* @return bool
*/
- static function canEditGlobal() {
- global $wgUser;
- static $canEditGlobal = null;
+ public function canEditGlobal() {
+ return $this->getUser()->isAllowed( 'abusefilter-modify-global'
);
+ }
- if ( is_null( $canEditGlobal ) ) {
- $canEditGlobal = $wgUser->isAllowed(
'abusefilter-modify-global' );
- }
-
- return $canEditGlobal;
+ /**
+ * Whether the user can edit the given filter.
+ *
+ * @param object $row Filter row
+ *
+ * @return bool
+ */
+ public function canEditFilter( $row ) {
+ return (
+ $this->canEdit() &&
+ !( isset( $row->af_global ) && $row->af_global == 1 &&
!$this->canEditGlobal() )
+ );
}
/**
@@ -60,7 +58,7 @@
static $canView = null;
if ( is_null( $canView ) ) {
- $canView = self::canEdit() || $wgUser->isAllowed(
'abusefilter-view-private' );
+ $canView = $wgUser->isAllowedAny( 'abusefilter-modify',
'abusefilter-view-private' );
}
return $canView;
diff --git a/Views/AbuseFilterViewEdit.php b/Views/AbuseFilterViewEdit.php
index 5d82db8..c71747e 100644
--- a/Views/AbuseFilterViewEdit.php
+++ b/Views/AbuseFilterViewEdit.php
@@ -59,9 +59,7 @@
// Don't allow adding a new global rule, or updating a
// rule that is currently global, without permissions.
- if ( ( $newRow->af_global == 1 ||
$newRow->mOriginalRow->af_global == 1 )
- && !$this->canEditGlobal()
- ) {
+ if ( !$this->canEditFilter( $newRow ) ||
!$this->canEditFilter( $newRow->mOriginalRow ) ) {
$out->addWikiMsg(
'abusefilter-edit-notallowed-global' );
return;
}
@@ -335,7 +333,7 @@
$readOnlyAttrib = array();
$cbReadOnlyAttrib = array(); // For checkboxes
- if ( !$this->canEdit() || ( isset( $row->af_global ) &&
$row->af_global == 1 && !$this->canEditGlobal() ) ) {
+ if ( !$this->canEditFilter( $row ) ) {
$readOnlyAttrib['readonly'] = 'readonly';
$cbReadOnlyAttrib['disabled'] = 'disabled';
}
@@ -405,7 +403,7 @@
$row->af_pattern,
'wpFilterRules',
true,
- $this->canEdit()
+ $this->canEditFilter( $row )
);
$fields['abusefilter-edit-notes'] = Xml::textarea(
'wpFilterNotes',
@@ -519,7 +517,7 @@
$this->buildConsequenceEditor( $row, $actions )
);
- if ( $this->canEdit() ) {
+ if ( $this->canEditFilter( $row ) ) {
$form .= Xml::submitButton(
$this->msg( 'abusefilter-edit-save' )->text(),
array( 'accesskey' => 's' )
@@ -585,7 +583,7 @@
$readOnlyAttrib = array();
$cbReadOnlyAttrib = array(); // For checkboxes
- if ( !$this->canEdit() ) {
+ if ( !$this->canEditFilter( $row ) ) {
$readOnlyAttrib['readonly'] = 'readonly';
$cbReadOnlyAttrib['disabled'] = 'disabled';
}
--
To view, visit https://gerrit.wikimedia.org/r/72724
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ica4e77536d315d8ef39a45666c6b8834315bee77
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/extensions/AbuseFilter
Gerrit-Branch: master
Gerrit-Owner: Hoo man <[email protected]>
Gerrit-Reviewer: Anomie <[email protected]>
Gerrit-Reviewer: CSteipp <[email protected]>
Gerrit-Reviewer: Hoo man <[email protected]>
Gerrit-Reviewer: Jeroen De Dauw <[email protected]>
Gerrit-Reviewer: Jforrester <[email protected]>
Gerrit-Reviewer: Werdna <[email protected]>
Gerrit-Reviewer: Yuvipanda <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits