r20475 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r20474‎ | r20475 | r20476 >
Date:02:52, 15 March 2007
Author:aaron
Status:old
Tags:
Comment:
*Add nifty JS function to grey out cascade option when it will not apply
Modified paths:
  • /trunk/phase3/includes/ProtectionForm.php (modified) (history)
  • /trunk/phase3/skins/common/protect.js (modified) (history)

Diff [purge]

Index: trunk/phase3/skins/common/protect.js
@@ -33,16 +33,36 @@
3434 check.checked = true;
3535 protectEnable(true);
3636 }
 37+
 38+ allowCascade();
3739
3840 return true;
3941 }
4042 return false;
4143 }
4244
 45+function allowCascade() {
 46+ var pr_types = document.getElementsByTagName("select");
 47+ for (var i = 0; i < pr_types.length; i++) {
 48+ if (pr_types[i].id.match(/^mwProtect-level-/)) {
 49+ var selected_level = pr_types[i].getElementsByTagName("option")[pr_types[i].selectedIndex].value;
 50+ for (var k=0; k < wgCascadeableLevels.length; k++) {
 51+ if ( wgCascadeableLevels[k] != selected_level ) {
 52+ document.getElementById('mwProtect-cascade').disabled=true;
 53+ return false;
 54+ }
 55+ }
 56+ }
 57+ }
 58+ document.getElementById('mwProtect-cascade').disabled=false;
 59+ return true;
 60+}
 61+
4362 function protectLevelsUpdate(source) {
4463 if (!protectUnchained()) {
4564 protectUpdateAll(source.selectedIndex);
4665 }
 66+ allowCascade();
4767 }
4868
4969 function protectChainUpdate() {
Index: trunk/phase3/includes/ProtectionForm.php
@@ -323,8 +323,17 @@
324324 }
325325
326326 function buildCleanupScript() {
327 - return '<script type="text/javascript">protectInitialize("mwProtectSet","' .
328 - wfEscapeJsString( wfMsg( 'protect-unchain' ) ) . '")</script>';
 327+ global $wgRestrictionLevels, $wgGroupPermissions;
 328+ $script = 'var wgCascadeableLevels=';
 329+ $CascadeableLevels = array();
 330+ foreach( $wgRestrictionLevels as $key ) {
 331+ if ( isset($wgGroupPermissions[$key]['protect']) && $wgGroupPermissions[$key]['protect'] ) {
 332+ $CascadeableLevels[]="'" . wfEscapeJsString($key) . "'";
 333+ }
 334+ }
 335+ $script .= "[" . implode(',',$CascadeableLevels) . "];\n";
 336+ $script .= 'protectInitialize("mwProtectSet","' . wfEscapeJsString( wfMsg( 'protect-unchain' ) ) . '")';
 337+ return '<script type="text/javascript">' . $script . '</script>';
329338 }
330339
331340 /**