Index: trunk/phase3/includes/specials/SpecialPreferences.php |
— | — | @@ -52,7 +52,6 @@ |
53 | 53 | return; |
54 | 54 | } |
55 | 55 | |
56 | | - $wgOut->addModules( 'mediawiki.legacy.prefs' ); |
57 | 56 | $wgOut->addModules( 'mediawiki.special.preferences' ); |
58 | 57 | |
59 | 58 | if ( $wgRequest->getCheck( 'success' ) ) { |
Index: trunk/phase3/resources/Resources.php |
— | — | @@ -566,12 +566,6 @@ |
567 | 567 | 'dependencies' => array( 'mediawiki.legacy.wikibits', 'jquery.client' ), |
568 | 568 | 'messages' => array( 'search-mwsuggest-enabled', 'search-mwsuggest-disabled' ), |
569 | 569 | ), |
570 | | - 'mediawiki.legacy.prefs' => array( |
571 | | - 'scripts' => 'common/prefs.js', |
572 | | - 'remoteBasePath' => $GLOBALS['wgStylePath'], |
573 | | - 'localBasePath' => "{$GLOBALS['IP']}/skins", |
574 | | - 'dependencies' => array( 'mediawiki.legacy.wikibits', 'mediawiki.htmlform' ), |
575 | | - ), |
576 | 570 | 'mediawiki.legacy.preview' => array( |
577 | 571 | 'scripts' => 'common/preview.js', |
578 | 572 | 'remoteBasePath' => $GLOBALS['wgStylePath'], |
Index: trunk/phase3/resources/mediawiki.special/mediawiki.special.preferences.js |
— | — | @@ -27,7 +27,7 @@ |
28 | 28 | .attr( 'href', '#preftab-' + i ) // Use #preftab-N instead of #prefsection-N to avoid jumping on click |
29 | 29 | .click( function() { |
30 | 30 | $(this).parent().parent().find( 'li' ).removeClass( 'selected' ); |
31 | | - $(this).parent().addClass( 'selected' ) |
| 31 | + $(this).parent().addClass( 'selected' ); |
32 | 32 | $( '#preferences > fieldset' ).hide(); |
33 | 33 | $( '#prefsection-' + i ).show(); |
34 | 34 | } ) |
— | — | @@ -80,4 +80,84 @@ |
81 | 81 | updateMailValidityLabel( $(this).val() ); |
82 | 82 | } ); |
83 | 83 | } ); |
| 84 | + |
| 85 | + |
| 86 | + |
| 87 | +/** |
| 88 | +* Timezone functions. |
| 89 | +* Guesses Timezone from browser and updates fields onchange |
| 90 | +*/ |
| 91 | + |
| 92 | +var $tzSelect = $( '#mw-input-wptimecorrection' ); |
| 93 | +var $tzTextbox = $( '#mw-input-wptimecorrection-other' ); |
| 94 | + |
| 95 | +var $localtimeHolder = $( '#wpLocalTime' ); |
| 96 | +var servertime = parseInt( $( 'input[name=wpServerTime]' ).val(), 10 ); |
| 97 | +var minuteDiff = 0; |
| 98 | + |
| 99 | +var minutesToHours = function( min ) { |
| 100 | + var tzHour = Math.floor( Math.abs( min ) / 60 ); |
| 101 | + var tzMin = Math.abs( min ) % 60; |
| 102 | + var tzString = ( ( min >= 0 ) ? '' : '-' ) + ( ( tzHour < 10 ) ? '0' : '' ) + tzHour + |
| 103 | + ':' + ( ( tzMin < 10 ) ? '0' : '' ) + tzMin; |
| 104 | + return tzString; |
| 105 | +}; |
| 106 | + |
| 107 | +var hoursToMinutes = function( hour ) { |
| 108 | + var arr = hour.split( ':' ); |
| 109 | + arr[0] = parseInt( arr[0], 10 ); |
| 110 | + |
| 111 | + if ( arr.length == 1 ) { |
| 112 | + // Specification is of the form [-]XX |
| 113 | + minutes = arr[0] * 60; |
| 114 | + } else { |
| 115 | + // Specification is of the form [-]XX:XX |
| 116 | + minutes = Math.abs( arr[0] ) * 60 + parseInt( arr[1], 10 ); |
| 117 | + if ( arr[0] < 0 ) { |
| 118 | + minutes *= -1; |
| 119 | + } |
| 120 | + } |
| 121 | + // Gracefully handle non-numbers. |
| 122 | + if ( isNaN( minutes ) ) { |
| 123 | + return 0; |
| 124 | + } else { |
| 125 | + return minutes; |
| 126 | + } |
| 127 | +}; |
| 128 | + |
| 129 | +var updateTimezoneSelection = function() { |
| 130 | + var type = $tzSelect.val(); |
| 131 | + if ( type == 'guess' ) { |
| 132 | + // Get browser timezone & fill it in |
| 133 | + minuteDiff = -new Date().getTimezoneOffset(); |
| 134 | + $tzTextbox.val( minutesToHours( minuteDiff ) ); |
| 135 | + $tzSelect.val( 'other' ); |
| 136 | + $tzTextbox.get( 0 ).disabled = false; |
| 137 | + } else if ( type == 'other' ) { |
| 138 | + // Grab data from the textbox, parse it. |
| 139 | + minuteDiff = hoursToMinutes( $tzTextbox.val() ); |
| 140 | + } else { |
| 141 | + // Grab data from the $tzSelect value |
| 142 | + minuteDiff = parseInt( type.split( '|' )[1], 10 ) || 0; |
| 143 | + $tzTextbox.val( minutesToHours( minuteDiff ) ); |
| 144 | + } |
| 145 | + |
| 146 | + // Determine local time from server time and minutes difference, for display. |
| 147 | + var localTime = servertime + minuteDiff; |
| 148 | + |
| 149 | + // Bring time within the [0,1440) range. |
| 150 | + while ( localTime < 0 ) { |
| 151 | + localTime += 1440; |
| 152 | + } |
| 153 | + while ( localTime >= 1440 ) { |
| 154 | + localTime -= 1440; |
| 155 | + } |
| 156 | + $localtimeHolder.text( minutesToHours( localTime ) ); |
| 157 | +}; |
| 158 | + |
| 159 | +if ( $tzSelect.length && $tzTextbox.length ) { |
| 160 | + $tzSelect.change( function() { updateTimezoneSelection(); } ); |
| 161 | + $tzTextbox.blur( function() { updateTimezoneSelection(); } ); |
| 162 | + updateTimezoneSelection(); |
| 163 | +} |
84 | 164 | } )( jQuery, mediaWiki ); |
\ No newline at end of file |
Index: trunk/phase3/skins/common/prefs.js |
— | — | @@ -1,138 +0,0 @@ |
2 | | -// Timezone stuff |
3 | | -// tz in format [+-]HHMM |
4 | | -window.checkTimezone = function( tz, msg ) { |
5 | | - var localclock = new Date(); |
6 | | - // returns negative offset from GMT in minutes |
7 | | - var tzRaw = localclock.getTimezoneOffset(); |
8 | | - var tzHour = Math.floor( Math.abs( tzRaw ) / 60 ); |
9 | | - var tzMin = Math.abs( tzRaw ) % 60; |
10 | | - var tzString = ( ( tzRaw >= 0 ) ? '-' : '+' ) + ( ( tzHour < 10 ) ? '0' : '' ) + tzHour + ( ( tzMin < 10 ) ? '0' : '' ) + tzMin; |
11 | | - if ( tz != tzString ) { |
12 | | - var junk = msg.split('$1'); |
13 | | - document.write( junk[0] + 'UTC' + tzString + junk[1] ); |
14 | | - } |
15 | | -}; |
16 | | - |
17 | | -window.timezoneSetup = function() { |
18 | | - var tzSelect = document.getElementById( 'mw-input-wptimecorrection' ); |
19 | | - var tzTextbox = document.getElementById( 'mw-input-wptimecorrection-other' ); |
20 | | - |
21 | | - if ( tzSelect && tzTextbox ) { |
22 | | - addHandler( tzSelect, 'change', function( e ) { updateTimezoneSelection( false ); } ); |
23 | | - addHandler( tzTextbox, 'blur', function( e ) { updateTimezoneSelection( true ); } ); |
24 | | - } |
25 | | - |
26 | | - updateTimezoneSelection( false ); |
27 | | -}; |
28 | | - |
29 | | -// in [-]HH:MM format... |
30 | | -// won't yet work with non-even tzs |
31 | | -window.fetchTimezone = function() { |
32 | | - // FIXME: work around Safari bug |
33 | | - var localclock = new Date(); |
34 | | - // returns negative offset from GMT in minutes |
35 | | - var tzRaw = localclock.getTimezoneOffset(); |
36 | | - var tzHour = Math.floor( Math.abs( tzRaw ) / 60 ); |
37 | | - var tzMin = Math.abs( tzRaw ) % 60; |
38 | | - var tzString = ( ( tzRaw >= 0 ) ? '-' : '' ) + ( ( tzHour < 10 ) ? '0' : '' ) + tzHour + |
39 | | - ':' + ( ( tzMin < 10 ) ? '0' : '' ) + tzMin; |
40 | | - return tzString; |
41 | | -}; |
42 | | - |
43 | | -window.guessTimezone = function() { |
44 | | - var textbox = document.getElementById( 'mw-input-wptimecorrection-other' ); |
45 | | - var selector = document.getElementById( 'mw-input-wptimecorrection' ); |
46 | | - |
47 | | - selector.value = 'other'; |
48 | | - textbox.value = fetchTimezone(); |
49 | | - textbox.disabled = false; // The changed handler doesn't trip, obviously. |
50 | | - updateTimezoneSelection( true ); |
51 | | -}; |
52 | | - |
53 | | -window.updateTimezoneSelection = function( force_offset ) { |
54 | | - var selector = document.getElementById( 'mw-input-wptimecorrection' ); |
55 | | - |
56 | | - if ( selector.value == 'guess' ) { |
57 | | - return guessTimezone(); |
58 | | - } |
59 | | - |
60 | | - var textbox = document.getElementById( 'mw-input-wptimecorrection-other' ); |
61 | | - var localtimeHolder = document.getElementById( 'wpLocalTime' ); |
62 | | - var servertime = document.getElementsByName( 'wpServerTime' )[0].value; |
63 | | - var minDiff = 0; |
64 | | - |
65 | | - // Compatibility code. |
66 | | - if ( !selector.value ) { |
67 | | - selector.value = selector.options[selector.selectedIndex].value; |
68 | | - } |
69 | | - |
70 | | - // Handle force_offset |
71 | | - if ( force_offset ) { |
72 | | - selector.value = 'other'; |
73 | | - } |
74 | | - |
75 | | - // Get min_diff |
76 | | - if ( selector.value == 'other' ) { |
77 | | - // Grab data from the textbox, parse it. |
78 | | - var diffArr = textbox.value.split(':'); |
79 | | - if ( diffArr.length == 1 ) { |
80 | | - // Specification is of the form [-]XX |
81 | | - minDiff = parseInt( diffArr[0], 10 ) * 60; |
82 | | - } else { |
83 | | - // Specification is of the form [-]XX:XX |
84 | | - minDiff = Math.abs( parseInt( diffArr[0], 10 ) ) * 60 + parseInt( diffArr[1], 10 ); |
85 | | - if ( parseInt( diffArr[0], 10 ) < 0 ) { |
86 | | - minDiff = -minDiff; |
87 | | - } |
88 | | - } |
89 | | - } else { |
90 | | - // Grab data from the selector value |
91 | | - var diffArr = selector.value.split('|'); |
92 | | - minDiff = parseInt( diffArr[1], 10 ); |
93 | | - } |
94 | | - |
95 | | - // Gracefully handle non-numbers. |
96 | | - if ( isNaN( minDiff ) ) { |
97 | | - minDiff = 0; |
98 | | - } |
99 | | - |
100 | | - // Determine local time from server time and minutes difference, for display. |
101 | | - var localTime = parseInt( servertime, 10 ) + minDiff; |
102 | | - |
103 | | - // Bring time within the [0,1440) range. |
104 | | - while ( localTime < 0 ) { |
105 | | - localTime += 1440; |
106 | | - } |
107 | | - while ( localTime >= 1440 ) { |
108 | | - localTime -= 1440; |
109 | | - } |
110 | | - |
111 | | - // Split to hour and minute |
112 | | - var hour = String( Math.floor( localTime / 60 ) ); |
113 | | - if ( hour.length < 2 ) { |
114 | | - hour = '0' + hour; |
115 | | - } |
116 | | - var min = String(localTime%60); |
117 | | - if ( min.length < 2 ) { |
118 | | - min = '0' + min; |
119 | | - } |
120 | | - changeText( localtimeHolder, hour + ':' + min ); |
121 | | - |
122 | | - // If the user selected from the drop-down, fill the offset field. |
123 | | - if ( selector.value != 'other' ) { |
124 | | - hour = String( Math.abs( Math.floor( minDiff / 60 ) ) ); |
125 | | - if ( hour.length < 2 ) { |
126 | | - hour = '0' + hour; |
127 | | - } |
128 | | - if ( minDiff < 0 ) { |
129 | | - hour = '-' + hour; |
130 | | - } |
131 | | - min = String(minDiff%60); |
132 | | - if ( min.length < 2 ) { |
133 | | - min = '0' + min; |
134 | | - } |
135 | | - textbox.value = hour + ':' + min; |
136 | | - } |
137 | | -}; |
138 | | - |
139 | | -addOnloadHook( timezoneSetup ); |