7541533d58a82ef20e71c177ea47668c90cfaea7
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
, types
) {
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
);
23 // If there is only one protection type, there is nothing to chain
25 var check
= document
.createElement( 'input' );
26 check
.id
= 'mwProtectUnchained';
27 check
.type
= 'checkbox';
28 col
.appendChild( check
);
29 addClickHandler( check
, protectChainUpdate
);
31 col
.appendChild( document
.createTextNode( ' ' ) );
32 var label
= document
.createElement( 'label' );
33 label
.htmlFor
= 'mwProtectUnchained';
34 label
.appendChild( document
.createTextNode( labelText
) );
35 col
.appendChild( label
);
37 check
.checked
= !protectAllMatch();
38 protectEnable( check
.checked
);
47 * Determine if, given the cascadeable protection levels
48 * and what is currently selected, if the cascade box
54 function setCascadeCheckbox() {
55 // For non-existent titles, there is no cascade option
56 if( !document
.getElementById( 'mwProtect-cascade' ) ) {
59 var lists
= protectSelectors();
60 for( var i
= 0; i
< lists
.length
; i
++ ) {
61 if( lists
[i
].selectedIndex
> -1 ) {
62 var items
= lists
[i
].getElementsByTagName( 'option' );
63 var selected
= items
[ lists
[i
].selectedIndex
].value
;
64 if( !isCascadeableLevel(selected
) ) {
65 document
.getElementById( 'mwProtect-cascade' ).checked
= false;
66 document
.getElementById( 'mwProtect-cascade' ).disabled
= true;
71 document
.getElementById( 'mwProtect-cascade' ).disabled
= false;
76 * Is this protection level cascadeable?
82 function isCascadeableLevel( level
) {
83 for (var k
= 0; k
< wgCascadeableLevels
.length
; k
++) {
84 if ( wgCascadeableLevels
[k
] == level
) {
92 * When protection levels are locked together, update the rest
93 * when one action's level changes
95 * @param Element source Level selector that changed
97 function protectLevelsUpdate(source
) {
98 if( !protectUnchained() )
99 protectUpdateAll( source
.selectedIndex
);
100 setCascadeCheckbox();
104 * When protection levels are locked together, update the
105 * expiries when one changes
107 * @param Element source expiry input that changed
110 function protectExpiryUpdate(source
) {
111 if( !protectUnchained() ) {
112 var expiry
= source
.value
;
113 expiryForInputs(function(set) {
120 * When protection levels are locked together, update the
121 * expiry lists when one changes and clear the custom inputs
123 * @param Element source expiry selector that changed
125 function protectExpiryListUpdate(source
) {
126 if( !protectUnchained() ) {
127 var expiry
= source
.value
;
128 expiryListForInputs(function(set) {
131 expiryForInputs(function(set) {
138 * Update chain status and enable/disable various bits of the UI
139 * when the user changes the "unlock move permissions" checkbox
141 function protectChainUpdate() {
142 if( protectUnchained() ) {
143 protectEnable( true );
146 protectEnable( false );
148 setCascadeCheckbox();
152 * Are all actions protected at the same level?
156 function protectAllMatch() {
157 var values
= new Array();
158 protectForSelectors(function(set) {
159 values
[values
.length
] = set.selectedIndex
;
161 for (var i
= 1; i
< values
.length
; i
++) {
162 if (values
[i
] != values
[0]) {
170 * Is protection chaining on or off?
174 function protectUnchained() {
175 var unchain
= document
.getElementById( 'mwProtectUnchained' );
178 : true; // No control, so we need to let the user set both levels
182 * Find the highest-protected action and set all others to that level
184 function protectChain() {
186 protectForSelectors(function(set) {
187 if (set.selectedIndex
> maxIndex
) {
188 maxIndex
= set.selectedIndex
;
191 protectUpdateAll(maxIndex
);
195 * Protect all actions at the specified level
197 * @param int index Protection level
199 function protectUpdateAll(index
) {
200 protectForSelectors(function(set) {
201 if (set.selectedIndex
!= index
) {
202 set.selectedIndex
= index
;
208 * Apply a callback to each protection selector
210 * @param callable func Callback function
212 function protectForSelectors(func
) {
213 var selectors
= protectSelectors();
214 for (var i
= 0; i
< selectors
.length
; i
++) {
220 * Get a list of all protection selectors on the page
224 function protectSelectors() {
225 var all
= document
.getElementsByTagName("select");
226 var ours
= new Array();
227 for (var i
= 0; i
< all
.length
; i
++) {
229 if (set.id
.match(/^mwProtect-level-/)) {
230 ours
[ours
.length
] = set;
237 * Apply a callback to each expiry input
239 * @param callable func Callback function
241 function expiryForInputs(func
) {
242 var inputs
= expiryInputs();
243 for (var i
= 0; i
< inputs
.length
; i
++) {
249 * Get a list of all expiry inputs on the page
253 function expiryInputs() {
254 var all
= document
.getElementsByTagName("input");
255 var ours
= new Array();
256 for (var i
= 0; i
< all
.length
; i
++) {
258 if (set.name
.match(/^mwProtect-expiry-/)) {
259 ours
[ours
.length
] = set;
266 * Apply a callback to each expiry selector list
267 * @param callable func Callback function
269 function expiryListForInputs(func
) {
270 var inputs
= expiryListInputs();
271 for (var i
= 0; i
< inputs
.length
; i
++) {
277 * Get a list of all expiry selector lists on the page
281 function expiryListInputs() {
282 var all
= document
.getElementsByTagName("select");
283 var ours
= new Array();
284 for (var i
= 0; i
< all
.length
; i
++) {
286 if (set.id
.match(/^mwProtectExpiryList-/)) {
287 ours
[ours
.length
] = set;
294 * Enable/disable protection selectors and expiry inputs
296 * @param boolean val Enable?
298 function protectEnable(val
) {
301 protectForSelectors(function(set) {
306 set.style
.visible
= val
? "visible" : "hidden";
310 expiryForInputs(function(set) {
315 set.style
.visible
= val
? "visible" : "hidden";
319 expiryListForInputs(function(set) {
324 set.style
.visible
= val
? "visible" : "hidden";