2 * Set up the protection chaining interface (i.e. "unlock move permissions" checkbox)
3 * on the protection form
5 * @param String tableId Identifier of the table containing UI bits
6 * @param String labelText Text to use for the checkbox label
8 function protectInitialize( tableId, labelText ) {
9 if( !( document.createTextNode && document.getElementById && document.getElementsByTagName ) )
12 var box = document.getElementById( tableId );
16 var tbody = box.getElementsByTagName( 'tbody' )[0];
17 var row = document.createElement( 'tr' );
18 tbody.appendChild( row );
20 row.appendChild( document.createElement( 'td' ) );
21 var col = document.createElement( 'td' );
22 row.appendChild( col );
24 var check = document.createElement( 'input' );
25 check.id = 'mwProtectUnchained';
26 check.type = 'checkbox';
27 col.appendChild( check );
28 addClickHandler( check, protectChainUpdate );
30 col.appendChild( document.createTextNode( ' ' ) );
31 var label = document.createElement( 'label' );
32 label.setAttribute( 'for', 'mwProtectUnchained' );
33 label.appendChild( document.createTextNode( labelText ) );
34 col.appendChild( label );
36 check.checked = !protectAllMatch();
37 protectEnable( check.checked );
44 function allowCascade() {
45 var lists = protectSelectors();
46 for( var i = 0; i < lists.length; i++ ) {
47 if( lists[i].selectedIndex > -1 ) {
48 var items = lists[i].getElementsByTagName( 'option' );
49 var selected = items[ lists[i].selectedIndex ].value;
50 if( wgCascadeableLevels.indexOf( selected ) == -1 ) {
51 document.getElementById( 'mwProtect-cascade' ).checked = false;
52 document.getElementById( 'mwProtect-cascade' ).disabled = true;
57 document.getElementById( 'mwProtect-cascade' ).disabled = false;
62 * When protection levels are locked together, update the rest
63 * when one action's level changes
65 * @param Element source Level selector that changed
67 function protectLevelsUpdate(source) {
68 if( !protectUnchained() )
69 protectUpdateAll( source.selectedIndex );
74 * Update chain status and enable/disable various bits of the UI
75 * when the user changes the "unlock move permissions" checkbox
77 function protectChainUpdate() {
78 if( protectUnchained() ) {
79 protectEnable( true );
82 protectEnable( false );
88 * Are all actions protected at the same level?
92 function protectAllMatch() {
93 var values = new Array();
94 protectForSelectors(function(set) {
95 values[values.length] = set.selectedIndex;
97 for (var i = 1; i < values.length; i++) {
98 if (values[i] != values[0]) {
106 * Is protection chaining on or off?
110 function protectUnchained() {
111 var unchain = document.getElementById( 'mwProtectUnchained' );
114 : true; // No control, so we need to let the user set both levels
118 * Find the highest-protected action and set all others to that level
120 function protectChain() {
122 protectForSelectors(function(set) {
123 if (set.selectedIndex > maxIndex) {
124 maxIndex = set.selectedIndex;
127 protectUpdateAll(maxIndex);
131 * Protect all actions at the specified level
133 * @param int index Protection level
135 function protectUpdateAll(index) {
136 protectForSelectors(function(set) {
137 if (set.selectedIndex != index) {
138 set.selectedIndex = index;
144 * Apply a callback to each protection selector
146 * @param callable func Callback function
148 function protectForSelectors(func) {
149 var selectors = protectSelectors();
150 for (var i = 0; i < selectors.length; i++) {
156 * Get a list of all protection selectors on the page
160 function protectSelectors() {
161 var all = document.getElementsByTagName("select");
162 var ours = new Array();
163 for (var i = 0; i < all.length; i++) {
165 if (set.id.match(/^mwProtect-level-/)) {
166 ours[ours.length] = set;
173 * Enable/disable protection selectors
175 * @param boolean val Enable?
177 function protectEnable(val) {
180 protectForSelectors(function(set) {
185 set.style.visible = val ? "visible" : "hidden";