r100103 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r100102‎ | r100103 | r100104 >
Date:00:41, 18 October 2011
Author:johnduhart
Status:deferred (Comments)
Tags:
Comment:
Major refactor to Video extension. Code for Video providers is less repetitive.

Some providers however were lost, but can be brought back later.
Modified paths:
  • /trunk/extensions/Video/Video.php (modified) (history)
  • /trunk/extensions/Video/VideoClass.php (modified) (history)
  • /trunk/extensions/Video/VideoPage.php (modified) (history)
  • /trunk/extensions/Video/providers/ArchiveOrgVideo.php (deleted) (history)
  • /trunk/extensions/Video/providers/BaseVideoProvider.php (added) (history)
  • /trunk/extensions/Video/providers/BlipTVVideo.php (modified) (history)
  • /trunk/extensions/Video/providers/DailyMotionVideo.php (modified) (history)
  • /trunk/extensions/Video/providers/FlashVideo.php (deleted) (history)
  • /trunk/extensions/Video/providers/GametrailersVideo.php (modified) (history)
  • /trunk/extensions/Video/providers/GamevideosVideo.php (deleted) (history)
  • /trunk/extensions/Video/providers/GoGreenTubeVideo.php (deleted) (history)
  • /trunk/extensions/Video/providers/GoogleVideo.php (modified) (history)
  • /trunk/extensions/Video/providers/HuluVideo.php (modified) (history)
  • /trunk/extensions/Video/providers/MTVNetworksVideo.php (added) (history)
  • /trunk/extensions/Video/providers/MetaCafeVideo.php (modified) (history)
  • /trunk/extensions/Video/providers/MovieClipsVideo.php (modified) (history)
  • /trunk/extensions/Video/providers/MySpaceVideo.php (deleted) (history)
  • /trunk/extensions/Video/providers/MyVideoVideo.php (modified) (history)
  • /trunk/extensions/Video/providers/NewsRoomVideo.php (deleted) (history)
  • /trunk/extensions/Video/providers/SevenloadVideo.php (modified) (history)
  • /trunk/extensions/Video/providers/SouthParkStudiosVideo.php (modified) (history)
  • /trunk/extensions/Video/providers/ViddlerVideo.php (modified) (history)
  • /trunk/extensions/Video/providers/VimeoVideo.php (modified) (history)
  • /trunk/extensions/Video/providers/WeGameVideo.php (modified) (history)
  • /trunk/extensions/Video/providers/YouTubeVideo.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Video/VideoClass.php
@@ -74,6 +74,42 @@
7575 protected $context;
7676
7777 /**
 78+ * Array of providers codes to classes
 79+ *
 80+ * @var array
 81+ */
 82+ static $providers = array(
 83+ //'archiveorg' => 'ArchiveOrgVideoProvider', // broken/dont know how this works
 84+ 'bliptv' => 'BlipTVVideoProvider',
 85+ 'dailymotion' => 'DailyMotionVideoProvider',
 86+ 'gametrailers' => 'GametrailersVideoProvider',
 87+ //'gamevideos' => 'GamevideosVideoProvider', // broken
 88+ //'gogreentube' => 'GoGreenTubeVideoProvider', // Down
 89+ 'google' => 'GoogleVideoProvider',
 90+ 'hulu' => 'HuluVideoProvider',
 91+ 'metacafe' => 'MetaCafeVideoProvider',
 92+ 'movieclips' => 'MovieClipsVideoProvider',
 93+ // I'd rather not wade through the shit that is MySpace to figure out
 94+ // how videos work, someone else can do that..
 95+ //'myspace' => 'MySpaceVideoProvider',
 96+ 'myvideo' => 'MyVideoVideoProvider',
 97+ //'thenewsroom' => 'NewsRoomVideoProvider', // Website sucks too much
 98+ 'sevenload' => 'SevenloadVideoProvider',
 99+ 'southparkstudios' => 'SouthParkStudiosVideoProvider',
 100+ 'youtube' => 'YouTubeVideoProvider',
 101+ 'viddler' => 'ViddlerVideoProvider',
 102+ 'vimeo' => 'VimeoVideoProvider',
 103+ 'wegame' => 'WeGameVideoProvider',
 104+ );
 105+
 106+ /**
 107+ * Array of domain name to provider codes
 108+ *
 109+ * @var null
 110+ */
 111+ static protected $providerDomains = null;
 112+
 113+ /**
78114 * Constructor -- create a new Video object from the given Title and set
79115 * some member variables
80116 *
@@ -398,69 +434,13 @@
399435 * @return String: video embed code
400436 */
401437 public function getEmbedCode() {
402 - switch( $this->getType() ) {
403 - case 'youtube':
404 - $provider = new YouTubeVideo( $this );
405 - break;
406 - case 'google':
407 - $provider = new GoogleVideo( $this );
408 - break;
409 - case 'metacafe':
410 - $provider = new MetaCafeVideo( $this );
411 - break;
412 - case 'myspace':
413 - $provider = new MySpaceVideo( $this );
414 - break;
415 - case 'dailymotion':
416 - $provider = new DailyMotionVideo( $this );
417 - break;
418 - case 'thenewsroom':
419 - $provider = new NewsRoomVideo( $this );
420 - break;
421 - case 'archiveorg':
422 - $provider = new ArchiveOrgVideo( $this );
423 - break;
424 - case 'bliptv':
425 - $provider = new BlipTVVideo( $this );
426 - break;
427 - case 'hulu':
428 - $provider = new HuluVideo( $this );
429 - break;
430 - case 'gametrailers':
431 - $provider = new GametrailersVideo( $this );
432 - break;
433 - case 'gamevideos':
434 - $provider = new GamevideosVideo( $this );
435 - break;
436 - case 'gogreentube':
437 - $provider = new GoGreenTubeVideo( $this );
438 - break;
439 - case 'movieclips':
440 - $provider = new MovieClipsVideo( $this );
441 - break;
442 - case 'myvideo':
443 - $provider = new MyVideoVideo( $this );
444 - break;
445 - case 'sevenload':
446 - $provider = new SevenloadVideo( $this );
447 - break;
448 - case 'southparkstudios':
449 - $provider = new SouthParkStudiosVideo( $this );
450 - break;
451 - case 'viddler':
452 - $provider = new ViddlerVideo( $this );
453 - break;
454 - case 'vimeo':
455 - $provider = new VimeoVideo( $this );
456 - break;
457 - case 'wegame':
458 - $provider = new WeGameVideo( $this );
459 - break;
460 - default:
461 - $provider = new FlashVideo( $this );
462 - break;
 438+ if ( !isset( self::$providers[$this->type] ) ) {
 439+ return '';
463440 }
464441
 442+ $class = self::$providers[$this->type];
 443+ $provider = new $class( $this );
 444+
465445 return $provider->getEmbedCode();
466446 }
467447
@@ -509,6 +489,36 @@
510490 }
511491
512492 /**
 493+ * Populates the $providerDomains variable
 494+ *
 495+ * @return void
 496+ */
 497+ protected static function getDomainsForProviders() {
 498+ if ( self::$providerDomains !== null ) {
 499+ return;
 500+ }
 501+
 502+ self::$providerDomains = array();
 503+ foreach ( self::$providers as $name => $class ) {
 504+ $domains = $class::getDomains();
 505+ foreach ( $domains as $domain ) {
 506+ self::$providerDomains[$domain] = $name;
 507+ }
 508+ }
 509+ }
 510+
 511+ /**
 512+ * Returns if $haystack ends with $needle
 513+ *
 514+ * @param $haystack String
 515+ * @param $needle String
 516+ * @return bool
 517+ */
 518+ protected static function endsWith( $haystack, $needle ) {
 519+ return ( substr( $haystack, ( strlen( $needle ) * -1 ) ) === $needle );
 520+ }
 521+
 522+ /**
513523 * Figure out the provider's name (lowercased) from a given URL.
514524 *
515525 * @param $url String: URL to check
@@ -516,85 +526,16 @@
517527 * it out
518528 */
519529 public static function getProviderByURL( $url ) {
520 - $text = preg_match( '/youtube\.com/i', $url );
521 - if( $text ) {
522 - return 'youtube';
 530+ $host = parse_url( $url, PHP_URL_HOST );
 531+
 532+ self::getDomainsForProviders();
 533+ foreach ( self::$providerDomains as $domain => $provider ) {
 534+ if ( self::endsWith( $host, $domain ) ) {
 535+ return $provider;
 536+ }
523537 }
524 - $text = preg_match( '/metacafe\.com/i', $url );
525 - if( $text ) {
526 - return 'metacafe';
527 - }
528 - $text = preg_match( '/google\.com/i', $url );
529 - if( $text ) {
530 - return 'google';
531 - }
532 - $text = preg_match( '/myspace(tv)?\.com/i', $url );
533 - if( $text ) {
534 - return 'myspace';
535 - }
536 - $text = preg_match( '/dailymotion\.com/i', $url );
537 - if( $text ) {
538 - return 'dailymotion';
539 - }
540 - $text = preg_match( '/thenewsroom\.com/i', $url );
541 - if( $text ) {
542 - return 'thenewsroom';
543 - }
544 - $text = preg_match( '/archive\.org/i', $url );
545 - if( $text ) {
546 - return 'archiveorg';
547 - }
548 - $text = preg_match( '/blip\.tv/i', $url );
549 - if( $text ) {
550 - return 'bliptv';
551 - }
552 - $text = preg_match( '/gametrailers\.com/i', $url );
553 - if( $text ) {
554 - return 'gametrailers';
555 - }
556 - $text = preg_match( '/gamevideos\.1up\.com/i', $url );
557 - if( $text ) {
558 - return 'gamevideos';
559 - }
560 - $text = preg_match( '/gogreentube\.com/i', $url );
561 - if( $text ) {
562 - return 'gogreentube';
563 - }
564 - $text = preg_match( '/hulu\.com/i', $url );
565 - if( $text ) {
566 - return 'hulu';
567 - }
568 - $text = preg_match( '/movieclips\.com/i', $url );
569 - if( $text ) {
570 - return 'movieclips';
571 - }
572 - $text = preg_match( '/myvideo\.de/i', $url );
573 - if( $text ) {
574 - return 'myvideo';
575 - }
576 - $text = preg_match( '/sevenload\.com/i', $url );
577 - if( $text ) {
578 - return 'sevenload';
579 - }
580 - $text = preg_match( '/southparkstudios\.com/i', $url );
581 - if( $text ) {
582 - return 'southparkstudios';
583 - }
584 - $text = preg_match( '/viddler\.com/i', $url );
585 - if( $text ) {
586 - return 'viddler';
587 - }
588 - $text = preg_match( '/vimeo\.com/i', $url );
589 - if( $text ) {
590 - return 'vimeo';
591 - }
592 - $text = preg_match( '/wegame\.com/i', $url );
593 - if( $text ) {
594 - return 'wegame';
595 - }
596 - if( !$text ) {
597 - return 'unknown';
598 - }
 538+
 539+ return 'unknown';
599540 }
600541
601542 public function setWidth( $width ) {
Index: trunk/extensions/Video/VideoPage.php
@@ -232,7 +232,7 @@
233233 array(),
234234 array(
235235 'wpTitle' => $this->video->getName(),
236 - 'wpForReUpload' => 1,
 236+ 'forReUpload' => 1,
237237 )
238238 );
239239 $wgOut->addHTML( "<li>{$ulink}</li>" );
Index: trunk/extensions/Video/Video.php
@@ -21,8 +21,8 @@
2222 // Extension credits that show up on Special:Version
2323 $wgExtensionCredits['other'][] = array(
2424 'name' => 'Video',
25 - 'version' => '1.3',
26 - 'author' => array( 'David Pean', 'Jack Phoenix' ),
 25+ 'version' => '1.4',
 26+ 'author' => array( 'David Pean', 'Jack Phoenix', 'John Du Hart' ),
2727 'description' => 'Allows new Video namespace for embeddable media on supported sites',
2828 'url' => 'http://www.mediawiki.org/wiki/Extension:Video',
2929 );
@@ -59,26 +59,27 @@
6060 $wgAutoloadClasses['Video'] = $dir . 'VideoClass.php';
6161
6262 // ...and the dozen different provider classes
63 -$wgAutoloadClasses['ArchiveOrgVideo'] = $dir . 'providers/ArchiveOrgVideo.php';
64 -$wgAutoloadClasses['BlipTVVideo'] = $dir . 'providers/BlipTVVideo.php';
65 -$wgAutoloadClasses['DailyMotionVideo'] = $dir . 'providers/DailyMotionVideo.php';
66 -$wgAutoloadClasses['FlashVideo'] = $dir . 'providers/FlashVideo.php';
67 -$wgAutoloadClasses['GametrailersVideo'] = $dir . 'providers/GametrailersVideo.php';
68 -$wgAutoloadClasses['GamevideosVideo'] = $dir . 'providers/GamevideosVideo.php';
69 -$wgAutoloadClasses['GoGreenTubeVideo'] = $dir . 'providers/GoGreenTubeVideo.php';
70 -$wgAutoloadClasses['GoogleVideo'] = $dir . 'providers/GoogleVideo.php';
71 -$wgAutoloadClasses['HuluVideo'] = $dir . 'providers/HuluVideo.php';
72 -$wgAutoloadClasses['MetaCafeVideo'] = $dir . 'providers/MetaCafeVideo.php';
73 -$wgAutoloadClasses['MySpaceVideo'] = $dir . 'providers/MySpaceVideo.php';
74 -$wgAutoloadClasses['MovieClipsVideo'] = $dir . 'providers/MovieClipsVideo.php';
75 -$wgAutoloadClasses['MyVideoVideo'] = $dir . 'providers/MyVideoVideo.php';
76 -$wgAutoloadClasses['NewsRoomVideo'] = $dir . 'providers/NewsRoomVideo.php';
77 -$wgAutoloadClasses['SevenloadVideo'] = $dir . 'providers/SevenloadVideo.php';
78 -$wgAutoloadClasses['SouthParkStudiosVideo'] = $dir . 'providers/SouthParkStudiosVideo.php';
79 -$wgAutoloadClasses['ViddlerVideo'] = $dir . 'providers/ViddlerVideo.php';
80 -$wgAutoloadClasses['VimeoVideo'] = $dir . 'providers/VimeoVideo.php';
81 -$wgAutoloadClasses['WeGameVideo'] = $dir . 'providers/WeGameVideo.php';
82 -$wgAutoloadClasses['YouTubeVideo'] = $dir . 'providers/YouTubeVideo.php';
 63+$wgAutoloadClasses['ArchiveOrgVideoProvider'] = $dir . 'providers/ArchiveOrgVideo.php';
 64+$wgAutoloadClasses['BlipTVVideoProvider'] = $dir . 'providers/BlipTVVideo.php';
 65+$wgAutoloadClasses['DailyMotionVideoProvider'] = $dir . 'providers/DailyMotionVideo.php';
 66+$wgAutoloadClasses['BaseVideoProvider'] = $dir . 'providers/BaseVideoProvider.php';
 67+$wgAutoloadClasses['GametrailersVideoProvider'] = $dir . 'providers/GametrailersVideo.php';
 68+$wgAutoloadClasses['GamevideosVideoProvider'] = $dir . 'providers/GamevideosVideo.php';
 69+$wgAutoloadClasses['GoGreenTubeVideoProvider'] = $dir . 'providers/GoGreenTubeVideo.php';
 70+$wgAutoloadClasses['GoogleVideoProvider'] = $dir . 'providers/GoogleVideo.php';
 71+$wgAutoloadClasses['HuluVideoProvider'] = $dir . 'providers/HuluVideo.php';
 72+$wgAutoloadClasses['MetaCafeVideoProvider'] = $dir . 'providers/MetaCafeVideo.php';
 73+$wgAutoloadClasses['MySpaceVideoProvider'] = $dir . 'providers/MySpaceVideo.php';
 74+$wgAutoloadClasses['MovieClipsVideoProvider'] = $dir . 'providers/MovieClipsVideo.php';
 75+$wgAutoloadClasses['MTVNetworksVideoProvider'] = $dir . 'providers/MTVNetworksVideo.php';
 76+$wgAutoloadClasses['MyVideoVideoProvider'] = $dir . 'providers/MyVideoVideo.php';
 77+$wgAutoloadClasses['NewsRoomVideoProvider'] = $dir . 'providers/NewsRoomVideo.php';
 78+$wgAutoloadClasses['SevenloadVideoProvider'] = $dir . 'providers/SevenloadVideo.php';
 79+$wgAutoloadClasses['SouthParkStudiosVideoProvider'] = $dir . 'providers/SouthParkStudiosVideo.php';
 80+$wgAutoloadClasses['ViddlerVideoProvider'] = $dir . 'providers/ViddlerVideo.php';
 81+$wgAutoloadClasses['VimeoVideoProvider'] = $dir . 'providers/VimeoVideo.php';
 82+$wgAutoloadClasses['WeGameVideoProvider'] = $dir . 'providers/WeGameVideo.php';
 83+$wgAutoloadClasses['YouTubeVideoProvider'] = $dir . 'providers/YouTubeVideo.php';
8384
8485 // User Interface stuff
8586 $wgAutoloadClasses['VideoPage'] = $dir . 'VideoPage.php';
Index: trunk/extensions/Video/providers/GoGreenTubeVideo.php
@@ -1,52 +0,0 @@
2 -<?php
3 -
4 -class GoGreenTubeVideo extends FlashVideo {
5 -
6 - var $video,
7 - $id,
8 - $url;
9 -
10 - public function __construct( $video ) {
11 - if( !is_object( $video ) ) {
12 - throw new MWException( 'GoGreenTubeVideo constructor given bogus video object.' );
13 - }
14 -
15 - $this->video =& $video;
16 - $this->video->ratio = 432 / 394; // or the other way around...
17 - $this->id = $this->extractID( $this->video->getURL() );
18 - $this->url = 'http://www.gogreentube.com/embed/' . $this->id;
19 - return $this;
20 - }
21 -
22 - public function getEmbedCode() {
23 - $height = $this->video->getHeight();
24 - $width = $this->video->getWidth();
25 - $ggid = $this->extractID();
26 - $url = "http://www.gogreentube.com/embed/{$ggid}";
27 - $output = "<script type=\"text/javascript\" src=\"{$url}\"></script>";
28 - return $output;
29 - }
30 -
31 - /**
32 - * Extract the video ID from its URL.
33 - *
34 - * @return Integer: video ID
35 - */
36 - private function extractID() {
37 - $url = $this->video->getURL();
38 -
39 - $id = $url;
40 -
41 - if( preg_match( '/^http:\/\/www\.gogreentube\.com\/watch\.php\?v=(.+)$/', $url, $preg ) ) {
42 - $id = $preg[1];
43 - } elseif( preg_match( '/^http:\/\/www\.gogreentube\.com\/embed\/(.+)$/', $url, $preg ) ) {
44 - $id = $preg[1];
45 - }
46 -
47 - preg_match( '/([0-9A-Za-z]+)/', $id, $preg );
48 - $id = $preg[1];
49 -
50 - return $id;
51 - }
52 -
53 -}
\ No newline at end of file
Index: trunk/extensions/Video/providers/NewsRoomVideo.php
@@ -1,12 +0,0 @@
2 -<?php
3 -
4 -class NewsRoomVideo extends FlashVideo {
5 -
6 - public function __construct( &$video ) {
7 - parent::__construct( $video );
8 - $this->video->width = 300;
9 - $this->video->height = 325;
10 - $this->video->ratio = 300 / 325;
11 - }
12 -
13 -}
\ No newline at end of file
Index: trunk/extensions/Video/providers/GamevideosVideo.php
@@ -1,60 +0,0 @@
2 -<?php
3 -
4 -class GamevideosVideo extends FlashVideo {
5 -
6 - var $video,
7 - $id,
8 - $url;
9 -
10 - public function __construct( $video ) {
11 - if( !is_object( $video ) ) {
12 - throw new MWException( 'GamevideosVideo constructor given bogus video object.' );
13 - }
14 -
15 - $this->video =& $video;
16 - $this->video->ratio = 500 / 319;
17 - $this->id = $this->extractID( $this->video->getURL() );
18 - $this->url = 'http://gamevideos.1up.com/video/id/' . $this->id;
19 - return $this;
20 - }
21 -
22 - public function getEmbedCode() {
23 - $height = $this->video->getHeight();
24 - $width = $this->video->getWidth();
25 - $output = '<embed wmode="transparent" type="application/x-shockwave-flash" width="' . $width . '" height="' . $height . '" src="http://gamevideos.1up.com/swf/gamevideos12.swf?embedded=1&amp;fullscreen=1&amp;autoplay=0&amp;src=http://gamevideos.1up.com/do/videoListXML%3Fid%3D' . $this->id . '%26adPlay%3Dtrue" align="middle"></embed>';
26 - return $output;
27 - }
28 -
29 - /**
30 - * Extract the video ID from its URL.
31 - * Copypasted from WikiaVideo's VideoPage.php's parseUrl().
32 - *
33 - * @return Integer: video ID
34 - */
35 - private function extractID() {
36 - $url = $this->video->getURL();
37 - $url = trim( $url );
38 -
39 - $fixed_url = strtoupper( $url );
40 - $test = strpos( $fixed_url, 'HTTP://' );
41 - if( !false === $test ) {
42 - return false;
43 - }
44 -
45 - $fixed_url = str_replace( 'HTTP://', '', $fixed_url );
46 - $fixed_parts = explode( '/', $fixed_url );
47 - $fixed_url = $fixed_parts[0];
48 -
49 - $id = '';
50 - $text = strpos( $fixed_url, 'GAMEVIDEOS.1UP.COM' );
51 - if( $text !== false ) {
52 - $parsed = explode( '/', $url );
53 - if( is_array( $parsed ) ) {
54 - $id = array_pop( $parsed );
55 - }
56 - }
57 -
58 - return $id;
59 - }
60 -
61 -}
\ No newline at end of file
Index: trunk/extensions/Video/providers/ArchiveOrgVideo.php
@@ -1,52 +0,0 @@
2 -<?php
3 -
4 -class ArchiveOrgVideo extends FlashVideo {
5 -
6 - var $video,
7 - $id,
8 - $url;
9 -
10 - public function __construct( $video ) {
11 - if( !is_object( $video ) ) {
12 - throw new MWException( 'ArchiveOrgVideo constructor given bogus video object.' );
13 - }
14 -
15 - $this->video =& $video;
16 - $this->video->ratio = 320 / 263; // or the other way around :) --Jack
17 - $this->id = $this->extractID( $this->video->getURL() );
18 - $this->url = "http://www.archive.org/download/{$this->id}.flv";
19 - return $this;
20 - }
21 -
22 - public function getEmbedCode() {
23 - $height = $this->video->getHeight();
24 - $width = $this->video->getWidth();
25 - $aovid = $this->extractID();
26 - $url = "http://www.archive.org/download/{$aovid}.flv";
27 - $output = "<object type=\"application/x-shockwave-flash\" data=\"http://www.archive.org/flv/FlowPlayerWhite.swf\" width=\"{$width}\" height=\"{$height}\">
28 - <param name=\"movie\" value=\"http://www.archive.org/flv/FlowPlayerWhite.swf\"/><param name=\"flashvars\" value=\"config={loop: false, videoFile: '{$url}', autoPlay: false}\"/>
29 - </object>";
30 - return $output;
31 - }
32 -
33 - /**
34 - * Extract the video ID from its URL.
35 - *
36 - * @return Integer: video ID
37 - */
38 - private function extractID() {
39 - $url = $this->video->getURL();
40 -
41 - $id = $url;
42 -
43 - if ( preg_match( '/http:\/\/www\.archive\.org\/download\/(.+)\.flv$/', $url, $preg ) ) {
44 - $id = $preg[1];
45 - }
46 -
47 - preg_match( '/([0-9A-Za-z_\/.]+)/', $id, $preg );
48 - $id = $preg[1];
49 -
50 - return $id;
51 - }
52 -
53 -}
\ No newline at end of file
Index: trunk/extensions/Video/providers/FlashVideo.php
@@ -1,29 +0,0 @@
2 -<?php
3 -
4 -class FlashVideo {
5 -
6 - var $video,
7 - $id,
8 - $url;
9 -
10 - public function __construct( $video ) {
11 - if( !is_object( $video ) ) {
12 - throw new MWException( 'FlashVideo constructor given bogus video object.' );
13 - }
14 -
15 - $this->video =& $video;
16 - $this->url = $this->video->getURL();
17 - return $this;
18 - }
19 -
20 - public function getEmbedCode() {
21 - $output = "<object width=\"{$this->video->getWidth()}px\" height=\"{$this->video->getHeight()}px\">";
22 - $output .= "<param name=\"movie\" value=\"{$this->url}\"></param>";
23 - $output .= '<param name="wmode" value="transparent"></param>';
24 - $output .= "<embed wmode=\"transparent\" base=\".\" allowScriptAccess=\"always\" src=\"{$this->url}\" type=\"application/x-shockwave-flash\" width=\"{$this->video->getWidth()}px\" height=\"{$this->video->getHeight()}px\">";
25 - $output .= '</embed>';
26 - $output .= '</object>';
27 - return $output;
28 - }
29 -
30 -}
\ No newline at end of file
Index: trunk/extensions/Video/providers/MySpaceVideo.php
@@ -1,30 +0,0 @@
2 -<?php
3 -
4 -class MySpaceVideo extends FlashVideo {
5 -
6 - var $video,
7 - $id,
8 - $url;
9 -
10 - public function __construct( $video ) {
11 - if( !is_object( $video ) ) {
12 - throw new MWException( 'MySpace constructor given bogus video object.' );
13 - }
14 - $this->video =& $video;
15 - $this->video->ratio = 430/346;
16 - $this->id = $this->extractID( $this->video->getURL() );
17 - $this->url = "http://lads.myspace.com/videos/vplayer.swf?m={$this->id}&v=2&type=video";
18 - return $this;
19 - }
20 -
21 - private function extractID() {
22 - $url = $this->video->getURL();
23 - //http://myspacetv.com/index.cfm?fuseaction=vids.individual&videoid=1388509
24 - //http://lads.myspace.com/videos/vplayer.swf?m=1505336&v=2&type=video
25 - $id = preg_replace( "%http\:\/\/(vids\.|www\.)?myspace(tv)?\.com/index\.cfm\?fuseaction=vids\.individual&VideoID=%i", '', $url );
26 - $id = preg_replace( "%http\:\/\/(vids\.|www\.|lads\.)?myspace(tv)?\.com\/videos\/vplayer\.swf\?m=%i", '', $id );
27 - //$id = preg_replace( "%&v=2&type=video%i", '', $id );
28 - return $id;
29 - }
30 -
31 -}
\ No newline at end of file
Index: trunk/extensions/Video/providers/MTVNetworksVideo.php
@@ -0,0 +1,9 @@
 2+<?php
 3+
 4+abstract class MTVNetworksVideoProvider extends BaseVideoProvider {
 5+ protected $embedTemplate = '<embed src="http://media.mtvnservices.com/$video_id" width="$width" height="$height" type="application/x-shockwave-flash" allowFullScreen="true" allowScriptAccess="always" base="." flashVars=""></embed>';
 6+
 7+ protected function getRatio() {
 8+ return 512 / 288;
 9+ }
 10+}
Index: trunk/extensions/Video/providers/MetaCafeVideo.php
@@ -1,27 +1,15 @@
22 <?php
33
4 -class MetaCafeVideo extends FlashVideo {
 4+class MetaCafeVideoProvider extends BaseVideoProvider {
 5+ protected $videoIdRegex = '#/watch/(\d+)/#';
 6+ // heh, the URL needed some text to work :)
 7+ protected $embedTemplate = '<embed flashVars="playerVars=autoPlay=no" src="http://www.metacafe.com/fplayer/$video_id/johnduhart_was_here.swf" width="$width" height="$height" wmode="transparent" allowFullScreen="true" allowScriptAccess="always" name="Metacafe_$video_id" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed>';
58
6 - public function __construct( &$video ) {
7 - parent::__construct( $video );
8 - $this->video->ratio = 400/345;
9 - $this->url = $this->video->getURL();
10 - $this->extractID( $this->video->getURL() );
 9+ protected function getRatio() {
 10+ return 400 / 345;
1111 }
1212
13 - private function extractID() {
14 - // Standard Metacafe browser URL
15 - $url = $this->video->getURL();
16 - $standard_inurl = strpos( strtoupper( $url ), 'HTTP://WWW.METACAFE.COM/WATCH/' );
17 -
18 - if( $standard_inurl !== false ) {
19 - $id = substr( $url, $standard_inurl + strlen( 'HTTP://WWW.METACAFE.COM/WATCH/' ), strlen( $url ) );
20 - $last_char = substr( $id, -1 ,1 );
21 -
22 - if( $last_char == '/' ) {
23 - $id = substr( $id, 0, strlen( $id )-1 );
24 - }
25 - $this->url = "http://www.metacafe.com/fplayer/{$id}.swf";
26 - }
 13+ public static function getDomains() {
 14+ return array( 'metacafe.com' );
2715 }
2816 }
\ No newline at end of file
Index: trunk/extensions/Video/providers/WeGameVideo.php
@@ -1,50 +1,14 @@
22 <?php
33
4 -class WeGameVideo extends FlashVideo {
 4+class WeGameVideoProvider extends BaseVideoProvider {
 5+ protected $videoIdRegex = '#/watch/([a-zA-Z0-9_\-]+)/#';
 6+ protected $embedTemplate = '<object width="$width" height="$height"><param name="movie" value="http://www.wegame.com/static/flash/player.swf?xmlrequest=http://www.wegame.com/player/video/$video_id"></param><param name="flashVars" value="xmlrequest=http://www.wegame.com/player/video/$video_id&embedPlayer=true"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.wegame.com/static/flash/player.swf?xmlrequest=http://www.wegame.com/player/video/$video_id&embedPlayer=true" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="$width" height="$height"></embed></object>';
57
6 - var $video,
7 - $id,
8 - $url;
9 -
10 - public function __construct( $video ) {
11 - if( !is_object( $video ) ) {
12 - throw new MWException( 'WeGameVideo constructor given bogus video object.' );
13 - }
14 -
15 - $this->video =& $video;
16 - $this->video->ratio = 488 / 387; // or the other way around...
17 - $this->id = $this->extractID( $this->video->getURL() );
18 - $this->url = 'http://www.wegame.com/watch/' . $this->id;
19 - return $this;
 8+ public static function getDomains() {
 9+ return array( 'wegame.com' );
2010 }
2111
22 - public function getEmbedCode() {
23 - $height = $this->video->getHeight();
24 - $width = $this->video->getWidth();
25 - $weid = $this->extractID();
26 - $output = "<object type=\"application/x-shockwave-flash\" data=\"http://www.wegame.com/static/flash/player2.swf\" width=\"{$width}\" height=\"{$height}\">";
27 - $output .= "<param name=\"flashvars\" value=\"tag={$weid}\"/></object>";
28 - return $output;
 12+ protected function getRatio() {
 13+ return 488 / 387;
2914 }
30 -
31 - /**
32 - * Extract the video ID from its URL.
33 - *
34 - * @return Integer: video ID
35 - */
36 - private function extractID() {
37 - $url = $this->video->getURL();
38 -
39 - $id = $url;
40 -
41 - if ( preg_match( '/^http:\/\/www\.wegame\.com\/watch\/(.+)\/$/', $url, $preg ) ) {
42 - $id = $preg[1];
43 - }
44 -
45 - preg_match( '/([0-9A-Za-z_-]+)/', $id, $preg );
46 - $id = $preg[1];
47 -
48 - return $id;
49 - }
50 -
5115 }
\ No newline at end of file
Index: trunk/extensions/Video/providers/MovieClipsVideo.php
@@ -4,61 +4,22 @@
55 * @author William Lee <wlee@wikia-inc.com>
66 * @see http://trac.wikia-code.com/changeset/39940
77 */
8 -class MovieClipsVideo extends FlashVideo {
98
10 - var $video,
11 - $id,
12 - $url;
 9+class MovieClipsVideoProvider extends BaseVideoProvider {
 10+ protected $videoIdRegex = '#/([a-zA-Z0-9]+)-.*?#';
 11+ protected $embedTemplate = '<object width="$width" height="$height" type="application/x-shockwave-flash" data="http://static.movieclips.com/embedplayer.swf?config=http://config.movieclips.com/player/config/embed/$video_id/%3Floc%3DUS&endpoint=http://movieclips.com/api/v1/player/test/action/&start=0&v=1.0.15" style="display:block; overflow:hidden;">
 12+<param name="movie" value="http://static.movieclips.com/embedplayer.swf?config=http://config.movieclips.com/player/config/embed/$video_id/%3Floc%3DUS&endpoint=http://movieclips.com/api/v1/player/test/action/&start=0&v=1.0.15" />
 13+<param name="wmode" value="transparent" />
 14+<param name="allowscriptaccess" value="always" />
 15+<param name="allowfullscreen" value="true" />
 16+<embed src="http://static.movieclips.com/embedplayer.swf?config=http://config.movieclips.com/player/config/embed/$video_id/%3Floc%3DUS&endpoint=http://movieclips.com/api/v1/player/test/action/&start=0&v=1.0.15" type="application/x-shockwave-flash" width="$width" height="$height" wmode="transparent" allowscriptaccess="always" allowfullscreen="true"></embed>
 17+</object>';
1318
14 - public function __construct( $video ) {
15 - if( !is_object( $video ) ) {
16 - throw new MWException( 'MovieClipsVideo constructor given bogus video object.' );
17 - }
18 -
19 - $this->video =& $video;
20 - $this->video->ratio = 560 / 304;
21 - $this->id = $this->extractID( $this->video->getURL() );
22 - $this->url = $url = 'http://movieclips.com/' . $this->id;
23 - return $this;
 19+ protected function getRatio() {
 20+ return 560 / 304;
2421 }
2522
26 - public function getEmbedCode() {
27 - $height = $this->video->getHeight();
28 - $width = $this->video->getWidth();
29 - $url = 'http://movieclips.com/e/' . $this->id . '/';
30 - $output = "<embed src=\"{$url}\" width=\"{$width}\" height=\"{$height}\" wmode=\"transparent\" allowScriptAccess=\"always\" allowfullscreen=\"true\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\"> </embed>";
31 - return $output;
 23+ public static function getDomains() {
 24+ return array( 'movieclips.com' );
3225 }
33 -
34 - /**
35 - * Extract the video ID from its URL.
36 - *
37 - * @return Mixed: video ID (integer) on success, boolean false on failure
38 - */
39 - private function extractID() {
40 - $url = $this->video->getURL();
41 - $url = trim( $url );
42 -
43 - $fixed_url = strtoupper( $url );
44 - $test = strpos( $fixed_url, 'HTTP://' );
45 - if( !false === $test ) {
46 - return false;
47 - }
48 -
49 - $fixed_url = str_replace( 'HTTP://', '', $fixed_url );
50 - $fixed_parts = explode( '/', $fixed_url );
51 - $fixed_url = $fixed_parts[0];
52 -
53 - $id = '';
54 - $text = strpos( $fixed_url, 'MOVIECLIPS.COM' );
55 - if( $text !== false ) {
56 - $url = trim( $url, '/' );
57 - $parsed = explode( '/', $url );
58 - if( is_array( $parsed ) ) {
59 - $id = array_pop( $parsed );
60 - }
61 - }
62 -
63 - return $id;
64 - }
6526 }
\ No newline at end of file
Index: trunk/extensions/Video/providers/GoogleVideo.php
@@ -1,36 +1,15 @@
22 <?php
33
4 -class GoogleVideo extends FlashVideo {
 4+class GoogleVideoProvider extends BaseVideoProvider {
55
6 - var $video,
7 - $id,
8 - $url;
 6+ protected $videoIdRegex = '#docid=(-?\d+)#i';
 7+ protected $embedTemplate = '<embed id=VideoPlayback src=http://video.google.com/googleplayer.swf?docid=-5227581495321189338&hl=en&fs=true style=width:$widthpx;height:$heightpx allowFullScreen=true allowScriptAccess=always type=application/x-shockwave-flash> </embed>';
98
10 - public function __construct( $video ) {
11 - if( !is_object( $video ) ) {
12 - throw new MWException( 'GoogleVideo constructor given bogus video object.' );
13 - }
14 - $this->video =& $video;
15 - $this->video->ratio = 425/355;
16 - $this->id = $this->extractID( $this->video->getURL() );
17 - $this->url = "http://video.google.com/googleplayer.swf?docId={$this->id}";
18 - return $this;
 9+ public static function getDomains() {
 10+ return array( 'video.google.com' );
1911 }
2012
21 - private function extractID() {
22 - // Standard Google browser URL
23 - $url = $this->video->getURL();
24 - $standard_inurl = strpos( strtoupper( $url ), 'VIDEOPLAY?DOCID=' );
25 -
26 - if( $standard_inurl !== false ) {
27 - $id = substr( $url, $standard_inurl + strlen( 'VIDEOPLAY?DOCID=' ), strlen( $url ) );
28 - }
29 - if( !$id ) {
30 - $id_test = preg_replace( "%http\:\/\/video\.google\.com\/googleplayer\.swf\?docId=%i", '', $url );
31 - if( $id_test != $url ) {
32 - $id = $id_test;
33 - }
34 - }
35 - return $id;
 13+ protected function getRatio() {
 14+ return 425 / 355;
3615 }
3716 }
\ No newline at end of file
Index: trunk/extensions/Video/providers/MyVideoVideo.php
@@ -1,63 +1,14 @@
22 <?php
33
4 -class MyVideoVideo extends FlashVideo {
 4+class MyVideoVideoProvider extends BaseVideoProvider {
 5+ protected $videoIdRegex = '#/watch/(\d+)/?#';
 6+ protected $embedTemplate = '<object width="$width" height="$height"><param name="movie" value="http://www.myvideo.de/movie/$video_id"></param><param name="AllowFullscreen" value="true"></param><param name="AllowScriptAccess" value="always"></param><embed src="http://www.myvideo.de/movie/$video_id" width="$width" height="$height" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true"></embed></object>';
57
6 - var $video,
7 - $id,
8 - $url;
9 -
10 - public function __construct( $video ) {
11 - if( !is_object( $video ) ) {
12 - throw new MWException( 'MyVideoVideo constructor given bogus video object.' );
13 - }
14 -
15 - $this->video =& $video;
16 - $this->video->ratio = 470 / 406;
17 - $this->id = $this->extractID( $this->video->getURL() );
18 - $this->url = 'http://www.myvideo.de/watch/' . $this->id;
19 - return $this;
 8+ protected function getRatio() {
 9+ return 470 / 406;
2010 }
2111
22 - public function getEmbedCode() {
23 - $height = $this->video->getHeight();
24 - $width = $this->video->getWidth();
25 - $output = "<object style=\"width:{$width}px;height:{$height}px;\" type=\"application/x-shockwave-flash\" data=\"http://www.myvideo.de/movie/{$this->id}\">";
26 - $output .= '<param name="wmode" value="transparent">';
27 - $output .= '<param name="movie" value="http://www.myvideo.de/movie/' . $this->id . '" />';
28 - $output .= '<param name="AllowFullscreen?" value="true" /> </object>';
29 - return $output;
 12+ public static function getDomains() {
 13+ return array( 'myvideo.de' );
3014 }
31 -
32 - /**
33 - * Extract the video ID from its URL.
34 - * Copypasted from WikiaVideo's VideoPage.php's parseUrl().
35 - *
36 - * @return Integer: video ID
37 - */
38 - private function extractID() {
39 - $url = $this->video->getURL();
40 - $url = trim( $url );
41 -
42 - $fixed_url = strtoupper( $url );
43 - $test = strpos( $fixed_url, 'HTTP://' );
44 - if( !false === $test ) {
45 - return false;
46 - }
47 -
48 - $fixed_url = str_replace( 'HTTP://', '', $fixed_url );
49 - $fixed_parts = explode( '/', $fixed_url );
50 - $fixed_url = $fixed_parts[0];
51 -
52 - $id = '';
53 - $text = strpos( $fixed_url, 'MYVIDEO.DE' );
54 - if( $text !== false ) {
55 - $parsed = explode( '/', $url );
56 - if( is_array( $parsed ) ) {
57 - $id = array_pop( $parsed );
58 - }
59 - }
60 -
61 - return $id;
62 - }
63 -
6415 }
\ No newline at end of file
Index: trunk/extensions/Video/providers/HuluVideo.php
@@ -4,124 +4,45 @@
55 * @author William Lee <wlee@wikia-inc.com>
66 * @see http://trac.wikia-code.com/changeset/38530
77 */
8 -class HuluVideo extends FlashVideo {
 8+class HuluVideoProvider extends BaseVideoProvider {
 9+ protected $embedTemplate = '<object width="$width" height="$height"><param name="movie" value="$video_id"></param><param name="allowFullScreen" value="true"></param><embed src="$video_id" type="application/x-shockwave-flash" width="$width" height="$height" allowFullScreen="true"></embed></object>';
910
10 - var $video,
11 - $id,
12 - $url;
13 -
14 - public function __construct( $video ) {
15 - if( !is_object( $video ) ) {
16 - throw new MWException( 'HuluVideo constructor given bogus video object.' );
17 - }
18 -
19 - $this->video =& $video;
20 - $this->video->ratio = 512 / 296;
21 - $this->id = $this->extractID( $this->video->getURL() );
22 - $this->url = 'http://www.hulu.com/watch/' . $this->id;
23 - return $this;
 11+ public static function getDomains() {
 12+ return array( 'hulu.com' );
2413 }
2514
26 - public function getEmbedCode() {
27 - $height = $this->video->getHeight();
28 - $width = $this->video->getWidth();
29 - $data = $this->getData();
30 - $url = 'http://www.hulu.com/embed/' . $data['embedId'];
31 - $output = "<embed src=\"{$url}\" width=\"{$width}\" height=\"{$height}\" wmode=\"transparent\" allowScriptAccess=\"always\" allowfullscreen=\"true\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\"> </embed>";
32 - return $output;
 15+ protected function getRatio() {
 16+ return 512 / 296;
3317 }
3418
35 - /**
36 - * Extract the video ID from its URL.
37 - *
38 - * @return Mixed: video ID (integer) on success, boolean false on failure
39 - */
40 - private function extractID() {
41 - $url = $this->video->getURL();
42 - $url = trim( $url );
 19+ protected function extractVideoId( $url ) {
 20+ global $wgMemc;
4321
44 - $fixed_url = strtoupper( $url );
45 - $test = strpos( $fixed_url, 'HTTP://' );
46 - if( !false === $test ) {
47 - return false;
 22+ if ( !preg_match( '#/watch/(?<id>\d+)/#', $url, $matches) ) {
 23+ return null;
4824 }
4925
50 - $fixed_url = str_replace( 'HTTP://', '', $fixed_url );
51 - $fixed_parts = explode( '/', $fixed_url );
52 - $fixed_url = $fixed_parts[0];
 26+ $videoId = $matches['id'];
5327
54 - $id = '';
55 - $text = strpos( $fixed_url, 'HULU.COM' );
56 - if( $text !== false ) {
57 - // Hulu goes like
58 - // http://www.hulu.com/watch/252775/[seo terms]
59 - $url = trim( $url, '/' );
60 - $parsed = explode( '/', $url );
61 - if( is_array( $parsed ) ) {
62 - // $id is a number, and it is either last or second to last element of $parsed
63 - $last = explode( '?', array_pop( $parsed ) );
64 - $last = $last[0];
65 - if ( is_numeric( $last ) ) {
66 - $id = $last;
67 - } else {
68 - $id = array_pop( $parsed );
69 - //$seo = $last;
70 - }
71 - /*
72 - $this->mData = null; // getData() works only if mData is null
73 - $huluData = $this->getData();
74 - $this->mData = array();
75 - if ( is_array( $huluData ) ) {
76 - foreach ( $huluData as $key => $value ) {
77 - $this->mData[] = $value;
78 - }
79 - }
80 - if ( !empty( $seo ) ) {
81 - $this->mData[] = $seo;
82 - }
83 - */
84 - }
 28+ $cacheKey = wfMemcKey( 'video', 'hulu', $videoId );
 29+ $cachedEmbedId = $wgMemc->get( $cacheKey );
 30+
 31+ if ( $cachedEmbedId !== false ) {
 32+ return $cachedEmbedId;
8533 }
8634
87 - return $id;
88 - }
 35+ $apiUrl = 'http://www.hulu.com/api/oembed.json?url=' . urlencode( $url );
 36+ $apiResult = Http::get( $apiUrl );
8937
90 - private function getData() {
91 - $data = array();
 38+ if ( $apiResult === false ) {
 39+ return null;
 40+ }
9241
93 - /*
94 - if ( !empty( $this->mData ) ) {
95 - // metadata could be a one-element array, expressed in serialized form.
96 - // If so, deserialize
97 - if ( sizeof( $this->mData ) == 1 ) {
98 - $this->mData = explode( ',', $this->mData[0] );
99 - }
 42+ $apiResult = FormatJson::decode( $apiResult, true );
 43+ $embedId = $apiResult['embed_url'];
10044
101 - $data['embedId'] = $this->mData[0];
102 - $data['thumbnailUrl'] = $this->mData[1];
103 - $data['videoName'] = $this->mData[2];
104 - if ( sizeof( $this->mData ) > 3 ) {
105 - $data['seo'] = $this->mData[3];
106 - }
107 - } else {*/
108 - wfSuppressWarnings();
109 - $file = Http::get(
110 - 'http://www.hulu.com/api/oembed.xml?url=' .
111 - urlencode( 'http://www.hulu.com/watch/' . $this->id ), false );
112 - wfRestoreWarnings();
 45+ $wgMemc->set( $cacheKey, $embedId, 60 * 60 * 24 );
11346
114 - if ( $file ) {
115 - $doc = new DOMDocument( '1.0', 'UTF-8' );
116 - wfSuppressWarnings();
117 - $doc->loadXML( $file );
118 - wfRestoreWarnings();
119 - $embedUrl = trim( $doc->getElementsByTagName( 'embed_url' )->item( 0 )->textContent );
120 - $embedUrlParts = explode( '/', $embedUrl );
121 - $data['embedId'] = array_pop( $embedUrlParts );
122 - $data['thumbnailUrl'] = trim( $doc->getElementsByTagName( 'thumbnail_url' )->item( 0 )->textContent );
123 - $data['videoName'] = trim( $doc->getElementsByTagName( 'title' )->item( 0 )->textContent );
124 - }
125 - /*}*/
126 - return $huluData;
 47+ return $embedId;
12748 }
12849 }
\ No newline at end of file
Index: trunk/extensions/Video/providers/GametrailersVideo.php
@@ -1,67 +1,27 @@
22 <?php
33
4 -class GametrailersVideo extends FlashVideo {
5 -
6 - var $video,
7 - $id,
8 - $url;
9 -
10 - public function __construct( $video ) {
11 - if( !is_object( $video ) ) {
12 - throw new MWException( 'GametrailersVideo constructor given bogus video object.' );
13 - }
14 -
15 - $this->video =& $video;
16 - $this->video->ratio = 480 / 392;
17 - $this->id = $this->extractID( $this->video->getURL() );
18 - $this->url = 'http://www.gametrailers.com/video/play/' . $this->id;
19 - return $this;
 4+class GametrailersVideoProvider extends MTVNetworksVideoProvider {
 5+ public static function getDomains() {
 6+ return array( 'gametrailers.com' );
207 }
218
22 - public function getEmbedCode() {
23 - $height = $this->video->getHeight();
24 - $width = $this->video->getWidth();
25 - $output = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" id="gtembed" width="' . $width . '" height="' . $height . '">
26 - <param name="allowScriptAccess" value="sameDomain" />
27 - <param name="allowFullScreen" value="true" />
28 - <param name="movie" value="http://www.gametrailers.com/remote_wrap.php?mid=' . $this->id . '"/>
29 - <param name="quality" value="high" />
30 - <embed src="http://www.gametrailers.com/remote_wrap.php?mid=' . $this->id . '" swLiveConnect="true" name="gtembed" align="middle" allowScriptAccess="sameDomain" allowFullScreen="true" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' . $width . '" height="' . $height . '"></embed>
31 - </object>';
32 - return $output;
33 - }
34 -
35 - /**
36 - * Extract the video ID from its URL.
37 - * Copypasted from WikiaVideo's VideoPage.php's parseUrl().
38 - *
39 - * @return Integer: video ID
40 - */
41 - private function extractID() {
42 - $url = $this->video->getURL();
43 - $url = trim( $url );
44 -
45 - $fixed_url = strtoupper( $url );
46 - $test = strpos( $fixed_url, 'HTTP://' );
47 - if( !false === $test ) {
48 - return false;
 9+ protected function extractVideoId( $url ) {
 10+ if ( !preg_match( '#/(?<type>user-movie|video)/[a-zA-Z0-9\-]+/(?<id>\d+)#', $url, $matches ) ) {
 11+ return null;
4912 }
5013
51 - $fixed_url = str_replace( 'HTTP://', '', $fixed_url );
52 - $fixed_parts = explode( '/', $fixed_url );
53 - $fixed_url = $fixed_parts[0];
54 -
55 - $id = '';
56 - $text = strpos( $fixed_url, 'GAMETRAILERS' );
57 - if( $text !== false ) {
58 - $parsed = explode( '/', $url );
59 - if( is_array( $parsed ) ) {
60 - $id = explode( '?', array_pop( $parsed ) );
61 - $id = $id[0];
62 - }
 14+ $vidType = '';
 15+ switch ( $matches['type'] ) {
 16+ case 'video':
 17+ $vidType = 'video';
 18+ break;
 19+ case 'user-movie':
 20+ $vidType = 'usermovie';
 21+ break;
 22+ default:
 23+ return null;
6324 }
6425
65 - return $id;
 26+ return "mgid:moses:$vidType:gametrailers.com:{$matches['id']}";
6627 }
67 -
6828 }
\ No newline at end of file
Index: trunk/extensions/Video/providers/VimeoVideo.php
@@ -1,68 +1,16 @@
22 <?php
33
4 -class VimeoVideo extends FlashVideo {
 4+class VimeoVideoProvider extends BaseVideoProvider {
55
6 - var $video,
7 - $id,
8 - $url;
 6+ protected $videoIdRegex = '/.*\/(.*)/';
 7+ protected $embedTemplate = '<iframe src="http://player.vimeo.com/video/$video_id" width="$width" height="$height" frameborder="0" webkitAllowFullScreen allowFullScreen></iframe>';
98
10 - public function __construct( $video ) {
11 - if( !is_object( $video ) ) {
12 - throw new MWException( 'VimeoVideo constructor given bogus video object.' );
13 - }
14 -
15 - $this->video =& $video;
16 - $this->video->ratio = 400 / 225;
17 - $this->id = $this->extractID( $this->video->getURL() );
18 - $this->url = 'http://www.vimeo.com/' . $this->id;
19 - return $this;
 9+ protected function getRatio() {
 10+ return 400 / 225;
2011 }
2112
22 - public function getEmbedCode() {
23 - $height = $this->video->getHeight();
24 - $width = $this->video->getWidth();
25 - $auto = '';#$autoplay ? '&amp;autoplay=1' : '';
26 - $output = '<object width="' . $width . '" height="' . $height . '">';
27 - $output .= '<param name="allowfullscreen" value="true" />';
28 - $output .= '<param name="wmode" value="transparent">';
29 - $output .= '<param name="allowscriptaccess" value="always" />';
30 - $output .= '<param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=' . $this->id .
31 - '&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1' . $auto . '" />';
32 - $output .= '<embed src="http://vimeo.com/moogaloop.swf?clip_id=' . $this->id . '&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1' . $auto . '" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="' . $width . '" height="' . $height . '">';
33 - $output .= '</embed></object>';
34 - return $output;
 13+ public static function getDomains() {
 14+ return array( 'vimeo.com' );
3515 }
3616
37 - /**
38 - * Extract the video ID from its URL.
39 - * Copypasted from WikiaVideo's VideoPage.php's parseUrl().
40 - *
41 - * @return Integer: video ID
42 - */
43 - private function extractID() {
44 - $url = $this->video->getURL();
45 - $url = trim( $url );
46 -
47 - $fixed_url = strtoupper( $url );
48 - $test = strpos( $fixed_url, 'HTTP://' );
49 - if( !false === $test ) {
50 - return false;
51 - }
52 -
53 - $fixed_url = str_replace( 'HTTP://', '', $fixed_url );
54 - $fixed_parts = explode( '/', $fixed_url );
55 - $fixed_url = $fixed_parts[0];
56 -
57 - $id = '';
58 - $text = strpos( $fixed_url, 'VIMEO.COM' );
59 - if( $text !== false ) {
60 - $parsed = explode( '/', $url );
61 - if( is_array( $parsed ) ) {
62 - $id = array_pop( $parsed );
63 - }
64 - }
65 -
66 - return $id;
67 - }
68 -
6917 }
\ No newline at end of file
Index: trunk/extensions/Video/providers/SevenloadVideo.php
@@ -10,69 +10,15 @@
1111 * ?username=XYZ&token-id=8b8453ca4b79f500e94aac1fc7025b0704f3f2c7
1212 */
1313
14 -class SevenloadVideo extends FlashVideo {
 14+class SevenloadVideoProvider extends BaseVideoProvider {
 15+ protected $videoIdRegex = '#/([a-zA-Z0-9]+)-[a-zA-Z0-9\-]*?(?:(?:\#|\?).*?)?$#';
 16+ protected $embedTemplate = '<object type="application/x-shockwave-flash" data="http://en.sevenload.com/pl/$video_id/$widthx$height/swf" width="$width" height="$height"><param name="allowFullscreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="movie" value="http://en.sevenload.com/pl/$video_id/$widthx$height/swf" /></object>';
1517
16 - var $video,
17 - $id,
18 - $url;
19 -
20 - public function __construct( $video ) {
21 - if( !is_object( $video ) ) {
22 - throw new MWException( 'SevenloadVideo constructor given bogus video object.' );
23 - }
24 -
25 - $this->video =& $video;
26 - $this->video->ratio = 500 / 408;
27 - $this->id = $this->extractID( $this->video->getURL() );
28 - $this->url = 'http://www.sevenload.com/videos/' . $this->id;
29 - return $this;
 18+ protected function getRatio() {
 19+ return 500 / 408;
3020 }
3121
32 - public function getEmbedCode() {
33 - $output = '<object style="visibility: visible;" id="sevenloadPlayer_' . $this->id .
34 - '" data="http://static.sevenload.com/swf/player/player.swf" type="application/x-shockwave-flash" height="' .
35 - $this->video->getHeight() .
36 - '" width="' . $this->video->getWidth() . '">';
37 - $output .= '<param name="wmode" value="transparent">';
38 - $output .= '<param value="always" name="allowScriptAccess">';
39 - $output .= '<param value="true" name="allowFullscreen">';
40 - $output .= '<param value="configPath=http%3A%2F%2Fflash.sevenload.com%2Fplayer%3FportalId%3Den%26autoplay%3D0%26itemId%3D' . $this->id .
41 - '&amp;locale=en_US&amp;autoplay=0&amp;environment=" name="flashvars">';
42 - $output .= '</object>';
43 - return $output;
 22+ public static function getDomains() {
 23+ return array( 'sevenload.com' );
4424 }
45 -
46 - /**
47 - * Extract the video ID from its URL.
48 - * Copypasted from WikiaVideo's VideoPage.php's parseUrl().
49 - *
50 - * @return Integer: video ID
51 - */
52 - private function extractID() {
53 - $url = $this->video->getURL();
54 - $url = trim( $url );
55 -
56 - $fixed_url = strtoupper( $url );
57 - $test = strpos( $fixed_url, 'HTTP://' );
58 - if( !false === $test ) {
59 - return false;
60 - }
61 -
62 - $fixed_url = str_replace( 'HTTP://', '', $fixed_url );
63 - $fixed_parts = explode( '/', $fixed_url );
64 - $fixed_url = $fixed_parts[0];
65 -
66 - $id = '';
67 - $text = strpos( $fixed_url, 'SEVENLOAD.COM' );
68 - if( $text !== false ) {
69 - $parsed = explode( '/', $url );
70 - $id = array_pop( $parsed );
71 - $parsed_id = explode( '-', $id );
72 - if( is_array( $parsed_id ) ) {
73 - $id = $parsed_id[0];
74 - }
75 - }
76 - return $id;
77 - }
78 -
7925 }
\ No newline at end of file
Index: trunk/extensions/Video/providers/BaseVideoProvider.php
@@ -0,0 +1,105 @@
 2+<?php
 3+
 4+abstract class BaseVideoProvider {
 5+
 6+ /**
 7+ * Video object for this embed
 8+ *
 9+ * @var Video
 10+ */
 11+ protected $video;
 12+
 13+ /**
 14+ * Video ID
 15+ *
 16+ * @var string
 17+ */
 18+ protected $videoId = null;
 19+
 20+ /**
 21+ * Regular expression used to extract the video ID
 22+ *
 23+ * @var null
 24+ */
 25+ protected $videoIdRegex = null;
 26+
 27+ /**
 28+ * Template for embedding
 29+ *
 30+ * @var null
 31+ */
 32+ protected $embedTemplate = null;
 33+
 34+ public function __construct( $video ) {
 35+ if ( !($video instanceof Video) ) {
 36+ throw new MWException( 'Video Provider constructor given bogus video object.' );
 37+ }
 38+
 39+ $this->video = $video;
 40+ // TODO: This sucks fix it
 41+ $this->video->ratio = $this->getRatio();
 42+
 43+ $matches = array();
 44+ if ( $this->videoIdRegex !== null && preg_match( $this->videoIdRegex, $this->video->getURL(), $matches ) ) {
 45+ $this->videoId = $matches[1];
 46+ } else {
 47+ $this->videoId = $this->extractVideoId( $this->video->getURL() );
 48+ }
 49+
 50+ if ( $this->videoId === null ) {
 51+ return null;
 52+ }
 53+ }
 54+
 55+ /**
 56+ * Function to extract the video id
 57+ *
 58+ * Override to use instead of regular expression
 59+ *
 60+ * @param $url
 61+ * @return null
 62+ */
 63+ protected function extractVideoId( $url ) {
 64+ return null;
 65+ }
 66+
 67+ /**
 68+ * Returns the raw HTML to embed the video
 69+ *
 70+ * @return string
 71+ */
 72+ public function getEmbedCode() {
 73+ if ( $this->embedTemplate === null ) {
 74+ return '';
 75+ }
 76+
 77+ return str_replace( array(
 78+ '$video_id',
 79+ '$height',
 80+ '$width',
 81+ ), array(
 82+ $this->videoId,
 83+ $this->video->getHeight(),
 84+ $this->video->getWidth(),
 85+ ), $this->embedTemplate );
 86+ }
 87+
 88+ /**
 89+ * Returns the (aspect?) ratio for the video
 90+ *
 91+ * @return int
 92+ */
 93+ protected function getRatio() {
 94+ return 1;
 95+ }
 96+
 97+ /**
 98+ * Returns all domains associated with the provider
 99+ *
 100+ * @return array
 101+ */
 102+ public static function getDomains() {
 103+ return array();
 104+ }
 105+
 106+}
\ No newline at end of file
Property changes on: trunk/extensions/Video/providers/BaseVideoProvider.php
___________________________________________________________________
Added: svn:eol-style
1107 + native
Index: trunk/extensions/Video/providers/DailyMotionVideo.php
@@ -1,26 +1,15 @@
22 <?php
33
4 -class DailyMotionVideo extends FlashVideo {
 4+class DailyMotionVideoProvider extends BaseVideoProvider {
55
6 - var $video,
7 - $id,
8 - $url;
 6+ protected $videoIdRegex = '#/video/([a-zA-Z0-9]+)_.*#';
 7+ protected $embedTemplate = '<iframe frameborder="0" width="$width" height="$height" src="http://www.dailymotion.com/embed/video/$video_id"></iframe>';
98
10 - public function __construct( $video ) {
11 - if( !is_object( $video ) ) {
12 - throw new MWException( 'DailyMotionVideo constructor given bogus video object.' );
13 - }
14 - $this->video =& $video;
15 - $this->video->ratio = 425/335;
16 - $this->id = $this->extractID( $this->video->getURL() );
17 - $this->url = "http://www.dailymotion.com/swf/{$this->id}";
18 - return $this;
 9+ protected function getRatio() {
 10+ return 425 / 355;
1911 }
2012
21 - private function extractID() {
22 - $url = $this->video->getURL();
23 - $id = preg_replace( '%http\:\/\/www\.dailymotion\.com\/(swf|video)\/%i', '', $url );
24 - return $id;
 13+ public static function getDomains() {
 14+ return array( 'dailymotion.com' );
2515 }
26 -
2716 }
\ No newline at end of file
Index: trunk/extensions/Video/providers/ViddlerVideo.php
@@ -1,114 +1,46 @@
22 <?php
33
4 -class ViddlerVideo extends FlashVideo {
 4+class ViddlerVideoProvider extends BaseVideoProvider {
 5+ const idRegex = '#src="http://www\.viddler\.com/player/(?<id>[a-zA-Z0-9]*?)/"#';
 6+ protected $embedTemplate = '<object width="$width" height="$height" id="viddlerplayer-$video_id"><param name="movie" value="http://www.viddler.com/player/$video_id/" /><param name="allowScriptAccess" value="always" /><param name="wmode" value="transparent" /><param name="allowFullScreen" value="true" /><embed src="http://www.viddler.com/player/$video_id/" width="$width" height="$height" type="application/x-shockwave-flash" wmode="transparent" allowScriptAccess="always" allowFullScreen="true" name="viddlerplayer-$video_id" ></embed></object>';
57
6 - var $video,
7 - $id,
8 - $url;
 8+ public static function getDomains() {
 9+ return array( 'viddler.com' );
 10+ }
911
10 - /**
11 - * @var String: Viddler API key -- this is Wikia's :)
12 - */
13 - const API_KEY = 'hacouneo6n6o3nysn0em';
14 -
15 - public function __construct( $video ) {
16 - if( !is_object( $video ) ) {
17 - throw new MWException( 'ViddlerVideo constructor given bogus video object.' );
18 - }
19 -
20 - $this->video =& $video;
21 - $this->video->ratio = 437 / 288;
22 - $this->id = $this->extractID( $this->video->getURL() );
23 - // This needs to take from their API, since they're doing some conversion on their side
24 - // URL ID -> embedding ID
25 - // The above is what Bartek once wrote on the WikiaVideo extension.
26 - // I'm not sure if my code is correct, but if it's not, feel free to
27 - // correct me...
28 - //$this->url = $this->getURLToEmbed();
29 - $this->url = 'http://www.viddler.com/explore/' . $this->id;
30 - return $this;
 12+ protected function getRatio() {
 13+ return 437 / 288;
3114 }
3215
33 - /**
34 - * This function is a combination of WikiaVideo's getUrlToEmbed() and
35 - * getViddlerTrueID() functions.
36 - * I removed memcached support -- if it ever worked that must've
37 - * been good luck, because the code was just...well, wtf: it used
38 - * uninitialized $url variable in the memcached key.
39 - *
40 - * @return Mixed: false in case of failure or video URL in case of success
41 - */
42 - private function getURLToEmbed() {
43 - //global $wgMemc;
4416
45 - //$cacheKey = wfMemcKey( 'wvi', 'viddlerid', $this->id, $url );
46 - //$obj = $wgMemc->get( $cacheKey );
 17+ protected function extractVideoId( $url ) {
 18+ global $wgMemc;
4719
48 - //if ( isset( $obj ) ) {
49 - // return $obj;
50 - //}
 20+ $cacheKey = wfMemcKey( 'video', 'viddler', sha1( $url ) );
 21+ $cachedEmbedId = $wgMemc->get( $cacheKey );
5122
52 - $url = 'http://api.viddler.com/rest/v1/?method=viddler.videos.getDetailsByUrl&api_key=' .
53 - self::API_KEY . '&url=http://www.viddler.com/explore/' . $this->id;
54 - wfSuppressWarnings();
55 - $file = Http::get( $url );
56 - $doc = new DOMDocument( '1.0', 'UTF-8' );
57 - $doc->loadXML( $file );
58 - wfRestoreWarnings();
59 - $trueID = trim( $doc->getElementsByTagName( 'id' )->item( 0 )->textContent );
60 - if ( empty( $trueID ) ) {
61 - return false;
 23+ if ( $cachedEmbedId !== false ) {
 24+ return $cachedEmbedId;
6225 }
6326
64 - //$wgMemc->set( $cacheKey, $trueID, 60 * 60 * 24 );
 27+ $apiUrl = 'http://lab.viddler.com/services/oembed/?format=json&url=' . urlencode( $url );
 28+ $apiResult = HTTP::get( $apiUrl );
6529
66 - return 'http://www.viddler.com/player/' . $trueID . '/';
67 - }
 30+ if ( $apiResult === false ) {
 31+ return null;
 32+ }
6833
69 - public function getEmbedCode() {
70 - $height = $this->video->getHeight();
71 - $width = $this->video->getWidth();
72 - $url = $this->getURLToEmbed();
73 - $output = "<embed src=\"{$url}\" width=\"{$width}\" height=\"{$height}\" wmode=\"transparent\" allowScriptAccess=\"always\" allowfullscreen=\"true\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\"> </embed>";
74 - return $output;
75 - }
 34+ $apiResult = FormatJson::decode( $apiResult, true );
7635
77 - /**
78 - * Extract the video ID from its URL.
79 - * Copypasted from WikiaVideo's VideoPage.php's parseUrl().
80 - *
81 - * @return Integer: video ID
82 - */
83 - private function extractID() {
84 - $url = $this->video->getURL();
85 - $url = trim( $url );
86 -
87 - $fixed_url = strtoupper( $url );
88 - $test = strpos( $fixed_url, 'HTTP://' );
89 - if( !false === $test ) {
90 - return false;
 36+ // Extract the player source from the HTML
 37+ if ( !preg_match( self::idRegex, $apiResult['html'], $matches ) ) {
 38+ return null;
9139 }
9240
93 - $fixed_url = str_replace( 'HTTP://', '', $fixed_url );
94 - $fixed_parts = explode( '/', $fixed_url );
95 - $fixed_url = $fixed_parts[0];
 41+ $embedId = $matches['id'];
9642
97 - $id = '';
98 - $text = strpos( $fixed_url, 'VIDDLER.COM' );
99 - if( $text !== false ) {
100 - $parsed = explode( '/explore/', strtolower( $url ) );
101 - if( is_array( $parsed ) ) {
102 - $mdata = array_pop( $parsed );
103 - if ( ( $mdata != '' ) && ( strpos( $mdata, '?' ) === false ) ) {
104 - $id = $mdata;
105 - } else {
106 - $id = array_pop( $parsed );
107 - }
108 - if ( substr( $id, -1, 1 ) != '/' ) {
109 - $id .= '/';
110 - }
111 - }
112 - }
 43+ $wgMemc->set( $cacheKey, $embedId, 60 * 60 * 24 );
11344
114 - return $id;
 45+ return $embedId;
11546 }
 47+}
\ No newline at end of file
Index: trunk/extensions/Video/providers/SouthParkStudiosVideo.php
@@ -1,65 +1,17 @@
22 <?php
33
4 -class SouthParkStudiosVideo extends FlashVideo {
 4+class SouthParkStudiosVideoProvider extends MTVNetworksVideoProvider {
 5+ protected $videoRegexId = '#/clips/(\d+)/#';
56
6 - var $video,
7 - $id,
8 - $url;
9 -
10 - public function __construct( $video ) {
11 - if( !is_object( $video ) ) {
12 - throw new MWException( 'SouthParkStudiosVideo constructor given bogus video object.' );
13 - }
14 -
15 - $this->video =& $video;
16 - $this->video->ratio = 480 / 400;
17 - $this->id = $this->extractID( $this->video->getURL() );
18 - $this->url = 'http://www.southparkstudios.com/clips/' . $this->id;
19 - return $this;
 7+ public static function getDomains() {
 8+ return array( 'southparkstudios.com' );
209 }
2110
22 - public function getEmbedCode() {
23 - $height = $this->video->getHeight();
24 - $width = $this->video->getWidth();
25 - $output = '<embed src="http://media.mtvnservices.com/mgid:cms:item:southparkstudios.com:' . $this->id . '" width="' . $width . '" height="' . $height . '" type="application/x-shockwave-flash" wmode="window" flashVars="autoPlay=false&dist=http://www.southparkstudios.com&orig=" allowFullScreen="true" allowScriptAccess="always" allownetworking="all" bgcolor="#000000"></embed>';
26 - return $output;
27 - }
28 -
29 - /**
30 - * Extract the video ID from its URL.
31 - * Copypasted from WikiaVideo's VideoPage.php's parseUrl().
32 - *
33 - * @return Integer: video ID
34 - */
35 - private function extractID() {
36 - $url = $this->video->getURL();
37 - $url = trim( $url );
38 -
39 - $fixed_url = strtoupper( $url );
40 - $test = strpos( $fixed_url, 'HTTP://' );
41 - if( !false === $test ) {
42 - return false;
 11+ protected function extractVideoId( $url ) {
 12+ if ( !preg_match( '#/clips/(\d+)/#', $url, $matches ) ) {
 13+ return null;
4314 }
4415
45 - $fixed_url = str_replace( 'HTTP://', '', $fixed_url );
46 - $fixed_parts = explode( '/', $fixed_url );
47 - $fixed_url = $fixed_parts[0];
48 -
49 - $id = '';
50 - $text = strpos( $fixed_url, 'SOUTHPARKSTUDIOS.COM' );
51 - if( $text !== false ) {
52 - $parsed = explode( '/', $url );
53 - if( is_array( $parsed ) ) {
54 - $mdata = array_pop( $parsed );
55 - if ( ( $mdata != '' ) && ( strpos( $mdata, '?' ) === false ) ) {
56 - $id = $mdata;
57 - } else {
58 - $id = array_pop( $parsed );
59 - }
60 - }
61 - }
62 -
63 - return $id;
 16+ return "mgid:cms:item:southparkstudios.com:{$matches[1]}";
6417 }
65 -
6618 }
\ No newline at end of file
Index: trunk/extensions/Video/providers/YouTubeVideo.php
@@ -1,37 +1,16 @@
22 <?php
33
4 -class YouTubeVideo extends FlashVideo {
 4+class YouTubeVideoProvider extends BaseVideoProvider {
55
6 - var $video,
7 - $id,
8 - $url;
 6+ protected $videoIdRegex = '/.*v=([A-Za-z0-9-_]+).*/';
97
10 - public function __construct( $video ) {
11 - if( !is_object( $video ) ) {
12 - throw new MWException( 'YouTube constructor given bogus video object.' );
13 - }
14 - $this->video =& $video;
15 - $this->video->ratio = 425/355;
16 - $this->id = $this->extractYouTubeID( $this->video->getURL() );
17 - $this->url = "http://www.youtube.com/v/{$this->id}";
18 - return $this;
 8+ protected $embedTemplate = '<object width="$width" height="$height"><param name="movie" value="http://www.youtube.com/v/$video_id&fs=1"></param><param name="wmode" value="transparent"></param><param name="allowFullScreen" value="true"></param><embed src="http://www.youtube.com/v/$video_id&fs=1" type="application/x-shockwave-flash" wmode="transparent" allowFullScreen="true" width="$width" height="$height"></embed></object>';
 9+
 10+ protected function getRatio() {
 11+ return 425 / 355;
1912 }
2013
21 - private function extractYouTubeID() {
22 - // Standard YouTube URL
23 - $url = $this->video->getURL();
24 - $standard_youtube_inurl = strpos( strtoupper( $url ), 'WATCH?V=' );
25 -
26 - $id = '';
27 - if( $standard_youtube_inurl !== false ) {
28 - $id = substr( $url, $standard_youtube_inurl + 8, strlen( $url ) );
29 - }
30 - if( empty( $id ) ) {
31 - $id_test = str_replace( 'http://www.youtube.com/v/', '', $url );
32 - if( $id_test != $url ) {
33 - $id = $id_test;
34 - }
35 - }
36 - return $id;
 14+ public static function getDomains() {
 15+ return array( 'youtube.com' );
3716 }
3817 }
\ No newline at end of file
Index: trunk/extensions/Video/providers/BlipTVVideo.php
@@ -2,125 +2,49 @@
33 /**
44 * @file
55 */
6 -class BlipTVVideo extends FlashVideo {
 6+class BlipTVVideoProvider extends BaseVideoProvider {
 7+ protected $embedTemplate = '<iframe src="http://blip.tv/play/$video_id.html" width="$width" height="$height" frameborder="0" allowfullscreen></iframe>';
78
8 - var $video,
9 - $id,
10 - $url;
11 -
12 - public function __construct( $video ) {
13 - if( !is_object( $video ) ) {
14 - throw new MWException( 'BlipTVVideo constructor given bogus video object.' );
15 - }
16 -
17 - $this->video =& $video;
18 - $this->video->ratio = 480 / 350;
19 - $this->id = $this->extractID( $this->video->getURL() );
20 - $this->url = 'http://blip.tv/file/' . $this->id;
21 - return $this;
 9+ public static function getDomains() {
 10+ return array( 'blip.tv' );
2211 }
2312
24 - public function getEmbedCode() {
25 - $height = $this->video->getHeight();
26 - $width = $this->video->getWidth();
27 - $result = $this->getData();
28 - $url = 'http://blip.tv/play/' . $result['mTrueID'];
29 - $output = "<embed src=\"{$url}\" width=\"{$width}\" height=\"{$height}\" wmode=\"transparent\" allowScriptAccess=\"always\" allowfullscreen=\"true\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\"> </embed>";
30 - return $output;
 13+ protected function getRatio() {
 14+ return 480 / 350;
3115 }
 16+
 17+ protected function extractVideoId( $url ) {
 18+ global $wgMemc;
3219
33 - /**
34 - * Extract the video ID from its URL.
35 - *
36 - * @return Integer: video ID
37 - */
38 - private function extractID() {
39 - $url = $this->video->getURL();
40 - $url = trim( $url );
41 -
42 - $fixed_url = strtoupper( $url );
43 - $test = strpos( $fixed_url, 'HTTP://' );
44 - if( !false === $test ) {
45 - return false;
 20+ // See if this is a valid url
 21+ if ( !preg_match( '#/[a-zA-Z0-9\-]+/[a-zA-Z0-9\-]*-(\d+)#', $url, $matches ) ) {
 22+ return null;
4623 }
4724
48 - $fixed_url = str_replace( 'HTTP://', '', $fixed_url );
49 - $fixed_parts = explode( '/', $fixed_url );
50 - $fixed_url = $fixed_parts[0];
 25+ $videoId = $matches[1];
5126
52 - $id = '';
53 - $text = strpos( $fixed_url, 'BLIP.TV' );
54 - if( $text !== false ) {
55 - $blip = '';
56 - $parsed = explode( '/', $url );
57 - if( is_array( $parsed ) ) {
58 - $mdata = array_pop( $parsed );
59 - if ( $mdata != '' ) {
60 - $blip = $mdata;
61 - } else {
62 - $blip = array_pop( $parsed );
63 - }
64 - $last = explode( '?', $blip );
65 - $id = $last[0];
66 - }
67 - }
 27+ $cacheKey = wfMemcKey( 'video', 'bliptv', $videoId );
 28+ $cachedEmbedId = $wgMemc->get( $cacheKey );
6829
69 - return $id;
70 - }
71 -
72 - /**
73 - * Get BlipTV data (true ID and thumbnail URL) via their API and hold in
74 - * memcached.
75 - * Thumbnail URL isn't used anywhere at the moment
76 - *
77 - * @return Mixed: array containing the true ID number and thumbnail URL on
78 - * sucess, boolean false on failure
79 - */
80 - private function getData() {
81 - global $wgMemc;
82 -
83 - // Try memcached first
84 - $cacheKey = wfMemcKey( 'video', 'bliptv', $this->id, $url );
85 - $obj = $wgMemc->get( $cacheKey );
86 -
87 - // Got something? Super! We can return here and give the cached data to
88 - // the user instead of having to make a HTTP request to Blip.tv API.
89 - if ( isset( $obj ) ) {
90 - return $obj;
 30+ if ( $cachedEmbedId !== false ) {
 31+ return $cachedEmbedId;
9132 }
9233
93 - $url = 'http://blip.tv/file/' . $this->id . '?skin=rss&version=3';
 34+ list( $apiUrl ) = explode( '?', $url);
 35+ $apiUrl .= '?skin=api';
9436
95 - wfSuppressWarnings();
96 - $file = Http::get( $url );
97 - wfRestoreWarnings();
98 - if ( empty( $file ) ) {
99 - return false;
 37+ $apiContents = Http::get( $apiUrl );
 38+ if ( empty( $apiContents ) ) {
 39+ return null;
10040 }
101 - $doc = new DOMDocument( '1.0', 'UTF-8' );
102 - wfSuppressWarnings();
103 - $doc->loadXML( $file );
104 - wfRestoreWarnings();
10541
106 - $mTrueID = trim( $doc->getElementsByTagNameNS( 'http://blip.tv/dtd/blip/1.0', 'embedLookup' )->item( 0 )->textContent );
107 - $thumbnailUrl = trim( $doc->getElementsByTagNameNS( 'http://search.yahoo.com/mrss/', 'thumbnail' )->item( 0 )->getAttribute( 'url' ) );
108 - $mType = trim( $doc->getElementsByTagNameNS( 'http://blip.tv/dtd/blip/1.0', 'embedUrl' )->item( 0 )->getAttribute( 'type' ) );
 42+ $dom = new DOMDocument( '1.0', 'UTF-8' );
 43+ $dom->loadXML( $apiContents );
10944
110 - if (
111 - ( $mType !== 'application/x-shockwave-flash' ) ||
112 - ( empty( $mTrueID ) ) || ( empty( $thumbnailUrl ) )
113 - )
114 - {
115 - return false;
116 - }
 45+ $embedId = $dom->getElementsByTagName( 'embedLookup' )->item( 0 )->textContent;
11746
118 - $obj = array(
119 - 'mTrueID' => $mTrueID,
120 - 'thumbnailUrl' => $thumbnailUrl
121 - );
 47+ $wgMemc->set( $cacheKey, $embedId, 60 * 60 * 24 );
12248
123 - $wgMemc->set( $cacheKey, $obj, 60 * 60 * 24 );
124 -
125 - return $obj;
 49+ return $embedId;
12650 }
12751 }
\ No newline at end of file

Follow-up revisions

RevisionCommit summaryAuthorDate
r100104Follow up r100103, native line endingsjohnduhart00:44, 18 October 2011
r100146Follow up to r100103, us wfParseUrl instead of parse_urljohnduhart19:33, 18 October 2011

Comments

#Comment by Jack Phoenix (talk | contribs)   12:40, 18 October 2011

Awesome! :D

At first seeing six instances of "(deleted)" on this CR page scared me a bit, but then I looked at the VideoClass.php diff and found out the reasoning for each and every removal. As for Archive.org, the code should work but I never tested it, I just copypasted it from Nef's YouTube extension (at trunk/extensions/YouTube) and modified accordingly; I dunno about Gamevideos, its code was also borrowed from the aforementioned YouTube extension. As for the other three, I don't think that it's such a big loss even if we'd completely drop support for those...besides, everyone and their aunt seems to be using Facebook instead of MySpace nowadays, so supporting their videos instead of MySpace's might be a smart idea. :)

Should getProviderByURL() in VideoClass.php use parse_url() (as it currently does) or wfParseUrl()? If the usage of parse_url() there is intentional, you might want to add a code comment for future reviewers.

Could you also update the on-wiki extension page with up-to-date instructions on how to add a new video provider?

All in all, great job — people like you make open source awesome!

#Comment by Johnduhart (talk | contribs)   14:22, 18 October 2011

Thanks for the praise, it's what makes this worth it :)

I wasn't aware of wfParseUrl() so I'll take a look at that, it sounds like I should be using that.

I'll be updating the wiki page soon :)

Status & tagging log