*Add nifty JS function to grey out cascade option when it will not apply
authorAaron Schulz <aaron@users.mediawiki.org>
Thu, 15 Mar 2007 02:52:28 +0000 (02:52 +0000)
committerAaron Schulz <aaron@users.mediawiki.org>
Thu, 15 Mar 2007 02:52:28 +0000 (02:52 +0000)
includes/ProtectionForm.php
skins/common/protect.js

index 9ebacd8..662b1df 100644 (file)
@@ -323,8 +323,17 @@ class ProtectionForm {
        }
 
        function buildCleanupScript() {
-               return '<script type="text/javascript">protectInitialize("mwProtectSet","' .
-                       wfEscapeJsString( wfMsg( 'protect-unchain' ) ) . '")</script>';
+               global $wgRestrictionLevels, $wgGroupPermissions;
+               $script = 'var wgCascadeableLevels=';
+               $CascadeableLevels = array();
+               foreach( $wgRestrictionLevels as $key ) {
+                       if ( isset($wgGroupPermissions[$key]['protect']) && $wgGroupPermissions[$key]['protect'] ) {
+                               $CascadeableLevels[]="'" . wfEscapeJsString($key) . "'";
+                       }
+               }
+               $script .= "[" . implode(',',$CascadeableLevels) . "];\n";
+               $script .= 'protectInitialize("mwProtectSet","' . wfEscapeJsString( wfMsg( 'protect-unchain' ) ) . '")';
+               return '<script type="text/javascript">' . $script . '</script>';
        }
 
        /**
index 8968607..f10c810 100644 (file)
@@ -33,16 +33,36 @@ function protectInitialize(tableId, labelText) {
                        check.checked = true;
                        protectEnable(true);
                }
+               
+               allowCascade();
 
                return true;
        }
        return false;
 }
 
+function allowCascade() {
+       var pr_types = document.getElementsByTagName("select");
+       for (var i = 0; i < pr_types.length; i++) {
+               if (pr_types[i].id.match(/^mwProtect-level-/)) {
+                       var selected_level = pr_types[i].getElementsByTagName("option")[pr_types[i].selectedIndex].value;
+                       for (var k=0; k < wgCascadeableLevels.length; k++) {
+                               if ( wgCascadeableLevels[k] != selected_level ) {
+                                       document.getElementById('mwProtect-cascade').disabled=true;
+                                       return false;
+                               }
+                       }
+               }
+       }
+       document.getElementById('mwProtect-cascade').disabled=false;
+       return true;
+}
+
 function protectLevelsUpdate(source) {
        if (!protectUnchained()) {
                protectUpdateAll(source.selectedIndex);
        }
+       allowCascade();
 }
 
 function protectChainUpdate() {