r54255 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r54254‎ | r54255 | r54256 >
Date:06:36, 3 August 2009
Author:dale
Status:deferred
Tags:
Comment:
* added flag $wgJs2VideoTagOut flag for use with js2 system ( $wgEnableJS2system )
** in video tag out mode, ogg handler outputs the video tag.
* added ( $wgEnableTemporalOggUrls ) for passing temporal url flag to mv_embed
** this enables mv_embed to optionally take advantage of oggz-chop server side for seeking with player that don't seek well and or don't cache well.
* moved $wgOgg[Video|Audio]Types to global for easy access from other extensions
* added msg for disabled javascript users with <video> tag output.
Modified paths:
  • /trunk/extensions/OggHandler/OggHandler.i18n.php (modified) (history)
  • /trunk/extensions/OggHandler/OggHandler.php (modified) (history)
  • /trunk/extensions/OggHandler/OggHandler_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/OggHandler/OggHandler.php
@@ -39,9 +39,17 @@
4040
4141 /******************* CONFIGURATION STARTS HERE **********************/
4242
 43+//set the supported ogg codecs:
 44+$wgOggVideoTypes = array( 'Theora' );
 45+$wgOggAudioTypes = array( 'Vorbis', 'Speex', 'FLAC' );
 46+
4347 //if wgPlayerStats collection is enabled or not
4448 $wgPlayerStatsCollection=false;
4549
 50+//if $wgEnableJS2system = true and the below variable is set to true
 51+// then we can output the <video> tag and its re-written by mv_embed
 52+$wgJs2VideoTagOut = true;
 53+
4654 // Location of the FFmpeg binary
4755 $wgFFmpegLocation = '/usr/bin/ffmpeg';
4856
Index: trunk/extensions/OggHandler/OggHandler_body.php
@@ -7,9 +7,6 @@
88
99 static $magicDone = false;
1010
11 - var $videoTypes = array( 'Theora' );
12 - var $audioTypes = array( 'Vorbis', 'Speex', 'FLAC' );
13 -
1411 function isEnabled() {
1512 return true;
1613 }
@@ -93,6 +90,7 @@
9491 }
9592
9693 function getImageSize( $file, $path, $metadata = false ) {
 94+ global $wgOggVideoTypes;
9795 // Just return the size of the first video stream
9896 if ( $metadata === false ) {
9997 $metadata = $file->getMetadata();
@@ -102,9 +100,9 @@
103101 return false;
104102 }
105103 foreach ( $metadata['streams'] as $stream ) {
106 - if ( in_array( $stream['type'], $this->videoTypes ) ) {
107 - return array(
108 - $stream['header']['PICW'],
 104+ if ( in_array( $stream['type'], $wgOggVideoTypes ) ) {
 105+ return array(
 106+ $stream['header']['PICW'],
109107 $stream['header']['PICH']
110108 );
111109 }
@@ -351,16 +349,16 @@
352350 }
353351
354352 function getShortDesc( $file ) {
355 - global $wgLang;
 353+ global $wgLang, $wgOggAudioTypes, $wgOggVideoTypes;
356354 wfLoadExtensionMessages( 'OggHandler' );
357355 $streamTypes = $this->getStreamTypes( $file );
358356 if ( !$streamTypes ) {
359357 return parent::getShortDesc( $file );
360358 }
361 - if ( array_intersect( $streamTypes, $this->videoTypes ) ) {
 359+ if ( array_intersect( $streamTypes, $wgOggVideoTypes ) ) {
362360 // Count multiplexed audio/video as video for short descriptions
363361 $msg = 'ogg-short-video';
364 - } elseif ( array_intersect( $streamTypes, $this->audioTypes ) ) {
 362+ } elseif ( array_intersect( $streamTypes, $wgOggAudioTypes ) ) {
365363 $msg = 'ogg-short-audio';
366364 } else {
367365 $msg = 'ogg-short-general';
@@ -370,20 +368,20 @@
371369 }
372370
373371 function getLongDesc( $file ) {
374 - global $wgLang;
 372+ global $wgLang, $wgOggVideoTypes, $wgOggAudioTypes;
375373 wfLoadExtensionMessages( 'OggHandler' );
376374 $streamTypes = $this->getStreamTypes( $file );
377375 if ( !$streamTypes ) {
378376 $unpacked = $this->unpackMetadata( $file->getMetadata() );
379377 return wfMsg( 'ogg-long-error', $unpacked['error']['message'] );
380378 }
381 - if ( array_intersect( $streamTypes, $this->videoTypes ) ) {
382 - if ( array_intersect( $streamTypes, $this->audioTypes ) ) {
 379+ if ( array_intersect( $streamTypes,$wgOggVideoTypes ) ) {
 380+ if ( array_intersect( $streamTypes, $wgOggAudioTypes ) ) {
383381 $msg = 'ogg-long-multiplexed';
384382 } else {
385383 $msg = 'ogg-long-video';
386384 }
387 - } elseif ( array_intersect( $streamTypes, $this->audioTypes ) ) {
 385+ } elseif ( array_intersect( $streamTypes, $wgOggAudioTypes ) ) {
388386 $msg = 'ogg-long-audio';
389387 } else {
390388 $msg = 'ogg-long-general';
@@ -426,32 +424,36 @@
427425
428426 function setHeaders( $out ) {
429427 global $wgOggScriptVersion, $wgCortadoJarFile, $wgServer, $wgUser, $wgScriptPath,
430 - $wgPlayerStatsCollection;
431 -
432 - if ( $out->hasHeadItem( 'OggHandler' ) ) {
433 - return;
434 - }
435 -
436 - wfLoadExtensionMessages( 'OggHandler' );
437 -
438 - $msgNames = array( 'ogg-play', 'ogg-pause', 'ogg-stop', 'ogg-no-player',
439 - 'ogg-player-videoElement', 'ogg-player-oggPlugin', 'ogg-player-cortado', 'ogg-player-vlc-mozilla',
440 - 'ogg-player-vlc-activex', 'ogg-player-quicktime-mozilla', 'ogg-player-quicktime-activex',
441 - 'ogg-player-totem', 'ogg-player-kaffeine', 'ogg-player-kmplayer', 'ogg-player-mplayerplug-in',
442 - 'ogg-player-thumbnail', 'ogg-player-selected', 'ogg-use-player', 'ogg-more', 'ogg-download',
443 - 'ogg-desc-link', 'ogg-dismiss', 'ogg-player-soundthumb', 'ogg-no-xiphqt' );
444 - $msgValues = array_map( 'wfMsg', $msgNames );
445 - $jsMsgs = Xml::encodeJsVar( (object)array_combine( $msgNames, $msgValues ) );
446 - $cortadoUrl = $wgCortadoJarFile;
447 - $scriptPath = self::getMyScriptPath();
448 - if( substr( $cortadoUrl, 0, 1 ) != '/'
449 - && substr( $cortadoUrl, 0, 4 ) != 'http' ) {
450 - $cortadoUrl = "$wgServer$scriptPath/$cortadoUrl";
451 - }
452 - $encCortadoUrl = Xml::encodeJsVar( $cortadoUrl );
453 - $encExtPathUrl = Xml::encodeJsVar( $scriptPath );
454 -
455 - $out->addHeadItem( 'OggHandler', <<<EOT
 428+ $wgPlayerStatsCollection, $wgJs2VideoTagOut, $wgEnableJS2system;
 429+
 430+ if( $wgJs2VideoTagOut && $wgEnableJS2system){
 431+ //all javascript is localized via script-loader
 432+ //and loaded on DOM ready if video tag is present
 433+ }else{
 434+ if ( $out->hasHeadItem( 'OggHandler' ) ) {
 435+ return;
 436+ }
 437+
 438+ wfLoadExtensionMessages( 'OggHandler' );
 439+
 440+ $msgNames = array( 'ogg-play', 'ogg-pause', 'ogg-stop', 'ogg-no-player',
 441+ 'ogg-player-videoElement', 'ogg-player-oggPlugin', 'ogg-player-cortado', 'ogg-player-vlc-mozilla',
 442+ 'ogg-player-vlc-activex', 'ogg-player-quicktime-mozilla', 'ogg-player-quicktime-activex',
 443+ 'ogg-player-totem', 'ogg-player-kaffeine', 'ogg-player-kmplayer', 'ogg-player-mplayerplug-in',
 444+ 'ogg-player-thumbnail', 'ogg-player-selected', 'ogg-use-player', 'ogg-more', 'ogg-download',
 445+ 'ogg-desc-link', 'ogg-dismiss', 'ogg-player-soundthumb', 'ogg-no-xiphqt' );
 446+ $msgValues = array_map( 'wfMsg', $msgNames );
 447+ $jsMsgs = Xml::encodeJsVar( (object)array_combine( $msgNames, $msgValues ) );
 448+ $cortadoUrl = $wgCortadoJarFile;
 449+ $scriptPath = self::getMyScriptPath();
 450+ if( substr( $cortadoUrl, 0, 1 ) != '/'
 451+ && substr( $cortadoUrl, 0, 4 ) != 'http' ) {
 452+ $cortadoUrl = "$wgServer$scriptPath/$cortadoUrl";
 453+ }
 454+ $encCortadoUrl = Xml::encodeJsVar( $cortadoUrl );
 455+ $encExtPathUrl = Xml::encodeJsVar( $scriptPath );
 456+
 457+ $out->addHeadItem( 'OggHandler', <<<EOT
456458 <script type="text/javascript" src="$scriptPath/OggPlayer.js?$wgOggScriptVersion"></script>
457459 <script type="text/javascript">
458460 wgOggPlayer.msg = $jsMsgs;
@@ -468,6 +470,7 @@
469471 </style>
470472 EOT
471473 );
 474+ }
472475
473476 //if collecting stats add relevant code:
474477 if( $wgPlayerStatsCollection ){
@@ -523,6 +526,7 @@
524527 }
525528
526529 function toHtml( $options = array() ) {
 530+ global $wgEnableTemporalOggUrls, $wgJs2VideoTagOut, $wgEnableJS2system;
527531 wfLoadExtensionMessages( 'OggHandler' );
528532 if ( count( func_get_args() ) == 2 ) {
529533 throw new MWException( __METHOD__ .' called in the old style' );
@@ -544,106 +548,154 @@
545549 $scriptPath = OggHandler::getMyScriptPath();
546550 $thumbDivAttribs = array();
547551 $showDescIcon = false;
548 - if ( $this->isVideo ) {
549 - $msgStartPlayer = wfMsg( 'ogg-play-video' );
550 - $imgAttribs = array(
551 - 'src' => $this->url,
552 - 'width' => $width,
553 - 'height' => $height,
554 - 'alt' => $alt );
555 - $playerHeight = $height;
556 - } else {
557 - // Sound file
558 - if ( $height > 100 ) {
559 - // Use a big file icon
 552+
 553+ //check if outputing to video tag or oggHandler
 554+ if( $wgJs2VideoTagOut && $wgEnableJS2system){
 555+ //video tag output:
 556+ if ( $this->isVideo ) {
 557+ $playerHeight = $height;
 558+ $thumb_url = $this->url;
 559+ }else{
 560+ // Sound file
560561 global $wgStylePath;
561 - $imgAttribs = array(
562 - 'src' => "$wgStylePath/common/images/icons/fileicon-ogg.png",
563 - 'width' => 125,
564 - 'height' => 125,
565 - 'alt' => $alt,
 562+ $thumb_url = "$wgStylePath/common/images/icons/fileicon-ogg.png";
 563+ if ( $height < 35 )
 564+ $playerHeight = 35;
 565+ else
 566+ $playerHeight = $height;
 567+ }
 568+ $id = "ogg_player_" . OggTransformOutput::$serial;
 569+ $linkAttribs = $this->getDescLinkAttribs( $alt );
 570+ $videoAttr = array(
 571+ 'id' => $id,
 572+ 'src' => $url,
 573+ 'style' => "width:{$width}px;height:{$playerHeight}px",
 574+ 'thumbnail'=>$thumb_url,
 575+ 'controls'=> 'true',
 576+ 'durationHint' => $length,
 577+ 'startOffset' => $offset,
 578+ 'linkback' => $linkAttribs['href']
 579+ );
 580+
 581+ if( $wgEnableTemporalOggUrls )
 582+ $videoAttr['URLTimeEncoding'] = 'true';
 583+
 584+ $s = Xml::tags( 'video', $videoAttr,
 585+ Xml::tags('div', array(
 586+ 'style'=>"overflow:hidden;".
 587+ "width:{$width}px;height:{$playerHeight}px"
 588+ ),
 589+ wfMsg('ogg-no-player-js', $url)
 590+ )
566591 );
567 - } else {
568 - // make an icon later if necessary
569 - $imgAttribs = false;
570 - $showDescIcon = !$this->noIcon;
571 - //$thumbDivAttribs = array( 'style' => 'text-align: right;' );
572 - }
573 - $msgStartPlayer = wfMsg( 'ogg-play-sound' );
574 - $playerHeight = 35;
575 - }
576 -
577 - // Set $thumb to the thumbnail img tag, or the thing that goes where
578 - // the thumbnail usually goes
579 - $descIcon = false;
580 - if ( !empty( $options['desc-link'] ) ) {
581 - $linkAttribs = $this->getDescLinkAttribs( $alt );
582 - if ( $showDescIcon ) {
583 - // Make image description icon link
 592+
 593+ return $s;
 594+
 595+
 596+ }else{
 597+ //oggHandler output:
 598+
 599+ if ( $this->isVideo ) {
 600+ $msgStartPlayer = wfMsg( 'ogg-play-video' );
584601 $imgAttribs = array(
585 - 'src' => "$scriptPath/info.png",
586 - 'width' => 22,
587 - 'height' => 22,
588 - 'alt' => $alt,
589 - );
590 - $linkAttribs['title'] = wfMsg( 'ogg-desc-link' );
591 - $descIcon = Xml::tags( 'a', $linkAttribs,
592 - Xml::element( 'img', $imgAttribs ) );
593 - $thumb = '';
594 - } elseif ( $imgAttribs ) {
595 - $thumb = Xml::tags( 'a', $linkAttribs,
596 - Xml::element( 'img', $imgAttribs ) );
 602+ 'src' => $this->url,
 603+ 'width' => $width,
 604+ 'height' => $height,
 605+ 'alt' => $alt );
 606+ $playerHeight = $height;
597607 } else {
598 - $thumb = '';
 608+ // Sound file
 609+ if ( $height > 100 ) {
 610+ // Use a big file icon
 611+ global $wgStylePath;
 612+ $imgAttribs = array(
 613+ 'src' => "$wgStylePath/common/images/icons/fileicon-ogg.png",
 614+ 'width' => 125,
 615+ 'height' => 125,
 616+ 'alt' => $alt,
 617+ );
 618+ } else {
 619+ // make an icon later if necessary
 620+ $imgAttribs = false;
 621+ $showDescIcon = !$this->noIcon;
 622+ //$thumbDivAttribs = array( 'style' => 'text-align: right;' );
 623+ }
 624+ $msgStartPlayer = wfMsg( 'ogg-play-sound' );
 625+ $playerHeight = 35;
599626 }
600 - $linkUrl = $linkAttribs['href'];
601 - } else {
602 - // We don't respect the file-link option, click-through to download is not appropriate
603 - $linkUrl = false;
604 - if ( $imgAttribs ) {
605 - $thumb = Xml::element( 'img', $imgAttribs );
 627+
 628+ // Set $thumb to the thumbnail img tag, or the thing that goes where
 629+ // the thumbnail usually goes
 630+ $descIcon = false;
 631+ if ( !empty( $options['desc-link'] ) ) {
 632+ $linkAttribs = $this->getDescLinkAttribs( $alt );
 633+ if ( $showDescIcon ) {
 634+ // Make image description icon link
 635+ $imgAttribs = array(
 636+ 'src' => "$scriptPath/info.png",
 637+ 'width' => 22,
 638+ 'height' => 22,
 639+ 'alt' => $alt,
 640+ );
 641+ $linkAttribs['title'] = wfMsg( 'ogg-desc-link' );
 642+ $descIcon = Xml::tags( 'a', $linkAttribs,
 643+ Xml::element( 'img', $imgAttribs ) );
 644+ $thumb = '';
 645+ } elseif ( $imgAttribs ) {
 646+ $thumb = Xml::tags( 'a', $linkAttribs,
 647+ Xml::element( 'img', $imgAttribs ) );
 648+ } else {
 649+ $thumb = '';
 650+ }
 651+ $linkUrl = $linkAttribs['href'];
606652 } else {
607 - $thumb = '';
 653+ // We don't respect the file-link option, click-through to download is not appropriate
 654+ $linkUrl = false;
 655+ if ( $imgAttribs ) {
 656+ $thumb = Xml::element( 'img', $imgAttribs );
 657+ } else {
 658+ $thumb = '';
 659+ }
608660 }
609 - }
610 -
611 - $id = "ogg_player_" . OggTransformOutput::$serial;
612 -
613 - $playerParams = Xml::encodeJsVar( (object)array(
614 - 'id' => $id,
615 - 'videoUrl' => $url,
616 - 'width' => $width,
617 - 'height' => $playerHeight,
618 - 'length' => $length,
619 - 'offset' => $offset,
620 - 'linkUrl' => $linkUrl,
621 - 'isVideo' => $this->isVideo ) );
622 -
623 - $s = Xml::tags( 'div',
624 - array(
625 - 'id' => $id,
626 - 'style' => "width: {$width}px;" ),
627 - ( $thumb ? Xml::tags( 'div', array(), $thumb ) : '' ) .
628 - Xml::tags( 'div', array(),
629 - Xml::tags( 'button',
630 - array(
631 - 'onclick' => "if (typeof(wgOggPlayer) != 'undefined') wgOggPlayer.init(false, $playerParams);",
632 - 'style' => "width: {$width}px; text-align: center",
633 - 'title' => $msgStartPlayer,
634 - ),
635 - Xml::element( 'img',
636 - array(
637 - 'src' => "$scriptPath/play.png",
638 - 'width' => 22,
639 - 'height' => 22,
640 - 'alt' => $msgStartPlayer
 661+
 662+ $id = "ogg_player_" . OggTransformOutput::$serial;
 663+
 664+ $playerParams = Xml::encodeJsVar( (object)array(
 665+ 'id' => $id,
 666+ 'videoUrl' => $url,
 667+ 'width' => $width,
 668+ 'height' => $playerHeight,
 669+ 'length' => $length,
 670+ 'offset' => $offset,
 671+ 'linkUrl' => $linkUrl,
 672+ 'isVideo' => $this->isVideo ) );
 673+
 674+ $s = Xml::tags( 'div',
 675+ array(
 676+ 'id' => $id,
 677+ 'style' => "width: {$width}px;" ),
 678+ ( $thumb ? Xml::tags( 'div', array(), $thumb ) : '' ) .
 679+ Xml::tags( 'div', array(),
 680+ Xml::tags( 'button',
 681+ array(
 682+ 'onclick' => "if (typeof(wgOggPlayer) != 'undefined') wgOggPlayer.init(false, $playerParams);",
 683+ 'style' => "width: {$width}px; text-align: center",
 684+ 'title' => $msgStartPlayer,
 685+ ),
 686+ Xml::element( 'img',
 687+ array(
 688+ 'src' => "$scriptPath/play.png",
 689+ 'width' => 22,
 690+ 'height' => 22,
 691+ 'alt' => $msgStartPlayer
 692+ )
641693 )
642694 )
643 - )
644 - ) .
645 - ( $descIcon ? Xml::tags( 'div', array(), $descIcon ) : '' )
646 - );
647 - return $s;
 695+ ) .
 696+ ( $descIcon ? Xml::tags( 'div', array(), $descIcon ) : '' )
 697+ );
 698+ return $s;
 699+ }
648700 }
649701 }
650702
Index: trunk/extensions/OggHandler/OggHandler.i18n.php
@@ -27,6 +27,9 @@
2828 'ogg-play-sound' => 'Play sound',
2929 'ogg-no-player' => 'Sorry, your system does not appear to have any supported player software.
3030 Please <a href="http://www.mediawiki.org/wiki/Extension:OggHandler/Client_download">download a player</a>.',
 31+ 'ogg-no-player-js' => 'Sorry, your system either has javascript disabled or does not have any supported player.<br>
 32+You can <a href="$1">Download the clip</a><br> or <br><a href="http://www.mediawiki.org/wiki/Extension:OggHandler/Client_download">download a player</a>
 33+to play the clip in your browser.',
3134 'ogg-no-xiphqt' => 'You do not appear to have the XiphQT component for QuickTime.
3235 QuickTime cannot play Ogg files without this component.
3336 Please <a href="http://www.mediawiki.org/wiki/Extension:OggHandler/Client_download">download XiphQT</a> or choose another player.',

Follow-up revisions

RevisionCommit summaryAuthorDate
r54259Follow-up r54255: tweak message for consistent spellingraymond09:32, 3 August 2009
r54504fix more breakage from r54255aaron04:06, 6 August 2009

Status & tagging log