summaryrefslogtreecommitdiff
path: root/includes/ProtectionForm.php
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2008-03-21 11:49:34 +0100
committerPierre Schmitz <pierre@archlinux.de>2008-03-21 11:49:34 +0100
commit086ae52d12011746a75f5588e877347bc0457352 (patch)
treee73263c7a29d0f94fafb874562610e16eb292ba8 /includes/ProtectionForm.php
parent749e7fb2bae7bbda855de3c9e319435b9f698ff7 (diff)
Update auf MediaWiki 1.12.0
Diffstat (limited to 'includes/ProtectionForm.php')
-rw-r--r--includes/ProtectionForm.php59
1 files changed, 34 insertions, 25 deletions
diff --git a/includes/ProtectionForm.php b/includes/ProtectionForm.php
index c249ec12..a5ff4f3e 100644
--- a/includes/ProtectionForm.php
+++ b/includes/ProtectionForm.php
@@ -28,17 +28,20 @@ class ProtectionForm {
var $mReason = '';
var $mCascade = false;
var $mExpiry = null;
+ var $mPermErrors = array();
+ var $mApplicableTypes = array();
function __construct( &$article ) {
global $wgRequest, $wgUser;
global $wgRestrictionTypes, $wgRestrictionLevels;
$this->mArticle =& $article;
$this->mTitle =& $article->mTitle;
+ $this->mApplicableTypes = $this->mTitle->exists() ? $wgRestrictionTypes : array('create');
if( $this->mTitle ) {
$this->mTitle->loadRestrictions();
- foreach( $wgRestrictionTypes as $action ) {
+ foreach( $this->mApplicableTypes as $action ) {
// Fixme: this form currently requires individual selections,
// but the db allows multiples separated by commas.
$this->mRestrictions[$action] = implode( '', $this->mTitle->getRestrictions( $action ) );
@@ -56,7 +59,7 @@ class ProtectionForm {
}
// The form will be available in read-only to show levels.
- $this->disabled = !$wgUser->isAllowed( 'protect' ) || wfReadOnly() || $wgUser->isBlocked();
+ $this->disabled = wfReadOnly() || ($this->mPermErrors = $this->mTitle->getUserPermissionsErrors('protect',$wgUser)) != array();
$this->disabledAttrib = $this->disabled
? array( 'disabled' => 'disabled' )
: array();
@@ -66,7 +69,7 @@ class ProtectionForm {
$this->mCascade = $wgRequest->getBool( 'mwProtect-cascade' );
$this->mExpiry = $wgRequest->getText( 'mwProtect-expiry' );
- foreach( $wgRestrictionTypes as $action ) {
+ foreach( $this->mApplicableTypes as $action ) {
$val = $wgRequest->getVal( "mwProtect-level-$action" );
if( isset( $val ) && in_array( $val, $wgRestrictionLevels ) ) {
$this->mRestrictions[$action] = $val;
@@ -94,7 +97,6 @@ class ProtectionForm {
$wgOut->setRobotpolicy( 'noindex,nofollow' );
if( is_null( $this->mTitle ) ||
- !$this->mTitle->exists() ||
$this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
$wgOut->showFatalError( wfMsg( 'badarticleerror' ) );
return;
@@ -114,9 +116,7 @@ class ProtectionForm {
$titles .= '* [[:' . $title->getPrefixedText() . "]]\n";
}
- $notice = wfMsgExt( 'protect-cascadeon', array('parsemag'), count($cascadeSources) ) . "\r\n$titles";
-
- $wgOut->addWikiText( $notice );
+ $wgOut->wrapWikiMsg( "$1\n$titles", array( 'protect-cascadeon', count($cascadeSources) ) );
}
$wgOut->setPageTitle( wfMsg( 'confirmprotect' ) );
@@ -125,22 +125,14 @@ class ProtectionForm {
# Show an appropriate message if the user isn't allowed or able to change
# the protection settings at this time
if( $this->disabled ) {
- if( $wgUser->isAllowed( 'protect' ) ) {
- if( $wgUser->isBlocked() ) {
- # Blocked
- $message = 'protect-locked-blocked';
- } else {
- # Database lock
- $message = 'protect-locked-dblock';
- }
- } else {
- # Permission error
- $message = 'protect-locked-access';
+ if( wfReadOnly() ) {
+ $wgOut->readOnlyPage();
+ } elseif( $this->mPermErrors ) {
+ $wgOut->addWikiText( $wgOut->formatPermissionsErrorMessage( $this->mPermErrors ) );
}
} else {
- $message = 'protect-text';
+ $wgOut->addWikiMsg( 'protect-text', $this->mTitle->getPrefixedText() );
}
- $wgOut->addWikiText( wfMsg( $message, wfEscapeWikiText( $this->mTitle->getPrefixedText() ) ) );
$wgOut->addHTML( $this->buildForm() );
@@ -185,7 +177,22 @@ class ProtectionForm {
}
- $ok = $this->mArticle->updateRestrictions( $this->mRestrictions, $this->mReason, $this->mCascade, $expiry );
+ # They shouldn't be able to do this anyway, but just to make sure, ensure that cascading restrictions aren't being applied
+ # to a semi-protected page.
+ global $wgGroupPermissions;
+
+ $edit_restriction = $this->mRestrictions['edit'];
+
+ if ($this->mCascade && ($edit_restriction != 'protect') &&
+ !(isset($wgGroupPermissions[$edit_restriction]['protect']) && $wgGroupPermissions[$edit_restriction]['protect'] ) )
+ $this->mCascade = false;
+
+ if ($this->mTitle->exists()) {
+ $ok = $this->mArticle->updateRestrictions( $this->mRestrictions, $this->mReason, $this->mCascade, $expiry );
+ } else {
+ $ok = $this->mTitle->updateTitleProtection( $this->mRestrictions['create'], $this->mReason, $expiry );
+ }
+
if( !$ok ) {
throw new FatalError( "Unknown error at restriction save time." );
}
@@ -222,6 +229,7 @@ class ProtectionForm {
$out .= "<table id='mwProtectSet'>";
$out .= "<tbody>";
$out .= "<tr>\n";
+
foreach( $this->mRestrictions as $action => $required ) {
/* Not all languages have V_x <-> N_x relation */
$out .= "<th>" . wfMsgHtml( 'restriction-' . $action ) . "</th>\n";
@@ -244,7 +252,7 @@ class ProtectionForm {
$out .= "<tbody>\n";
global $wgEnableCascadingProtection;
- if( $wgEnableCascadingProtection )
+ if( $wgEnableCascadingProtection && $this->mTitle->exists() )
$out .= '<tr><td></td><td>' . $this->buildCascadeInput() . "</td></tr>\n";
$out .= $this->buildExpiryInput();
@@ -311,6 +319,7 @@ class ProtectionForm {
'</td><td>' .
wfElement( 'input', array(
'size' => 60,
+ 'maxlength' => 255,
'name' => $id,
'id' => $id,
'value' => $this->mReason ) );
@@ -359,12 +368,12 @@ class ProtectionForm {
$script = 'var wgCascadeableLevels=';
$CascadeableLevels = array();
foreach( $wgRestrictionLevels as $key ) {
- if ( isset($wgGroupPermissions[$key]['protect']) && $wgGroupPermissions[$key]['protect'] ) {
+ if ( (isset($wgGroupPermissions[$key]['protect']) && $wgGroupPermissions[$key]['protect']) || $key == 'protect' ) {
$CascadeableLevels[]="'" . wfEscapeJsString($key) . "'";
}
}
$script .= "[" . implode(',',$CascadeableLevels) . "];\n";
- $script .= 'protectInitialize("mwProtectSet","' . wfEscapeJsString( wfMsg( 'protect-unchain' ) ) . '")';
+ $script .= 'protectInitialize("mwProtectSet","' . wfEscapeJsString( wfMsg( 'protect-unchain' ) ) . '","' . count($this->mApplicableTypes) . '")';
return '<script type="text/javascript">' . $script . '</script>';
}
@@ -383,4 +392,4 @@ class ProtectionForm {
$logViewer->showList( $out );
}
-} \ No newline at end of file
+}