public function execute() { global $wgUser, $wgEnabledTranscodeSet, $wgEnableTranscode, $wgWaitTimeForTranscodeReset; // Check if transcoding is enabled on this wiki at all: if( !$wgEnableTranscode ){ $this->dieUsage( 'Transcode is disabled on this wiki', 'disabledtranscode' ); } // Confirm the user has the transcode-reset right if( !$wgUser->isAllowed( 'transcode-reset' ) ){ $this->dieUsage( 'You don\'t have permission to reset transcodes', 'missingpermission' ); } $params = $this->extractRequestParams(); // Make sure we have a valid Title $titleObj = Title::newFromText( $params['title'] ); if ( !$titleObj || $titleObj->isExternal() ) { $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) ); } // Make sure the title can be transcoded if( !TimedMediaHandlerHooks::isTranscodableTitle( $titleObj ) ){ $this->dieUsage( array( 'invalidtranscodetitle', $params['title'] ) ); } $transcodeKey = false; // Make sure its a enabled transcode key we are trying to remove: // ( if you update your transcode keys the api is not how you purge the database of expired keys ) if( isset( $params['transcodekey'] ) ){ global $wgEnabledTranscodeSet; if( !in_array( $params['transcodekey'], $wgEnabledTranscodeSet ) ){ $this->dieUsage( 'Invalid or disabled transcode key: ' . htmlspecialchars( $params['transcodekey'] ) , 'badtranscodekey' ); } else { $transcodeKey = $params['transcodekey']; } } // Don't reset if less than 1 hour has passed and we have no error ) $timeSinceLastReset = self::checkTimeSinceLastRest( $titleObj->getDBKey(), $transcodeKey ); if( $timeSinceLastReset < $wgWaitTimeForTranscodeReset){ $this->dieUsage( 'Not enough time has passed since the last reset of this transcode. ' . TimedMediaHandler::getTimePassedMsg( $wgWaitTimeForTranscodeReset - $timeSinceLastReset ) . ' until this transcode can be reset', 'notenoughtimereset'); } // All good do the transcode removal: WebVideoTranscode::removeTranscodes( $titleObj, $transcodeKey ); $this->getResult()->addValue(null, 'success', 'removed transcode'); }
public static function getStatusMsg( $file, $state ){ // Check for success: if( !is_null( $state['time_success'] ) ) { return wfMsgHtml('timedmedia-completed-on', $state['time_success'] ); } // Check for error: if( !is_null( $state['time_error'] ) ){ if( !is_null( $state['error'] ) ){ $showErrorLink = self::$linker->link( $file->getTitle(), wfMsg('timedmedia-show-error'), array( 'title' => wfMsgHtml('timedmedia-error-on', $state['time_error'] ), 'class' => 'errorlink', 'data-error' => $state['error'] )); } return wfMsgHtml('timedmedia-error-on', $state['time_error'] ) . $showErrorLink; } $db = wfGetDB( DB_SLAVE ); // Check for started encoding if( !is_null( $state['time_startwork'] ) ){ $timePassed = wfTimestampNow() - $db->timestamp( $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 = wfMsgHtml('timedmedia-unknown-target-size', $wgLang->formatSize( filesize( $filePath ) ) ); } else { $doneMsg = wfMsgHtml('timedmedia-percent-done', round( filesize( $filePath ) / $targetSize, 2 ) ); } } */ // Predicting percent done is not working well right now ( disabled for now ) $doneMsg = ''; return wfMsgHtml('timedmedia-started-transcode', TimedMediaHandler::getTimePassedMsg( $timePassed ), $doneMsg ); } // Check for job added ( but not started encoding ) if( !is_null( $state['time_addjob'] ) ){ $timePassed = wfTimestampNow() - $db->timestamp( $state['time_addjob'] ) ; return wfMsgHtml('timedmedia-in-job-queue', TimedMediaHandler::getTimePassedMsg( $timePassed ) ); } // Return unknown status error: return wfMsgHtml('timedmedia-status-unknown'); }