fu: Close-up of Fu, bringing a scoop of water to her mouth (Default)
fu ([personal profile] fu) wrote in [site community profile] changelog2011-09-28 10:34 am

[dw-free] Allow more sites in embed whitelist

[commit: http://hg.dwscoalition.org/dw-free/rev/7668453087d1]

http://bugs.dwscoalition.org/show_bug.cgi?id=3707

Allow embeds of files from wikimedia.

Patch by [personal profile] fu.

Files modified:
  • cgi-bin/DW/Hooks/EmbedWhitelist.pm
  • t/embed-whitelist.t
--------------------------------------------------------------------------------
diff -r 1a9e72748119 -r 7668453087d1 cgi-bin/DW/Hooks/EmbedWhitelist.pm
--- a/cgi-bin/DW/Hooks/EmbedWhitelist.pm	Tue Sep 27 20:25:57 2011 -0500
+++ b/cgi-bin/DW/Hooks/EmbedWhitelist.pm	Wed Sep 28 18:32:09 2011 +0800
@@ -84,6 +84,10 @@
         return 1 if match_full_path( qr!/embed/[-_a-zA-Z0-9]{11,}!, $uri_path );
     }
 
+    if ( $uri_host eq "commons.wikimedia.org" ) {
+        return 1 if $uri_path =~ m!^/wiki/File:! && $parsed_uri->query =~ m/embedplayer=yes/;
+    }
+
     return 0;
 
 } );
diff -r 1a9e72748119 -r 7668453087d1 t/embed-whitelist.t
--- a/t/embed-whitelist.t	Tue Sep 27 20:25:57 2011 -0500
+++ b/t/embed-whitelist.t	Wed Sep 28 18:32:09 2011 +0800
@@ -1,7 +1,7 @@
 # -*-perl-*-
 use strict;
 
-use Test::More tests => 24;
+use Test::More tests => 26;
 use lib "$ENV{LJHOME}/cgi-bin";
 require 'ljlib.pl';
 
@@ -71,7 +71,10 @@
     test_good_url( "http://www.slideshare.net/slideshow/embed_code/12312312" );
 
     test_good_url( "http://player.vimeo.com/video/123123123?title=0&byline=0&portrait=0" );
-    test_bad_url("http://player.vimeo.com/video/123abc?title=0&byline=0&portrait=0");
+    test_bad_url( "http://player.vimeo.com/video/123abc?title=0&byline=0&portrait=0" );
+
+    test_good_url( "http://commons.wikimedia.org/wiki/File:somethingsomethingsomething.ogv?withJS=MediaWiki:MwEmbed.js&embedplayer=yes" );
+    test_bad_url( "http://commons.wikimedia.org/wiki/File:1903_Burnley_Ironworks_company_steam_engine_in_use.ogv?withJS=MediaWiki:MwEmbed.js" );
 }
 
 
--------------------------------------------------------------------------------