1 function protectInitialize(tableId
, labelText
) {
2 if (document
.createTextNode
) {
3 var box
= document
.getElementById(tableId
);
7 var tbody
= box
.getElementsByTagName('tbody')[0];
8 var row
= document
.createElement('tr');
9 tbody
.appendChild(row
);
11 row
.appendChild(document
.createElement('td'));
12 var col2
= document
.createElement('td');
13 row
.appendChild(col2
);
15 var check
= document
.createElement('input');
16 check
.id
= "mwProtectUnchained";
17 check
.type
= "checkbox";
18 check
.addEventListener( 'click', protectChainUpdate
, false );
19 col2
.appendChild(check
);
21 var space
= document
.createTextNode(" ");
22 col2
.appendChild(space
);
24 var label
= document
.createElement('label');
25 label
.setAttribute("for", "mwProtectUnchained");
26 label
.appendChild(document
.createTextNode(labelText
));
27 col2
.appendChild(label
);
29 if (protectAllMatch()) {
30 check
.checked
= false;
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;
61 function protectLevelsUpdate(source
) {
62 if (!protectUnchained()) {
63 protectUpdateAll(source
.selectedIndex
);
68 function protectChainUpdate() {
69 if (protectUnchained()) {
79 function protectAllMatch() {
80 var values
= new Array();
81 protectForSelectors(function(set) {
82 values
[values
.length
] = set.selectedIndex
;
84 for (var i
= 1; i
< values
.length
; i
++) {
85 if (values
[i
] != values
[0]) {
92 function protectUnchained() {
93 var unchain
= document
.getElementById("mwProtectUnchained");
95 alert("This shouldn't happen");
98 return unchain
.checked
;
101 function protectChain() {
102 // Find the highest-protected action and bump them all to this level
104 protectForSelectors(function(set) {
105 if (set.selectedIndex
> maxIndex
) {
106 maxIndex
= set.selectedIndex
;
109 protectUpdateAll(maxIndex
);
112 function protectUpdateAll(index
) {
113 protectForSelectors(function(set) {
114 if (set.selectedIndex
!= index
) {
115 set.selectedIndex
= index
;
120 function protectForSelectors(func
) {
121 var selectors
= protectSelectors();
122 for (var i
= 0; i
< selectors
.length
; i
++) {
127 function protectSelectors() {
128 var all
= document
.getElementsByTagName("select");
129 var ours
= new Array();
130 for (var i
= 0; i
< all
.length
; i
++) {
132 if (set.id
.match(/^mwProtect-level-/)) {
133 ours
[ours
.length
] = set;
139 function protectEnable(val
) {
142 protectForSelectors(function(set) {
147 set.style
.visible
= val
? "visible" : "hidden";