+
+ /**
+ * Return current schema (executes SELECT current_schema())
+ * Needs transaction
+ *
+ * @since 1.20
+ * @return string return default schema for the current session
+ */
+ function getCurrentSchema() {
+ $res = $this->query( "SELECT current_schema()", __METHOD__);
+ $row = $this->fetchRow( $res );
+ return $row[0];
+ }
+
+ /**
+ * Return list of schemas which are accessible without schema name
+ * This is list does not contain magic keywords like "$user"
+ * Needs transaction
+ *
+ * @seealso getSearchPath()
+ * @seealso setSearchPath()
+ * @since 1.20
+ * @return array list of actual schemas for the current sesson
+ */
+ function getSchemas() {
+ $res = $this->query( "SELECT current_schemas(false)", __METHOD__);
+ $row = $this->fetchRow( $res );
+ $schemas = array();
+ /* PHP pgsql support does not support array type, "{a,b}" string is returned */
+ return $this->pg_array_parse($row[0], $schemas);
+ }
+
+ /**
+ * Return search patch for schemas
+ * This is different from getSchemas() since it contain magic keywords
+ * (like "$user").
+ * Needs transaction
+ *
+ * @since 1.20
+ * @return array how to search for table names schemas for the current user
+ */
+ function getSearchPath() {
+ $res = $this->query( "SHOW search_path", __METHOD__);
+ $row = $this->fetchRow( $res );
+ /* PostgreSQL returns SHOW values as strings */
+ return explode(",", $row[0]);
+ }
+
+ /**
+ * Update search_path, values should already be sanitized
+ * Values may contain magic keywords like "$user"
+ * @since 1.20
+ *
+ * @param $search_path array list of schemas to be searched by default
+ */
+ function setSearchPath( $search_path ) {
+ $this->query( "SET search_path = " . implode(", ", $search_path) );
+ }
+
+ /**
+ * Determine default schema for MediaWiki core
+ * Adjust this session schema search path if desired schema exists
+ * and is not alread there.
+ *
+ * We need to have name of the core schema stored to be able
+ * to query database metadata.
+ *
+ * This will be also called by the installer after the schema is created
+ *
+ * @since 1.20
+ * @param desired_schema string
+ */
+ function determineCoreSchema( $desired_schema ) {
+ $this->begin( __METHOD__ );
+ if ( $this->schemaExists( $desired_schema ) ) {
+ if ( in_array( $desired_schema, $this->getSchemas() ) ) {
+ $this->mCoreSchema = $desired_schema;
+ wfDebug("Schema \"" . $desired_schema . "\" already in the search path\n");
+ } else {
+ /**
+ * Append our schema (e.g. 'mediawiki') in front
+ * of the search path
+ * Fixes bug 15816
+ */
+ $search_path = $this->getSearchPath();
+ array_unshift( $search_path,
+ $this->addIdentifierQuotes( $desired_schema ));
+ $this->setSearchPath( $search_path );
+ $this->mCoreSchema = $desired_schema;
+ wfDebug("Schema \"" . $desired_schema . "\" added to the search path\n");
+ }