mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AbuseFilter.git
synced 2024-11-24 06:03:49 +00:00
Merge "Add typehinting for every object-only parameter"
This commit is contained in:
commit
7a8a2fa3e1
|
@ -27,7 +27,7 @@ class AFComputedVariable {
|
|||
*
|
||||
* @return object
|
||||
*/
|
||||
public function parseNonEditWikitext( $wikitext, $article ) {
|
||||
public function parseNonEditWikitext( $wikitext, Article $article ) {
|
||||
static $cache = [];
|
||||
|
||||
$cacheKey = md5( $wikitext ) . ':' . $article->getTitle()->getPrefixedText();
|
||||
|
@ -118,7 +118,7 @@ class AFComputedVariable {
|
|||
* @param Article $article
|
||||
* @return array
|
||||
*/
|
||||
public static function getLinksFromDB( $article ) {
|
||||
public static function getLinksFromDB( Article $article ) {
|
||||
// Stolen from ConfirmEdit, SimpleCaptcha::getLinksFromTracker
|
||||
$id = $article->getId();
|
||||
if ( !$id ) {
|
||||
|
@ -145,7 +145,7 @@ class AFComputedVariable {
|
|||
* @throws MWException
|
||||
* @throws AFPException
|
||||
*/
|
||||
public function compute( $vars ) {
|
||||
public function compute( AbuseFilterVariableHolder $vars ) {
|
||||
$parameters = $this->mParameters;
|
||||
$result = null;
|
||||
|
||||
|
|
|
@ -269,7 +269,7 @@ class AbuseFilter {
|
|||
* @param User $user
|
||||
* @return AbuseFilterVariableHolder
|
||||
*/
|
||||
public static function generateUserVars( $user ) {
|
||||
public static function generateUserVars( User $user ) {
|
||||
$vars = new AbuseFilterVariableHolder;
|
||||
|
||||
$vars->setLazyLoadVar(
|
||||
|
@ -506,7 +506,7 @@ class AbuseFilter {
|
|||
* @throws Exception
|
||||
*/
|
||||
public static function checkConditions(
|
||||
$conds, $vars, $ignoreError = true
|
||||
$conds, AbuseFilterVariableHolder $vars, $ignoreError = true
|
||||
) {
|
||||
global $wgAbuseFilterParserClass;
|
||||
|
||||
|
@ -545,7 +545,7 @@ class AbuseFilter {
|
|||
* @return bool[] Map of (integer filter ID => bool)
|
||||
*/
|
||||
public static function checkAllFilters(
|
||||
$vars,
|
||||
AbuseFilterVariableHolder $vars,
|
||||
$group = 'default',
|
||||
Title $title = null,
|
||||
$mode = 'execute'
|
||||
|
@ -648,7 +648,7 @@ class AbuseFilter {
|
|||
*/
|
||||
public static function checkFilter(
|
||||
$row,
|
||||
$vars,
|
||||
AbuseFilterVariableHolder $vars,
|
||||
Title $title = null,
|
||||
$prefix = '',
|
||||
$mode = 'execute'
|
||||
|
@ -854,7 +854,7 @@ class AbuseFilter {
|
|||
* @param string $prefix
|
||||
* @return array[]
|
||||
*/
|
||||
public static function loadConsequencesFromDB( $dbr, $filters, $prefix = '' ) {
|
||||
public static function loadConsequencesFromDB( IDatabase $dbr, $filters, $prefix = '' ) {
|
||||
$actionsByFilter = [];
|
||||
foreach ( $filters as $filter ) {
|
||||
$actionsByFilter[$prefix . $filter] = [];
|
||||
|
@ -901,7 +901,12 @@ class AbuseFilter {
|
|||
* an array listing the actions taken. $status->getErrors() etc. will provide
|
||||
* the errors and warnings to be shown to the user to explain the actions.
|
||||
*/
|
||||
public static function executeFilterActions( $filters, $title, $vars, User $user ) {
|
||||
public static function executeFilterActions(
|
||||
$filters,
|
||||
Title $title,
|
||||
AbuseFilterVariableHolder $vars,
|
||||
User $user
|
||||
) {
|
||||
global $wgMainCacheType;
|
||||
|
||||
$actionsByFilter = self::getConsequencesForFilters( $filters );
|
||||
|
@ -1294,7 +1299,12 @@ class AbuseFilter {
|
|||
* @param AbuseFilterVariableHolder $vars
|
||||
* @param string $group The filter's group (as defined in $wgAbuseFilterValidGroups)
|
||||
*/
|
||||
public static function addLogEntries( $actions_taken, $log_template, $vars, $group = 'default' ) {
|
||||
public static function addLogEntries(
|
||||
$actions_taken,
|
||||
$log_template,
|
||||
AbuseFilterVariableHolder $vars,
|
||||
$group = 'default'
|
||||
) {
|
||||
$dbw = wfGetDB( DB_MASTER );
|
||||
|
||||
$central_log_template = [
|
||||
|
@ -1447,7 +1457,7 @@ class AbuseFilter {
|
|||
*
|
||||
* @return int|null
|
||||
*/
|
||||
public static function storeVarDump( $vars, $global = false ) {
|
||||
public static function storeVarDump( AbuseFilterVariableHolder $vars, $global = false ) {
|
||||
global $wgCompressRevisions;
|
||||
|
||||
// Get all variables yet set and compute old and new wikitext if not yet done
|
||||
|
@ -1579,8 +1589,15 @@ class AbuseFilter {
|
|||
* or null if no action was taken. The message is given as an array
|
||||
* containing the message key followed by any message parameters.
|
||||
*/
|
||||
public static function takeConsequenceAction( $action, $parameters, $title,
|
||||
$vars, $rule_desc, $rule_number, User $user ) {
|
||||
public static function takeConsequenceAction(
|
||||
$action,
|
||||
$parameters,
|
||||
Title $title,
|
||||
AbuseFilterVariableHolder $vars,
|
||||
$rule_desc,
|
||||
$rule_number,
|
||||
User $user
|
||||
) {
|
||||
global $wgAbuseFilterCustomActionsHandlers, $wgRequest;
|
||||
|
||||
$message = null;
|
||||
|
@ -1808,7 +1825,7 @@ class AbuseFilter {
|
|||
* @param bool $global
|
||||
* @return bool
|
||||
*/
|
||||
public static function isThrottled( $throttleId, $types, $title, $rateCount,
|
||||
public static function isThrottled( $throttleId, $types, Title $title, $rateCount,
|
||||
$ratePeriod, $global = false
|
||||
) {
|
||||
$stash = ObjectCache::getMainStashInstance();
|
||||
|
@ -1846,7 +1863,7 @@ class AbuseFilter {
|
|||
* @param Title $title
|
||||
* @return int|string
|
||||
*/
|
||||
public static function throttleIdentifier( $type, $title ) {
|
||||
public static function throttleIdentifier( $type, Title $title ) {
|
||||
global $wgUser, $wgRequest;
|
||||
|
||||
switch ( $type ) {
|
||||
|
@ -1887,7 +1904,7 @@ class AbuseFilter {
|
|||
* @param bool $global
|
||||
* @return string
|
||||
*/
|
||||
public static function throttleKey( $throttleId, $type, $title, $global = false ) {
|
||||
public static function throttleKey( $throttleId, $type, Title $title, $global = false ) {
|
||||
$types = explode( ',', $type );
|
||||
|
||||
$identifiers = [];
|
||||
|
@ -1934,7 +1951,7 @@ class AbuseFilter {
|
|||
* @param User $user
|
||||
* @return string
|
||||
*/
|
||||
public static function autoPromoteBlockKey( $user ) {
|
||||
public static function autoPromoteBlockKey( User $user ) {
|
||||
return wfMemcKey( 'abusefilter', 'block-autopromote', $user->getId() );
|
||||
}
|
||||
|
||||
|
@ -2227,7 +2244,13 @@ class AbuseFilter {
|
|||
* @param array $actions
|
||||
* @return Status
|
||||
*/
|
||||
public static function saveFilter( $page, $filter, $request, $newRow, $actions ) {
|
||||
public static function saveFilter(
|
||||
AbuseFilterViewEdit $page,
|
||||
$filter,
|
||||
$request,
|
||||
$newRow,
|
||||
$actions
|
||||
) {
|
||||
$validationStatus = Status::newGood();
|
||||
|
||||
// Check the syntax
|
||||
|
@ -2344,7 +2367,7 @@ class AbuseFilter {
|
|||
$filter,
|
||||
$actions,
|
||||
$wasGlobal,
|
||||
$page
|
||||
AbuseFilterViewEdit $page
|
||||
) {
|
||||
$user = $page->getUser();
|
||||
$dbw = wfGetDB( DB_MASTER );
|
||||
|
@ -2748,7 +2771,7 @@ class AbuseFilter {
|
|||
* @param Page|null $page
|
||||
* @return AbuseFilterVariableHolder
|
||||
*/
|
||||
public static function getEditVars( $title, Page $page = null ) {
|
||||
public static function getEditVars( Title $title = null, Page $page = null ) {
|
||||
$vars = new AbuseFilterVariableHolder;
|
||||
|
||||
// NOTE: $page may end up remaining null, e.g. if $title points to a special page.
|
||||
|
@ -3007,8 +3030,9 @@ class AbuseFilter {
|
|||
* @return string|null the content of the revision as some kind of string,
|
||||
* or an empty string if it can not be found
|
||||
*/
|
||||
public static function revisionToString( $revision, $audience = Revision::FOR_THIS_USER ) {
|
||||
if ( !$revision instanceof Revision ) {
|
||||
public static function revisionToString( Revision $revision = null,
|
||||
$audience = Revision::FOR_THIS_USER ) {
|
||||
if ( !$revision ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
|
|
|
@ -230,8 +230,8 @@ class AbuseFilterHooks {
|
|||
* @param int $baseRevId
|
||||
*/
|
||||
public static function onPageContentSaveComplete(
|
||||
WikiPage $wikiPage, $user, $content, $summary, $minoredit, $watchthis, $sectionanchor,
|
||||
$flags, $revision, $status, $baseRevId
|
||||
WikiPage $wikiPage, User $user, $content, $summary, $minoredit, $watchthis, $sectionanchor,
|
||||
$flags, Revision $revision, Status $status, $baseRevId
|
||||
) {
|
||||
if ( !self::$successful_action_vars || !$revision ) {
|
||||
self::$successful_action_vars = false;
|
||||
|
@ -300,7 +300,7 @@ class AbuseFilterHooks {
|
|||
* @param User $user
|
||||
* @param array &$promote
|
||||
*/
|
||||
public static function onGetAutoPromoteGroups( $user, &$promote ) {
|
||||
public static function onGetAutoPromoteGroups( User $user, &$promote ) {
|
||||
if ( $promote ) {
|
||||
$key = AbuseFilter::autoPromoteBlockKey( $user );
|
||||
$blocked = (bool)ObjectCache::getInstance( 'hash' )->getWithSetCallback(
|
||||
|
@ -351,7 +351,8 @@ class AbuseFilterHooks {
|
|||
* @param Status $status
|
||||
* @return bool
|
||||
*/
|
||||
public static function onArticleDelete( $article, $user, $reason, &$error, $status ) {
|
||||
public static function onArticleDelete( WikiPage $article, User $user, $reason, &$error,
|
||||
Status $status ) {
|
||||
$vars = new AbuseFilterVariableHolder;
|
||||
|
||||
$vars->addHolders(
|
||||
|
@ -373,7 +374,7 @@ class AbuseFilterHooks {
|
|||
/**
|
||||
* @param RecentChange $recentChange
|
||||
*/
|
||||
public static function onRecentChangeSave( $recentChange ) {
|
||||
public static function onRecentChangeSave( RecentChange $recentChange ) {
|
||||
$title = Title::makeTitle(
|
||||
$recentChange->getAttribute( 'rc_namespace' ),
|
||||
$recentChange->getAttribute( 'rc_title' )
|
||||
|
@ -659,7 +660,7 @@ class AbuseFilterHooks {
|
|||
* Updater callback to create the AbuseFilter user after the user tables have been updated.
|
||||
* @param DatabaseUpdater $updater
|
||||
*/
|
||||
public static function createAbuseFilterUser( $updater ) {
|
||||
public static function createAbuseFilterUser( DatabaseUpdater $updater ) {
|
||||
$username = wfMessage( 'abusefilter-blocker' )->inContentLanguage()->text();
|
||||
$user = User::newFromName( $username );
|
||||
|
||||
|
@ -677,7 +678,7 @@ class AbuseFilterHooks {
|
|||
* @param array &$tools
|
||||
* @param SpecialPage $sp for context
|
||||
*/
|
||||
public static function onContributionsToolLinks( $id, $nt, array &$tools, SpecialPage $sp ) {
|
||||
public static function onContributionsToolLinks( $id, Title $nt, array &$tools, SpecialPage $sp ) {
|
||||
$username = $nt->getText();
|
||||
if ( $sp->getUser()->isAllowed( 'abusefilter-log' ) && !IP::isValidRange( $username ) ) {
|
||||
$linkRenderer = $sp->getLinkRenderer();
|
||||
|
|
|
@ -14,7 +14,7 @@ abstract class AbuseFilterView extends ContextSource {
|
|||
* @param SpecialAbuseFilter $page
|
||||
* @param array $params
|
||||
*/
|
||||
public function __construct( $page, $params ) {
|
||||
public function __construct( SpecialAbuseFilter $page, $params ) {
|
||||
$this->mPage = $page;
|
||||
$this->mParams = $params;
|
||||
$this->setContext( $this->mPage->getContext() );
|
||||
|
|
|
@ -6,7 +6,7 @@ class AbuseFilterViewEdit extends AbuseFilterView {
|
|||
* @param SpecialAbuseFilter $page
|
||||
* @param array $params
|
||||
*/
|
||||
public function __construct( $page, $params ) {
|
||||
public function __construct( SpecialAbuseFilter $page, $params ) {
|
||||
parent::__construct( $page, $params );
|
||||
$this->mFilter = $page->mFilter;
|
||||
$this->mHistoryID = $page->mHistoryID;
|
||||
|
|
|
@ -5,7 +5,7 @@ class AbuseFilterViewHistory extends AbuseFilterView {
|
|||
* @param SpecialAbuseFilter $page
|
||||
* @param array $params
|
||||
*/
|
||||
public function __construct( $page, $params ) {
|
||||
public function __construct( SpecialAbuseFilter $page, $params ) {
|
||||
parent::__construct( $page, $params );
|
||||
$this->mFilter = $page->mFilter;
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ class ApiQueryAbuseFilters extends ApiQueryBase {
|
|||
* @param ApiQuery $query
|
||||
* @param string $moduleName
|
||||
*/
|
||||
public function __construct( $query, $moduleName ) {
|
||||
public function __construct( ApiQuery $query, $moduleName ) {
|
||||
parent::__construct( $query, $moduleName, 'abf' );
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ class ApiQueryAbuseLog extends ApiQueryBase {
|
|||
* @param ApiQuery $query
|
||||
* @param string $moduleName
|
||||
*/
|
||||
public function __construct( $query, $moduleName ) {
|
||||
public function __construct( ApiQuery $query, $moduleName ) {
|
||||
parent::__construct( $query, $moduleName, 'afl' );
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ class AbuseFilterExaminePager extends ReverseChronologicalPager {
|
|||
* @param AbuseFilterViewExamine $page
|
||||
* @param AbuseFilterChangesList $changesList
|
||||
*/
|
||||
public function __construct( $page, $changesList ) {
|
||||
public function __construct( AbuseFilterViewExamine $page, AbuseFilterChangesList $changesList ) {
|
||||
parent::__construct();
|
||||
$this->mChangesList = $changesList;
|
||||
$this->mPage = $page;
|
||||
|
|
|
@ -12,7 +12,8 @@ class AbuseFilterHistoryPager extends TablePager {
|
|||
* @param string $user User name
|
||||
* @param LinkRenderer $linkRenderer
|
||||
*/
|
||||
public function __construct( $filter, $page, $user, $linkRenderer ) {
|
||||
public function __construct( $filter, AbuseFilterViewHistory $page, $user,
|
||||
LinkRenderer $linkRenderer ) {
|
||||
$this->mFilter = $filter;
|
||||
$this->mPage = $page;
|
||||
$this->mUser = $user;
|
||||
|
|
|
@ -20,7 +20,8 @@ class AbuseFilterPager extends TablePager {
|
|||
* @param LinkRenderer $linkRenderer
|
||||
* @param array $query
|
||||
*/
|
||||
public function __construct( $page, $conds, $linkRenderer, $query ) {
|
||||
public function __construct( AbuseFilterViewList $page, $conds, LinkRenderer $linkRenderer,
|
||||
$query ) {
|
||||
$this->mPage = $page;
|
||||
$this->mConds = $conds;
|
||||
$this->linkRenderer = $linkRenderer;
|
||||
|
|
|
@ -17,7 +17,7 @@ class AbuseLogPager extends ReverseChronologicalPager {
|
|||
* @param SpecialAbuseLog $form
|
||||
* @param array $conds
|
||||
*/
|
||||
public function __construct( $form, $conds = [] ) {
|
||||
public function __construct( SpecialAbuseLog $form, $conds = [] ) {
|
||||
$this->mForm = $form;
|
||||
$this->mConds = $conds;
|
||||
parent::__construct();
|
||||
|
|
|
@ -11,7 +11,7 @@ class GlobalAbuseFilterPager extends AbuseFilterPager {
|
|||
* @param array $conds
|
||||
* @param LinkRenderer $linkRenderer
|
||||
*/
|
||||
public function __construct( $page, $conds, $linkRenderer ) {
|
||||
public function __construct( AbuseFilterViewList $page, $conds, LinkRenderer $linkRenderer ) {
|
||||
parent::__construct( $page, $conds, $linkRenderer, [ '', 'LIKE' ] );
|
||||
$this->mDb = wfGetDB(
|
||||
DB_REPLICA, [], $this->getConfig()->get( 'AbuseFilterCentralDB' ) );
|
||||
|
|
|
@ -7,7 +7,7 @@ class AFPParserState {
|
|||
* @param AFPToken $token
|
||||
* @param int $pos
|
||||
*/
|
||||
public function __construct( $token, $pos ) {
|
||||
public function __construct( AFPToken $token, $pos ) {
|
||||
$this->token = $token;
|
||||
$this->pos = $pos;
|
||||
}
|
||||
|
|
|
@ -841,7 +841,7 @@ class SpecialAbuseLog extends SpecialPage {
|
|||
* @param User $user The user who accessed the private details
|
||||
* @return void
|
||||
*/
|
||||
public static function addLogEntry( $logID, $reason, $user ) {
|
||||
public static function addLogEntry( $logID, $reason, User $user ) {
|
||||
$target = self::getTitleFor( 'AbuseLog', $logID );
|
||||
|
||||
$logEntry = new ManualLogEntry( 'abusefilterprivatedetails', 'access' );
|
||||
|
|
Loading…
Reference in a new issue