Page MenuHomePhabricator

wgRestrictionEdit should be defined (as an empty array) on Education Program pages
Closed, ResolvedPublic


According to the docs, this is supposed to be an array (possibly empty) of strings, but on pages such as,_TV_e_Internet%29_%282016%29
it is actually null instead of []. This caused errors in one of our gadgets (which assumed that would be defined, and tested for mw.config.get( 'wgRestrictionEdit' ).length to determine if the array was empty or not).

Event Timeline

divadsn added a subscriber: divadsn.

I will fix that issue :)

So after looking up the code I noticed that EducationProgram pages are not extending OutputPage, but implementing the Page interface in order to use a WikiPage instance, which does also not extend the OutputPage.
Looking further I noticed also that those JS vars are only applied for OutputPage instances in ParserOutput, so the only dirty way would be by adding that to includes/DefaultSettings.php.

In the end those Gadgets needs to be fixed manually by adding a default parameter, so instead of this:

mw.config.get( 'wgRestrictionEdit' ).length

It should be:

mw.config.get( 'wgRestrictionEdit', [] ).length

Which should then return an empty array if no such key exists, which should also then prevent the rest from erroring. Please correct me if my analysis is wrong. :)

Edit: Actually OutputPage does handle Education Program pages as well, but without restriction types.

Change 400134 had a related patch set uploaded (by Divadsn; owner: Divadsn):
[mediawiki/core@master] Always define wgRestrictionEdit as an empty array for pages

Change 400134 abandoned by Divadsn:
Always define wgRestrictionEdit as an empty array for pages

Terrible idea, there should be a better way to fix that.

Change 400134 restored by Divadsn:
Always define wgRestrictionEdit as an empty array for pages

Umherirrender added a subscriber: Umherirrender.

According to Title::getFilteredRestrictionTypes the edit permission is not present for non-existing titles, so the javascript variable 'wgRestrictionEdit' is not set on client side (it is not null).

EducationProgram sets the known flag for the pages in hook TitleIsAlwaysKnown, but that is not checked. I am not sure, if that should be checked when setting the javascript variable or the restriction list in api [1]

Use mw.config.exists to check, if the variable is set or use the empty array as default.
Or create the page you want edit.
Or use hook TitleGetRestrictionTypes to set edit permission and remove the create permission similar to the TitleIsAlwaysKnown hook (seems the best solution)

Or update the documentation on


    "batchcomplete": "",
    "query": {
        "pages": {
            "-1": {
                "ns": 446,
                "title": "Ensino:Faculdade C\u00e1sper L\u00edbero/Ci\u00eancia Pol\u00edtica (R\u00e1dio, TV e Internet) (2016)",
                "missing": "",
                "known": "",
                "contentmodel": "wikitext",
                "pagelanguage": "pt",
                "pagelanguagehtmlcode": "pt",
                "pagelanguagedir": "ltr",
                "protection": [],
                "restrictiontypes": [

Couldn't this be changed somewhere in the extension itself? However: I updated the doc to say, that if a page does not exist, that the variable is not set.

This comment was removed by Albert221.

Change 400134 abandoned by Divadsn:
Always define wgRestrictionEdit as an empty array for pages

As previously stated, terrible solution.

Here's the code that is eventually adding $wgRestrictionEdit to vars:

foreach ( $title->getRestrictionTypes() as $type ) {
    // Following keys are set in $vars:
    // wgRestrictionCreate, wgRestrictionEdit, wgRestrictionMove, wgRestrictionUpload
    $vars['wgRestriction' . ucfirst( $type )] = $title->getRestrictions( $type );

I really don't think that adding a wgRestrictionEdit index to $vars array as @divadsn did in his patch would be a good solution, because why edit restriction would be in this array and create, move and upload not? It would make no logical sense and would lead to confusing other contributors and just complicated code. I second what @Florian wrote, I'm going to look at this thing from other perspective :)

It also - theoretically - cannot be null on the backend side, because Title::getRestrictions() (used in code above) never returns null, either empty array or some array from Title::mRestrictions.

public function getRestrictions( $action ) {
    if ( !$this->mRestrictionsLoaded ) {
    return isset( $this->mRestrictions[$action] )
            ? $this->mRestrictions[$action]
            : [];

The problem is not only with wgRestrictionEdit but with Move and Upload one too:

> []
> null
> null
> null

so it tells us, that Title::getFilteredRestrictionTypes() method is being called with false parameter and then upload key is removed because namespace of the page is not a File.
This false parameter means, that page does not exist. It's from the Title::exists() that returns false.

As of the Title::exists() PHP documentation:

For historical reasons, this function simply
checks for the existence of the title in the page table, and will
thus return false for interwiki links, special pages and the like.
If you want to know if a title can be meaningfully viewed, you should
probably call the isKnown() method instead.

I've finally found the cause of this problem! It's because Title::getArticleID() returns Title::mArticleID which is... 0 and this makes Title::exists() return false!

image.png (773×510 px, 106 KB)

So the solution for that problem is to manually set the mArticleID to something other than 0, but I don't know whether that wouldn't change in the MediawikiCore and I would like a response from @Florian about that :)

If that would help in this case (haven't checked), I would suggest to use the [[ | TitleExists hook ]] and return true, whenever the EducationProgram page should be recognized as existing (I'm not sure, if there's a function to find out if such a page has content or something like that).

Change 401411 had a related patch set uploaded (by Albert221; owner: Albert221):
[mediawiki/extensions/EducationProgram@master] Fix wgRestrictionEdit not exists in mw.config

Change 401411 merged by jenkins-bot:
[mediawiki/extensions/EducationProgram@master] Fix wgRestrictionEdit not exists in mw.config