From 8d4aaa2121c2281e4ccbb4d0c8deb16031a7b6f7 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Tue, 11 Dec 2007 22:10:44 +0000 Subject: [PATCH] More title protection clean up. JS errors were being thrown calling the non-existent cascade checkbox. Also the chain box was showing for non-existent titles even though 'create' was the only available protection type. --- includes/ProtectionForm.php | 2 +- skins/common/protect.js | 57 +++++++++++++++++++++++++------------ 2 files changed, 40 insertions(+), 19 deletions(-) diff --git a/includes/ProtectionForm.php b/includes/ProtectionForm.php index b042bb7cc9..96fc080deb 100644 --- a/includes/ProtectionForm.php +++ b/includes/ProtectionForm.php @@ -372,7 +372,7 @@ class ProtectionForm { } } $script .= "[" . implode(',',$CascadeableLevels) . "];\n"; - $script .= 'protectInitialize("mwProtectSet","' . wfEscapeJsString( wfMsg( 'protect-unchain' ) ) . '")'; + $script .= 'protectInitialize("mwProtectSet","' . wfEscapeJsString( wfMsg( 'protect-unchain' ) ) . '","' . count($this->mApplicableTypes) . '")'; return ''; } diff --git a/skins/common/protect.js b/skins/common/protect.js index 90ff35636d..4cf3d79280 100644 --- a/skins/common/protect.js +++ b/skins/common/protect.js @@ -5,7 +5,7 @@ * @param String tableId Identifier of the table containing UI bits * @param String labelText Text to use for the checkbox label */ -function protectInitialize( tableId, labelText ) { +function protectInitialize( tableId, labelText, types ) { if( !( document.createTextNode && document.getElementById && document.getElementsByTagName ) ) return false; @@ -20,28 +20,42 @@ function protectInitialize( tableId, labelText ) { row.appendChild( document.createElement( 'td' ) ); var col = document.createElement( 'td' ); row.appendChild( col ); - - var check = document.createElement( 'input' ); - check.id = 'mwProtectUnchained'; - check.type = 'checkbox'; - col.appendChild( check ); - addClickHandler( check, protectChainUpdate ); + // If there is only one protection type, there is nothing to chain + if( types > 1 ) { + var check = document.createElement( 'input' ); + check.id = 'mwProtectUnchained'; + check.type = 'checkbox'; + col.appendChild( check ); + addClickHandler( check, protectChainUpdate ); - col.appendChild( document.createTextNode( ' ' ) ); - var label = document.createElement( 'label' ); - label.setAttribute( 'for', 'mwProtectUnchained' ); - label.appendChild( document.createTextNode( labelText ) ); - col.appendChild( label ); + col.appendChild( document.createTextNode( ' ' ) ); + var label = document.createElement( 'label' ); + label.setAttribute( 'for', 'mwProtectUnchained' ); + label.appendChild( document.createTextNode( labelText ) ); + col.appendChild( label ); - check.checked = !protectAllMatch(); - protectEnable( check.checked ); + check.checked = !protectAllMatch(); + protectEnable( check.checked ); + } - allowCascade(); + setCascadeCheckbox(); return true; } -function allowCascade() { +/** +* Determine if, given the cascadeable protection levels +* and what is currently selected, if the cascade box +* can be checked +* +* @return boolean +* +*/ +function setCascadeCheckbox() { + // For non-existent titles, there is no cascade option + if( !document.getElementById( 'mwProtect-cascade' ) ) { + return false; + } var lists = protectSelectors(); for( var i = 0; i < lists.length; i++ ) { if( lists[i].selectedIndex > -1 ) { @@ -58,6 +72,13 @@ function allowCascade() { return true; } +/** +* Is this protection level cascadeable? +* @param String level +* +* @return boolean +* +*/ function isCascadeableLevel( level ) { for (var k = 0; k < wgCascadeableLevels.length; k++) { if ( wgCascadeableLevels[k] == level ) { @@ -76,7 +97,7 @@ function isCascadeableLevel( level ) { function protectLevelsUpdate(source) { if( !protectUnchained() ) protectUpdateAll( source.selectedIndex ); - allowCascade(); + setCascadeCheckbox(); } /** @@ -90,7 +111,7 @@ function protectChainUpdate() { protectChain(); protectEnable( false ); } - allowCascade(); + setCascadeCheckbox(); } /** -- 2.20.1