summaryrefslogtreecommitdiff
path: root/includes/filerepo/ForeignAPIFile.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/filerepo/ForeignAPIFile.php')
-rw-r--r--includes/filerepo/ForeignAPIFile.php83
1 files changed, 62 insertions, 21 deletions
diff --git a/includes/filerepo/ForeignAPIFile.php b/includes/filerepo/ForeignAPIFile.php
index c46b1f8f..56fed75e 100644
--- a/includes/filerepo/ForeignAPIFile.php
+++ b/includes/filerepo/ForeignAPIFile.php
@@ -1,8 +1,14 @@
<?php
+/**
+ * Foreign file accessible through api.php requests.
+ *
+ * @file
+ * @ingroup FileRepo
+ */
-/**
- * Very hacky and inefficient
- * do not use :D
+/**
+ * Foreign file accessible through api.php requests.
+ * Very hacky and inefficient, do not use :D
*
* @ingroup FileRepo
*/
@@ -15,16 +21,47 @@ class ForeignAPIFile extends File {
$this->mInfo = $info;
$this->mExists = $exists;
}
-
+
+ /**
+ * @static
+ * @param $title Title
+ * @param $repo ForeignApiRepo
+ * @return ForeignAPIFile|null
+ */
static function newFromTitle( $title, $repo ) {
- $info = $repo->getImageInfo( $title );
+ $data = $repo->fetchImageQuery( array(
+ 'titles' => 'File:' . $title->getDBKey(),
+ 'iiprop' => self::getProps(),
+ 'prop' => 'imageinfo' ) );
+
+ $info = $repo->getImageInfo( $data );
+
if( $info ) {
- return new ForeignAPIFile( $title, $repo, $info, true );
+ $lastRedirect = isset( $data['query']['redirects'] )
+ ? count( $data['query']['redirects'] ) - 1
+ : -1;
+ if( $lastRedirect >= 0 ) {
+ $newtitle = Title::newFromText( $data['query']['redirects'][$lastRedirect]['to']);
+ $img = new ForeignAPIFile( $newtitle, $repo, $info, true );
+ if( $img ) {
+ $img->redirectedFrom( $title->getDBkey() );
+ }
+ } else {
+ $img = new ForeignAPIFile( $title, $repo, $info, true );
+ }
+ return $img;
} else {
return null;
}
}
+ /**
+ * Get the property string for iiprop and aiprop
+ */
+ static function getProps() {
+ return 'timestamp|user|comment|url|size|sha1|metadata|mime';
+ }
+
// Dummy functions...
public function exists() {
return $this->mExists;
@@ -40,10 +77,10 @@ class ForeignAPIFile extends File {
return parent::transform( $params, $flags );
}
$thumbUrl = $this->repo->getThumbUrlFromCache(
- $this->getName(),
- isset( $params['width'] ) ? $params['width'] : -1,
- isset( $params['height'] ) ? $params['height'] : -1 );
- return $this->handler->getTransform( $this, 'bogus', $thumbUrl, $params );;
+ $this->getName(),
+ isset( $params['width'] ) ? $params['width'] : -1,
+ isset( $params['height'] ) ? $params['height'] : -1 );
+ return $this->handler->getTransform( $this, 'bogus', $thumbUrl, $params );
}
// Info we can get from API...
@@ -74,27 +111,33 @@ class ForeignAPIFile extends File {
}
public function getSize() {
- return intval( @$this->mInfo['size'] );
+ return isset( $this->mInfo['size'] ) ? intval( $this->mInfo['size'] ) : null;
}
public function getUrl() {
- return strval( @$this->mInfo['url'] );
+ return isset( $this->mInfo['url'] ) ? strval( $this->mInfo['url'] ) : null;
}
public function getUser( $method='text' ) {
- return strval( @$this->mInfo['user'] );
+ return isset( $this->mInfo['user'] ) ? strval( $this->mInfo['user'] ) : null;
}
public function getDescription() {
- return strval( @$this->mInfo['comment'] );
+ return isset( $this->mInfo['comment'] ) ? strval( $this->mInfo['comment'] ) : null;
}
function getSha1() {
- return wfBaseConvert( strval( @$this->mInfo['sha1'] ), 16, 36, 31 );
+ return isset( $this->mInfo['sha1'] ) ?
+ wfBaseConvert( strval( $this->mInfo['sha1'] ), 16, 36, 31 ) :
+ null;
}
function getTimestamp() {
- return wfTimestamp( TS_MW, strval( @$this->mInfo['timestamp'] ) );
+ return wfTimestamp( TS_MW,
+ isset( $this->mInfo['timestamp'] ) ?
+ strval( $this->mInfo['timestamp'] ) :
+ null
+ );
}
function getMimeType() {
@@ -122,15 +165,13 @@ class ForeignAPIFile extends File {
*/
function getThumbPath( $suffix = '' ) {
if ( $this->repo->canCacheThumbs() ) {
- global $wgUploadDirectory;
- $path = $wgUploadDirectory . '/thumb/' . $this->getHashPath( $this->getName() );
+ $path = $this->repo->getZonePath('thumb') . '/' . $this->getHashPath( $this->getName() );
if ( $suffix ) {
$path = $path . $suffix . '/';
}
return $path;
- }
- else {
- return null;
+ } else {
+ return null;
}
}