Page MenuHomePhabricator

Fix namespace blocks of removed extension namespaces (and actions)
Closed, ResolvedPublic3 Estimated Story Points

Description

Some namespaces are added by extensions. Users can be partially blocked against namespaces, including extension namespaces.

If a block blocks namespaces, the namespaces are shown in Special:BlockList:

image.png (163×173 px, 6 KB)

If the extension is then uninstalled, the namespaces no longer appear, but instead we see empty bullet points:

image.png (153×147 px, 4 KB)

The empty bullet points should not display if the namespace doesn't exist.

Loading the block into Special:Block/Blockable in order to edit Blockable's block also doesn't work properly, and on submission there is an error:

image.png (721×311 px, 22 KB)

(The workaround is to open Special:Block, and enter Blockable as the target, instead of opening Special:Block/Blockable.)


What needs doing

  • The list of partial block restrictions is built in BlockListPager::getRestrictionListHTML. There's handling for PageRestrictions where the title no longer exists, and we should add something similar for NamespaceRestrictions and ActionRestrictions.
  • The Special:Block form is populated in SpecialBlock::maybeAlterFormDefaults. Again, there's a check for whether this title exists, and we should add something similar for the namespace and action.

Event Timeline

Note that whatever fix we introduce for this may need to be applied to action blocks too, since actions can be added by extensions.

Tchanders renamed this task from Fix namespace blocks of removed extension namespaces to Fix namespace blocks of removed extension namespaces (and actions).Apr 28 2021, 5:25 PM
Tchanders updated the task description. (Show Details)

Change 686496 had a related patch set uploaded (by STran; author: STran):

[mediawiki/core@master] Add null checks for namespaces and actions in blocks

https://gerrit.wikimedia.org/r/686496

Change 686496 merged by jenkins-bot:

[mediawiki/core@master] Add null checks for namespaces and actions in blocks

https://gerrit.wikimedia.org/r/686496

dom_walden subscribed.

Blocking someone from actions[1] and namespaces[2] which I then disable.

In Special:BlockList:

  • Removes bullet points of disabled namespaces
  • Removes entire "namespaces" section if there are no more non-disabled namespaces
    blocklist_remove_ns.png (500×221 px, 21 KB)
  • Action restrictions still appear (I believe we will be doing this in a separate ticket)

Special:Block:

  • Disabled namespaces do not appear in the form. You can submit successfully and the disabled namespace restrictions get removed from the DB.
  • Similarly for disabled Actions.

I also tested (although I don't think they will be affected by this work):

  • Special:CentralAuth
    • Disabled namespaces and actions still appear
  • Special:Investigate/Timeline
    • Entries for blocks are unchanged even if namespaces or actions are disabled
      • (Namespace restrictions are always shown as Special:AllPages)
  • Special:Log/block
    • Namespaces are removed but look confusing (raised as T282458)
    • Disabled actions remain

Notes

  1. Actions are disabled by setting $wgEnablePartialActionBlocks to false
  2. For namespaces, I tested both(?) ways adding/removing namespaces:
    • Create custom namespaces via $wgExtraNamespaces and then removing them
    • Installing SecurePoll extension, which has its own namespace, and then disabling the extension

Test environment: local docker MediaWiki 1.37.0-alpha (7abcde0) 08:12, 10 May 2021

@STran The patch introduced a regression that causes the Special:Block form never to include "main space" for anyone partially blocked against ns0.

@STran The patch introduced a regression that causes the Special:Block form never to include "main space" for anyone partially blocked against ns0.

I can confirm this on beta. I am guessing it is because $this->getLanguage()->getFormattedNsText() returns '' for NS_MAIN.

@STran The patch introduced a regression that causes the Special:Block form never to include "main space" for anyone partially blocked against ns0.

I can confirm this on beta. I am guessing it is because $this->getLanguage()->getFormattedNsText() returns '' for NS_MAIN.

Thanks. This need to be fixed soon as possible, as it may cause sysops to unintentionally unblock users just by changing their block expiry.

@STran FYI, reproduction steps:

  1. Go to Special:Block
  2. Enter a $username or $ip
  3. Select "Partial" and in the namespace input select "(Article)"
  4. Select an expiration time
  5. Submit form
  6. Go to Special:Block/$username or Special:Block/$ip

The "(Article)" namespace will not be there.

And you can see it on beta by going here: https://en.wikipedia.beta.wmflabs.org/wiki/Special:Block/Drwpb

@STran @dom_walden Is there something, in particular, I need to do to get "Article" in the namespace? It doesn't show for me.
I tried to get the error by disabling the wgSecurePollUseNamespace value and it was working fine for me.
Thanks!

Screen Shot 2021-07-21 at 11.29.16 AM.png (647×815 px, 66 KB)

I can confirm this on beta. I am guessing it is because $this->getLanguage()->getFormattedNsText() returns '' for NS_MAIN.

As I understand it, you're trying to check whether the namespace exists before adding it to the output. Is that correct? If so, then \NamespaceInfo::exists() should allow you to test whether a namespace exists by ID, i.e.

includes/specials/SpecialBlock.php
// ...
if (
    $restriction instanceof NamespaceRestriction &&

    // TODO: Inject the NamespaceInfo service via the constructor
    $this->namespaceInfo->exists( $restriction->getValue() )
) {
  // ...
}

\NamespaceInfo::exists() should handle namespaces (and associated talk namespaces) defined in MediaWiki Core or in extensions for you.

Change 713295 had a related patch set uploaded (by TsepoThoabala; author: TsepoThoabala):

[mediawiki/core@master] Fix namespace blocks of removed extension namespaces

https://gerrit.wikimedia.org/r/713295

Change 713295 merged by jenkins-bot:

[mediawiki/core@master] Fix namespace blocks of removed extension namespaces

https://gerrit.wikimedia.org/r/713295

I can no longer reproduce the bug in T280798#7214861 on beta.

The original purpose of this bug was to correctly remove disabled namespaces and actions. To check that it is still doing this, I redid the testing for Special:Block and Special:BlockList that I described in T280798#7077202 on my local docker.

I saw no exceptions in the beta logs or my local logs.

Test Environments: