| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 
 | <?php
namespace MediaWiki\Installer;
use MediaWiki\Status\Status;
use Wikimedia\Rdbms\DatabasePostgres;
/**
 * @internal
 */
class PostgresSettingsForm extends DatabaseSettingsForm {
	public function getHtml() {
		if ( $this->getPostgresInstaller()->canCreateAccounts() ) {
			$noCreateMsg = false;
		} else {
			$noCreateMsg = 'config-db-web-no-create-privs';
		}
		$s = $this->getWebUserBox( $noCreateMsg );
		return $s;
	}
	public function submit() {
		$status = $this->submitWebUserBox();
		if ( !$status->isOK() ) {
			return $status;
		}
		$same = $this->getVar( 'wgDBuser' ) === $this->getVar( '_InstallUser' );
		if ( $same ) {
			$exists = true;
		} else {
			// Check if the web user exists
			// Connect to the database with the install user
			$status = $this->getPostgresInstaller()->getConnection( DatabaseInstaller::CONN_CREATE_DATABASE );
			if ( !$status->isOK() ) {
				return $status;
			}
			$conn = $status->getDB();
			'@phan-var DatabasePostgres $conn'; /** @var DatabasePostgres $conn */
			$exists = $conn->roleExists( $this->getVar( 'wgDBuser' ) );
		}
		// Validate the create checkbox
		if ( $this->getPostgresInstaller()->canCreateAccounts() && !$same && !$exists ) {
			$create = $this->getVar( '_CreateDBAccount' );
		} else {
			$this->setVar( '_CreateDBAccount', false );
			$create = false;
		}
		if ( !$create && !$exists ) {
			if ( $this->getPostgresInstaller()->canCreateAccounts() ) {
				$msg = 'config-install-user-missing-create';
			} else {
				$msg = 'config-install-user-missing';
			}
			return Status::newFatal( $msg, $this->getVar( 'wgDBuser' ) );
		}
		if ( !$exists ) {
			// No more checks to do
			return Status::newGood();
		}
		// Existing web account. Test the connection.
		$status = $this->getPostgresInstaller()->openConnectionToAnyDB(
			$this->getVar( 'wgDBuser' ),
			$this->getVar( 'wgDBpassword' ) );
		if ( !$status->isOK() ) {
			return $status;
		}
		// The web user is conventionally the table owner in PostgreSQL
		// installations. Make sure the install user is able to create
		// objects on behalf of the web user.
		if ( $same || $this->getPostgresInstaller()->canCreateObjectsForWebUser() ) {
			return Status::newGood();
		} else {
			return Status::newFatal( 'config-pg-not-in-role' );
		}
	}
	/**
	 * Downcast the DatabaseInstaller
	 * @return PostgresInstaller
	 */
	private function getPostgresInstaller(): PostgresInstaller {
		// @phan-suppress-next-line PhanTypeMismatchReturnSuperType
		return $this->dbInstaller;
	}
}
 |