/** @var FileBackend */
protected $backend;
+
/** @var Array Map of zones to config */
protected $zones = array();
- var $thumbScriptUrl, $transformVia404;
- var $descBaseUrl, $scriptDirUrl, $scriptExtension, $articleUrl;
- var $fetchDescription, $initialCapital;
- var $pathDisclosureProtection = 'simple'; // 'paranoid'
- var $descriptionCacheExpiry, $url, $thumbUrl;
- var $hashLevels, $deletedHashLevels;
+ /** @var string URL of thumb.php */
+ protected $thumbScriptUrl;
+
+ /** @var bool Whether to skip media file transformation on parse and rely
+ * on a 404 handler instead. */
+ protected $transformVia404;
+
+ /** @var string URL of image description pages, e.g.
+ * http://en.wikipedia.org/wiki/File:
+ */
+ protected $descBaseUrl;
+
+ /** @var string URL of the MediaWiki installation, equivalent to
+ * $wgScriptPath, e.g. https://en.wikipedia.org/w
+ */
+ protected $scriptDirUrl;
+
+ /** @var string Script extension of the MediaWiki installation, equivalent
+ * to $wgScriptExtension, e.g. .php5 defaults to .php */
+ protected $scriptExtension;
+
+ /** @var string Equivalent to $wgArticlePath, e.g. http://en.wikipedia.org/wiki/$1 */
+ protected $articleUrl;
+
+ /** @var bool Whether to fetch commons image description pages and display
+ * them on the local wiki */
+ public $fetchDescription;
+
+ /** @var bool Equivalent to $wgCapitalLinks (or $wgCapitalLinkOverrides[NS_FILE],
+ * determines whether filenames implicitly start with a capital letter.
+ * The current implementation may give incorrect description page links
+ * when the local $wgCapitalLinks and initialCapital are mismatched.
+ */
+ protected $initialCapital;
+
+ /** @var string May be 'paranoid' to remove all parameters from error
+ * messages, 'none' to leave the paths in unchanged, or 'simple' to
+ * replace paths with placeholders. Default for LocalRepo is
+ * 'simple'.
+ */
+ protected $pathDisclosureProtection = 'simple';
+
+ /** @var int */
+ public $descriptionCacheExpiry;
+
+ /** @var bool Public zone URL. */
+ protected $url;
+
+ /** @var string The base thumbnail URL. Defaults to "<url>/thumb". */
+ protected $thumbUrl;
+
+ /** @var int The number of directory levels for hash-based division of files */
+ protected $hashLevels;
+
+ /** @var int The number of directory levels for hash-based division of deleted files */
+ protected $deletedHashLevels;
+
+ /** @var int File names over this size will use the short form of thumbnail
+ * names. Short thumbnail names only have the width, parameters, and the
+ * extension.
+ */
protected $abbrvThreshold;
/**
* Factory functions for creating new files
* Override these in the base class
*/
- var $fileFactory = array( 'UnregisteredLocalFile', 'newFromTitle' );
- var $oldFileFactory = false;
- var $fileFactoryKey = false, $oldFileFactoryKey = false;
+ protected $fileFactory = array( 'UnregisteredLocalFile', 'newFromTitle' );
+ protected $oldFileFactory = false;
+ protected $fileFactoryKey = false;
+ protected $oldFileFactoryKey = false;
/**
* @param $info array|null
|| !array_key_exists( 'name', $info )
|| !array_key_exists( 'backend', $info )
) {
- throw new MWException( __CLASS__ . " requires an array of options having both 'name' and 'backend' keys.\n" );
+ throw new MWException( __CLASS__ .
+ " requires an array of options having both 'name' and 'backend' keys.\n" );
}
// Required settings
throw new MWException( "No '$zone' zone defined in the {$this->name} repo." );
}
}
+
return $status;
}
if ( $suffix !== false ) {
$path .= '/' . rawurlencode( $suffix );
}
+
return $path;
}
*
* @param string $zone One of: public, deleted, temp, thumb
* @param string|null $ext Optional file extension
- * @return String or false
+ * @return string|bool
*/
public function getZoneUrl( $zone, $ext = null ) {
- if ( in_array( $zone, array( 'public', 'temp', 'thumb', 'transcoded' ) ) ) { // standard public zones
+ if ( in_array( $zone, array( 'public', 'temp', 'thumb', 'transcoded' ) ) ) {
+ // standard public zones
if ( $ext !== null && isset( $this->zones[$zone]['urlsByExt'][$ext] ) ) {
- return $this->zones[$zone]['urlsByExt'][$ext]; // custom URL for extension/zone
+ // custom URL for extension/zone
+ return $this->zones[$zone]['urlsByExt'][$ext];
} elseif ( isset( $this->zones[$zone]['url'] ) ) {
- return $this->zones[$zone]['url']; // custom URL for zone
+ // custom URL for zone
+ return $this->zones[$zone]['url'];
}
}
switch ( $zone ) {
*/
public function getZoneHandlerUrl( $zone ) {
if ( isset( $this->zones[$zone]['handlerUrl'] )
- && in_array( $zone, array( 'public', 'temp', 'thumb', 'transcoded' ) ) )
- {
+ && in_array( $zone, array( 'public', 'temp', 'thumb', 'transcoded' ) )
+ ) {
return $this->zones[$zone]['handlerUrl'];
}
+
return false;
}
if ( !$base ) {
throw new MWException( __METHOD__ . ": invalid zone: $zone" );
}
+
return $base . '/' . rawurldecode( $rel );
}
if ( !isset( $this->zones[$zone] ) ) {
return array( null, null ); // bogus
}
+
return array( $this->zones[$zone]['container'], $this->zones[$zone]['directory'] );
}
if ( $base != '' ) { // may not be set
$base = "/{$base}";
}
+
return "mwstore://$backendName/{$container}{$base}";
}
}
if ( $img->exists() ) {
$img->redirectedFrom( $title->getDBkey() );
+
return $img;
}
}
+
return false;
}
$result[$file->getTitle()->getDBkey()] = $file;
}
}
+
return $result;
}
}
}
}
+
return false;
}
$result[$hash] = $files;
}
}
+
return $result;
}
}
/**
- * Get the name of an image from its title object
+ * Get the name of a file from its title object
*
* @param $title Title
* @return String
} else {
$name = $title->getDBkey();
}
+
return $name;
}
for ( $i = 1; $i <= $levels; $i++ ) {
$path .= substr( $hash, 0, $i ) . '/';
}
+
return $path;
}
}
public function makeUrl( $query = '', $entry = 'index' ) {
if ( isset( $this->scriptDirUrl ) ) {
$ext = isset( $this->scriptExtension ) ? $this->scriptExtension : '.php';
+
return wfAppendQuery( "{$this->scriptDirUrl}/{$entry}{$ext}", $query );
}
+
return false;
}
public function getDescriptionUrl( $name ) {
$encName = wfUrlencode( $name );
if ( !is_null( $this->descBaseUrl ) ) {
- # "http://example.com/wiki/Image:"
+ # "http://example.com/wiki/File:"
return $this->descBaseUrl . $encName;
}
if ( !is_null( $this->articleUrl ) ) {
# and just sort of hope index.php is right. ;)
return $this->makeUrl( "title=Image:$encName" );
}
+
return false;
}
return $this->makeUrl( 'title=MediaWiki:Filepage.css&' .
wfArrayToCgi( Skin::getDynamicStylesheetQuery() ) );
}
+
return false;
}
$temp = $this->getVirtualUrl( 'temp' );
if ( substr( $virtualUrl, 0, strlen( $temp ) ) != $temp ) {
wfDebug( __METHOD__ . ": Invalid temp virtual URL\n" );
+
return false;
}
*/
public function fileExists( $file ) {
$result = $this->fileExistsBatch( array( $file ) );
+
return $result[0];
}
$file = $this->resolveToStoragePath( $file );
$result[$key] = $this->backend->fileExists( array( 'src' => $file ) );
}
+
return $result;
}
for ( $i = 0; $i < $this->deletedHashLevels; $i++ ) {
$path .= $key[$i] . '/';
}
+
return $path;
}
if ( $this->isVirtualUrl( $path ) ) {
return $this->resolveVirtualUrl( $path );
}
+
return $path;
}
*/
public function getLocalCopy( $virtualUrl ) {
$path = $this->resolveToStoragePath( $virtualUrl );
+
return $this->backend->getLocalCopy( array( 'src' => $path ) );
}
*/
public function getLocalReference( $virtualUrl ) {
$path = $this->resolveToStoragePath( $virtualUrl );
+
return $this->backend->getLocalReference( array( 'src' => $path ) );
}
*/
public function getFileProps( $virtualUrl ) {
$path = $this->resolveToStoragePath( $virtualUrl );
+
return $this->backend->getFileProps( array( 'src' => $path ) );
}
*/
public function getFileTimestamp( $virtualUrl ) {
$path = $this->resolveToStoragePath( $virtualUrl );
+
return $this->backend->getFileTimestamp( array( 'src' => $path ) );
}
*/
public function getFileSize( $virtualUrl ) {
$path = $this->resolveToStoragePath( $virtualUrl );
+
return $this->backend->getFileSize( array( 'src' => $path ) );
}
*/
public function getFileSha1( $virtualUrl ) {
$path = $this->resolveToStoragePath( $virtualUrl );
+
return $this->backend->getFileSha1Base36( array( 'src' => $path ) );
}
public function streamFile( $virtualUrl, $headers = array() ) {
$path = $this->resolveToStoragePath( $virtualUrl );
$params = array( 'src' => $path, 'headers' => $headers );
+
return $this->backend->streamFile( $params )->isOK();
}
if ( strval( $filename ) == '' ) {
return false;
}
+
return FileBackend::isPathTraversalFree( $filename );
}
public function newFatal( $message /*, parameters...*/ ) {
$params = func_get_args();
array_unshift( $params, $this );
+
return call_user_func_array( array( 'FileRepoStatus', 'newFatal' ), $params );
}
* STUB
* @param $title Title of image
*/
- public function invalidateImageRedirect( Title $title ) {}
+ public function invalidateImageRedirect( Title $title ) {
+ }
/**
* Get the human-readable name of the repo
if ( $this->isLocal() ) {
return null;
}
+
// 'shared-repo-name-wikimediacommons' is used when $wgUseInstantCommons = true
return wfMessageFallback( 'shared-repo-name-' . $this->name, 'shared-repo' )->text();
}
$ext = FileBackend::extensionFromPath( $name );
$name = ( $ext == '' ) ? 'thumbnail' : "thumbnail.$ext";
}
+
return $name;
}
public function getLocalCacheKey( /*...*/ ) {
$args = func_get_args();
array_unshift( $args, 'filerepo', $this->getName() );
+
return call_user_func_array( 'wfMemcKey', $args );
}
),
'thumb' => array(
'container' => $this->zones['thumb']['container'],
- 'directory' => ( $this->zones['thumb']['directory'] == '' )
+ 'directory' => $this->zones['thumb']['directory'] == ''
? 'temp'
: $this->zones['thumb']['directory'] . '/temp'
),
'transcoded' => array(
'container' => $this->zones['transcoded']['container'],
- 'directory' => ( $this->zones['transcoded']['directory'] == '' )
+ 'directory' => $this->zones['transcoded']['directory'] == ''
? 'temp'
: $this->zones['transcoded']['directory'] . '/temp'
)
* @return void
* @throws MWException
*/
- protected function assertWritableRepo() {}
-
+ protected function assertWritableRepo() {
+ }
/**
* Return information about the repository.
* @since 1.22
*/
public function getInfo() {
- return array(
+ $ret = array(
'name' => $this->getName(),
'displayname' => $this->getDisplayName(),
- 'rootUrl' => $this->getRootUrl(),
+ 'rootUrl' => $this->getZoneUrl( 'public' ),
'local' => $this->isLocal(),
);
+
+ $optionalSettings = array(
+ 'url', 'thumbUrl', 'initialCapital', 'descBaseUrl', 'scriptDirUrl', 'articleUrl',
+ 'fetchDescription', 'descriptionCacheExpiry', 'scriptExtension'
+ );
+ foreach ( $optionalSettings as $k ) {
+ if ( isset( $this->$k ) ) {
+ $ret[$k] = $this->$k;
+ }
+ }
+
+ return $ret;
}
}