Index: trunk/phase3/js2/apiProxyPage.js |
— | — | @@ -1,28 +0,0 @@ |
2 | | -/* |
3 | | -* mwProxy js2 page system. |
4 | | -* |
5 | | -* Invokes the apiProxy system |
6 | | -*/ |
7 | | - |
8 | | -/* |
9 | | - * Since this is proxy server set a pre-append debug flag to know which debug msgs are coming from where |
10 | | - */ |
11 | | - |
12 | | -mw.conf['debug_pre'] = 'Proxy'; |
13 | | - |
14 | | -if ( !mwApiProxyConfig ) |
15 | | - var mwApiProxyConfig = { }; |
16 | | - |
17 | | -// The default mwApiProxyConfig config |
18 | | -// (presently hard coded but should read from user and site config) |
19 | | -var mwApiProxyDefaultConfig = { |
20 | | - 'master_whitelist' : [ 'en.wikipedia.org', 'localhost', '127.1.1.100' ], |
21 | | - 'master_blacklist' : [] |
22 | | -}; |
23 | | - |
24 | | -// User white_list should also be checked and configured at runtime. |
25 | | -js2AddOnloadHook( function() { |
26 | | - // build our configuration from the default and mwApiProxyConfig vars |
27 | | - mwApiProxyConfig = $j.extend( true, mwApiProxyDefaultConfig, mwApiProxyConfig ); |
28 | | - $j.apiProxy( 'server', mwApiProxyConfig ); |
29 | | -} ); |
Index: trunk/phase3/js2/ajaxcategories.js |
— | — | @@ -1,326 +0,0 @@ |
2 | | -loadGM( { |
3 | | - "ajax-add-category" : "[Add Category]", |
4 | | - "ajax-add-category-submit" : "[Add]", |
5 | | - "ajax-confirm-prompt" : "[Confirmation Text]", |
6 | | - "ajax-confirm-title" : "[Confirmation Title]", |
7 | | - "ajax-confirm-save" : "[Save]", |
8 | | - "ajax-add-category-summary" : "[Add category $1]", |
9 | | - "ajax-remove-category-summary" : "[Remove category $2]", |
10 | | - "ajax-confirm-actionsummary" : "[Summary]", |
11 | | - "ajax-error-title" : "Error", |
12 | | - "ajax-error-dismiss" : "OK", |
13 | | - "ajax-remove-category-error" : "[RemoveErr]" |
14 | | -} ); |
15 | | - |
16 | | -var ajaxCategories = { |
17 | | - handleAddLink : function( e ) { |
18 | | - e.preventDefault(); |
19 | | - |
20 | | - // Make sure the suggestion plugin is loaded. Load everything else while we're at it |
21 | | - mvJsLoader.doLoad( |
22 | | - ['$j.ui', '$j.ui.dialog', '$j.fn.suggestions'], |
23 | | - function() { |
24 | | - $j( '#mw-addcategory-prompt' ).toggle(); |
25 | | - |
26 | | - $j( '#mw-addcategory-input' ).suggestions( { |
27 | | - 'fetch':ajaxCategories.fetchSuggestions, |
28 | | - 'cancel': function() { |
29 | | - var req = ajaxCategories.request; |
30 | | - if ( req.abort ) |
31 | | - req.abort(); |
32 | | - } |
33 | | - } ); |
34 | | - |
35 | | - $j( '#mw-addcategory-input' ).suggestions(); |
36 | | - } |
37 | | - ); |
38 | | - }, |
39 | | - |
40 | | - fetchSuggestions : function( query ) { |
41 | | - var that = this; |
42 | | - var request = $j.ajax( { |
43 | | - url: wgScriptPath + '/api.php', |
44 | | - data: { |
45 | | - 'action': 'query', |
46 | | - 'list': 'allpages', |
47 | | - 'apnamespace': 14, |
48 | | - 'apprefix': $j( this ).val(), |
49 | | - 'format': 'json' |
50 | | - }, |
51 | | - dataType: 'json', |
52 | | - success: function( data ) { |
53 | | - // Process data.query.allpages into an array of titles |
54 | | - var pages = data.query.allpages; |
55 | | - var titleArr = []; |
56 | | - |
57 | | - $j.each( pages, function( i, page ) { |
58 | | - var title = page.title.split( ':', 2 )[1]; |
59 | | - titleArr.push( title ); |
60 | | - } ); |
61 | | - |
62 | | - $j( that ).suggestions( 'suggestions', titleArr ); |
63 | | - } |
64 | | - } ); |
65 | | - |
66 | | - ajaxCategories.request = request; |
67 | | - }, |
68 | | - |
69 | | - reloadCategoryList : function( response ) { |
70 | | - var holder = $j( '<div/>' ); |
71 | | - |
72 | | - holder.load( |
73 | | - window.location.href + ' .catlinks', |
74 | | - function() { |
75 | | - $j( '.catlinks' ).replaceWith( holder.find( '.catlinks' ) ); |
76 | | - ajaxCategories.setupAJAXCategories(); |
77 | | - ajaxCategories.removeProgressIndicator( $j( '.catlinks' ) ); |
78 | | - } |
79 | | - ); |
80 | | - }, |
81 | | - |
82 | | - confirmEdit : function( page, fn, actionSummary, doneFn ) { |
83 | | - // Load jQuery UI |
84 | | - mvJsLoader.doLoad( |
85 | | - ['$j.ui', '$j.ui.dialog', '$j.fn.suggestions'], |
86 | | - function() { |
87 | | - // Produce a confirmation dialog |
88 | | - |
89 | | - var dialog = $j( '<div/>' ); |
90 | | - |
91 | | - dialog.addClass( 'mw-ajax-confirm-dialog' ); |
92 | | - dialog.attr( 'title', gM( 'ajax-confirm-title' ) ); |
93 | | - |
94 | | - // Intro text. |
95 | | - var confirmIntro = $j( '<p/>' ); |
96 | | - confirmIntro.text( gM( 'ajax-confirm-prompt' ) ); |
97 | | - dialog.append( confirmIntro ); |
98 | | - |
99 | | - // Summary of the action to be taken |
100 | | - var summaryHolder = $j( '<p/>' ); |
101 | | - var summaryLabel = $j( '<strong/>' ); |
102 | | - summaryLabel.text( gM( 'ajax-confirm-actionsummary' ) + " " ); |
103 | | - summaryHolder.text( actionSummary ); |
104 | | - summaryHolder.prepend( summaryLabel ); |
105 | | - dialog.append( summaryHolder ); |
106 | | - |
107 | | - // Reason textbox. |
108 | | - var reasonBox = $j( '<input type="text" size="45" />' ); |
109 | | - reasonBox.addClass( 'mw-ajax-confirm-reason' ); |
110 | | - dialog.append( reasonBox ); |
111 | | - |
112 | | - // Submit button |
113 | | - var submitButton = $j( '<input type="button"/>' ); |
114 | | - submitButton.val( gM( 'ajax-confirm-save' ) ); |
115 | | - |
116 | | - var submitFunction = function() { |
117 | | - ajaxCategories.addProgressIndicator( dialog ); |
118 | | - ajaxCategories.doEdit( |
119 | | - page, |
120 | | - fn, |
121 | | - reasonBox.val(), |
122 | | - function() { |
123 | | - doneFn(); |
124 | | - dialog.dialog( 'close' ); |
125 | | - ajaxCategories.removeProgressIndicator( dialog ); |
126 | | - } |
127 | | - ); |
128 | | - }; |
129 | | - |
130 | | - var buttons = { }; |
131 | | - buttons[gM( 'ajax-confirm-save' )] = submitFunction; |
132 | | - var dialogOptions = { |
133 | | - 'AutoOpen' : true, |
134 | | - 'buttons' : buttons, |
135 | | - 'width' : 450 |
136 | | - }; |
137 | | - |
138 | | - $j( '#catlinks' ).prepend( dialog ); |
139 | | - dialog.dialog( dialogOptions ); |
140 | | - } |
141 | | - ); |
142 | | - }, |
143 | | - |
144 | | - doEdit : function( page, fn, summary, doneFn ) { |
145 | | - // Get an edit token for the page. |
146 | | - var getTokenVars = { |
147 | | - 'action':'query', |
148 | | - 'prop':'info|revisions', |
149 | | - 'intoken':'edit', |
150 | | - 'titles':page, |
151 | | - 'rvprop':'content|timestamp', |
152 | | - 'format':'json' |
153 | | - }; |
154 | | - |
155 | | - $j.get( wgScriptPath + '/api.php', getTokenVars, |
156 | | - function( reply ) { |
157 | | - var infos = reply.query.pages; |
158 | | - $j.each( |
159 | | - infos, |
160 | | - function( pageid, data ) { |
161 | | - var token = data.edittoken; |
162 | | - var timestamp = data.revisions[0].timestamp; |
163 | | - var oldText = data.revisions[0]['*']; |
164 | | - |
165 | | - var newText = fn( oldText ); |
166 | | - |
167 | | - if ( newText === false ) return; |
168 | | - |
169 | | - var postEditVars = { |
170 | | - 'action':'edit', |
171 | | - 'title':page, |
172 | | - 'text':newText, |
173 | | - 'summary':summary, |
174 | | - 'token':token, |
175 | | - 'basetimestamp':timestamp, |
176 | | - 'format':'json' |
177 | | - }; |
178 | | - |
179 | | - $j.post( wgScriptPath + '/api.php', postEditVars, doneFn, 'json' ); |
180 | | - } |
181 | | - ); |
182 | | - } |
183 | | - , 'json' ); |
184 | | - }, |
185 | | - |
186 | | - addProgressIndicator : function( elem ) { |
187 | | - var indicator = $j( '<div/>' ); |
188 | | - |
189 | | - indicator.addClass( 'mw-ajax-loader' ); |
190 | | - |
191 | | - elem.append( indicator ); |
192 | | - }, |
193 | | - |
194 | | - removeProgressIndicator : function( elem ) { |
195 | | - elem.find( '.mw-ajax-loader' ).remove(); |
196 | | - }, |
197 | | - |
198 | | - handleCategoryAdd : function( e ) { |
199 | | - // Grab category text |
200 | | - var category = $j( '#mw-addcategory-input' ).val(); |
201 | | - var appendText = "\n[[" + wgFormattedNamespaces[14] + ":" + category + "]]\n"; |
202 | | - var summary = gM( 'ajax-add-category-summary', category ); |
203 | | - |
204 | | - ajaxCategories.confirmEdit( |
205 | | - wgPageName, |
206 | | - function( oldText ) { return oldText + appendText }, |
207 | | - summary, |
208 | | - ajaxCategories.reloadCategoryList |
209 | | - ); |
210 | | - }, |
211 | | - |
212 | | - handleDeleteLink : function( e ) { |
213 | | - e.preventDefault(); |
214 | | - |
215 | | - var category = $j( this ).parent().find( 'a' ).text(); |
216 | | - |
217 | | - // Build a regex that matches legal invocations of that category. |
218 | | - |
219 | | - // In theory I should escape the aliases, but there's no JS function for it |
220 | | - // Shouldn't have any real impact, can't be exploited or anything, so we'll |
221 | | - // leave it for now. |
222 | | - var categoryNSFragment = ''; |
223 | | - $j.each( wgNamespaceIds, function( name, id ) { |
224 | | - if ( id == 14 ) { |
225 | | - // Allow the first character to be any case |
226 | | - var firstChar = name.charAt( 0 ); |
227 | | - firstChar = '[' + firstChar.toUpperCase() + firstChar.toLowerCase() + ']'; |
228 | | - categoryNSFragment += '|' + firstChar + name.substr( 1 ); |
229 | | - } |
230 | | - } ); |
231 | | - categoryNSFragment = categoryNSFragment.substr( 1 ); // Remove leading | |
232 | | - |
233 | | - // Build the regex |
234 | | - var titleFragment = category; |
235 | | - |
236 | | - firstChar = category.charAt( 0 ); |
237 | | - firstChar = '[' + firstChar.toUpperCase() + firstChar.toLowerCase() + ']'; |
238 | | - titleFragment = firstChar + category.substr( 1 ); |
239 | | - var categoryRegex = '\\[\\[' + categoryNSFragment + ':' + titleFragment + '(\\|[^\\]]*)?\\]\\]'; |
240 | | - categoryRegex = new RegExp( categoryRegex, 'g' ); |
241 | | - |
242 | | - var summary = gM( 'ajax-remove-category-summary', category ); |
243 | | - |
244 | | - ajaxCategories.confirmEdit( |
245 | | - wgPageName, |
246 | | - function( oldText ) { |
247 | | - var newText = oldText.replace( categoryRegex, '' ); |
248 | | - |
249 | | - if ( newText == oldText ) { |
250 | | - var error = gM( 'ajax-remove-category-error' ); |
251 | | - ajaxCategories.showError( error ); |
252 | | - ajaxCategories.removeProgressIndicator( $j( '.mw-ajax-confirm-dialog' ) ); |
253 | | - $j( '.mw-ajax-confirm-dialog' ).dialog( 'close' ); |
254 | | - return false; |
255 | | - } |
256 | | - |
257 | | - return newText; |
258 | | - }, |
259 | | - summary, ajaxCategories.reloadCategoryList |
260 | | - ); |
261 | | - }, |
262 | | - |
263 | | - showError : function( str ) { |
264 | | - var dialog = $j( '<div/>' ); |
265 | | - dialog.text( str ); |
266 | | - |
267 | | - $j( '#bodyContent' ).append( dialog ); |
268 | | - |
269 | | - var buttons = { }; |
270 | | - buttons[gM( 'ajax-error-dismiss' )] = function( e ) { |
271 | | - dialog.dialog( 'close' ); |
272 | | - }; |
273 | | - var dialogOptions = { |
274 | | - 'buttons' : buttons, |
275 | | - 'AutoOpen' : true, |
276 | | - 'title' : gM( 'ajax-error-title' ) |
277 | | - }; |
278 | | - |
279 | | - dialog.dialog( dialogOptions ); |
280 | | - }, |
281 | | - |
282 | | - setupAJAXCategories : function() { |
283 | | - // Only do it for articles. |
284 | | - if ( !wgIsArticle ) return; |
285 | | - |
286 | | - var clElement = $j( '.catlinks' ); |
287 | | - |
288 | | - // Unhide hidden category holders. |
289 | | - clElement.removeClass( 'catlinks-allhidden' ); |
290 | | - |
291 | | - var addLink = $j( '<a/>' ); |
292 | | - addLink.addClass( 'mw-ajax-addcategory' ); |
293 | | - |
294 | | - // Create [Add Category] link |
295 | | - addLink.text( gM( 'ajax-add-category' ) ); |
296 | | - addLink.attr( 'href', '#' ); |
297 | | - addLink.click( ajaxCategories.handleAddLink ); |
298 | | - clElement.append( addLink ); |
299 | | - |
300 | | - // Create add category prompt |
301 | | - var promptContainer = $j( '<div id="mw-addcategory-prompt"/>' ); |
302 | | - var promptTextbox = $j( '<input type="text" size="45" id="mw-addcategory-input"/>' ); |
303 | | - var addButton = $j( '<input type="button" id="mw-addcategory-button"/>' ); |
304 | | - addButton.val( gM( 'ajax-add-category-submit' ) ); |
305 | | - |
306 | | - promptTextbox.keypress( ajaxCategories.handleCategoryInput ); |
307 | | - addButton.click( ajaxCategories.handleCategoryAdd ); |
308 | | - |
309 | | - promptContainer.append( promptTextbox ); |
310 | | - promptContainer.append( addButton ); |
311 | | - promptContainer.hide(); |
312 | | - |
313 | | - // Create delete link for each category. |
314 | | - $j( '.catlinks div span a' ).each( function( e ) { |
315 | | - // Create a remove link |
316 | | - var deleteLink = $j( '<a class="mw-remove-category" href="#"/>' ); |
317 | | - |
318 | | - deleteLink.click( ajaxCategories.handleDeleteLink ); |
319 | | - |
320 | | - $j( this ).after( deleteLink ); |
321 | | - } ); |
322 | | - |
323 | | - clElement.append( promptContainer ); |
324 | | - } |
325 | | -}; |
326 | | - |
327 | | -js2AddOnloadHook( ajaxCategories.setupAJAXCategories ); |
Index: trunk/phase3/js2/remoteMwEmbed.js |
— | — | @@ -1,263 +0,0 @@ |
2 | | -/* |
3 | | - * This file exposes some of the functionality of mwEmbed to wikis |
4 | | - * that do not yet have js2 enabled |
5 | | - */ |
6 | | - |
7 | | -var urlparts = getRemoteEmbedPath(); |
8 | | -var mwEmbedHostPath = urlparts[0]; |
9 | | -var mwRemoteVersion = '1.10'; |
10 | | -var mwUseScriptLoader = true; |
11 | | - |
12 | | -// setup up request Params: |
13 | | -var reqParts = urlparts[1].substring( 1 ).split( '&' ); |
14 | | -var mwReqParam = { }; |
15 | | -for ( var i = 0; i < reqParts.length; i++ ) { |
16 | | - var p = reqParts[i].split( '=' ); |
17 | | - if ( p.length == 2 ) |
18 | | - mwReqParam[ p[0] ] = p[1]; |
19 | | -} |
20 | | - |
21 | | -addOnloadHook( function() { |
22 | | - // Only do rewrites if MV_EMBED / js2 is "off" |
23 | | - if ( typeof MV_EMBED_VERSION == 'undefined' ) { |
24 | | - doPageSpecificRewrite(); |
25 | | - } |
26 | | -} ); |
27 | | - |
28 | | -function doPageSpecificRewrite() { |
29 | | - // Add media wizard |
30 | | - if ( wgAction == 'edit' || wgAction == 'submit' ) { |
31 | | - var jsSetEdit = [ 'remoteSearchDriver', '$j.fn.textSelection', '$j.ui', '$j.ui.sortable' ] |
32 | | - mwr_load_mv_embed( jsSetEdit, function() { |
33 | | - loadExternalJs( mwEmbedHostPath + '/editPage.js?' + mwGetReqArgs() ); |
34 | | - } ); |
35 | | - } |
36 | | - |
37 | | - // Timed text display: |
38 | | - if ( wgPageName.indexOf( "TimedText" ) === 0 ) { |
39 | | - mwr_load_mv_embed( function() { |
40 | | - // Load with mw loader to get localized interface: |
41 | | - mw.load( ['mvTimeTextEdit'], function() { |
42 | | - // could run init here (but mvTimeTextEdit already included onLoad actions) |
43 | | - } ); |
44 | | - } ); |
45 | | - } |
46 | | - |
47 | | - // Firefogg integration |
48 | | - if ( wgPageName == "Special:Upload" ) { |
49 | | - var jsSetUpload = [ 'mvBaseUploadInterface', 'mvFirefogg' , '$j.ui', |
50 | | - '$j.ui.progressbar', '$j.ui.dialog', '$j.ui.draggable' ]; |
51 | | - mwr_load_mv_embed( jsSetUpload, function() { |
52 | | - loadExternalJs( mwEmbedHostPath + '/uploadPage.js?' + mwGetReqArgs() ); |
53 | | - } ); |
54 | | - } |
55 | | - |
56 | | - // Special api proxy page |
57 | | - if ( wgPageName == 'MediaWiki:ApiProxy' ) { |
58 | | - var wgEnableIframeApiProxy = true; |
59 | | - mwr_load_mv_embed( [ 'mw.proxy' ], function() { |
60 | | - loadExternalJs( mwEmbedHostPath + '/apiProxyPage.js?' + mwGetReqArgs() ); |
61 | | - } ); |
62 | | - } |
63 | | - |
64 | | - // OggHandler rewrite for view pages: |
65 | | - var vidIdList = []; |
66 | | - var divs = document.getElementsByTagName( 'div' ); |
67 | | - for ( var i = 0; i < divs.length; i++ ) { |
68 | | - if ( divs[i].id && divs[i].id.substring( 0, 11 ) == 'ogg_player_' ) { |
69 | | - vidIdList.push( divs[i].getAttribute( "id" ) ); |
70 | | - } |
71 | | - } |
72 | | - if ( vidIdList.length > 0 ) { |
73 | | - var jsSetVideo = [ 'embedVideo', '$j.ui', 'ctrlBuilder', '$j.cookie', '$j.ui.slider', 'kskinConfig' ]; |
74 | | - // Quick sniff use java if IE and native if firefox |
75 | | - // ( other browsers will run detect and get on-demand ) |
76 | | - if (navigator.userAgent.indexOf("MSIE") != -1) |
77 | | - jsSetVideo.push( 'javaEmbed' ); |
78 | | - |
79 | | - if ( navigator.userAgent && navigator.userAgent.indexOf("Firefox") != -1 ) |
80 | | - jsSetVideo.push( 'nativeEmbed' ); |
81 | | - |
82 | | - mwr_load_mv_embed( jsSetVideo, function() { |
83 | | - mvJsLoader.embedVideoCheck( function() { |
84 | | - // Do utility rewrite of OggHandler content: |
85 | | - rewrite_for_OggHandler( vidIdList ); |
86 | | - } ); |
87 | | - } ); |
88 | | - } |
89 | | -} |
90 | | -// This will be depreciated in favour of updates to OggHandler |
91 | | -function rewrite_for_OggHandler( vidIdList ) { |
92 | | - function procVidId( vidId ) { |
93 | | - // don't process empty vids |
94 | | - if ( !vidId ) |
95 | | - return ; |
96 | | - js_log( 'vidIdList on: ' + vidId + ' length: ' + vidIdList.length + ' left in the set: ' + vidIdList ); |
97 | | - |
98 | | - tag_type = 'video'; |
99 | | - // Check type: |
100 | | - var pwidth = $j( '#' + vidId ).width(); |
101 | | - var $pimg = $j( '#' + vidId + ' img:first' ); |
102 | | - if( $pimg.attr('src').split('/').pop() == 'play.png'){ |
103 | | - tag_type = 'audio'; |
104 | | - poster_attr = ''; |
105 | | - pheight = 0; |
106 | | - }else{ |
107 | | - var poster_attr = 'poster = "' + $pimg.attr( 'src' ) + '" '; |
108 | | - var pheight = $pimg.attr( 'height' ); |
109 | | - } |
110 | | - |
111 | | - |
112 | | - // Parsed values: |
113 | | - var src = ''; |
114 | | - var duration_attr = ''; |
115 | | - var wikiTitleKey = $j( '#' + vidId + ' img' ).filter( ':first' ).attr( 'src' ).split( '/' ); |
116 | | - wikiTitleKey = unescape( wikiTitleKey[ wikiTitleKey.length - 2 ] ); |
117 | | - var re = new RegExp( /videoUrl(":?\s*)*([^&]*)/ ); |
118 | | - src = re.exec( $j( '#' + vidId ).html() )[2]; |
119 | | - |
120 | | - var re = new RegExp( /length(":?\s*)*([^,]*)/ ); |
121 | | - var dv = re.exec( $j( '#' + vidId ).html() )[2]; |
122 | | - if ( dv ) { |
123 | | - duration_attr = 'durationHint="' + dv + '" '; |
124 | | - } |
125 | | - |
126 | | - var re = new RegExp( /offset(":?\s*)*([^&]*)/ ); |
127 | | - offset = re.exec( $j( '#' + vidId ).html() )[2]; |
128 | | - var offset_attr = offset ? 'startOffset="' + offset + '"' : ''; |
129 | | - |
130 | | - if ( src ) { |
131 | | - var html_out = ''; |
132 | | - |
133 | | - var common_attr = ' id="mwe_' + vidId + '" ' + |
134 | | - 'wikiTitleKey="' + wikiTitleKey + '" ' + |
135 | | - 'src="' + src + '" ' + |
136 | | - duration_attr + |
137 | | - offset_attr + ' ' + |
138 | | - 'class="kskin" '; |
139 | | - |
140 | | - if ( tag_type == 'audio' ) { |
141 | | - html_out = '<audio' + common_attr + ' style="width:' + pwidth + 'px;"></audio>'; |
142 | | - } else { |
143 | | - html_out = '<video' + common_attr + |
144 | | - poster_attr + ' ' + |
145 | | - 'style="width:' + pwidth + 'px;height:' + pheight + 'px;">' + |
146 | | - '</video>'; |
147 | | - } |
148 | | - // Set the video tag inner html and update the height |
149 | | - $j( '#' + vidId ).html( html_out ) |
150 | | - .css( 'height', pheight + 30 ); |
151 | | - |
152 | | - // Do the actual rewrite |
153 | | - rewrite_by_id( 'mwe_' + vidId, function() { |
154 | | - if ( vidIdList.length != 0 ) { |
155 | | - setTimeout( function() { |
156 | | - procVidId( vidIdList.pop() ) |
157 | | - }, 10 ); |
158 | | - } |
159 | | - } ); |
160 | | - |
161 | | - } |
162 | | - }; |
163 | | - // process each item in the vidIdList (with setTimeout to avoid locking) |
164 | | - procVidId( vidIdList.pop() ); |
165 | | -} |
166 | | -function getRemoteEmbedPath() { |
167 | | - for ( var i = 0; i < document.getElementsByTagName( 'script' ).length; i++ ) { |
168 | | - var s = document.getElementsByTagName( 'script' )[i]; |
169 | | - if ( s.src.indexOf( '/remoteMwEmbed.js' ) != - 1 ) { |
170 | | - var reqStr = ''; |
171 | | - var scriptPath = ''; |
172 | | - if ( s.src.indexOf( '?' ) != - 1 ) { |
173 | | - reqStr = s.src.substr( s.src.indexOf( '?' ) ); |
174 | | - scriptPath = s.src.substr( 0, s.src.indexOf( '?' ) ).replace( '/remoteMwEmbed.js', '' ); |
175 | | - } else { |
176 | | - scriptPath = s.src.replace( '/remoteMwEmbed.js', '' ) |
177 | | - } |
178 | | - // Use the external_media_wizard path: |
179 | | - return [scriptPath, reqStr]; |
180 | | - } |
181 | | - } |
182 | | -} |
183 | | -function mwGetReqArgs() { |
184 | | - var rurl = ''; |
185 | | - if ( mwReqParam['debug'] ) |
186 | | - rurl += 'debug=true&'; |
187 | | - |
188 | | - if ( mwReqParam['uselang'] ) |
189 | | - rurl += 'uselang=' + mwReqParam['uselang'] + '&'; |
190 | | - |
191 | | - if ( mwReqParam['urid'] ) { |
192 | | - rurl += 'urid=' + mwReqParam['urid']; |
193 | | - } else { |
194 | | - // Make sure to use an urid |
195 | | - // This way remoteMwEmbed can control version of code being requested |
196 | | - rurl += 'urid=' + mwRemoteVersion; |
197 | | - } |
198 | | - return rurl; |
199 | | -} |
200 | | -/** |
201 | | -* @param {mixed} function or classSet to preload |
202 | | -* classSet saves round trips to the server by grabbing things we will likely need in the first request. |
203 | | -* ( this is essentially a shortcut to mv_jqueryBindings in mv_embed.js ) |
204 | | -* @param {callback} function callback to be called once mv_embed is ready |
205 | | -*/ |
206 | | -function mwr_load_mv_embed( classSet, callback ) { |
207 | | - if( typeof classSet == 'function') |
208 | | - callback = classSet; |
209 | | - // Inject mv_embed if needed |
210 | | - if ( typeof mw == 'undefined' ) { |
211 | | - if ( ( mwReqParam['uselang'] || mwReqParam['useloader'] ) && mwUseScriptLoader ) { |
212 | | - var rurl = mwEmbedHostPath + '/mwEmbed/jsScriptLoader.php?class=mv_embed'; |
213 | | - |
214 | | - // Add jQuery too if we need it: |
215 | | - if ( typeof window.jQuery == 'undefined' ) { |
216 | | - rurl += ',window.jQuery'; |
217 | | - } |
218 | | - |
219 | | - // Add requested classSet |
220 | | - for( var i=0; i < classSet.length; i++ ){ |
221 | | - var cName = classSet[i]; |
222 | | - if( !mwr_check_obj_path( cName ) ){ |
223 | | - rurl += ',' + cName; |
224 | | - } |
225 | | - } |
226 | | - |
227 | | - // Add the remaining arguments |
228 | | - rurl += '&' + mwGetReqArgs(); |
229 | | - |
230 | | - importScriptURI( rurl ); |
231 | | - } else { |
232 | | - // Ingore classSet (will be loaded onDemand ) |
233 | | - importScriptURI( mwEmbedHostPath + '/mwEmbed/mv_embed.js?' + mwGetReqArgs() ); |
234 | | - } |
235 | | - } |
236 | | - mwr_check_for_mv_embed( callback ); |
237 | | -} |
238 | | - |
239 | | -function mwr_check_for_mv_embed( callback ) { |
240 | | - if ( typeof mw == 'undefined' ) { |
241 | | - setTimeout( function() { |
242 | | - mwr_check_for_mv_embed( callback ); |
243 | | - }, 25 ); |
244 | | - } else { |
245 | | - callback(); |
246 | | - } |
247 | | -} |
248 | | - |
249 | | -function mwr_check_obj_path ( libVar ) { |
250 | | - if ( !libVar ) |
251 | | - return false; |
252 | | - var objPath = libVar.split( '.' ) |
253 | | - var cur_path = ''; |
254 | | - for ( var p = 0; p < objPath.length; p++ ) { |
255 | | - cur_path = ( cur_path == '' ) ? cur_path + objPath[p] : cur_path + '.' + objPath[p]; |
256 | | - eval( 'var ptest = typeof ( ' + cur_path + ' ); ' ); |
257 | | - if ( ptest == 'undefined' ) { |
258 | | - this.missing_path = cur_path; |
259 | | - return false; |
260 | | - } |
261 | | - } |
262 | | - this.cur_path = cur_path; |
263 | | - return true; |
264 | | -}; |
Index: trunk/phase3/js2/uploadPage.js |
— | — | @@ -1,143 +0,0 @@ |
2 | | -/* |
3 | | - * This script is run on [[Special:Upload]]. |
4 | | - * It controls the invocation of the mvUploader class based on local config. |
5 | | - */ |
6 | | - |
7 | | -var mwUploadFormSelector = '#mw-upload-form'; |
8 | | -// Set up the upload form bindings once all DOM manipulation is done |
9 | | -var mwUploadHelper = { |
10 | | - init: function() { |
11 | | - var _this = this; |
12 | | - // If wgEnableFirefogg is not boolean false, set to true |
13 | | - if ( typeof wgEnableFirefogg == 'undefined' ) |
14 | | - wgEnableFirefogg = true; |
15 | | - |
16 | | - if ( wgEnableFirefogg ) { |
17 | | - // Set up the upload handler to Firefogg. Should work with the HTTP uploads too. |
18 | | - $j( '#wpUploadFile' ).firefogg( { |
19 | | - // An API URL (we won't submit directly to action of the form) |
20 | | - 'api_url': wgServer + wgScriptPath + '/api.php', |
21 | | - 'form_rewrite': true, |
22 | | - // MediaWiki API supports chunk uploads: |
23 | | - 'enable_chunks' : true, |
24 | | - 'edit_form_selector': mwUploadFormSelector, |
25 | | - 'new_source_cb': function( orgFilename, oggName ) { |
26 | | - $j( '#wpDestFile' ).val( oggName ); |
27 | | - $j( '#wpDestFile' ).doDestCheck( { |
28 | | - 'warn_target': '#wpDestFile-warning' |
29 | | - } ); |
30 | | - } |
31 | | - } ); |
32 | | - } else { |
33 | | - // Add basic upload profile support ( http status monitoring, progress box for |
34 | | - // browsers that support it, etc.) |
35 | | - if ( $j( '#wpUploadFileURL' ).length != 0 ) { |
36 | | - $j( '#wpUploadFileURL' ).baseUploadInterface( { |
37 | | - 'api_url': wgServer + wgScriptPath + '/api.php', |
38 | | - 'edit_form_selector': mwUploadFormSelector |
39 | | - } ); |
40 | | - } |
41 | | - } |
42 | | - |
43 | | - if ( wgAjaxUploadDestCheck ) { |
44 | | - // Do destination check |
45 | | - $j( '#wpDestFile' ).change( function() { |
46 | | - $j( '#wpDestFile' ).doDestCheck( { |
47 | | - 'warn_target':'#wpDestFile-warning' |
48 | | - } ); |
49 | | - } ); |
50 | | - } |
51 | | - |
52 | | - // Check if we have HTTP enabled & setup enable/disable toggle: |
53 | | - if ( $j( '#wpUploadFileURL' ).length != 0 ) { |
54 | | - // Set the initial toggleUpType |
55 | | - _this.toggleUpType( true ); |
56 | | - |
57 | | - $j( "input[name='wpSourceType']" ).click( function() { |
58 | | - _this.toggleUpType( this.id == 'wpSourceTypeFile' ); |
59 | | - } ); |
60 | | - } |
61 | | - $j( '#wpUploadFile,#wpUploadFileURL' ) |
62 | | - .focus( function() { |
63 | | - _this.toggleUpType( this.id == 'wpUploadFile' ); |
64 | | - } ) |
65 | | - // Also setup the onChange event binding: |
66 | | - .change( function() { |
67 | | - if ( wgUploadAutoFill ) { |
68 | | - mwUploadHelper.doDestinationFill( this ); |
69 | | - } |
70 | | - } ); |
71 | | - }, |
72 | | - /** |
73 | | - * Set the upload radio buttons |
74 | | - * |
75 | | - * @boolean set |
76 | | - */ |
77 | | - toggleUpType: function( set ) { |
78 | | - $j( '#wpSourceTypeFile' ).attr( 'checked', set ); |
79 | | - $j( '#wpUploadFile' ).attr( 'disabled', !set ); |
80 | | - |
81 | | - $j( '#wpSourceTypeURL' ).attr( 'checked', !set ); |
82 | | - $j( '#wpUploadFileURL' ).attr( 'disabled', set ); |
83 | | - |
84 | | - // If Firefogg is enabled, toggle action according to wpSourceTypeFile selection |
85 | | - if ( wgEnableFirefogg ) { |
86 | | - $j( '#wpUploadFile' ).firefogg( { |
87 | | - 'firefogg_form_action': $j( '#wpSourceTypeFile' ).attr( 'checked' ) |
88 | | - } ); |
89 | | - } |
90 | | - }, |
91 | | - /** |
92 | | - * Fill in a destination file-name based on a source asset name. |
93 | | - */ |
94 | | - doDestinationFill: function( targetElm ) { |
95 | | - js_log( "doDestinationFill" ) |
96 | | - // Remove any previously flagged errors |
97 | | - $j( '#mw-upload-permitted,#mw-upload-prohibited' ).hide(); |
98 | | - |
99 | | - var path = $j( targetElm ).val(); |
100 | | - // Find trailing part |
101 | | - var slash = path.lastIndexOf( '/' ); |
102 | | - var backslash = path.lastIndexOf( '\\' ); |
103 | | - var fname; |
104 | | - if ( slash == -1 && backslash == -1 ) { |
105 | | - fname = path; |
106 | | - } else if ( slash > backslash ) { |
107 | | - fname = path.substring( slash + 1, 10000 ); |
108 | | - } else { |
109 | | - fname = path.substring( backslash + 1, 10000 ); |
110 | | - } |
111 | | - // URLs are less likely to have a useful extension. Don't include them in the extension check. |
112 | | - if ( wgFileExtensions && $j( targetElm ).attr( 'id' ) != 'wpUploadFileURL' ) { |
113 | | - var found = false; |
114 | | - if ( fname.lastIndexOf( '.' ) != -1 ) { |
115 | | - var ext = fname.substr( fname.lastIndexOf( '.' ) + 1 ); |
116 | | - for ( var i = 0; i < wgFileExtensions.length; i++ ) { |
117 | | - if ( wgFileExtensions[i].toLowerCase() == ext.toLowerCase() ) |
118 | | - found = true; |
119 | | - } |
120 | | - } |
121 | | - if ( !found ) { |
122 | | - // Clear the upload. Set mw-upload-permitted to error. |
123 | | - $j( targetElm ).val( '' ); |
124 | | - $j( '#mw-upload-permitted,#mw-upload-prohibited' ).show().addClass( 'error' ); |
125 | | - $j( '#wpDestFile' ).val( '' ); |
126 | | - return false; |
127 | | - } |
128 | | - } |
129 | | - // Capitalise first letter and replace spaces by underscores |
130 | | - fname = fname.charAt( 0 ).toUpperCase().concat( fname.substring( 1, 10000 ) ).replace(/ /g, '_' ); |
131 | | - // Output result |
132 | | - $j( '#wpDestFile' ).val( fname ); |
133 | | - |
134 | | - // Do a destination check |
135 | | - $j( '#wpDestFile' ).doDestCheck( { |
136 | | - 'warn_target': '#wpDestFile-warning' |
137 | | - } ); |
138 | | - } |
139 | | -} |
140 | | - |
141 | | - |
142 | | -js2AddOnloadHook( function() { |
143 | | - mwUploadHelper.init(); |
144 | | -} ); |
\ No newline at end of file |
Index: trunk/phase3/js2/README |
— | — | @@ -1,4 +0,0 @@ |
2 | | -MediaWiki Javascript phase 2 |
3 | | - |
4 | | -See Documentation on wiki: |
5 | | -http://www.mediawiki.org/wiki/JS2_Overview |
\ No newline at end of file |
Index: trunk/phase3/js2/editPage.js |
— | — | @@ -1,69 +0,0 @@ |
2 | | -/* |
3 | | - * JS2-style replacement for MediaWiki edit.js |
4 | | - * (right now it just supports the toolbar) |
5 | | - */ |
6 | | - |
7 | | -// Setup configuration vars (if not set already) |
8 | | -if ( !mwAddMediaConfig ) |
9 | | - var mwAddMediaConfig = { }; |
10 | | - |
11 | | -// The default editPage AMW config |
12 | | -var defaultAddMediaConfig = { |
13 | | - 'profile': 'mediawiki_edit', |
14 | | - 'target_textbox': '#wpTextbox1', |
15 | | - // Note: selections in the textbox will take over the default query |
16 | | - 'default_query': wgTitle, |
17 | | - 'target_title': wgPageName, |
18 | | - // Here we can setup the content provider overrides |
19 | | - 'enabled_cps':['wiki_commons'], |
20 | | - // The local wiki API URL: |
21 | | - 'local_wiki_api_url': wgServer + wgScriptPath + '/api.php' |
22 | | -}; |
23 | | - |
24 | | -js2AddOnloadHook( function() { |
25 | | - js_log( "edit page js2AddOnloadHook::" ); |
26 | | - var amwConf = $j.extend( true, defaultAddMediaConfig, mwAddMediaConfig ); |
27 | | - // kind of tricky, it would be nice to use run on ready "loader" call here |
28 | | - var didWikiEditorBind = false; |
29 | | - |
30 | | - // Set-up the drag drop binding (will only work for html5 upload browsers) |
31 | | - // $j('textarea#wpTextbox1').dragFileUpload(); |
32 | | - |
33 | | - // set up the add-media-wizard binding: |
34 | | - if ( typeof $j.wikiEditor != 'undefined' ) { |
35 | | - // the below seems to be broken :( |
36 | | - $j( 'textarea#wpTextbox1' ).bind( 'wikiEditor-toolbar-buildSection-main', |
37 | | - function( e, section ) { |
38 | | - didWikiEditorBind = true; |
39 | | - if ( typeof section.groups.insert.tools.file !== 'undefined' ) { |
40 | | - section.groups.insert.tools.file.action = { |
41 | | - 'type': 'callback', |
42 | | - 'execute': function() { |
43 | | - js_log( 'click add media wiz' ); |
44 | | - $j.addMediaWiz( amwConf ); |
45 | | - } |
46 | | - }; |
47 | | - } |
48 | | - } |
49 | | - ); |
50 | | - } |
51 | | - // Add to old toolbar if wikiEditor did not remove '#toolbar' from the page: |
52 | | - setTimeout( function() { |
53 | | - if ( $j( '#btn-add-media-wiz' ).length == 0 && $j( '#toolbar' ).length != 0 ) { |
54 | | - js_log( 'Do old toolbar bind:' ); |
55 | | - didWikiEditorBind = true; |
56 | | - $j( '#toolbar' ).append( '<img style="cursor:pointer" id="btn-add-media-wiz" src="' + |
57 | | - mv_skin_img_path + 'Button_add_media.png">' ); |
58 | | - $j( '#btn-add-media-wiz' ).addMediaWiz( |
59 | | - amwConf |
60 | | - ); |
61 | | - } else { |
62 | | - // Make sure the wikieditor got binded: |
63 | | - if ( !didWikiEditorBind ) { |
64 | | - js_log( 'Failed to bind via build section bind via target:' ); |
65 | | - $j( ".tool[rel='file']" ).unbind().addMediaWiz( amwConf ); |
66 | | - } |
67 | | - } |
68 | | - }, 120 ) |
69 | | - |
70 | | -} ); |