r99840 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99839‎ | r99840 | r99841 >
Date:02:23, 15 October 2011
Author:brion
Status:ok (Comments)
Tags:
Comment:
Followup to r99653 (bug 31643) -- reenable client-side thumbnailing of SVGs on Special:Upload, with workaround for Firefox 7 regression.

Upstream firefox bug for hang loading some SVGs via data URI: https://bugzilla.mozilla.org/show_bug.cgi?id=694165
A fix may land as soon as Firefox 8.

This rev works around the bug by using window.URL.createObjectURL() instead of loading a data URI via FileReader; the object URL loads more cleanly and doesn't have the same hanging bug.

Needs to be replicated to UploadWizard (or moved to a shared lib!), some other fixes coming so no rush.
Modified paths:
  • /trunk/phase3/resources/mediawiki.special/mediawiki.special.upload.js (modified) (history)

Diff [purge]

Index: trunk/phase3/resources/mediawiki.special/mediawiki.special.upload.js
@@ -25,7 +25,7 @@
2626 * @return boolean
2727 */
2828 function fileIsPreviewable( file ) {
29 - var known = ['image/png', 'image/gif', 'image/jpeg'],
 29+ var known = ['image/png', 'image/gif', 'image/jpeg', 'image/svg+xml'],
3030 tooHuge = 10 * 1024 * 1024;
3131 return ( $.inArray( file.type, known ) !== -1 ) && file.size > 0 && file.size < tooHuge;
3232 }
@@ -160,20 +160,33 @@
161161 */
162162 function fetchPreview( file, callback, callbackBinary ) {
163163 var reader = new FileReader();
164 - reader.onload = function() {
165 - if ( callbackBinary ) {
 164+ if ( callbackBinary ) {
 165+ // To fetch JPEG metadata we need a binary string; start there.
 166+ // todo:
 167+ reader.onload = function() {
166168 callbackBinary( reader.result );
167 - reader.onload = function() {
168 - callback( reader.result );
169 - };
170 - reader.readAsDataURL( file );
171 - } else {
172 - callback( reader.result );
173 - }
174 - };
175 - if ( callbackBinary ) {
 169+
 170+ // Now run back through the regular code path.
 171+ fetchPreview(file, callback );
 172+ };
176173 reader.readAsBinaryString( file );
 174+ } else if ('URL' in window && 'createObjectURL' in window.URL) {
 175+ // Supported in Firefox 4.0 and above <https://developer.mozilla.org/en/DOM/window.URL.createObjectURL>
 176+ // WebKit has it in a namespace for now but that's ok. ;)
 177+ //
 178+ // Lifetime of this URL is until document close, which is fine
 179+ // for Special:Upload -- if this code gets used on longer-running
 180+ // pages, add a revokeObjectURL() when it's no longer needed.
 181+ //
 182+ // Prefer this over readAsDataURL for Firefox 7 due to bug reading
 183+ // some SVG files from data URIs <https://bugzilla.mozilla.org/show_bug.cgi?id=694165>
 184+ callback(window.URL.createObjectURL(file));
177185 } else {
 186+ // This ends up decoding the file to base-64 and back again, which
 187+ // feels horribly inefficient.
 188+ reader.onload = function() {
 189+ callback( reader.result );
 190+ };
178191 reader.readAsDataURL( file );
179192 }
180193 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r107938MFT r96774, r98690, r99840reedy21:00, 3 January 2012

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r99653Temporarily disable pre-upload SVG thumbnailing in Special:Upload and Special...brion22:46, 12 October 2011

Comments

#Comment by Brion VIBBER (talk | contribs)   20:59, 15 October 2011

Should merge to 1.18 (release issue -- can cause hangs on Firefox 7) and 1.18wmf1.

#Comment by Catrope (talk | contribs)   21:31, 8 November 2011

That's not entirely accurate, is it? If we don't backport this rev to 1.18, wouldn't 1.18 simply not attempt to scale SVGs, hence not hang?

#Comment by Catrope (talk | contribs)   21:32, 8 November 2011

Diff to the known variable makes me feel pretty confident that's indeed the case. Untagging for 1.18 cause this is not an emergency backport.

#Comment by Catrope (talk | contribs)   10:52, 28 October 2011
+	 * @todo put SVG back after working around Firefox 7 bug <[https://bugzilla.wikimedia.org/show_bug.cgi?id=31643 https://bugzilla.wikimedia.org/show_bug.cgi?id=31643]>

Was added in r99653, should be removed here then.

+			// todo: 

?!?

#Comment by Catrope (talk | contribs)   16:53, 4 January 2012

Untagging myself. I don't really understand this revision, the only reason I commented on it is that I was going through the 1.18 backports list at the time and removed it from that list because it wasn't urgent enough in my opinion.

Maybe someone like Neil or Ian should review this?

Status & tagging log