From 19973572dd7ffb506506a3a3ee97749d86b20e63 Mon Sep 17 00:00:00 2001 From: Marius Hoch Date: Thu, 22 Nov 2012 22:04:40 +0100 Subject: [PATCH] Disable protection in case there aren't any restriction types 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 | 14 ++++++- includes/SkinLegacy.php | 4 +- includes/SkinTemplate.php | 2 +- languages/messages/MessagesEn.php | 60 +++++++++++++++--------------- languages/messages/MessagesQqq.php | 2 + maintenance/language/messages.inc | 2 + 6 files changed, 51 insertions(+), 33 deletions(-) diff --git a/includes/ProtectionForm.php b/includes/ProtectionForm.php index e844a1e9ab..fe871b9bd8 100644 --- a/includes/ProtectionForm.php +++ b/includes/ProtectionForm.php @@ -207,6 +207,7 @@ class ProtectionForm { global $wgOut; $wgOut->setRobotPolicy( 'noindex,nofollow' ); + $wgOut->addBacklinkSubtitle( $this->mTitle ); if ( is_array( $err ) ) { $wgOut->wrapWikiMsg( "

\n$1\n

\n", $err ); @@ -214,6 +215,18 @@ class ProtectionForm { $wgOut->addHTML( "

{$err}

\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 ); } diff --git a/includes/SkinLegacy.php b/includes/SkinLegacy.php index 7fb17a7dbe..90cd131982 100644 --- a/includes/SkinLegacy.php +++ b/includes/SkinLegacy.php @@ -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' ); diff --git a/includes/SkinTemplate.php b/includes/SkinTemplate.php index da4af61e72..5b7f168329 100644 --- a/includes/SkinTemplate.php +++ b/includes/SkinTemplate.php @@ -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, diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index c774840bd0..cae5ed6de9 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -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', diff --git a/languages/messages/MessagesQqq.php b/languages/messages/MessagesQqq.php index e5067314da..3f0312b1ee 100644 --- a/languages/messages/MessagesQqq.php +++ b/languages/messages/MessagesQqq.php @@ -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}}', diff --git a/maintenance/language/messages.inc b/maintenance/language/messages.inc index 5e20920304..428c1907f9 100644 --- a/maintenance/language/messages.inc +++ b/maintenance/language/messages.inc @@ -2015,6 +2015,8 @@ $wgMessageStructure = array( 'prot_1movedto2', 'protect-badnamespace-title', 'protect-badnamespace-text', + 'protect-norestrictiontypes-text', + 'protect-norestrictiontypes-title', 'protect-legend', 'protectcomment', 'protectexpiry', -- 2.20.1