Disable protection in case there aren't any restriction types
authorMarius Hoch <hoo@online.de>
Thu, 22 Nov 2012 21:04:40 +0000 (22:04 +0100)
committerdaniel <daniel.kinzler@wikimedia.de>
Mon, 7 Jan 2013 13:26:59 +0000 (14:26 +0100)
This change disables the protection form and hides the protect
links in case there aren't any restriction types avialable.
Having no restriction types available let to a PHP notice and an
uggly, broken form. This became necessary as there are cases
in which no restriction types are avialable (caused by extensions)
eg. https://gerrit.wikimedia.org/r/34662

Change-Id: I0e5d3cfb299808ca14ead6baec0a18091acaa2b2

includes/ProtectionForm.php
includes/SkinLegacy.php
includes/SkinTemplate.php
languages/messages/MessagesEn.php
languages/messages/MessagesQqq.php
maintenance/language/messages.inc

index e844a1e..fe871b9 100644 (file)
@@ -207,6 +207,7 @@ class ProtectionForm {
                global $wgOut;
 
                $wgOut->setRobotPolicy( 'noindex,nofollow' );
+               $wgOut->addBacklinkSubtitle( $this->mTitle );
 
                if ( is_array( $err ) ) {
                        $wgOut->wrapWikiMsg( "<p class='error'>\n$1\n</p>\n", $err );
@@ -214,6 +215,18 @@ class ProtectionForm {
                        $wgOut->addHTML( "<p class='error'>{$err}</p>\n" );
                }
 
+               if ( $this->mTitle->getRestrictionTypes() === array() ) {
+                       // No restriction types available for the current title
+                       // this might happen if an extension alters the available types
+                       $wgOut->setPageTitle( wfMessage( 'protect-norestrictiontypes-title', $this->mTitle->getPrefixedText() ) );
+                       $wgOut->addWikiText( wfMessage( 'protect-norestrictiontypes-text' )->text() );
+
+                       // Show the log in case protection was possible once
+                       $this->showLogExtract( $wgOut );
+                       // return as there isn't anything else we can do
+                       return;
+               }
+
                list( $cascadeSources, /* $restrictions */ ) = $this->mTitle->getCascadeProtectionSources();
                if ( $cascadeSources && count($cascadeSources) > 0 ) {
                        $titles = '';
@@ -236,7 +249,6 @@ class ProtectionForm {
                                wfEscapeWikiText( $this->mTitle->getPrefixedText() ) );
                }
 
-               $wgOut->addBacklinkSubtitle( $this->mTitle );
                $wgOut->addHTML( $this->buildForm() );
                $this->showLogExtract( $wgOut );
        }
index 7fb17a7..90cd131 100644 (file)
@@ -345,7 +345,7 @@ class LegacyTemplate extends BaseTemplate {
                                        $s .= $this->deleteThisPage();
                                }
 
-                               if ( $wgUser->isAllowed( 'protect' ) ) {
+                               if ( $wgUser->isAllowed( 'protect' ) && $title->getRestrictionTypes() ) {
                                        $s .= $sep . $this->protectThisPage();
                                }
 
@@ -610,7 +610,7 @@ class LegacyTemplate extends BaseTemplate {
                $diff = $wgRequest->getVal( 'diff' );
                $title = $this->getSkin()->getTitle();
 
-               if ( $title->getArticleID() && ( ! $diff ) && $wgUser->isAllowed( 'protect' ) ) {
+               if ( $title->getArticleID() && ( ! $diff ) && $wgUser->isAllowed( 'protect' ) && $title->getRestrictionTypes() ) {
                        if ( $title->isProtected() ) {
                                $text = wfMessage( 'unprotectthispage' )->text();
                                $query = array( 'action' => 'unprotect' );
index da4af61..5b7f168 100644 (file)
@@ -957,7 +957,7 @@ class SkinTemplate extends Skin {
                                        }
                                }
 
-                               if ( $title->getNamespace() !== NS_MEDIAWIKI && $title->quickUserCan( 'protect', $user ) ) {
+                               if ( $title->getNamespace() !== NS_MEDIAWIKI && $title->quickUserCan( 'protect', $user ) && $title->getRestrictionTypes() ) {
                                        $mode = $title->isProtected() ? 'unprotect' : 'protect';
                                        $content_navigation['actions'][$mode] = array(
                                                'class' => ( $onPage && $action == $mode ) ? 'selected' : false,
index c774840..cae5ed6 100644 (file)
@@ -2978,32 +2978,34 @@ this action has been canceled as a precaution against session hijacking.
 Go back to the previous page, reload that page and then try again.',
 
 # Protect
-'protectlogpage'              => 'Protection log',
-'protectlogtext'              => 'Below is a list of changes to page protections.
+'protectlogpage'                   => 'Protection log',
+'protectlogtext'                   => 'Below is a list of changes to page protections.
 See the [[Special:ProtectedPages|protected pages list]] for the list of currently operational page protections.',
-'protectedarticle'            => 'protected "[[$1]]"',
-'modifiedarticleprotection'   => 'changed protection level for "[[$1]]"',
-'unprotectedarticle'          => 'removed protection from "[[$1]]"',
-'movedarticleprotection'      => 'moved protection settings from "[[$2]]" to "[[$1]]"',
-'protect-title'               => 'Change protection level for "$1"',
-'protect-title-notallowed'    => 'View protection level of "$1"',
-'prot_1movedto2'              => '[[$1]] moved to [[$2]]',
-'protect-badnamespace-title'  => 'Non-protectable namespace',
-'protect-badnamespace-text'   => 'Pages in this namespace cannot be protected.',
-'protect-legend'              => 'Confirm protection',
-'protectcomment'              => 'Reason:',
-'protectexpiry'               => 'Expires:',
-'protect_expiry_invalid'      => 'Expiry time is invalid.',
-'protect_expiry_old'          => 'Expiry time is in the past.',
-'protect-unchain-permissions' => 'Unlock further protect options',
-'protect-text'                => "Here you may view and change the protection level for the page '''$1'''.",
-'protect-locked-blocked'      => "You cannot change protection levels while blocked.
+'protectedarticle'                 => 'protected "[[$1]]"',
+'modifiedarticleprotection'        => 'changed protection level for "[[$1]]"',
+'unprotectedarticle'               => 'removed protection from "[[$1]]"',
+'movedarticleprotection'           => 'moved protection settings from "[[$2]]" to "[[$1]]"',
+'protect-title'                    => 'Change protection level for "$1"',
+'protect-title-notallowed'         => 'View protection level of "$1"',
+'prot_1movedto2'                   => '[[$1]] moved to [[$2]]',
+'protect-badnamespace-title'       => 'Non-protectable namespace',
+'protect-badnamespace-text'        => 'Pages in this namespace cannot be protected.',
+'protect-norestrictiontypes-title' => 'Non-protectable page',
+'protect-norestrictiontypes-text'  => 'This page can\'t be protected as there aren\'t any restriction types available.',
+'protect-legend'                   => 'Confirm protection',
+'protectcomment'                   => 'Reason:',
+'protectexpiry'                    => 'Expires:',
+'protect_expiry_invalid'           => 'Expiry time is invalid.',
+'protect_expiry_old'               => 'Expiry time is in the past.',
+'protect-unchain-permissions'      => 'Unlock further protect options',
+'protect-text'                     => "Here you may view and change the protection level for the page '''$1'''.",
+'protect-locked-blocked'           => "You cannot change protection levels while blocked.
 Here are the current settings for the page '''$1''':",
-'protect-locked-dblock'       => "Protection levels cannot be changed due to an active database lock.
+'protect-locked-dblock'            => "Protection levels cannot be changed due to an active database lock.
 Here are the current settings for the page '''$1''':",
-'protect-locked-access'       => "Your account does not have permission to change page protection levels.
+'protect-locked-access'            => "Your account does not have permission to change page protection levels.
 Here are the current settings for the page '''$1''':",
-'protect-cascadeon'           => "This page is currently protected because it is included in the following {{PLURAL:$1|page, which has|pages, which have}} cascading protection turned on.
+'protect-cascadeon'                => "This page is currently protected because it is included in the following {{PLURAL:$1|page, which has|pages, which have}} cascading protection turned on.
 You can change this page's protection level, but it will not affect the cascading protection.",
 'protect-default'             => 'Allow all users',
 'protect-fallback'            => 'Require "$1" permission',
@@ -3026,13 +3028,13 @@ You can change this page's protection level, but it will not affect the cascadin
 ** Excessive spamming
 ** Counter-productive edit warring
 ** High traffic page',
-'protect-edit-reasonlist'     => 'Edit protection reasons',
-'protect-expiry-options'      => '1 hour:1 hour,1 day:1 day,1 week:1 week,2 weeks:2 weeks,1 month:1 month,3 months:3 months,6 months:6 months,1 year:1 year,infinite:infinite',
-'restriction-type'            => 'Permission:',
-'restriction-level'           => 'Restriction level:',
-'minimum-size'                => 'Min size',
-'maximum-size'                => 'Max size:',
-'pagesize'                    => '(bytes)',
+'protect-edit-reasonlist'          => 'Edit protection reasons',
+'protect-expiry-options'           => '1 hour:1 hour,1 day:1 day,1 week:1 week,2 weeks:2 weeks,1 month:1 month,3 months:3 months,6 months:6 months,1 year:1 year,infinite:infinite',
+'restriction-type'                 => 'Permission:',
+'restriction-level'                => 'Restriction level:',
+'minimum-size'                     => 'Min size',
+'maximum-size'                     => 'Max size:',
+'pagesize'                         => '(bytes)',
 
 # Restrictions (nouns)
 'restriction-edit'   => 'Edit',
index e506731..3f0312b 100644 (file)
@@ -4603,6 +4603,8 @@ Example:
 'prot_1movedto2' => 'Message description: [[mw:Manual:Interface/1movedto2]]',
 'protect-badnamespace-title' => 'Title of error page when trying to access action=protect on a non-protectable namespace (currently this only for the MediaWiki: namespace).',
 'protect-badnamespace-text' => 'Content of the error page that goes with {{msg-mw|protect-badnamespace-title}}.',
+'protect-norestrictiontypes-title' => 'Page title in case there aren\'t any restriction types (like edit or create) available ($1 represents the page title).',
+'protect-norestrictiontypes-text' => 'Content of the error page in case there aren\'t any restriction types (like edit or create) available.',
 'protect-legend' => 'Legend of the fieldset around the input form of the protection form.',
 'protectcomment' => '{{Identical|Reason}}',
 'protectexpiry' => '{{Identical|Expires}}',
index 5e20920..428c190 100644 (file)
@@ -2015,6 +2015,8 @@ $wgMessageStructure = array(
                'prot_1movedto2',
                'protect-badnamespace-title',
                'protect-badnamespace-text',
+               'protect-norestrictiontypes-text',
+               'protect-norestrictiontypes-title',
                'protect-legend',
                'protectcomment',
                'protectexpiry',