addModules( array( 'ext.tmh.transcodetable' ) );
$o = '
' . wfMessage( 'timedmedia-status-header' )->escaped() . '
';
// Give the user a purge page link
$o.= Linker::link(
$file->getTitle(),
wfMessage('timedmedia-update-status')->escaped(),
array(),
array( 'action'=> 'purge' )
);
$o.= Xml::openElement( 'table', array( 'class' => 'wikitable mw-filepage-transcodestatus' ) ) . "\n"
. ''
. '' . wfMessage( 'timedmedia-transcodeinfo' )->escaped() . ' | '
. '' . wfMessage( 'timedmedia-transcodebitrate' )->escaped() . ' | '
. '' . wfMessage( 'timedmedia-direct-link' )->escaped() . ' | ';
if( $wgUser->isAllowed( 'transcode-reset' ) ) {
$o.= '' . wfMessage( 'timedmedia-actions' )->escaped() . ' | ';
}
$o.= '' . wfMessage( 'timedmedia-status' )->escaped() . ' | ';
$o.= '' . wfMessage( 'timedmedia-transcodeduration' )->escaped() . ' | ';
$o.= "
\n";
$o.= self::getTranscodeRows( $file );
$o.= Xml::closeElement( 'table' );
return $o;
}
/**
* Get the video or audio codec for the defined transcode,
* for grouping/sorting purposes.
*/
public static function codecFromTranscodeKey( $key ) {
if ( isset( WebVideoTranscode::$derivativeSettings[$key] ) ) {
$settings = WebVideoTranscode::$derivativeSettings[$key];
if ( isset( $settings['videoCodec'] ) ) {
return $settings['videoCodec'];
} else if ( isset( $settings['audioCodec'] ) ) {
return $settings['audioCodec'];
} else {
// this this shouldn't happen...
// fall through
}
} else {
// derivative type no longer defined or invalid def?
// fall through
}
return $key;
}
/**
* @param $file File
* @return string
*/
public static function getTranscodeRows( $file ){
global $wgUser, $wgLang;
$o='';
$transcodeRows = WebVideoTranscode::getTranscodeState( $file );
uksort( $transcodeRows, function( $a, $b ) {
$formatOrder = array( 'vp9', 'vp8', 'h264', 'theora', 'opus', 'vorbis', 'aac' );
$aFormat = self::codecFromTranscodeKey( $a );
$bFormat = self::codecFromTranscodeKey( $b );
$aIndex = array_search( $aFormat, $formatOrder );
$bIndex = array_search( $bFormat, $formatOrder );
if ( $aIndex === false && $bIndex === false ) {
return -strnatcmp( $a, $b );
} else if ( $aIndex === false ) {
return 1;
} else if ( $bIndex === false ) {
return -1;
} else if ( $aIndex === $bIndex ) {
return -strnatcmp( $a, $b );
} else {
return ( $aIndex - $bIndex );
}
} );
foreach( $transcodeRows as $transcodeKey => $state ){
$o.='';
// Encode info:
$o.='' . wfMessage('timedmedia-derivative-' . $transcodeKey )->escaped() . ' | ';
$o.='' . self::getTranscodeBitrate( $file, $state ) . ' | ';
// Download file
$o.='';
$o.= ( !is_null( $state['time_success'] ) ) ?
' ' .
wfMessage('timedmedia-download' )->escaped(). ' | ' :
wfMessage('timedmedia-not-ready' )->escaped();
$o.='';
// Check if we should include actions:
if( $wgUser->isAllowed( 'transcode-reset' ) ){
// include reset transcode action buttons
$o.='' . wfMessage('timedmedia-reset')->escaped() .
' | ';
}
// Status:
$o.='' . self::getStatusMsg( $file, $state ) . ' | ';
$o.='' . self::getTranscodeDuration( $file, $state ) . ' | ';
$o.='
';
}
return $o;
}
/**
* @param $file File
* @param $transcodeKey string
* @return string
*/
public static function getSourceUrl( $file, $transcodeKey ){
return WebVideoTranscode::getTranscodedUrlForFile( $file, $transcodeKey );
}
/**
* @param $file File
* @param $state
* @return string
*/
public static function getTranscodeDuration( $file, $state ) {
global $wgLang;
if( !is_null( $state['time_success'] ) ) {
$startTime = wfTimestamp( TS_UNIX, $state['time_startwork'] );
$endTime = wfTimestamp( TS_UNIX, $state['time_success'] );
$delta = $endTime - $startTime;
$duration = $wgLang->formatTimePeriod( $delta );
return $duration;
} else {
return '';
}
}
/**
* @param $file File
* @param $state
* @return string
*/
public static function getTranscodeBitrate( $file, $state ) {
global $wgLang;
if( !is_null( $state['time_success'] ) ) {
return $wgLang->formatBitrate( $state['final_bitrate'] );
} else {
return '';
}
}
/**
* @param $file File
* @param $state
* @return string
*/
public static function getStatusMsg( $file, $state ){
global $wgContLang;
// Check for success:
if( !is_null( $state['time_success'] ) ) {
return wfMessage( 'timedmedia-completed-on',
$wgContLang->timeAndDate( $state[ 'time_success' ] ) )->escaped();
}
// Check for error:
if( !is_null( $state['time_error'] ) ){
$attribs = array();
if( !is_null( $state['error'] ) ){
$attribs = array(
'class' => 'mw-tmh-pseudo-error-link',
'data-error' => $state['error'],
);
}
return Html::rawElement( 'span', $attribs,
wfMessage( 'timedmedia-error-on',
$wgContLang->timeAndDate( $state['time_error'] ) )->escaped()
);
}
//$db = wfGetDB( DB_SLAVE );
// Check for started encoding
if( !is_null( $state['time_startwork'] ) ){
$timePassed = time() - wfTimestamp ( TS_UNIX, $state['time_startwork'] );
// Get the rough estimate of time done: ( this is not very costly considering everything else
// that happens in an action=purge video page request )
/*$filePath = WebVideoTranscode::getTargetEncodePath( $file, $state['key'] );
if( is_file( $filePath ) ){
$targetSize = WebVideoTranscode::getProjectedFileSize( $file, $state['key'] );
if( $targetSize === false ){
$doneMsg = wfMessage( 'timedmedia-unknown-target-size', $wgLang->formatSize( filesize( $filePath ) ) )->escaped();
} else {
$doneMsg = wfMessage('timedmedia-percent-done', round( filesize( $filePath ) / $targetSize, 2 ) )->escaped();
}
} */
// Predicting percent done is not working well right now ( disabled for now )
$doneMsg = '';
return wfMessage(
'timedmedia-started-transcode',
TimedMediaHandler::getTimePassedMsg( $timePassed ), $doneMsg
)->escaped();
}
// Check for job added ( but not started encoding )
if( !is_null( $state['time_addjob'] ) ){
$timePassed = time() - wfTimestamp ( TS_UNIX, $state['time_addjob'] );
return wfMessage(
'timedmedia-in-job-queue',
TimedMediaHandler::getTimePassedMsg( $timePassed )
)->escaped();
}
// Return unknown status error:
return wfMessage('timedmedia-status-unknown')->escaped();
}
}