Page MenuHomePhabricator
Paste P11105

Partial blocks from actions
ArchivedPublic

Authored by DannyS712 on May 1 2020, 4:25 AM.
Tags
None
Referenced Files
F31789359: raw.txt
May 1 2020, 4:31 AM
F31789357: raw.txt
May 1 2020, 4:29 AM
F31789347: raw.txt
May 1 2020, 4:25 AM
Subscribers
None
https://gerrit.wikimedia.org/r/plugins/gitiles/mediawiki/core/+/refs/heads/master/maintenance/tables.sql
ipblocks_restrictions
Note that:
`ir_type` is either 1 or 2, shown as `page` or `namespace` to ease understanding
`ir_value` can only be an int, meaning that it cannot hold the action as a string
Multiple rows for a single block with multiple restrictions
Proposed implementation:
ActionRestriction, like for namespace / page
type: 3
ir_value - constant mapping with string to int, more added by hook (for thanks)
ActionRestriction::ACTION_CREATE_VALUE => 1
ActionRestriction::ACTION_UPLOAD_VALUE => 2
ActionRestriction::ACTION_MOVE_VALUE => 3
run hook
ACTION_THANK_VALUE = 101
Hook requires that no values override existing mapping
Values 1-100 are reserved for core
+-----------+-----------+----------+
| ir_ipb_id | type | ir_value |
+-----------+-----------+----------+
| 9562223 | action | 1 |
| 9562223 | action | 2 |
| 9563237 | action | 101 |
+-----------+-----------+----------+
^ 1 block from creating and uploading, and another block from thanks

Event Timeline

Current table
CREATE TABLE /*_*/ipblocks_restrictions (
  -- The ipb_id from ipblocks
  ir_ipb_id int NOT NULL,
  -- The restriction type id.
  ir_type tinyint(1) NOT NULL,
  -- The restriction id that corrposponds to the type. Typically a Page ID or a
  -- Namespace ID.
  ir_value int NOT NULL,
  PRIMARY KEY (ir_ipb_id, ir_type, ir_value)
) /*$wgDBTableOptions*/;
Example query
MariaDB [enwiki_p]> SELECT ir_ipb_id, CASE WHEN ( ir_type = 1 ) THEN 'page' ELSE 'namespace' END AS 'type', ir_value FROM ipblocks_restrictions LIMIT 25;
+-----------+-----------+----------+
| ir_ipb_id | type      | ir_value |
+-----------+-----------+----------+
|   9435157 | namespace |        4 |
|   9495590 | page      | 57861199 |
|   9497043 | page      | 30859855 |
|   9498101 | page      |  2333491 |
|   9498101 | page      | 42165878 |
|   9517403 | page      | 28280067 |
|   9517475 | page      |    50803 |
|   9517475 | page      |    87276 |
|   9517475 | page      | 19629641 |
|   9517475 | page      | 21347867 |
|   9517475 | page      | 23871476 |
|   9517475 | page      | 25169060 |
|   9517475 | page      | 61818020 |
|   9531962 | page      | 24758230 |
|   9533323 | page      |   497526 |
|   9536130 | page      |  2015570 |
|   9540101 | namespace |        0 |
|   9542727 | page      |   165094 |
|   9559276 | namespace |        0 |
|   9559540 | page      |   654157 |
|   9561071 | page      | 59625567 |
|   9561107 | page      | 62990726 |
|   9562223 | page      |   585629 |
|   9562223 | page      | 21486360 |
|   9563237 | page      | 34355486 |
+-----------+-----------+----------+

Restriction::matches only receives a title - use the special page? Or don't use, and instead implement some other way?

tinyint supports 0-255, so its okay for extensions to start with 101

Restriction::matches only receives a title - use the special page? Or don't use, and instead implement some other way?

Special:MovePage and Special:Upload (and Special:Thanks) exist, but there isn't one for page creation. Hack Special:CreatePage?

AbstractBlock::appliesToRight
/**
 * Determine whether the block prevents a given right. A right
 * may be blacklisted or whitelisted, or determined from a
 * property on the block object. For certain rights, the property
 * may be overridden according to global configs.
 *
 * @since 1.33
 * @param string $right
 * @return bool|null The block applies to the right, or null if
 *  unsure (e.g. unrecognized right or unset property)
 */
public function appliesToRight( $right ) {
	$config = RequestContext::getMain()->getConfig();
	$blockDisablesLogin = $config->get( 'BlockDisablesLogin' );

	$res = null;
	switch ( $right ) {
		case 'edit':
			// TODO: fix this case to return proper value
			$res = true;
			break;
		case 'createaccount':
			$res = $this->isCreateAccountBlocked();
			break;
		case 'sendemail':
			$res = $this->isEmailBlocked();
			break;
		case 'upload':
			// Until T6995 is completed
			$res = $this->isSitewide();
			break;
		case 'read':
			$res = false;
			break;
		case 'purge':
			$res = false;
			break;
	}
	if ( !$res && $blockDisablesLogin ) {
		// If a block would disable login, then it should
		// prevent any right that all users cannot do
		$permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
		$anon = new User;
		$res = $permissionManager->userHasRight( $anon, $right ) ? $res : true;
	}

	return $res;
}

Should work for create, move, and upload - no right is needed for thanks?