コード例 #1
0
 public function doSubmit()
 {
     global $wgOut, $wgRequest, $wgUser;
     $replaced = false;
     if ('' == $wgRequest->getVal('wpWikiaVideoAddName')) {
         if ('' != $wgRequest->getVal('wpWikiaVideoAddPrefilled')) {
             $this->mName = $wgRequest->getVal('wpWikiaVideoAddPrefilled');
             $replaced = true;
         } else {
             $this->mName = '';
         }
     } else {
         $this->mName = $wgRequest->getVal('wpWikiaVideoAddName');
     }
     '' != $wgRequest->getVal('wpWikiaVideoAddUrl') ? $this->mUrl = $wgRequest->getVal('wpWikiaVideoAddUrl') : ($this->mUrl = '');
     if ('' != $this->mName && '' != $this->mUrl) {
         $this->mName = ucfirst($this->mName);
         // sanitize all video titles
         $this->mName = VideoFileUploader::sanitizeTitle($this->mName);
         $title = Title::makeTitleSafe(NS_VIDEO, $this->mName);
         if ($title instanceof Title) {
             $permErrors = $title->getUserPermissionsErrors('edit', $wgUser);
             $permErrorsUpload = $title->getUserPermissionsErrors('upload', $wgUser);
             $permErrorsCreate = $title->exists() ? array() : $title->getUserPermissionsErrors('create', $wgUser);
             if ($permErrors || $permErrorsUpload || $permErrorsCreate) {
                 header('X-screen-type: error');
                 $wgOut->addWikiMsg('wva-protected');
                 return;
             }
             if (WikiaFileHelper::useVideoHandlersExtForEmbed()) {
                 $res = null;
                 try {
                     $res = VideoFileUploader::URLtoTitle($this->mUrl, $this->mName);
                 } catch (Exception $e) {
                 }
                 if (!$res) {
                     $wgOut->addHTML(wfMsg('wva-failure'));
                     return;
                 }
             }
             if (WikiaFileHelper::useWikiaVideoExtForEmbed()) {
                 $video = new VideoPage($title);
                 $video->parseUrl($this->mUrl);
                 $video->setName($this->mName);
                 $video->save();
             }
             $sk = RequestContext::getMain()->getSkin();
             $link_back = $sk->makeKnownLinkObj($title);
             if ($replaced) {
                 $wgOut->addHTML(wfMsg('wva-success-replaced', $link_back));
             } else {
                 $wgOut->addHTML(wfMsg('wva-success', $link_back));
             }
         } else {
             //bad title returned
             $wgOut->addHTML(wfMsg('wva-failure'));
         }
     } else {
         //one of two params blank
         $wgOut->addHTML(wfMsg('wva-failure'));
     }
 }
コード例 #2
0
	static function processVideo( $raw_video_name ) {
		global $wgExternalDatawareDB, $wgCityId, $providers;
		$dbw_dataware = wfGetDB( DB_MASTER, array(), $wgExternalDatawareDB );

		$status			= STATUS_UNKNOWN;
		$statusMsg		= '';
		$videoName		= substr($raw_video_name, 1);
		$isNameTaken	= 0;
		$meta			= '';
		$fullResponse	= '';
		$provider		= false;
		$thumbnail		= '';
		$apiUrl			= '';
		$videoOrgId		= '';
		$bl				= 0;


		// start processing video
		$titleOrg = Title::newFromText( $videoName, NS_VIDEO );
		$titleNew = Title::newFromText( $videoName, NS_FILE );

		if($titleNew && $titleNew->exists() ) {
			echo ("[CONFLICT] Article in NS_FILE namespace already exists\n");
			$isNameTaken = 1;
		}
		$videoOrg = new VideoPage( $titleOrg );
		$videoOrg->load();
		$videoOrgId = $videoOrg->getVideoId();
		$videoOrgProviderId = $videoOrg->getProvider();

		// ugly fix for ugly MW logic
		if ( empty( $videoOrgId ) || empty( $videoOrgProviderId ) ) {

			$titleOrg = Title::newFromText( 'Video:'.$videoName );
			$titleNew = Title::newFromText( 'File:'.$videoName );

			if($titleNew && $titleNew->exists() ) {
				echo ("[CONFLICT] Article in NS_FILE namespace already exists\n");
				$isNameTaken = 1;
			}
			$videoOrg = new VideoPage( $titleOrg );
			$videoOrg->load();
			$videoOrgId = $videoOrg->getVideoId();
			$videoOrgProviderId = $videoOrg->getProvider();
		}

		if(isset($backlinks[$raw_video_name])) {
			$bl = $backlinks[$raw_video_name];
		}

		if( !isset( $providers[ $videoOrgProviderId ] ) ) {
			echo ("Provider: unsupported ($videoOrgProviderId)\n");
			$status = STATUS_NOT_SUPPORTED;
		} else {
			$provider = $providers[ $videoOrgProviderId ];
			echo ("Provider: $provider\n");

			$retries = 0;
			$retry = true;
			while($retries < 20 && $retry) {
				try {
					$className = ucfirst( $provider ) . 'ApiWrapper';
					if(is_subclass_of($className, 'PseudoApiWrapper')) {
						$apiWrapper = F::build( $className, array( $videoName ) );
					} else {
						$apiWrapper = F::build( $className, array( $videoOrgId ) );
					}
					$meta = $apiWrapper->getMetadata();
					if( $retries == 0 ) {
						echo ("Got data\n");
					} else {
						echo ("Got data after $retries failed tries\n");
					}
					$status = STATUS_OK;
					$thumbnail = $apiWrapper->getThumbnailUrl();
					break;
				}

				catch( VideoNotFoundException $e ) {
					echo ("[ERROR] video not found\n");
					$retry = false;
					$status = STATUS_KNOWN_ERROR;
					$statusMsg = 'NOT_FOUND';
					if(!is_subclass_of($className, 'PseudoApiWrapper')) {
						// if a video failed that used regular provider
						// just get fake metadata (from old entry)
						$apiWrapper = F::build( 'FakeApiWrapper', array( $videoName ) );
						$meta = $apiWrapper->getMetadata();
					}
					break;
				}
				catch( VideoIsPrivateException $e ) {
					echo ("[ERROR] video is private\n");
					$retry = false;
					$status = STATUS_KNOWN_ERROR;
					$statusMsg = 'PRIVATE';
					if(!is_subclass_of($className, 'PseudoApiWrapper')) {
						// if a video failed that used regular provider
						// just get fake metadata (from old entry)
						$apiWrapper = F::build( 'FakeApiWrapper', array( $videoName ) );
						$meta = $apiWrapper->getMetadata();
					}
					break;
				}
				catch( VideoQuotaExceededException $e ) {
					echo ("[ERROR] quota exceeded, will retry\n");
					$retries += 1;
					sleep(2);
					continue;
				}
				catch( NegativeResponseException $e ) {
					echo ("[ERROR] negative response\n");
					$retry = false;
					$status = STATUS_UNKNOWN_ERROR;
					$fullResponse = $e->content;
					if(!is_subclass_of($className, 'PseudoApiWrapper')) {
						// if a video failed that used regular provider
						// just get fake metadata (from old entry)
						$apiWrapper = F::build( 'FakeApiWrapper', array( $videoName ) );
						$meta = $apiWrapper->getMetadata();
					}
					break;
				}
				catch( Exception $e ) {
					echo ("[ERROR] Unknown error: ". $e->getMessage() . "\n");
					// unknown error
					$retry = false;
					$status = STATUS_UNKNOWN_ERROR;
					$fullResponse = $e->getMessage();
					if( isset($e->apiUrl) ) {
						$apiUrl = $e->apiUrl;
					}
					if(!is_subclass_of($className, 'PseudoApiWrapper')) {
						// if a video failed that used regular provider
						// just get fake metadata (from old entry)
						$apiWrapper = F::build( 'FakeApiWrapper', array( $videoName ) );
						$meta = $apiWrapper->getMetadata();
					}
					break;
				}
			}
			if( $retries == 20 ) {
				echo ("[ERROR] unable to fetch metadata\n");
				$status = STATUS_UNKNOWN_ERROR;
				$statusMsg = 'TOO_MANY_RETRIES';
			}
		}



		$dbprovider = $provider ? $provider : $videoOrgProviderId;
		if(empty($dbprovider)) {
			$dbprovider = 'EMPTY';
		}

		$video = array(
			'img_name'		=> $videoName,
			'wiki_id'		=> $wgCityId,
			'provider'		=> $dbprovider,
			'new_metadata'	=> serialize($meta),
			'is_name_taken'	=> $isNameTaken,
			'status'		=> $status,
			'status_msg'	=> $statusMsg,
			'full_response'	=> serialize($fullResponse),
			'thumbnail_url'	=> $thumbnail,
			'api_url'		=> $apiUrl,
			'video_id'		=> $videoOrgId,
			'backlinks'		=> $bl,
		);

		if(isset(static::$previouslyProcessed[$videoName])) {
			// update

			// if status was unsupported and still is
			// no need to update
			if( static::$previouslyProcessed[$videoName]['status'] == STATUS_NOT_SUPPORTED && $status == STATUS_NOT_SUPPORTED ) {
				return (object)$video;
			}

			$dbw_dataware->update('video_premigrate',
				array(
					'provider' 		=> $dbprovider,
					'new_metadata'	=> serialize($meta),
					'is_name_taken'	=> $isNameTaken,
					'status'		=> $status,
					'status_msg'	=> $statusMsg,
					'full_response'	=> serialize($fullResponse),
					'thumbnail_url'	=> $thumbnail,
					'api_url'		=> $apiUrl,
					'video_id'		=> $videoOrgId,
					'backlinks'		=> $bl,
				),
				array(
					'img_name'		=> $videoName,
					'wiki_id'		=> $wgCityId,
				)
			);
		} else {
			// insert
			$dbw_dataware->insert('video_premigrate', $video );
		}

		return (object)$video;
	}
コード例 #3
0
	static function set_video_height($height) {
		self::$video_height = $height;
	}
コード例 #4
0
<?php
/*
NOTE:

You have to add 	webm|ogv|OGV|WEBM| to FilesMatch in assets/.htaccess 
*/

// let us upload webm and ogv files
File::$allowed_extensions = array_merge(File::$allowed_extensions, array('webm', 'ogv'));

// set video/poster dimensions
VideoPage::set_video_width(300);
VideoPage::set_video_height(200);


VideoPage::$video_types = array(
	'ogv' => 'video/ogg'
);

コード例 #5
0
ファイル: conflict.tmpl.php プロジェクト: schwarer2006/wikia
<?php

$title = Title::newFromText($name, NS_VIDEO);
$video_fake = new VideoPage($title);
$video_real = new VideoPage($title);
$video_fake->loadFromPars($provider, $id, $metadata);
$video_real->load();
echo wfMsg('vet-conflict-inf', $name);
?>
<table cellspacing="0" id="VideoEmbedConflictTable">
	<tr>
		<td style="border-right: 1px solid #CCC;">
			<h2><?php 
echo wfMsg('vet-rename');
?>
</h2>
			<div style="margin: 5px 0;">
				<input type="text" id="VideoEmbedRenameName" value="<?php 
echo $name;
?>
" />
				<input type="button" value="<?php 
echo wfMsg('vet-insert');
?>
" onclick="VET_insertFinalVideo(event, 'rename');" />
			</div>
		</td>
		<td>
			<h2><?php 
echo wfMsg('vet-existing');
?>