r34536 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r34535‎ | r34536 | r34537 >
Date:20:59, 9 May 2008
Author:brion
Status:old
Tags:
Comment:
Pluck a few more KB of crap out of wikibits.js -- break out prefs.js for Special:Preferences
Modified paths:
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/includes/SpecialPreferences.php (modified) (history)
  • /trunk/phase3/skins/common/prefs.js (added) (history)
  • /trunk/phase3/skins/common/wikibits.js (modified) (history)

Diff [purge]

Index: trunk/phase3/skins/common/prefs.js
@@ -0,0 +1,119 @@
 2+
 3+// generate toc from prefs form, fold sections
 4+// XXX: needs testing on IE/Mac and safari
 5+// more comments to follow
 6+function tabbedprefs() {
 7+ var prefform = document.getElementById('preferences');
 8+ if (!prefform || !document.createElement) {
 9+ return;
 10+ }
 11+ if (prefform.nodeName.toLowerCase() == 'a') {
 12+ return; // Occasional IE problem
 13+ }
 14+ prefform.className = prefform.className + 'jsprefs';
 15+ var sections = [];
 16+ var children = prefform.childNodes;
 17+ var seci = 0;
 18+ for (var i = 0; i < children.length; i++) {
 19+ if (children[i].nodeName.toLowerCase() == 'fieldset') {
 20+ children[i].id = 'prefsection-' + seci;
 21+ children[i].className = 'prefsection';
 22+ if (is_opera || is_khtml) {
 23+ children[i].className = 'prefsection operaprefsection';
 24+ }
 25+ var legends = children[i].getElementsByTagName('legend');
 26+ sections[seci] = {};
 27+ legends[0].className = 'mainLegend';
 28+ if (legends[0] && legends[0].firstChild.nodeValue) {
 29+ sections[seci].text = legends[0].firstChild.nodeValue;
 30+ } else {
 31+ sections[seci].text = '# ' + seci;
 32+ }
 33+ sections[seci].secid = children[i].id;
 34+ seci++;
 35+ if (sections.length != 1) {
 36+ children[i].style.display = 'none';
 37+ } else {
 38+ var selectedid = children[i].id;
 39+ }
 40+ }
 41+ }
 42+ var toc = document.createElement('ul');
 43+ toc.id = 'preftoc';
 44+ toc.selectedid = selectedid;
 45+ for (i = 0; i < sections.length; i++) {
 46+ var li = document.createElement('li');
 47+ if (i === 0) {
 48+ li.className = 'selected';
 49+ }
 50+ var a = document.createElement('a');
 51+ a.href = '#' + sections[i].secid;
 52+ a.onmousedown = a.onclick = uncoversection;
 53+ a.appendChild(document.createTextNode(sections[i].text));
 54+ a.secid = sections[i].secid;
 55+ li.appendChild(a);
 56+ toc.appendChild(li);
 57+ }
 58+ prefform.parentNode.insertBefore(toc, prefform.parentNode.childNodes[0]);
 59+ document.getElementById('prefsubmit').id = 'prefcontrol';
 60+}
 61+
 62+function uncoversection() {
 63+ var oldsecid = this.parentNode.parentNode.selectedid;
 64+ var newsec = document.getElementById(this.secid);
 65+ if (oldsecid != this.secid) {
 66+ var ul = document.getElementById('preftoc');
 67+ document.getElementById(oldsecid).style.display = 'none';
 68+ newsec.style.display = 'block';
 69+ ul.selectedid = this.secid;
 70+ var lis = ul.getElementsByTagName('li');
 71+ for (var i = 0; i< lis.length; i++) {
 72+ lis[i].className = '';
 73+ }
 74+ this.parentNode.className = 'selected';
 75+ }
 76+ return false;
 77+}
 78+
 79+// Timezone stuff
 80+// tz in format [+-]HHMM
 81+function checkTimezone(tz, msg) {
 82+ var localclock = new Date();
 83+ // returns negative offset from GMT in minutes
 84+ var tzRaw = localclock.getTimezoneOffset();
 85+ var tzHour = Math.floor( Math.abs(tzRaw) / 60);
 86+ var tzMin = Math.abs(tzRaw) % 60;
 87+ var tzString = ((tzRaw >= 0) ? "-" : "+") + ((tzHour < 10) ? "0" : "") + tzHour + ((tzMin < 10) ? "0" : "") + tzMin;
 88+ if (tz != tzString) {
 89+ var junk = msg.split('$1');
 90+ document.write(junk[0] + "UTC" + tzString + junk[1]);
 91+ }
 92+}
 93+
 94+function unhidetzbutton() {
 95+ var tzb = document.getElementById('guesstimezonebutton');
 96+ if (tzb) {
 97+ tzb.style.display = 'inline';
 98+ }
 99+}
 100+
 101+// in [-]HH:MM format...
 102+// won't yet work with non-even tzs
 103+function fetchTimezone() {
 104+ // FIXME: work around Safari bug
 105+ var localclock = new Date();
 106+ // returns negative offset from GMT in minutes
 107+ var tzRaw = localclock.getTimezoneOffset();
 108+ var tzHour = Math.floor( Math.abs(tzRaw) / 60);
 109+ var tzMin = Math.abs(tzRaw) % 60;
 110+ var tzString = ((tzRaw >= 0) ? "-" : "") + ((tzHour < 10) ? "0" : "") + tzHour +
 111+ ":" + ((tzMin < 10) ? "0" : "") + tzMin;
 112+ return tzString;
 113+}
 114+
 115+function guessTimezone(box) {
 116+ document.getElementsByName("wpHourDiff")[0].value = fetchTimezone();
 117+}
 118+
 119+hookEvent("load", unhidetzbutton);
 120+hookEvent("load", tabbedprefs);
Property changes on: trunk/phase3/skins/common/prefs.js
___________________________________________________________________
Added: svn:eol-style
1121 + native
Index: trunk/phase3/skins/common/wikibits.js
@@ -76,122 +76,6 @@
7777 }
7878 }
7979
80 -// generate toc from prefs form, fold sections
81 -// XXX: needs testing on IE/Mac and safari
82 -// more comments to follow
83 -function tabbedprefs() {
84 - var prefform = document.getElementById('preferences');
85 - if (!prefform || !document.createElement) {
86 - return;
87 - }
88 - if (prefform.nodeName.toLowerCase() == 'a') {
89 - return; // Occasional IE problem
90 - }
91 - prefform.className = prefform.className + 'jsprefs';
92 - var sections = [];
93 - var children = prefform.childNodes;
94 - var seci = 0;
95 - for (var i = 0; i < children.length; i++) {
96 - if (children[i].nodeName.toLowerCase() == 'fieldset') {
97 - children[i].id = 'prefsection-' + seci;
98 - children[i].className = 'prefsection';
99 - if (is_opera || is_khtml) {
100 - children[i].className = 'prefsection operaprefsection';
101 - }
102 - var legends = children[i].getElementsByTagName('legend');
103 - sections[seci] = {};
104 - legends[0].className = 'mainLegend';
105 - if (legends[0] && legends[0].firstChild.nodeValue) {
106 - sections[seci].text = legends[0].firstChild.nodeValue;
107 - } else {
108 - sections[seci].text = '# ' + seci;
109 - }
110 - sections[seci].secid = children[i].id;
111 - seci++;
112 - if (sections.length != 1) {
113 - children[i].style.display = 'none';
114 - } else {
115 - var selectedid = children[i].id;
116 - }
117 - }
118 - }
119 - var toc = document.createElement('ul');
120 - toc.id = 'preftoc';
121 - toc.selectedid = selectedid;
122 - for (i = 0; i < sections.length; i++) {
123 - var li = document.createElement('li');
124 - if (i === 0) {
125 - li.className = 'selected';
126 - }
127 - var a = document.createElement('a');
128 - a.href = '#' + sections[i].secid;
129 - a.onmousedown = a.onclick = uncoversection;
130 - a.appendChild(document.createTextNode(sections[i].text));
131 - a.secid = sections[i].secid;
132 - li.appendChild(a);
133 - toc.appendChild(li);
134 - }
135 - prefform.parentNode.insertBefore(toc, prefform.parentNode.childNodes[0]);
136 - document.getElementById('prefsubmit').id = 'prefcontrol';
137 -}
138 -
139 -function uncoversection() {
140 - var oldsecid = this.parentNode.parentNode.selectedid;
141 - var newsec = document.getElementById(this.secid);
142 - if (oldsecid != this.secid) {
143 - var ul = document.getElementById('preftoc');
144 - document.getElementById(oldsecid).style.display = 'none';
145 - newsec.style.display = 'block';
146 - ul.selectedid = this.secid;
147 - var lis = ul.getElementsByTagName('li');
148 - for (var i = 0; i< lis.length; i++) {
149 - lis[i].className = '';
150 - }
151 - this.parentNode.className = 'selected';
152 - }
153 - return false;
154 -}
155 -
156 -// Timezone stuff
157 -// tz in format [+-]HHMM
158 -function checkTimezone(tz, msg) {
159 - var localclock = new Date();
160 - // returns negative offset from GMT in minutes
161 - var tzRaw = localclock.getTimezoneOffset();
162 - var tzHour = Math.floor( Math.abs(tzRaw) / 60);
163 - var tzMin = Math.abs(tzRaw) % 60;
164 - var tzString = ((tzRaw >= 0) ? "-" : "+") + ((tzHour < 10) ? "0" : "") + tzHour + ((tzMin < 10) ? "0" : "") + tzMin;
165 - if (tz != tzString) {
166 - var junk = msg.split('$1');
167 - document.write(junk[0] + "UTC" + tzString + junk[1]);
168 - }
169 -}
170 -
171 -function unhidetzbutton() {
172 - var tzb = document.getElementById('guesstimezonebutton');
173 - if (tzb) {
174 - tzb.style.display = 'inline';
175 - }
176 -}
177 -
178 -// in [-]HH:MM format...
179 -// won't yet work with non-even tzs
180 -function fetchTimezone() {
181 - // FIXME: work around Safari bug
182 - var localclock = new Date();
183 - // returns negative offset from GMT in minutes
184 - var tzRaw = localclock.getTimezoneOffset();
185 - var tzHour = Math.floor( Math.abs(tzRaw) / 60);
186 - var tzMin = Math.abs(tzRaw) % 60;
187 - var tzString = ((tzRaw >= 0) ? "-" : "") + ((tzHour < 10) ? "0" : "") + tzHour +
188 - ":" + ((tzMin < 10) ? "0" : "") + tzMin;
189 - return tzString;
190 -}
191 -
192 -function guessTimezone(box) {
193 - document.getElementsByName("wpHourDiff")[0].value = fetchTimezone();
194 -}
195 -
19680 function showTocToggle() {
19781 if (document.createTextNode) {
19882 // Uses DOM calls to avoid document.write + XHTML issues
@@ -1127,8 +1011,6 @@
11281012 // might cause the function to terminate prematurely
11291013 doneOnloadHook = true;
11301014
1131 - unhidetzbutton();
1132 - tabbedprefs();
11331015 updateTooltipAccessKeys( null );
11341016 akeytt( null );
11351017 scrollEditBox();
Index: trunk/phase3/includes/SpecialPreferences.php
@@ -525,6 +525,7 @@
526526 $wgOut->setPageTitle( wfMsg( 'preferences' ) );
527527 $wgOut->setArticleRelated( false );
528528 $wgOut->setRobotpolicy( 'noindex,nofollow' );
 529+ $wgOut->addScriptFile( 'prefs.js' );
529530
530531 $wgOut->disallowUserJs(); # Prevent hijacked user scripts from sniffing passwords etc.
531532
Index: trunk/phase3/includes/DefaultSettings.php
@@ -1347,7 +1347,7 @@
13481348 * to ensure that client-side caches don't keep obsolete copies of global
13491349 * styles.
13501350 */
1351 -$wgStyleVersion = '143';
 1351+$wgStyleVersion = '144';
13521352
13531353
13541354 # Server-side caching:

Status & tagging log