Page MenuHomePhabricator

12650.patch

Authored By
bzimport
Nov 21 2014, 10:02 PM
Size
15 KB
Referenced Files
None
Subscribers
None

12650.patch

Index: includes/Article.php
===================================================================
--- includes/Article.php (revision 39867)
+++ includes/Article.php (working copy)
@@ -1817,7 +1817,7 @@
* @param string $reason
* @return bool true on success
*/
- function updateRestrictions( $limit = array(), $reason = '', $cascade = 0, $expiry = null ) {
+ function updateRestrictions( $limit = array(), $reason = '', $cascade = 0, $expiry = array() ) {
global $wgUser, $wgRestrictionTypes, $wgContLang;
$id = $this->mTitle->getArticleID();
@@ -1835,15 +1835,17 @@
# FIXME: Same limitations as described in ProtectionForm.php (line 37);
# we expect a single selection, but the schema allows otherwise.
$current = array();
- foreach( $wgRestrictionTypes as $action )
+ $updated = Article::flattenRestrictions( $limit );
+ $changed = false;
+ foreach( $wgRestrictionTypes as $action ) {
$current[$action] = implode( '', $this->mTitle->getRestrictions( $action ) );
+ $changed = ($changed || ($this->mTitle->mRestrictionsExpiry[$action] != $expiry[$action]) );
+ }
$current = Article::flattenRestrictions( $current );
- $updated = Article::flattenRestrictions( $limit );
- $changed = ( $current != $updated );
+ $changed = ($changed || ( $current != $updated ) );
$changed = $changed || ($updated && $this->mTitle->areRestrictionsCascading() != $cascade);
- $changed = $changed || ($updated && $this->mTitle->mRestrictionsExpiry != $expiry);
$protect = ( $updated != '' );
# If nothing's changed, do nothing
@@ -1852,13 +1854,20 @@
$dbw = wfGetDB( DB_MASTER );
- $encodedExpiry = Block::encodeExpiry($expiry, $dbw );
-
- $expiry_description = '';
- if ( $encodedExpiry != 'infinity' ) {
- $expiry_description = ' (' . wfMsgForContent( 'protect-expiring', $wgContLang->timeanddate( $expiry, false, false ) ).')';
+ $protect_description = '';
+ $encodedExpiry = array();
+ ksort( $limit );
+ foreach( $limit as $action => $restrictions ) {
+ if( $restrictions != '' ) {
+ $protect_description .= "[$action=$restrictions]";
+ $encodedExpiry[$action] = Block::encodeExpiry($expiry[$action], $dbw );
+ if ($encodedExpiry[$action] == 'infinity' ) {
+ $protect_description .= ' (' . wfMsgForContent( 'protect-expiry-indefinite' ).') ';
+ } else {
+ $protect_description .= ' (' . wfMsgForContent( 'protect-expiring', $wgContLang->timeanddate( $expiry[$action], false, false ) ).') ';
+ }
+ }
}
-
# Prepare a null revision to be added to the history
$modified = $current != '' && $protect;
if ( $protect ) {
@@ -1885,10 +1894,8 @@
if( $reason )
$comment .= ": $reason";
- if( $protect )
- $comment .= " [$updated]";
- if ( $expiry_description && $protect )
- $comment .= "$expiry_description";
+ if ( $protect_description && $protect )
+ $comment .= "$protect_description";
if ( $cascade )
$comment .= "$cascade_description";
@@ -1898,7 +1905,7 @@
$dbw->replace( 'page_restrictions', array(array('pr_page', 'pr_type')),
array( 'pr_page' => $id, 'pr_type' => $action
, 'pr_level' => $restrictions, 'pr_cascade' => $cascade ? 1 : 0
- , 'pr_expiry' => $encodedExpiry ), __METHOD__ );
+ , 'pr_expiry' => $encodedExpiry[$action] ), __METHOD__ );
} else {
$dbw->delete( 'page_restrictions', array( 'pr_page' => $id,
'pr_type' => $action ), __METHOD__ );
@@ -1928,7 +1935,7 @@
$log = new LogPage( 'protect' );
if( $protect ) {
$log->addEntry( $modified ? 'modify' : 'protect', $this->mTitle,
- trim( $reason . " [$updated]$cascade_description$expiry_description" ) );
+ trim( $reason . " $protect_description$cascade_description" ) );
} else {
$log->addEntry( 'unprotect', $this->mTitle, $reason );
}
Index: includes/DefaultSettings.php
===================================================================
--- includes/DefaultSettings.php (revision 39867)
+++ includes/DefaultSettings.php (working copy)
@@ -1382,7 +1382,7 @@
* to ensure that client-side caches don't keep obsolete copies of global
* styles.
*/
-$wgStyleVersion = '169';
+$wgStyleVersion = '170';
# Server-side caching:
Index: includes/ProtectionForm.php
===================================================================
--- includes/ProtectionForm.php (revision 39867)
+++ includes/ProtectionForm.php (working copy)
@@ -26,7 +26,7 @@
var $mRestrictions = array();
var $mReason = '';
var $mCascade = false;
- var $mExpiry = null;
+ var $mExpiry = array();
var $mPermErrors = array();
var $mApplicableTypes = array();
@@ -44,18 +44,18 @@
// Fixme: this form currently requires individual selections,
// but the db allows multiples separated by commas.
$this->mRestrictions[$action] = implode( '', $this->mTitle->getRestrictions( $action ) );
+
+ if ( $this->mTitle->mRestrictionsExpiry[$action] == 'infinity' ) {
+ $this->mExpiry[$action] = 'infinite';
+ } else if ( strlen($this->mTitle->mRestrictionsExpiry[$action]) == 0 ) {
+ $this->mExpiry[$action] = '';
+ } else {
+ // FIXME: this format is not user friendly
+ $this->mExpiry[$action] = wfTimestamp( TS_ISO_8601, $this->mTitle->mRestrictionsExpiry[$action] );
+ }
}
$this->mCascade = $this->mTitle->areRestrictionsCascading();
-
- if ( $this->mTitle->mRestrictionsExpiry == 'infinity' ) {
- $this->mExpiry = 'infinite';
- } else if ( strlen($this->mTitle->mRestrictionsExpiry) == 0 ) {
- $this->mExpiry = '';
- } else {
- // FIXME: this format is not user friendly
- $this->mExpiry = wfTimestamp( TS_ISO_8601, $this->mTitle->mRestrictionsExpiry );
- }
}
// The form will be available in read-only to show levels.
@@ -67,9 +67,9 @@
if( $wgRequest->wasPosted() ) {
$this->mReason = $wgRequest->getText( 'mwProtect-reason' );
$this->mCascade = $wgRequest->getBool( 'mwProtect-cascade' );
- $this->mExpiry = $wgRequest->getText( 'mwProtect-expiry' );
foreach( $this->mApplicableTypes as $action ) {
+ $this->mExpiry[$action] = $wgRequest->getText( "mwProtect-expiry-$action" );
$val = $wgRequest->getVal( "mwProtect-level-$action" );
if( isset( $val ) && in_array( $val, $wgRestrictionLevels ) ) {
//prevent users from setting levels that they cannot later unset
@@ -163,31 +163,33 @@
$this->show( wfMsg( 'sessionfailure' ) );
return false;
}
+
+ $expiry = array();
+ foreach( $this->mApplicableTypes as $action ) {
+ if ( strlen( $this->mExpiry[$action] ) == 0 ) {
+ $this->mExpiry[$action] = 'infinite';
+ }
- if ( strlen( $this->mExpiry ) == 0 ) {
- $this->mExpiry = 'infinite';
- }
+ if ( $this->mExpiry[$action] == 'infinite' || $this->mExpiry[$action] == 'indefinite' ) {
+ $expiry[$action] = Block::infinity();
+ } else {
+ # Convert GNU-style date, on error returns -1 for PHP <5.1 and false for PHP >=5.1
+ $expiry[$action] = strtotime( $this->mExpiry[$action] );
- if ( $this->mExpiry == 'infinite' || $this->mExpiry == 'indefinite' ) {
- $expiry = Block::infinity();
- } else {
- # Convert GNU-style date, on error returns -1 for PHP <5.1 and false for PHP >=5.1
- $expiry = strtotime( $this->mExpiry );
+ if ( $expiry[$action] < 0 || $expiry[$action] === false ) {
+ $this->show( wfMsg( 'protect_expiry_invalid' ) );
+ return false;
+ }
- if ( $expiry < 0 || $expiry === false ) {
- $this->show( wfMsg( 'protect_expiry_invalid' ) );
- return false;
- }
+ // Fixme: non-qualified absolute times are not in users specified timezone
+ // and there isn't notice about it in the ui
+ $expiry[$action] = wfTimestamp( TS_MW, $expiry[$action] );
- // Fixme: non-qualified absolute times are not in users specified timezone
- // and there isn't notice about it in the ui
- $expiry = wfTimestamp( TS_MW, $expiry );
-
- if ( $expiry < wfTimestampNow() ) {
- $this->show( wfMsg( 'protect_expiry_old' ) );
- return false;
+ if ( $expiry[$action] < wfTimestampNow() ) {
+ $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
@@ -203,7 +205,7 @@
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 );
+ $ok = $this->mTitle->updateTitleProtection( $this->mRestrictions['create'], $this->mReason, $expiry['create'] );
}
if( !$ok ) {
@@ -239,24 +241,25 @@
$out .= Xml::openElement( 'fieldset' ) .
Xml::element( 'legend', null, wfMsg( 'protect-legend' ) ) .
Xml::openElement( 'table', array( 'id' => 'mwProtectSet' ) ) .
- Xml::openElement( 'tbody' ) .
- "<tr>\n";
+ Xml::openElement( 'tbody' );
- foreach( $this->mRestrictions as $action => $required ) {
+ foreach( $this->mRestrictions as $action => $selected ) {
/* Not all languages have V_x <-> N_x relation */
$label = Xml::element( 'label',
array( 'for' => "mwProtect-level-$action" ),
wfMsg( 'restriction-' . $action ) );
- $out .= "<th>$label</th>";
- }
- $out .= "</tr>
- <tr>\n";
- foreach( $this->mRestrictions as $action => $selected ) {
- $out .= "<td>" .
+ $out .= "<tr><th>$label</th></tr>\n";
+ $out .= "<tr><td>" .
$this->buildSelector( $action, $selected ) .
- "</td>";
+ "</td></tr>";
+ $attribs = array( "id" => "mwProtect-$action-expires", "onkeyup" => "protectExpiryUpdate(this)" ) + $this->disabledAttrib;
+ $out .= "<tr><td class='mw-label'>" .
+ Xml::label( wfMsgExt( 'protectexpiry', array( 'parseinline' ) ), "mwProtect-$action-expires" ) .
+ '</td>
+ <td class="mw-input">' .
+ Xml::input( "mwProtect-expiry-$action", 60, $this->mExpiry[$action], $attribs ) .
+ '</td></tr>';
}
- $out .= "</tr>\n";
// JavaScript will add another row with a value-chaining checkbox
@@ -274,16 +277,6 @@
</tr>\n";
}
- $attribs = array( 'id' => 'expires' ) + $this->disabledAttrib;
- $out .= "<tr>
- <td class='mw-label'>" .
- Xml::label( wfMsgExt( 'protectexpiry', array( 'parseinline' ) ), 'expires' ) .
- '</td>
- <td class="mw-input">' .
- Xml::input( 'mwProtect-expiry', 60, $this->mExpiry, $attribs ) .
- '</td>
- </tr>';
-
if( !$this->disabled ) {
$id = 'mwProtect-reason';
$out .= "<tr>
Index: includes/Title.php
===================================================================
--- includes/Title.php (revision 39867)
+++ includes/Title.php (working copy)
@@ -56,7 +56,7 @@
var $mRestrictions = array(); ///< Array of groups allowed to edit this article
var $mOldRestrictions = false;
var $mCascadeRestriction; ///< Cascade restrictions on this page to included templates and images?
- var $mRestrictionsExpiry; ///< When do the restrictions on this page expire?
+ var $mRestrictionsExpiry = array(); ///< When do the restrictions on this page expire?
var $mHasCascadingRestrictions; ///< Are cascading restrictions in effect on this page?
var $mCascadeRestrictionSources; ///< Where are the cascading restrictions coming from on this page?
var $mRestrictionsLoaded = false; ///< Boolean for initialisation on demand
@@ -1362,7 +1362,7 @@
global $wgUser,$wgContLang;
if ($create_perm == implode(',',$this->getRestrictions('create'))
- && $expiry == $this->mRestrictionsExpiry) {
+ && $expiry == $this->mRestrictionsExpiry['create']) {
// No change
return true;
}
@@ -1377,7 +1377,10 @@
if ( $encodedExpiry != 'infinity' ) {
$expiry_description = ' (' . wfMsgForContent( 'protect-expiring', $wgContLang->timeanddate( $expiry ) ).')';
}
-
+ else {
+ $expiry_description .= ' (' . wfMsgForContent( 'protect-expiry-indefinite' ).')';
+ }
+
# Update protection table
if ($create_perm != '' ) {
$dbw->replace( 'protected_titles', array(array('pt_namespace', 'pt_title')),
@@ -1756,10 +1759,10 @@
foreach( $wgRestrictionTypes as $type ){
$this->mRestrictions[$type] = array();
+ $this->mRestrictionsExpiry[$type] = Block::decodeExpiry('');
}
$this->mCascadeRestriction = false;
- $this->mRestrictionsExpiry = Block::decodeExpiry('');
# Backwards-compatibility: also load the restrictions from the page record (old format).
@@ -1803,7 +1806,7 @@
// Only apply the restrictions if they haven't expired!
if ( !$expiry || $expiry > $now ) {
- $this->mRestrictionsExpiry = $expiry;
+ $this->mRestrictionsExpiry[$row->pr_type] = $expiry;
$this->mRestrictions[$row->pr_type] = explode( ',', trim( $row->pr_level ) );
$this->mCascadeRestriction |= $row->pr_cascade;
@@ -1844,13 +1847,13 @@
if (!$expiry || $expiry > $now) {
// Apply the restrictions
- $this->mRestrictionsExpiry = $expiry;
+ $this->mRestrictionsExpiry['create'] = $expiry;
$this->mRestrictions['create'] = explode(',', trim($pt_create_perm) );
} else { // Get rid of the old restrictions
Title::purgeExpiredRestrictions();
}
} else {
- $this->mRestrictionsExpiry = Block::decodeExpiry('');
+ $this->mRestrictionsExpiry['create'] = Block::decodeExpiry('');
}
$this->mRestrictionsLoaded = true;
}
Index: languages/messages/MessagesEn.php
===================================================================
--- languages/messages/MessagesEn.php (revision 39867)
+++ languages/messages/MessagesEn.php (working copy)
@@ -2286,6 +2286,7 @@
'protect-level-sysop' => 'Sysops only',
'protect-summary-cascade' => 'cascading',
'protect-expiring' => 'expires $1 (UTC)',
+'protect-expiry-indefinite' => 'indefinite',
'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.',
'restriction-type' => 'Permission:',
Index: skins/common/protect.js
===================================================================
--- skins/common/protect.js (revision 39867)
+++ skins/common/protect.js (working copy)
@@ -101,6 +101,22 @@
}
/**
+ * When protection levels are locked together, update the
+ * expiries when one changes
+ *
+ * @param Element source expiry input that changed
+ */
+
+function protectExpiryUpdate(source) {
+ if( !protectUnchained() ) {
+ var expiry = source.value;
+ expiryForInputs(function(set) {
+ set.value = expiry;
+ });
+ }
+}
+
+/**
* Update chain status and enable/disable various bits of the UI
* when the user changes the "unlock move permissions" checkbox
*/
@@ -200,8 +216,37 @@
}
/**
- * Enable/disable protection selectors
+ * Apply a callback to each expiry input
*
+ * @param callable func Callback function
+ */
+function expiryForInputs(func) {
+ var inputs = expiryInputs();
+ for (var i = 0; i < inputs.length; i++) {
+ func(inputs[i]);
+ }
+}
+
+/**
+ * Get a list of all expiry inputs on the page
+ *
+ * @return Array
+ */
+function expiryInputs() {
+ var all = document.getElementsByTagName("input");
+ var ours = new Array();
+ for (var i = 0; i < all.length; i++) {
+ var set = all[i];
+ if (set.name.match(/^mwProtect-expiry-/)) {
+ ours[ours.length] = set;
+ }
+ }
+ return ours;
+}
+
+/**
+ * Enable/disable protection selectors and expiry inputs
+ *
* @param boolean val Enable?
*/
function protectEnable(val) {
@@ -215,4 +260,13 @@
set.style.visible = val ? "visible" : "hidden";
}
});
+ first = true;
+ expiryForInputs(function(set) {
+ if (first) {
+ first = false;
+ } else {
+ set.disabled = !val;
+ set.style.visible = val ? "visible" : "hidden";
+ }
+ });
}

File Metadata

Mime Type
text/x-diff
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
4195
Default Alt Text
12650.patch (15 KB)

Event Timeline