From 537d20c03be13d87253dd6e97254dc0fea7f34f0 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Sat, 6 Sep 2008 23:20:58 +0000 Subject: [PATCH] * Add time/reason dropdown for protect form (bug 10799) * Shorten message --- includes/ProtectionForm.php | 113 ++++++++++++++++++++++++------ languages/messages/MessagesEn.php | 9 ++- maintenance/language/messages.inc | 3 + 3 files changed, 101 insertions(+), 24 deletions(-) diff --git a/includes/ProtectionForm.php b/includes/ProtectionForm.php index 969382ce7a..569b9334d7 100644 --- a/includes/ProtectionForm.php +++ b/includes/ProtectionForm.php @@ -65,8 +65,14 @@ class ProtectionForm { : array(); $this->mReason = $wgRequest->getText( 'mwProtect-reason' ); + $this->mReasonList = $wgRequest->getText( 'wpProtectReasonList' ); $this->mCascade = $wgRequest->getBool( 'mwProtect-cascade', $this->mCascade ); - $this->mExpiry = $wgRequest->getText( 'mwProtect-expiry', $this->mExpiry ); + // Let dropdown have 'infinite' for unprotected pages + if( !($expiry = $wgRequest->getText( 'mwProtect-expiry' )) && $this->mExpiry != 'infinite' ) { + $expiry = $this->mExpiry; + } + $this->mExpiry = $expiry; + $this->mExpiryList = $wgRequest->getText( 'wpProtectExpiryList', $this->mExpiry ? '' : 'infinite' ); foreach( $this->mApplicableTypes as $action ) { $val = $wgRequest->getVal( "mwProtect-level-$action" ); @@ -150,20 +156,29 @@ class ProtectionForm { function save() { global $wgRequest, $wgUser, $wgOut; - - if( $this->disabled ) { + # Permission check! + if ( $this->disabled ) { $this->show(); return false; } $token = $wgRequest->getVal( 'wpEditToken' ); - if( !$wgUser->matchEditToken( $token ) ) { + if ( !$wgUser->matchEditToken( $token ) ) { $this->show( wfMsg( 'sessionfailure' ) ); return false; } - + + # Create reason string. Use list and/or custom string. + $reasonstr = $this->mReasonList; + if ( $reasonstr != 'other' && $this->mReason != '' ) { + // Entry from drop down menu + additional comment + $reasonstr .= ': ' . $this->mReason; + } elseif ( $reasonstr == 'other' ) { + $reasonstr = $this->mReason; + } + # Custom expiry takes precedence if ( strlen( $this->mExpiry ) == 0 ) { - $this->mExpiry = 'infinite'; + $this->mExpiry = strlen($this->mExpiryList) ? $this->mExpiryList : 'infinite'; } if ( $this->mExpiry == 'infinite' || $this->mExpiry == 'indefinite' ) { @@ -185,7 +200,6 @@ class ProtectionForm { $this->show( wfMsg( 'protect_expiry_old' ) ); return false; } - } # They shouldn't be able to do this anyway, but just to make sure, ensure that cascading restrictions aren't being applied @@ -199,9 +213,9 @@ class ProtectionForm { $this->mCascade = false; if ($this->mTitle->exists()) { - $ok = $this->mArticle->updateRestrictions( $this->mRestrictions, $this->mReason, $this->mCascade, $expiry ); + $ok = $this->mArticle->updateRestrictions( $this->mRestrictions, $reasonstr, $this->mCascade, $expiry ); } else { - $ok = $this->mTitle->updateTitleProtection( $this->mRestrictions['create'], $this->mReason, $expiry ); + $ok = $this->mTitle->updateTitleProtection( $this->mRestrictions['create'], $reasonstr, $expiry ); } if( !$ok ) { @@ -225,13 +239,20 @@ class ProtectionForm { function buildForm() { global $wgUser; + $mProtectexpiry = Xml::label( wfMsg( 'protectexpiry' ), 'mwProtectExpiryList' ); + $mProtectother = Xml::label( wfMsg( 'protect-otheroption' ), 'expires' ); + $mProtectreasonother = Xml::label( wfMsg( 'protectcomment' ), 'wpProtectReasonList' ); + $mProtectreason = Xml::label( wfMsg( 'protect-otherreason' ), 'mwProtect-reason' ); + $out = ''; if( !$this->disabled ) { $out .= $this->buildScript(); // The submission needs to reenable the move permission selector // if it's in locked mode, or some browsers won't submit the data. - $out .= Xml::openElement( 'form', array( 'method' => 'post', 'action' => $this->mTitle->getLocalUrl( 'action=protect' ), 'id' => 'mw-Protect-Form', 'onsubmit' => 'protectEnable(true)' ) ) . - Xml::hidden( 'wpEditToken',$wgUser->editToken() ); + $out .= Xml::openElement( 'form', array( 'method' => 'post', + 'action' => $this->mTitle->getLocalUrl( 'action=protect' ), + 'id' => 'mw-Protect-Form', 'onsubmit' => 'protectEnable(true)' ) ); + $out .= Xml::hidden( 'wpEditToken',$wgUser->editToken() ); } $out .= Xml::openElement( 'fieldset' ) . @@ -255,9 +276,27 @@ class ProtectionForm { ""; } $out .= "\n"; + + $scExpiryOptions = wfMsgForContent( 'ipboptions' ); // FIXME: use its own message + + $showProtectOptions = ($scExpiryOptions !== '-' && !$this->disabled); + if( !$showProtectOptions ) + $mProtectother = $mProtectexpiry; + + $expiryFormOptions = Xml::option( wfMsg( 'protect-otheroption' ), 'wpProtectExpiryList' ); + foreach( explode(',', $scExpiryOptions) as $option ) { + if ( strpos($option, ":") === false ) $option = "$option:$option"; + list($show, $value) = explode(":", $option); + $show = htmlspecialchars($show); + $value = htmlspecialchars($value); + $expiryFormOptions .= Xml::option( $show, $value, $this->mExpiryList === $value ? true : false ) . "\n"; + } + + $reasonDropDown = Xml::listDropDown( 'wpProtectReasonList', + wfMsgForContent( 'protect-dropdown' ), + wfMsgForContent( 'protect-otherreason' ), '', 'mwProtect-reason', 4 ); // JavaScript will add another row with a value-chaining checkbox - $out .= Xml::closeElement( 'tbody' ) . Xml::closeElement( 'table' ) . Xml::openElement( 'table', array( 'id' => 'mw-protect-table2' ) ) . @@ -267,29 +306,57 @@ class ProtectionForm { $out .= ' ' . - Xml::checkLabel( wfMsg( 'protect-cascade' ), 'mwProtect-cascade', 'mwProtect-cascade', $this->mCascade, $this->disabledAttrib ) . + Xml::checkLabel( wfMsg( 'protect-cascade' ), 'mwProtect-cascade', 'mwProtect-cascade', + $this->mCascade, $this->disabledAttrib ) . " \n"; } - + # Add expiry dropdown + if( $showProtectOptions && !$this->disabled ) { + $out .= " + + + {$mProtectexpiry} + + " . + Xml::tags( 'select', + array( + 'id' => 'mwProtectExpiryList', + 'name' => 'wpProtectExpiryList', + 'onchange' => "document.getElementById('expires').value='';", + 'tabindex' => '2' ) + $this->disabledAttrib, + $expiryFormOptions ) . + " + "; + } + # Add custom expiry field $attribs = array( 'id' => 'expires' ) + $this->disabledAttrib; $out .= " " . - Xml::label( wfMsgExt( 'protectexpiry', array( 'parseinline' ) ), 'expires' ) . + $mProtectother . ' ' . Xml::input( 'mwProtect-expiry', 60, $this->mExpiry, $attribs ) . ' '; - + # Add manual and custom reason field/selects if( !$this->disabled ) { - $id = 'mwProtect-reason'; - $out .= " - " . - Xml::label( wfMsg( 'protectcomment' ), $id ) . - ' - ' . - Xml::input( $id, 60, $this->mReason, array( 'type' => 'text', 'id' => $id, 'maxlength' => 255 ) ) . + $out .= " + + + {$mProtectreasonother} + + + {$reasonDropDown} + + + + + {$mProtectreason} + + " . + Xml::input( 'mwProtect-reason', 60, $this->mReason, array( 'type' => 'text', + 'id' => 'mwProtect-reason', 'maxlength' => 255 ) ) . " diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index 4adcfb565e..11f74de50e 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -663,7 +663,7 @@ XHTML id names. 'deletethispage' => 'Delete this page', 'undelete_short' => 'Undelete {{PLURAL:$1|one edit|$1 edits}}', 'protect' => 'Protect', -'protect_change' => 'change protection', +'protect_change' => 'change', 'protectthispage' => 'Protect this page', 'unprotect' => 'Unprotect', 'unprotectthispage' => 'Unprotect this page', @@ -2298,6 +2298,13 @@ You can change this page's protection level, but it will not affect the cascadin 'protect-expiring' => 'expires $1 (UTC)', 'protect-cascade' => 'Protect pages included in this page (cascading protection)', 'protect-cantedit' => 'You cannot change the protection levels of this page, because you do not have permission to edit it.', +'protect-otheroption' => 'other', +'protect-otherreason' => 'other/additional:', +'protect-dropdown' => '*Common protection reasons +** Excessive vandalism +** Excessive spamming +** Counter-productive edit warring +** High traffic page', 'restriction-type' => 'Permission:', 'restriction-level' => 'Restriction level:', 'minimum-size' => 'Min size', diff --git a/maintenance/language/messages.inc b/maintenance/language/messages.inc index 0602fd9225..d9f4bac2d0 100644 --- a/maintenance/language/messages.inc +++ b/maintenance/language/messages.inc @@ -1524,6 +1524,9 @@ $wgMessageStructure = array( 'protect-expiring', 'protect-cascade', 'protect-cantedit', + 'protect-otheroption', + 'protect-otherreason', + 'protect-dropdown', 'restriction-type', 'restriction-level', 'minimum-size', -- 2.20.1