Page MenuHomePhabricator

add $wgLockAuthorIncludedNamespaces
Open, Needs TriagePublicFeature

Description

Feature summary (what you would like to be able to do and where):
I would like to restrict the extension to certain namespaces with a config variable $wgLockAuthorIncludedNamespaces.

Use case(s) (list the steps that you performed to discover that problem, and describe the actual underlying problem which you want to solve. Do not describe only a solution):

  • I use a multi-tenancy setup and therefore when installing the extension:
    • I would need to go through every customer's configuration file and add all publicly accessible custom namespaces to $wgLockAuthorExcludedNamespaces
    • and whenever a customer requests a feature that requires a new namespace, I need to remember to add it to the $wgLockAuthorExcludedNamespaces

Benefits
When I want this extension to work for certain namespaces only (imagine e.g., Draft or Proposal) I can configure the extension for the customer that needs it and don't have to worry about the others.

I am willing to offer a merge request. My proposal would be to introduce another config variable wgLockAuthorNamespaceStrategy which defaults to e.g., exclude to maintain backwards compatibility. When set to e.g., include, $wgLockAuthorIncludedNamespaces will be used instead of $wgLockAuthorExcludedNamespaces to determine the course of action. I think the code will be more explicit and readable when a third config variable is used. Alternatively, a Boolean could be used: wgLockAuthorUseIncludedNamespaces which defaults to false.

Please let me know if you are interested.

Event Timeline

@Schtom, sounds like a reasonably feature per the use case you mentioned above. Adding 2 more configuration variables/setting (as it's called nowadays) is not a bad idea but let's not make them too many because once we introduce them, it's hard to remove :).

From a quick glance, $wgLockAuthorIncludedNamespaces would be an array that holds all the namespaces to be included.

A quick question: Could we use a whilelist vs blacklist approach so that we make the assumption that if something is in the "excluded namespace", it means it's not in the included namespace and vise versa? My reasoning here is to potentially avoid adding more settings (if possible) but it that approach doesn't suite this use-case, then we can introduce the settings and make room for backward compatibility as you mentioned in the task description.

I can offer code review/testing of the feature once a patch is up. Thank you!

Thanks for coming back to this. I do like the black/whitelist approach. I fully agree with you to keep the number of settings low. However, some time passed and of course my use case changed a little. Clients needed different restrictions per namespace. So after forking I ended up with the config below. I find it odd, because it drifts away from the original use case. But it works for me as I don't use the exclude config at all. For this use case it seems difficult to use black/whitelists while retaining backwards compatibility (in the sense that it bloats the codebase) .

Should we be consistent and use a action-based config for the exclusion of namespaces as well? I am just asking myself what the following would actually mean and if it's sensible:

  • $wgLockAuthorExcludedNamespaces[NS_DRAFT] = ['read', 'edit', 'create']; block all namespaces except read/edit/create for NS_DRAFT?
  • $wgLockAuthorExcludedNamespaces[NS_USER] = ['edit', 'create']; block all namespaces except edit/create for NS_USER?

Let me know what you think and if you see ways to integrate it. I think, the alternative would be to keep it simple and drop the action-based configuration altogether.

initial config

  • $wgLockAuthorExcludedNamespaces - array of namespaces to be excluded from checks
  • $wgLockAuthorActions - array of actions to be checked; default is [ 'edit', 'create' ]

added config

  • $wgLockAuthorUseIncludedNamespaces - boolean, when set to true, uses $wgLockAuthorIncludedNamespaces instead of $wgLockAuthorExcludedNamespaces (default is false)
  • $wgLockAuthorIncludedNamespaces - array of namespaces and actions per namespace to be included in checks; default is []
## example config when using the included mode

$wgLockAuthorUseIncludedNamespaces = true;

# only author can read and edit pages in this namespace
$wgLockAuthorIncludedNamespaces[NS_DRAFT] = ['read', 'edit', 'create']; 

# only author can edit pages in this namespace
$wgLockAuthorIncludedNamespaces[NS_USER] = ['edit', 'create'];

Should we be consistent and use a action-based config for the exclusion of namespaces as well?

Yes, I would support being consistent with the current state of how configs are setup in this extension.

  • $wgLockAuthorExcludedNamespaces[NS_DRAFT] = ['read', 'edit', 'create']; block all namespaces except read/edit/create for NS_DRAFT?
  • $wgLockAuthorExcludedNamespaces[NS_USER] = ['edit', 'create']; block all namespaces except edit/create for NS_USER?

Let me know what you think and if you see ways to integrate it. I think, the alternative would be to keep it simple and drop the action-based configuration altogether.

Yes, the way you've suggested above makes sense to me and it reads clearly.

added config

  • $wgLockAuthorUseIncludedNamespaces - boolean, when set to true, uses $wgLockAuthorIncludedNamespaces instead of $wgLockAuthorExcludedNamespaces (default is false)
  • $wgLockAuthorIncludedNamespaces - array of namespaces and actions per namespace to be included in checks; default is []

How about we check the content of $wgLockAuthorIncludedNamespaces and if it's not an empty array, we assume it and use it instead, but it it's empty, we use the content of $wgLockAuthorExcludedNamespaces instead of adding another setting/config just for a status flag. That way, we avoid adding $wgLockAuthorUseIncludedNamespaces, but we'll have to add some documentation on $wgLockAuthorIncludedNamespaces that states clearly that usage of its configuration or the other is implicitly deduced based on the content of its array. Let me know if I'm clear here.

## example config when using the included mode

$wgLockAuthorUseIncludedNamespaces = true;

# only author can read and edit pages in this namespace
$wgLockAuthorIncludedNamespaces[NS_DRAFT] = ['read', 'edit', 'create']; 

# only author can edit pages in this namespace
$wgLockAuthorIncludedNamespaces[NS_USER] = ['edit', 'create'];

Then here we can do something like:

$wgLockAuthorIncludedNamespaces = [
    [ NS_DRAFT => [ 'read', 'edit', 'create' ] ],
    [ NS_USER => [ 'edit', 'create' ] ],
];