Revert "Revert "Add typehinting for every object-only parameter""

This reverts commit 1ed75b4ae0.
Fixed the one which caused errors, by making articleFromTitle
only use WikiPage, instead of silently mixing WikiPage and Article.

Note for reviewers: this patch is identical to the one which was
previously +2ed, which was mostly correct. To see the actual change,
diff AFComputedVariable with 1..current.

Change-Id: I6747eaed861af6c40a3b1610aebcc1174296e9ed
This commit is contained in:
Daimona Eaytoy 2018-10-17 05:15:21 +00:00
parent 213c2aa011
commit badde6ba75
15 changed files with 80 additions and 54 deletions

View file

@ -23,11 +23,11 @@ class AFComputedVariable {
*
*
* @param string $wikitext
* @param Article $article
* @param WikiPage $article
*
* @return object
*/
public function parseNonEditWikitext( $wikitext, $article ) {
public function parseNonEditWikitext( $wikitext, WikiPage $article ) {
static $cache = [];
$cacheKey = md5( $wikitext ) . ':' . $article->getTitle()->getPrefixedText();
@ -93,9 +93,9 @@ class AFComputedVariable {
/**
* @param int $namespace
* @param string $title
* @return Article
* @return WikiPage
*/
public static function articleFromTitle( $namespace, $title ) {
public static function pageFromTitle( $namespace, $title ) {
if ( isset( self::$articleCache["$namespace:$title"] ) ) {
return self::$articleCache["$namespace:$title"];
}
@ -105,20 +105,19 @@ class AFComputedVariable {
}
$logger = LoggerFactory::getInstance( 'AbuseFilter' );
$logger->debug( "Creating article object for $namespace:$title in cache" );
$logger->debug( "Creating wikipage object for $namespace:$title in cache" );
// TODO: use WikiPage instead!
$t = Title::makeTitle( $namespace, $title );
self::$articleCache["$namespace:$title"] = new Article( $t );
self::$articleCache["$namespace:$title"] = WikiPage::factory( $t );
return self::$articleCache["$namespace:$title"];
}
/**
* @param Article $article
* @param WikiPage $article
* @return array
*/
public static function getLinksFromDB( $article ) {
public static function getLinksFromDB( WikiPage $article ) {
// Stolen from ConfirmEdit, SimpleCaptcha::getLinksFromTracker
$id = $article->getId();
if ( !$id ) {
@ -145,7 +144,7 @@ class AFComputedVariable {
* @throws MWException
* @throws AFPException
*/
public function compute( $vars ) {
public function compute( AbuseFilterVariableHolder $vars ) {
$parameters = $this->mParameters;
$result = null;
@ -201,7 +200,7 @@ class AFComputedVariable {
if ( isset( $parameters['article'] ) ) {
$article = $parameters['article'];
} else {
$article = self::articleFromTitle(
$article = self::pageFromTitle(
$parameters['namespace'],
$parameters['title']
);
@ -219,8 +218,8 @@ class AFComputedVariable {
// Otherwise fall back to database
case 'links-from-wikitext-nonedit':
case 'links-from-wikitext-or-database':
// TODO: use Content object instead, if available! In any case, use WikiPage, not Article.
$article = self::articleFromTitle(
// TODO: use Content object instead, if available!
$article = self::pageFromTitle(
$parameters['namespace'],
$parameters['title']
);
@ -268,7 +267,7 @@ class AFComputedVariable {
if ( isset( $parameters['article'] ) ) {
$article = $parameters['article'];
} else {
$article = self::articleFromTitle(
$article = self::pageFromTitle(
$parameters['namespace'],
$parameters['title']
);
@ -291,8 +290,8 @@ class AFComputedVariable {
}
// Otherwise fall back to database
case 'parse-wikitext-nonedit':
// TODO: use Content object instead, if available! In any case, use WikiPage, not Article.
$article = self::articleFromTitle( $parameters['namespace'], $parameters['title'] );
// TODO: use Content object instead, if available!
$article = self::pageFromTitle( $parameters['namespace'], $parameters['title'] );
$textVar = $parameters['wikitext-var'];
if ( $article->getContentModel() === CONTENT_MODEL_WIKITEXT ) {

View file

@ -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 = [];
@ -1929,7 +1946,7 @@ class AbuseFilter {
* @param User $user
* @return string
*/
public static function autoPromoteBlockKey( $user ) {
public static function autoPromoteBlockKey( User $user ) {
$cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
return $cache->makeKey( 'abusefilter', 'block-autopromote', $user->getId() );
@ -2294,7 +2311,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
@ -2420,7 +2443,7 @@ class AbuseFilter {
$filter,
$actions,
$wasGlobal,
$page
AbuseFilterViewEdit $page
) {
$user = $page->getUser();
$dbw = wfGetDB( DB_MASTER );
@ -2824,7 +2847,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.
@ -3116,8 +3139,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 '';
}

View file

@ -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();

View file

@ -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() );

View file

@ -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;

View file

@ -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;
}

View file

@ -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' );
}

View file

@ -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' );
}

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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();

View file

@ -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' ) );

View file

@ -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;
}

View file

@ -843,7 +843,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' );