r24427 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r24426‎ | r24427 | r24428 >
Date:14:32, 29 July 2007
Author:robchurch
Status:old
Tags:
Comment:
(bug 10732 and others) Further fixes to protect chaining JavaScript; introduce addClickHandler() to work around missing addEventListener() in IE and other browsers that suck
Modified paths:
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/skins/common/protect.js (modified) (history)
  • /trunk/phase3/skins/common/wikibits.js (modified) (history)

Diff [purge]

Index: trunk/phase3/skins/common/protect.js
@@ -1,44 +1,37 @@
2 -function protectInitialize(tableId, labelText) {
3 - if (document.createTextNode) {
4 - var box = document.getElementById(tableId);
5 - if (!box)
6 - return false;
7 -
8 - var tbody = box.getElementsByTagName('tbody')[0];
9 - var row = document.createElement('tr');
10 - tbody.appendChild(row);
11 -
12 - row.appendChild(document.createElement('td'));
13 - var col2 = document.createElement('td');
14 - row.appendChild(col2);
15 -
16 - var check = document.createElement('input');
17 - check.id = "mwProtectUnchained";
18 - check.type = "checkbox";
19 - check.addEventListener( 'click', protectChainUpdate, false );
20 - col2.appendChild(check);
21 -
22 - var space = document.createTextNode(" ");
23 - col2.appendChild(space);
24 -
25 - var label = document.createElement('label');
26 - label.setAttribute("for", "mwProtectUnchained");
27 - label.appendChild(document.createTextNode(labelText));
28 - col2.appendChild(label);
29 -
30 - if (protectAllMatch()) {
31 - check.checked = false;
32 - protectEnable(false);
33 - } else {
34 - check.checked = true;
35 - protectEnable(true);
36 - }
 2+function protectInitialize( tableId, labelText ) {
 3+ if( !( document.createTextNode && document.getElementById && document.getElementsByTagName ) )
 4+ return false;
375
38 - allowCascade();
 6+ var box = document.getElementById( tableId );
 7+ if( !box )
 8+ return false;
 9+
 10+ var tbody = box.getElementsByTagName( 'tbody' )[0];
 11+ var row = document.createElement( 'tr' );
 12+ tbody.appendChild( row );
 13+
 14+ row.appendChild( document.createElement( 'td' ) );
 15+ var col = document.createElement( 'td' );
 16+ row.appendChild( col );
 17+
 18+ var check = document.createElement( 'input' );
 19+ check.id = 'mwProtectUnchained';
 20+ check.type = 'checkbox';
 21+ col.appendChild( check );
 22+ addClickHandler( check, protectChainUpdate );
3923
40 - return true;
41 - }
42 - return false;
 24+ col.appendChild( document.createTextNode( ' ' ) );
 25+ var label = document.createElement( 'label' );
 26+ label.setAttribute( 'for', 'mwProtectUnchained' );
 27+ label.appendChild( document.createTextNode( labelText ) );
 28+ col.appendChild( label );
 29+
 30+ check.checked = !protectAllMatch();
 31+ protectEnable( check.checked );
 32+
 33+ allowCascade();
 34+
 35+ return true;
4336 }
4437
4538 function allowCascade() {
@@ -90,12 +83,10 @@
9184 }
9285
9386 function protectUnchained() {
94 - var unchain = document.getElementById("mwProtectUnchained");
95 - if (!unchain) {
96 - alert("This shouldn't happen");
97 - return false;
98 - }
99 - return unchain.checked;
 87+ var unchain = document.getElementById( 'mwProtectUnchained' );
 88+ return unchain
 89+ ? unchain.checked
 90+ : true; // No control, so we need to let the user set both levels
10091 }
10192
10293 function protectChain() {
Index: trunk/phase3/skins/common/wikibits.js
@@ -1302,8 +1302,24 @@
13031303 }
13041304 }
13051305
 1306+/**
 1307+ * Add a click event handler to an element
 1308+ *
 1309+ * We use addEventListener() where available, otherwise
 1310+ * we use a workaround to avoid breaking the chain
 1311+ *
 1312+ * @param Element element Element to add handler to
 1313+ * @param callable handler Event handler callback
 1314+ */
 1315+function addClickHandler( element, handler ) {
 1316+ if( window.addEventListener ) {
 1317+ element.addEventListener( 'click', handler, false );
 1318+ } else if( window.attachEvent ) {
 1319+ element.attachEvent( 'onclick', handler );
 1320+ }
 1321+}
 1322+
13061323 //note: all skins should call runOnloadHook() at the end of html output,
13071324 // so the below should be redundant. It's there just in case.
13081325 hookEvent("load", runOnloadHook);
1309 -
1310 -hookEvent("load", mwSetupToolbar);
 1326+hookEvent("load", mwSetupToolbar);
\ No newline at end of file
Index: trunk/phase3/includes/DefaultSettings.php
@@ -1195,7 +1195,7 @@
11961196 * to ensure that client-side caches don't keep obsolete copies of global
11971197 * styles.
11981198 */
1199 -$wgStyleVersion = '91';
 1199+$wgStyleVersion = '92';
12001200
12011201
12021202 # Server-side caching:

Follow-up revisions

RevisionCommit summaryAuthorDate
r24502Merged revisions 24415-24479 via svnmerge from...david22:31, 31 July 2007

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r24419* (bug 10732) Protection chaining checkbox broken - this appears to have regr...robchurch23:09, 28 July 2007

Status & tagging log