*
* @file
*/
+use MediaWiki\MediaWikiServices;
/**
* This class contains a list of pages that the client has requested.
}
$generator = $dbSource->getModuleManager()->getModule( $generatorName, null, true );
if ( $generator === null ) {
- $this->dieUsage( 'Unknown generator=' . $generatorName, 'badgenerator' );
+ $this->dieWithError( [ 'apierror-badgenerator-unknown', $generatorName ], 'badgenerator' );
}
if ( !$generator instanceof ApiQueryGeneratorBase ) {
- $this->dieUsage( "Module $generatorName cannot be used as a generator", 'badgenerator' );
+ $this->dieWithError( [ 'apierror-badgenerator-notgenerator', $generatorName ], 'badgenerator' );
}
// Create a temporary pageset to store generator's output,
// add any additional fields generator may need, and execute pageset to populate titles/pageids
// populate this pageset with the generator output
if ( !$isDryRun ) {
$generator->executeGenerator( $this );
- Hooks::run( 'APIQueryGeneratorAfterExecute', [ &$generator, &$this ] );
+
+ // Avoid PHP 7.1 warning of passing $this by reference
+ $apiModule = $this;
+ Hooks::run( 'APIQueryGeneratorAfterExecute', [ &$generator, &$apiModule ] );
} else {
// Prevent warnings from being reported on these parameters
$main = $this->getMain();
}
if ( isset( $this->mParams['pageids'] ) ) {
if ( isset( $dataSource ) ) {
- $this->dieUsage( "Cannot use 'pageids' at the same time as '$dataSource'", 'multisource' );
+ $this->dieWithError(
+ [
+ 'apierror-invalidparammix-cannotusewith',
+ $this->encodeParamName( 'pageids' ),
+ $this->encodeParamName( $dataSource )
+ ],
+ 'multisource'
+ );
}
$dataSource = 'pageids';
}
if ( isset( $this->mParams['revids'] ) ) {
if ( isset( $dataSource ) ) {
- $this->dieUsage( "Cannot use 'revids' at the same time as '$dataSource'", 'multisource' );
+ $this->dieWithError(
+ [
+ 'apierror-invalidparammix-cannotusewith',
+ $this->encodeParamName( 'revids' ),
+ $this->encodeParamName( $dataSource )
+ ],
+ 'multisource'
+ );
}
$dataSource = 'revids';
}
break;
case 'revids':
if ( $this->mResolveRedirects ) {
- $this->setWarning( 'Redirect resolution cannot be used ' .
- 'together with the revids= parameter. Any redirects ' .
- 'the revids= point to have not been resolved.' );
+ $this->addWarning( 'apiwarn-redirectsandrevids' );
}
$this->mResolveRedirects = false;
$this->initFromRevIDs( $this->mParams['revids'] );
}
// Get gender information
- $genderCache = GenderCache::singleton();
+ $genderCache = MediaWikiServices::getInstance()->getGenderCache();
$genderCache->doQuery( $usernames, __METHOD__ );
}
$this->mAllPages[0][$title] = $this->mFakePageId;
$this->mInvalidTitles[$this->mFakePageId] = [
'title' => $title,
- 'invalidreason' => $ex->getMessage(),
+ 'invalidreason' => $this->getErrorFormatter()->formatException( $ex, [ 'bc' => true ] ),
];
$this->mFakePageId--;
continue; // There's nothing else we can do
}
}
// Get gender information
- $genderCache = GenderCache::singleton();
+ $genderCache = MediaWikiServices::getInstance()->getGenderCache();
$genderCache->doQuery( $usernames, __METHOD__ );
return $linkBatch;
ApiBase::PARAM_DFLT => false,
ApiBase::PARAM_HELP_MSG => [
'api-pageset-param-converttitles',
- new DeferredStringifier(
- function ( IContextSource $context ) {
- return $context->getLanguage()
- ->commaList( LanguageConverter::$languagesWithVariants );
- },
- $this
- )
+ [ Message::listParam( LanguageConverter::$languagesWithVariants, 'text' ) ],
],
],
];