Threw together a really quick hack FileRepo class to grab images from the remote wiki using the MediaWiki API.
Amazingly it sort of works -- be warned however:
* no scaling seems to be done yet -- multi-megapixel images in your browser :D
* no caching of lookups -- verrrry slow
* lookups are done one at a time, not in any kind of batching
* probably doesn't properly support lots and lots of things
'File' => 'includes/filerepo/File.php',
'FileRepo' => 'includes/filerepo/FileRepo.php',
'FileRepoStatus' => 'includes/filerepo/FileRepoStatus.php',
+ 'ForeignAPIFile' => 'includes/filerepo/ForeignAPIFile.php',
+ 'ForeignAPIRepo' => 'includes/filerepo/ForeignAPIRepo.php',
'ForeignDBFile' => 'includes/filerepo/ForeignDBFile.php',
'ForeignDBRepo' => 'includes/filerepo/ForeignDBRepo.php',
'ForeignDBViaLBRepo' => 'includes/filerepo/ForeignDBViaLBRepo.php',
--- /dev/null
+<?php
+
+// Very hacky and inefficient
+// do not use :D
+
+class ForeignAPIFile extends File {
+ function __construct( $title, $repo, $info ) {
+ parent::__construct( $title, $repo );
+
+ // For some reason API doesn't currently provide type info
+ $magic = MimeMagic::singleton();
+ $info['mime'] = $magic->guessTypesForExtension( $this->getExtension() );
+ list( $info['major_mime'], $info['minor_mime'] ) = self::splitMime( $info['mime'] );
+ $info['media_type'] = $magic->getMediaType( null, $info['mime'] );
+
+ $this->mInfo = $info;
+ }
+
+ // Dummy functions...
+ public function exists() {
+ return true;
+ }
+
+ public function getPath() {
+ return false;
+ }
+
+ function getThumbPath( $suffix = false ) {
+ return false; // hrmmm
+ }
+
+ function getThumbUrl( $suffix = false ) {
+ return false; // FLKDSJLKFDJS
+ }
+
+ // Info we can get from API...
+ public function getWidth( $page = 1 ) {
+ return intval( $this->mInfo['width'] );
+ }
+
+ public function getHeight( $page = 1 ) {
+ return intval( $this->mInfo['height'] );
+ }
+
+ public function getMetadata() {
+ return $this->mInfo['metadata'];
+ }
+
+ public function getSize() {
+ return intval( $this->mInfo['size'] );
+ }
+
+ public function getUrl() {
+ return $this->mInfo['url'];
+ }
+
+ public function getUser( $method='text' ) {
+ return $this->mInfo['user'];
+ }
+
+ public function getComment() {
+ return $this->mInfo['comment'];
+ }
+
+ // Info we had to guess...
+ function getMimeType() {
+ return $this->mInfo['mime'];
+ }
+
+ function getMediaType() {
+ return $this->mInfo['media_type'];
+ }
+}
--- /dev/null
+<?php
+
+/**
+ * File repository with no files, for performance testing
+ */
+
+class ForeignAPIRepo extends FileRepo {
+ function __construct( $info ) {
+ parent::__construct( $info );
+ $this->mApiBase = $info['apibase']; // http://commons.wikimedia.org/w/api.php
+ }
+
+ function storeBatch( $triplets, $flags = 0 ) {
+ return false;
+ }
+
+ function storeTemp( $originalName, $srcPath ) {
+ return false;
+ }
+ function publishBatch( $triplets, $flags = 0 ) {
+ return false;
+ }
+ function deleteBatch( $sourceDestPairs ) {
+ return false;
+ }
+ function getFileProps( $virtualUrl ) {
+ return false;
+ }
+ function newFile( $title, $time = false ) {
+ return false;
+ }
+ function findFile( $title, $time = false ) {
+ $url = $this->mApiBase .
+ '?' .
+ wfArrayToCgi( array(
+ 'format' => 'json',
+ 'action' => 'query',
+ 'titles' => $title, // fixme -- canonical namespacea
+ 'prop' => 'imageinfo',
+ 'iiprop' => 'timestamp|user|comment|url|size|sha1|metadata' ) );
+ $json = Http::get( $url );
+ $data = json_decode( $json, true );
+
+ if( isset( $data['query']['pages'] ) ) {
+ foreach( $data['query']['pages'] as $pageid => $info ) {
+ if( isset( $info['imageinfo'][0] ) ) {
+ return new ForeignAPIFile( $title, $this, $info['imageinfo'][0] );
+ }
+ }
+ }
+ return false;
+ }
+}
<?php
/**
- * A foreign repository with an accessible MediaWiki database
+ * A foreign repository with a remote MediaWiki with an API thingy
+ * Very hacky and inefficient
+ * do not use :D
*/
class ForeignDBRepo extends LocalRepo {