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 checkArticleDeleteComplete( &$article, &$user, $reason, $id ){ // Check if the article is a file and remove transcode files: if( $article->getTitle()->getNamespace() == NS_FILE ) { $file = wfFindFile( $article->getTitle() ); if( self::isTranscodableFile( $file ) ){ WebVideoTranscode::removeTranscodes( $file ); } } return true; }