mediawiki-extensions-AbuseF.../Views/AbuseFilterView.php
Matěj Suchánek 0b956a0d07 Disallow editing abuse filters for blocked users
This also changes the previous behavior - users who lost their rights
between opening and saving a filter now also get the message.

Additionally, User::matchEditToken() now doesn't use the global
$wgRequest.

Bug: T142389
Change-Id: I931068ff79a6835ad6e63a12ce9dbfcc1cb6c8b9
2017-04-11 06:29:36 +00:00

114 lines
2.4 KiB
PHP

<?php
use MediaWiki\MediaWikiServices;
abstract class AbuseFilterView extends ContextSource {
public $mFilter, $mHistoryID, $mSubmit;
/**
* @var \MediaWiki\Linker\LinkRenderer
*/
protected $linkRenderer;
/**
* @param $page SpecialAbuseFilter
* @param $params array
*/
function __construct( $page, $params ) {
$this->mPage = $page;
$this->mParams = $params;
$this->setContext( $this->mPage->getContext() );
$this->linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
}
/**
* @param string $subpage
* @return Title
*/
function getTitle( $subpage = '' ) {
return $this->mPage->getPageTitle( $subpage );
}
abstract function show();
/**
* @return bool
*/
public function canEdit() {
return (
!$this->getUser()->isBlocked() &&
$this->getUser()->isAllowed( 'abusefilter-modify' )
);
}
/**
* @return bool
*/
public function canEditGlobal() {
return $this->getUser()->isAllowed( 'abusefilter-modify-global' );
}
/**
* 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() )
);
}
/**
* @static
* @return bool
*/
static function canViewPrivate() {
global $wgUser;
static $canView = null;
if ( is_null( $canView ) ) {
$canView = $wgUser->isAllowedAny( 'abusefilter-modify', 'abusefilter-view-private' );
}
return $canView;
}
}
class AbuseFilterChangesList extends OldChangesList {
/**
* @param $s
* @param $rc
* @param $classes array
*/
public function insertExtra( &$s, &$rc, &$classes ) {
$examineParams = empty( $rc->examineParams ) ? array() : $rc->examineParams;
$title = SpecialPage::getTitleFor( 'AbuseFilter', 'examine/' . $rc->mAttribs['rc_id'] );
$examineLink = $this->linkRenderer->makeLink(
$title,
new HtmlArmor( $this->msg( 'abusefilter-changeslist-examine' )->parse() ),
array(),
$examineParams
);
$s .= ' '.$this->msg( 'parentheses' )->rawParams( $examineLink )->escaped();
# If we have a match..
if ( isset( $rc->filterResult ) ) {
$class = $rc->filterResult ?
'mw-abusefilter-changeslist-match' :
'mw-abusefilter-changeslist-nomatch';
$classes[] = $class;
}
}
// Kill rollback links.
public function insertRollback( &$s, &$rc ) {
}
}