* @file
*/
+use Wikimedia\Rdbms\IDatabase;
+
/**
* This abstract class implements many basic API functions, and is the base of
* all API classes.
*/
const PARAM_EXTRA_NAMESPACES = 18;
+ /*
+ * (boolean) Is the parameter sensitive? Note 'password'-type fields are
+ * always sensitive regardless of the value of this field.
+ * @since 1.29
+ */
+ const PARAM_SENSITIVE = 19;
+
/**@}*/
const ALL_DEFAULT_STRING = '*';
/**
* Indicates whether this module requires write mode
+ *
+ * This should return true for modules that may require synchronous database writes.
+ * Modules that do not need such writes should also not rely on master database access,
+ * since only read queries are needed and each master DB is a single point of failure.
+ * Additionally, requests that only need replica DBs can be efficiently routed to any
+ * datacenter via the Promise-Non-Write-API-Action header.
+ *
* @return bool
*/
public function isWriteMode() {
/**
* Gets a default replica DB connection object
- * @return Database
+ * @return IDatabase
*/
protected function getDB() {
if ( !isset( $this->mSlaveDB ) ) {
} else {
$type = 'NULL'; // allow everything
}
+
+ if ( $type == 'password' || !empty( $paramSettings[self::PARAM_SENSITIVE] ) ) {
+ $this->getMain()->markParamsSensitive( $encParamName );
+ }
}
if ( $type == 'boolean' ) {
throw new MWException( 'Successful status passed to ApiBase::dieStatus' );
}
+ // ApiUsageException needs a fatal status, but this method has
+ // historically accepted any non-good status. Convert it if necessary.
+ $status->setOK( false );
+ if ( !$status->getErrorsByType( 'error' ) ) {
+ $newStatus = Status::newGood();
+ foreach ( $status->getErrorsByType( 'warning' ) as $err ) {
+ call_user_func_array(
+ [ $newStatus, 'fatal' ],
+ array_merge( [ $err['message'] ], $err['params'] )
+ );
+ }
+ if ( !$newStatus->getErrorsByType( 'error' ) ) {
+ $newStatus->fatal( 'unknownerror-nocode' );
+ }
+ $status = $newStatus;
+ }
+
throw new ApiUsageException( $this, $status );
}
$params['token'] = [
ApiBase::PARAM_TYPE => 'string',
ApiBase::PARAM_REQUIRED => true,
+ ApiBase::PARAM_SENSITIVE => true,
ApiBase::PARAM_HELP_MSG => [
'api-help-param-token',
$this->needsToken(),