}
} elseif ( $namespace == NS_FILE ) {
# Show a hint to shared repo
- $file = wfFindFile( $this->mTitle );
+ $file = MediaWikiServices::getInstance()->getRepoGroup()->findFile( $this->mTitle );
if ( $file && !$file->isLocal() ) {
$descUrl = $file->getDescriptionUrl();
# there must be a description url to show a hint to shared repo
function wfIsBadImage( $name, $contextTitle = false, $blacklist = null ) {
# Handle redirects; callers almost always hit wfFindFile() anyway,
# so just use that method because it has a fast process cache.
- $file = wfFindFile( $name ); // get the final name
+ $file = MediaWikiServices::getInstance()->getRepoGroup()->findFile( $name ); // get the final name
$name = $file ? $file->getTitle()->getDBkey() : $name;
# Run the extension hook
# Use manually specified thumbnail
$manual_title = Title::makeTitleSafe( NS_FILE, $frameParams['manualthumb'] );
if ( $manual_title ) {
- $manual_img = wfFindFile( $manual_title );
+ $manual_img = MediaWikiServices::getInstance()->getRepoGroup()
+ ->findFile( $manual_title );
if ( $manual_img ) {
$thumb = $manual_img->getUnscaledThumb( $handlerParams );
$manualthumb = true;
$label = $title->getPrefixedText();
}
$encLabel = htmlspecialchars( $label );
- $currentExists = $time ? ( wfFindFile( $title ) != false ) : false;
+ $file = MediaWikiServices::getInstance()->getRepoGroup()->findFile( $title );
+ $currentExists = $time ? ( $file != false ) : false;
if ( ( $wgUploadMissingFileUrl || $wgUploadNavigationUrl || $wgEnableUploads )
&& !$currentExists
* @since 1.16.3
* @param LinkTarget $title
* @param string $html Pre-sanitized HTML
- * @param string $time MW timestamp of file creation time
+ * @param string|false $time MW timestamp of file creation time
* @return string HTML
*/
public static function makeMediaLinkObj( $title, $html = '', $time = false ) {
- $img = wfFindFile( $title, [ 'time' => $time ] );
+ $img = MediaWikiServices::getInstance()->getRepoGroup()->findFile(
+ $title, [ 'time' => $time ]
+ );
return self::makeMediaLinkFile( $title, $img, $html );
}
# Is it an existing file?
if ( $nt->getNamespace() == NS_FILE ) {
- $file = wfLocalFile( $nt );
+ $file = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo()
+ ->newFile( $nt );
$file->load( File::READ_LATEST );
if ( $file->exists() ) {
wfDebug( __METHOD__ . ": file exists\n" );
return true; // any interwiki link might be viewable, for all we know
}
+ $services = MediaWikiServices::getInstance();
switch ( $this->mNamespace ) {
case NS_MEDIA:
case NS_FILE:
// file exists, possibly in a foreign repo
- return (bool)wfFindFile( $this );
+ return (bool)$services->getRepoGroup()->findFile( $this );
case NS_SPECIAL:
// valid special page
- return MediaWikiServices::getInstance()->getSpecialPageFactory()->
- exists( $this->mDbkeyform );
+ return $services->getSpecialPageFactory()->exists( $this->mDbkeyform );
case NS_MAIN:
// selflink, possibly with fragment
return $this->mDbkeyform == '';
// Display image SHA-1 value
if ( $title->inNamespace( NS_FILE ) ) {
- $fileObj = wfFindFile( $title );
+ $fileObj = $services->getRepoGroup()->findFile( $title );
if ( $fileObj !== false ) {
// Convert the base-36 sha1 value obtained from database to base-16
$output = Wikimedia\base_convert( $fileObj->getSha1(), 36, 16, 40 );
<?php
+
+use MediaWiki\MediaWikiServices;
+
/**
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
}
}
- $file = wfFindFile( $title, [ 'latest' => true ] );
+ $file = MediaWikiServices::getInstance()->getRepoGroup()->findFile(
+ $title, [ 'latest' => true ]
+ );
if ( !$file ) {
$r['result'] = 'Failure';
$r['errors'] = $this->getErrorFormatter()->arrayFromStatus(
* @file
*/
+use MediaWiki\MediaWikiServices;
+
/**
* API Module to move pages
* @ingroup API
if ( $toTitle->getNamespace() == NS_FILE
&& !RepoGroup::singleton()->getLocalRepo()->findFile( $toTitle )
- && wfFindFile( $toTitle )
+ && MediaWikiServices::getInstance()->getRepoGroup()->findFile( $toTitle )
) {
if ( !$params['ignorewarnings'] && $user->isAllowed( 'reupload-shared' ) ) {
$this->dieWithError( 'apierror-fileexists-sharedrepo-perm' );
if ( !isset( $images[$title] ) ) {
if ( isset( $prop['uploadwarning'] ) || isset( $prop['badfile'] ) ) {
// uploadwarning and badfile need info about non-existing files
- $images[$title] = wfLocalFile( $title );
+ $images[$title] = MediaWikiServices::getInstance()->getRepoGroup()
+ ->getLocalRepo()->newFile( $title );
// Doesn't exist, so set an empty image repository
$info['imagerepository'] = '';
} else {
<?php
+use MediaWiki\MediaWikiServices;
+
/**
* Content handler for File: files
* TODO: this handler s not used directly now,
if ( NS_FILE != $title->getNamespace() ) {
return [];
}
- $file = wfLocalFile( $title );
+ $file = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo()
+ ->newFile( $title );
if ( !$file || !$file->exists() ) {
return [];
}
}
if ( $t->inNamespace( NS_FILE ) ) {
- $entities[] = wfLocalFile( $t->getText() );
+ $entities[] = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo()
+ ->newFile( $t->getText() );
}
if ( $t->inNamespace( NS_USER ) ) {
$entities[] = User::newFromName( $t->getText(), false );
*/
function writeUploads( $row, $dumpContents = false ) {
if ( $row->page_namespace == NS_FILE ) {
- $img = wfLocalFile( $row->page_title );
+ $img = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo()
+ ->newFile( $row->page_title );
if ( $img && $img->exists() ) {
$out = '';
foreach ( array_reverse( $img->getHistory() ) as $ver ) {
*
* RepoGroup::singleton()->getLocalRepo()->newFile( $title );
*
- * The convenience functions wfLocalFile() and wfFindFile() should be sufficient
- * in most cases.
+ * Consider the services container below;
+ *
+ * $services = MediaWikiServices::getInstance();
+ *
+ * The convenience services $services->getRepoGroup()->getLocalRepo()->newFile()
+ * and $services->getRepoGroup()->findFile() should be sufficient in most cases.
+ *
+ * @TODO: DI - Instead of using MediaWikiServices::getInstance(), a service should
+ * ideally accept a RepoGroup in its constructor and then, use $this->repoGroup->findFile()
+ * and $this->repoGroup->getLocalRepo()->newFile().
*
* @ingroup FileAbstraction
*/
*
* RepoGroup::singleton()->getLocalRepo()->newFile( $title );
*
- * The convenience functions wfLocalFile() and wfFindFile() should be sufficient
- * in most cases.
+ * Consider the services container below;
+ *
+ * $services = MediaWikiServices::getInstance();
+ *
+ * The convenience services $services->getRepoGroup()->getLocalRepo()->newFile()
+ * and $services->getRepoGroup()->findFile() should be sufficient in most cases.
+ *
+ * @TODO: DI - Instead of using MediaWikiServices::getInstance(), a service should
+ * ideally accept a RepoGroup in its constructor and then, use $this->repoGroup->findFile()
+ * and $this->repoGroup->getLocalRepo()->newFile().
*
* @ingroup FileAbstraction
*/
* @return Status
*/
function move( $target ) {
+ $localRepo = MediaWikiServices::getInstance()->getRepoGroup();
if ( $this->getRepo()->getReadOnlyReason() !== false ) {
return $this->readOnlyFatalStatus();
}
wfDebugLog( 'imagemove', "Finished moving {$this->name}" );
// Purge the source and target files...
- $oldTitleFile = wfLocalFile( $this->title );
- $newTitleFile = wfLocalFile( $target );
+ $oldTitleFile = $localRepo->findFile( $this->title );
+ $newTitleFile = $localRepo->findFile( $target );
// To avoid slow purges in the transaction, move them outside...
DeferredUpdates::addUpdate(
new AutoCommitUpdate(
* @ingroup FileAbstraction
*/
+use MediaWiki\MediaWikiServices;
use Wikimedia\Rdbms\IDatabase;
/**
public function execute() {
$repo = $this->file->repo;
$status = $repo->newGood();
- $destFile = wfLocalFile( $this->target );
+ $destFile = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo()
+ ->newFile( $this->target );
$this->file->lock();
$destFile->lock(); // quickly fail if destination is not available
<?php
+
+use MediaWiki\MediaWikiServices;
+
/**
* Image gallery.
*
# Fetch and register the file (file title may be different via hooks)
list( $img, $nt ) = $this->mParser->fetchFileAndTitle( $nt, $options );
} else {
- $img = wfFindFile( $nt );
+ $img = MediaWikiServices::getInstance()->getRepoGroup()->findFile( $nt );
}
} else {
$img = false;
$file = OldLocalFile::newFromArchiveName( $importableRevision->getTitle(),
RepoGroup::singleton()->getLocalRepo(), $archiveName );
} else {
- $file = wfLocalFile( $importableRevision->getTitle() );
+ $file = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo()
+ ->newFile( $importableRevision->getTitle() );
$file->load( File::READ_LATEST );
$this->logger->debug( __METHOD__ . 'Importing new file as ' . $file->getName() . "\n" );
if ( $file->exists() && $file->getTimestamp() > $importableRevision->getTimestamp() ) {
* @ingroup JobQueue
*/
+use MediaWiki\MediaWikiServices;
+
/**
* Job for asynchronous rendering of thumbnails.
*
$transformParams = $this->params['transformParams'];
- $file = wfLocalFile( $this->title );
+ $file = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo()
+ ->newFile( $this->title );
$file->load( File::READ_LATEST );
if ( $file && $file->exists() ) {
Hooks::run( 'ImagePageFindFile', [ $this, &$img, &$this->displayImg ] );
if ( !$img ) { // not set by hook?
- $img = wfFindFile( $this->getTitle() );
+ $services = MediaWikiServices::getInstance();
+ $img = $services->getRepoGroup()->findFile( $this->getTitle() );
if ( !$img ) {
- $img = wfLocalFile( $this->getTitle() );
+ $img = $services->getRepoGroup()->getLocalRepo()->newFile( $this->getTitle() );
}
}
$this->mPage->setFile( $img );
$restoreFiles = $restoreAll || !empty( $fileVersions );
if ( $restoreFiles && $this->title->getNamespace() == NS_FILE ) {
- $img = wfLocalFile( $this->title );
+ /** @var LocalFile $img */
+ $img = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo()
+ ->newFile( $this->title );
$img->load( File::READ_LATEST );
$this->fileStatus = $img->restore( $fileVersions, $unsuppress );
if ( !$this->fileStatus->isOK() ) {
* @file
*/
+use MediaWiki\MediaWikiServices;
use Wikimedia\Rdbms\FakeResultWrapper;
/**
* @return bool
*/
protected function loadFile() {
+ $services = MediaWikiServices::getInstance();
if ( $this->mFileLoaded ) {
return true;
}
$this->mFileLoaded = true;
- $this->mFile = wfFindFile( $this->mTitle );
+ $this->mFile = $services->getRepoGroup()->findFile( $this->mTitle );
if ( !$this->mFile ) {
- $this->mFile = wfLocalFile( $this->mTitle ); // always a File
+ $this->mFile = $services->getRepoGroup()->getLocalRepo()
+ ->newFile( $this->mTitle ); // always a File
}
$this->mRepo = $this->mFile->getRepo();
return true;
* @return array|string
*/
public static function filepath( $parser, $name = '', $argA = '', $argB = '' ) {
- $file = wfFindFile( $name );
+ $file = MediaWikiServices::getInstance()->getRepoGroup()->findFile( $name );
if ( $argA == 'nowiki' ) {
// {{filepath: | option [| size] }}
} elseif ( isset( $options['sha1'] ) ) { // get by (sha1,timestamp)
$file = RepoGroup::singleton()->findFileFromKey( $options['sha1'], $options );
} else { // get by (name,timestamp)
- $file = wfFindFile( $title, $options );
+ $file = MediaWikiServices::getInstance()->getRepoGroup()->findFile( $title, $options );
}
return $file;
}
* @ingroup RevisionDelete
*/
+use MediaWiki\MediaWikiServices;
use Wikimedia\Rdbms\IDatabase;
/**
}
public function doPostCommitUpdates( array $visibilityChangeMap ) {
- $file = wfLocalFile( $this->title );
+ $file = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo()
+ ->newFile( $this->title );
$file->purgeCache();
$file->purgeDescription();
<?php
+use MediaWiki\MediaWikiServices;
+
/**
* Implementation of near match title search.
* TODO: split into service/implementation.
# There may have been a funny upload, or it may be on a shared
# file repository such as Wikimedia Commons.
if ( $title->getNamespace() == NS_FILE ) {
- $image = wfFindFile( $title );
+ $image = MediaWikiServices::getInstance()->getRepoGroup()->findFile( $title );
if ( $image ) {
return $title;
}
*/
protected function initFromTitle( $title ) {
$this->mTitle = $title;
+ $services = MediaWikiServices::getInstance();
if ( !is_null( $this->mTitle ) ) {
$id = false;
Hooks::run( 'SearchResultInitFromTitle', [ $title, &$id ] );
$this->mRevision = Revision::newFromTitle(
$this->mTitle, $id, Revision::READ_NORMAL );
if ( $this->mTitle->getNamespace() === NS_FILE ) {
- $this->mImage = wfFindFile( $this->mTitle );
+ $this->mImage = $services->getRepoGroup()->findFile( $this->mTitle );
}
}
- $this->searchEngine = MediaWikiServices::getInstance()->newSearchEngine();
+ $this->searchEngine = $services->newSearchEngine();
}
/**
$this->hash = '';
$title = Title::newFromText( $this->filename, NS_FILE );
if ( $title && $title->getText() != '' ) {
- $this->file = wfFindFile( $title );
+ $this->file = MediaWikiServices::getInstance()->getRepoGroup()->findFile( $title );
}
$out = $this->getOutput();
if ( $nt->getNamespace() == NS_FILE
&& !( $this->moveOverShared && $user->isAllowed( 'reupload-shared' ) )
&& !RepoGroup::singleton()->getLocalRepo()->findFile( $nt )
- && wfFindFile( $nt )
+ && MediaWikiServices::getInstance()->getRepoGroup()->findFile( $nt )
) {
$this->showForm( [ [ 'file-exists-sharedrepo' ] ] );
// Delete an associated image if there is
if ( $nt->getNamespace() == NS_FILE ) {
- $file = wfLocalFile( $nt );
+ $file = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo()
+ ->newFile( $nt );
$file->load( File::READ_LATEST );
if ( $file->exists() ) {
$file->delete( $reason, false, $user );
* @ingroup SpecialPage
*/
+use MediaWiki\MediaWikiServices;
+
/**
* A special page that redirects to: the user for a numeric user id,
* the file for a given filename, or the page for a given revision id.
} catch ( MalformedTitleException $e ) {
return Status::newFatal( $e->getMessageObject() );
}
- $file = wfFindFile( $title );
+ $file = MediaWikiServices::getInstance()->getRepoGroup()->findFile( $title );
if ( !$file || !$file->exists() ) {
// Message: redirect-not-exists
return true;
}
- $local = wfLocalFile( $this->mDesiredDestName );
+ $local = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo()
+ ->newFile( $this->mDesiredDestName );
if ( $local && $local->exists() ) {
// We're uploading a new version of an existing file.
// No creation, so don't watch it if we're not already.
* @author Soxred93 <soxred93@gmail.com>
*/
+use MediaWiki\MediaWikiServices;
+
/**
* Querypage that lists the most wanted files
*
/**
* Does the file exist?
*
- * Use wfFindFile so we still think file namespace pages without
- * files are missing, but valid file redirects and foreign files are ok.
+ * Use findFile() so we still think file namespace pages without files
+ * are missing, but valid file redirects and foreign files are ok.
*
* @param Title $title
* @return bool
*/
protected function existenceCheck( Title $title ) {
- return (bool)wfFindFile( $title );
+ return (bool)MediaWikiServices::getInstance()->getRepoGroup()->findFile( $title );
}
function getQueryInfo() {
* @throws MWException
*/
function formatValue( $field, $value ) {
- $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
+ $services = MediaWikiServices::getInstance();
+ $linkRenderer = $services->getLinkRenderer();
switch ( $field ) {
case 'thumb':
$opt = [ 'time' => wfTimestamp( TS_MW, $this->mCurrentRow->img_timestamp ) ];
$filePage,
$filePage->getText()
);
- $download = Xml::element( 'a',
- [ 'href' => wfLocalFile( $filePage )->getUrl() ],
+ $download = Xml::element(
+ 'a',
+ [ 'href' => $services->getRepoGroup()->findFile( $filePage )->getUrl() ],
$imgfile
);
$download = $this->msg( 'parentheses' )->rawParams( $download )->escaped();
$partname = $n ? substr( $filename, 0, $n ) : $filename;
return (
- substr( $partname, 3, 3 ) == 'px-' ||
- substr( $partname, 2, 3 ) == 'px-'
- ) &&
- preg_match( "/[0-9]{2}/", substr( $partname, 0, 2 ) );
+ substr( $partname, 3, 3 ) == 'px-' ||
+ substr( $partname, 2, 3 ) == 'px-'
+ ) &&
+ preg_match( "/[0-9]{2}/", substr( $partname, 0, 2 ) );
}
/**
use Hooks;
use HtmlArmor;
use MediaWiki\Linker\LinkRenderer;
+use MediaWiki\MediaWikiServices;
use SearchResult;
use SpecialSearch;
use Title;
$descHtml = null;
$thumbHtml = null;
- $img = $result->getFile() ?: wfFindFile( $title );
+ $img = $result->getFile() ?: MediaWikiServices::getInstance()->getRepoGroup()
+ ->findFile( $title );
if ( $img ) {
$thumb = $img->transform( [ 'width' => 120, 'height' => 120 ] );
if ( $thumb ) {
* @ingroup Maintenance
*/
+use MediaWiki\MediaWikiServices;
+
require_once __DIR__ . '/Maintenance.php';
/**
$this->output( $title->getPrefixedText() );
if ( $title->getNamespace() == NS_FILE ) {
- $img = wfFindFile( $title, [ 'ignoreRedirect' => true ] );
+ $img = MediaWikiServices::getInstance()->getRepoGroup()->findFile(
+ $title, [ 'ignoreRedirect' => true ]
+ );
if ( $img && $img->isLocal() && !$img->delete( $reason ) ) {
$this->output( " FAILED to delete associated file... " );
}
* @ingroup Maintenance
*/
+use MediaWiki\MediaWikiServices;
+
require_once __DIR__ . '/Maintenance.php';
/**
}
function outputItem( $name, $shared ) {
- $file = wfFindFile( $name );
+ $file = MediaWikiServices::getInstance()->getRepoGroup()->findFile( $name );
if ( $file && $this->filterItem( $file, $shared ) ) {
$filename = $file->getLocalRefPath();
$rel = wfRelativePath( $filename, $this->mBasePath );
* @ingroup Maintenance
*/
+use MediaWiki\MediaWikiServices;
+
require_once __DIR__ . '/Maintenance.php';
/**
$afile = ArchivedFile::newFromRow( $row );
}
- $file = wfLocalFile( $filename );
+ $file = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo()->newFile( $filename );
if ( $file->exists() ) {
$this->fatalError( "File '$filename' is still a public file, use the delete form.\n" );
}
* @author Mij <mij@bitchx.it>
*/
+use MediaWiki\MediaWikiServices;
+
require_once __DIR__ . '/Maintenance.php';
class ImportImages extends Maintenance {
}
# Check existence
- $image = wfLocalFile( $title );
+ $image = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo()
+ ->newFile( $title );
if ( $image->exists() ) {
if ( $this->hasOption( 'overwrite' ) ) {
$this->output( "{$base} exists, overwriting..." );
* @ingroup Maintenance
*/
+use MediaWiki\MediaWikiServices;
use MediaWiki\Shell\Shell;
require_once __DIR__ . '/Maintenance.php';
wfWaitForSlaves();
}
- $file = wfLocalFile( $row->img_name );
+ $file = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo()
+ ->newFile( $row->img_name );
if ( !$file ) {
continue;
}
function addMissingImage( $filename, $fullpath ) {
$timestamp = $this->dbw->timestamp( $this->getRepo()->getFileTimestamp( $fullpath ) );
+ $services = MediaWikiServices::getInstance();
- $altname = MediaWikiServices::getInstance()->getContentLanguage()->
- checkTitleEncoding( $filename );
+ $altname = $services->getContentLanguage()->checkTitleEncoding( $filename );
if ( $altname != $filename ) {
if ( $this->dryrun ) {
$filename = $altname;
return;
}
if ( !$this->dryrun ) {
- $file = wfLocalFile( $filename );
+ $file = $services->getRepoGroup()->getLocalRepo()->newFile( $filename );
if ( !$file->recordUpload(
'',
'(recovered file, missing upload log entry)',