* which may not necessarily be the same as the local DB.
*
* TODO: allow querying non-local repos.
- * @return Database
+ * @return IDatabase
*/
protected function getDB() {
- return $this->mRepo->getSlaveDB();
+ return $this->mRepo->getReplicaDB();
}
public function execute() {
*/
public function executeGenerator( $resultPageSet ) {
if ( $resultPageSet->isResolvingRedirects() ) {
- $this->dieUsage(
- 'Use "gaifilterredir=nonredirects" option instead of "redirects" ' .
- 'when using allimages as a generator',
- 'params'
- );
+ $this->dieWithError( 'apierror-allimages-redirect', 'invalidparammix' );
}
$this->run( $resultPageSet );
private function run( $resultPageSet = null ) {
$repo = $this->mRepo;
if ( !$repo instanceof LocalRepo ) {
- $this->dieUsage(
- 'Local file repository does not support querying all images',
- 'unsupportedrepo'
- );
+ $this->dieWithError( 'apierror-unsupportedrepo' );
}
$prefix = $this->getModulePrefix();
$disallowed = [ 'start', 'end', 'user' ];
foreach ( $disallowed as $pname ) {
if ( isset( $params[$pname] ) ) {
- $this->dieUsage(
- "Parameter '{$prefix}{$pname}' can only be used with {$prefix}sort=timestamp",
- 'badparams'
+ $this->dieWithError(
+ [
+ 'apierror-invalidparammix-mustusewith',
+ "{$prefix}{$pname}",
+ "{$prefix}sort=timestamp"
+ ],
+ 'invalidparammix'
);
}
}
if ( $params['filterbots'] != 'all' ) {
- $this->dieUsage(
- "Parameter '{$prefix}filterbots' can only be used with {$prefix}sort=timestamp",
- 'badparams'
+ $this->dieWithError(
+ [
+ 'apierror-invalidparammix-mustusewith',
+ "{$prefix}filterbots",
+ "{$prefix}sort=timestamp"
+ ],
+ 'invalidparammix'
);
}
$disallowed = [ 'from', 'to', 'prefix' ];
foreach ( $disallowed as $pname ) {
if ( isset( $params[$pname] ) ) {
- $this->dieUsage(
- "Parameter '{$prefix}{$pname}' can only be used with {$prefix}sort=name",
- 'badparams'
+ $this->dieWithError(
+ [
+ 'apierror-invalidparammix-mustusewith',
+ "{$prefix}{$pname}",
+ "{$prefix}sort=name"
+ ],
+ 'invalidparammix'
);
}
}
if ( !is_null( $params['user'] ) && $params['filterbots'] != 'all' ) {
// Since filterbots checks if each user has the bot right, it
// doesn't make sense to use it with user
- $this->dieUsage(
- "Parameters '{$prefix}user' and '{$prefix}filterbots' cannot be used together",
- 'badparams'
+ $this->dieWithError(
+ [ 'apierror-invalidparammix-cannotusewith', "{$prefix}user", "{$prefix}filterbots" ]
);
}
if ( isset( $params['sha1'] ) ) {
$sha1 = strtolower( $params['sha1'] );
if ( !$this->validateSha1Hash( $sha1 ) ) {
- $this->dieUsage( 'The SHA1 hash provided is not valid', 'invalidsha1hash' );
+ $this->dieWithError( 'apierror-invalidsha1hash' );
}
$sha1 = Wikimedia\base_convert( $sha1, 16, 36, 31 );
} elseif ( isset( $params['sha1base36'] ) ) {
$sha1 = strtolower( $params['sha1base36'] );
if ( !$this->validateSha1Base36Hash( $sha1 ) ) {
- $this->dieUsage( 'The SHA1Base36 hash provided is not valid', 'invalidsha1base36hash' );
+ $this->dieWithError( 'apierror-invalidsha1base36hash' );
}
}
if ( $sha1 ) {
if ( !is_null( $params['mime'] ) ) {
if ( $this->getConfig()->get( 'MiserMode' ) ) {
- $this->dieUsage( 'MIME search disabled in Miser Mode', 'mimesearchdisabled' );
+ $this->dieWithError( 'apierror-mimesearchdisabled' );
}
$mimeConds = [];