MediaWiki  REL1_23
MssqlInstaller.php
Go to the documentation of this file.
00001 <?php
00030 class MssqlInstaller extends DatabaseInstaller {
00031 
00032     protected $globalNames = array(
00033         'wgDBserver',
00034         'wgDBname',
00035         'wgDBuser',
00036         'wgDBpassword',
00037         'wgDBmwschema',
00038         'wgDBprefix',
00039         'wgDBWindowsAuthentication',
00040     );
00041 
00042     protected $internalDefaults = array(
00043         '_InstallUser' => 'sa',
00044         '_InstallWindowsAuthentication' => 'sqlauth',
00045         '_WebWindowsAuthentication' => 'sqlauth',
00046     );
00047 
00048     public $minimumVersion = '9.00.1399'; // SQL Server 2005 RTM (TODO: are SQL Express version numbers different?)
00049 
00050     // These are schema-level privs
00051     // Note: the web user will be created will full permissions if possible, this permission
00052     // list is only used if we are unable to grant full permissions.
00053     public $webUserPrivs = array(
00054         'DELETE',
00055         'INSERT',
00056         'SELECT',
00057         'UPDATE',
00058         'EXECUTE',
00059     );
00060 
00064     public function getName() {
00065         return 'mssql';
00066     }
00067 
00071     public function isCompiled() {
00072         return self::checkExtension( 'sqlsrv' );
00073     }
00074 
00078     public function getConnectForm() {
00079         if ( $this->getVar( '_InstallWindowsAuthentication' ) == 'windowsauth' ) {
00080             $displayStyle = 'display: none;';
00081         } else {
00082             $displayStyle = 'display: block;';
00083         }
00084 
00085         return $this->getTextBox(
00086             'wgDBserver',
00087             'config-db-host',
00088             array(),
00089             $this->parent->getHelpBox( 'config-db-host-help' )
00090         ) .
00091             Html::openElement( 'fieldset' ) .
00092             Html::element( 'legend', array(), wfMessage( 'config-db-wiki-settings' )->text() ) .
00093             $this->getTextBox( 'wgDBname', 'config-db-name', array( 'dir' => 'ltr' ),
00094                 $this->parent->getHelpBox( 'config-db-name-help' ) ) .
00095             $this->getTextBox( 'wgDBmwschema', 'config-db-schema', array( 'dir' => 'ltr' ),
00096                 $this->parent->getHelpBox( 'config-db-schema-help' ) ) .
00097             $this->getTextBox( 'wgDBprefix', 'config-db-prefix', array( 'dir' => 'ltr' ),
00098                 $this->parent->getHelpBox( 'config-db-prefix-help' ) ) .
00099             Html::closeElement( 'fieldset' ) .
00100             Html::openElement( 'fieldset' ) .
00101             Html::element( 'legend', array(), wfMessage( 'config-db-install-account' )->text() ) .
00102             $this->getRadioSet( array(
00103                 'var' => '_InstallWindowsAuthentication',
00104                 'label' => 'config-mssql-auth',
00105                 'itemLabelPrefix' => 'config-mssql-',
00106                 'values' => array( 'sqlauth', 'windowsauth' ),
00107                 'itemAttribs' => array(
00108                     'sqlauth' => array(
00109                         'class' => 'showHideRadio',
00110                         'rel' => 'dbCredentialBox',
00111                     ),
00112                     'windowsauth' => array(
00113                         'class' => 'hideShowRadio',
00114                         'rel' => 'dbCredentialBox',
00115                     )
00116                 ),
00117                 'help' => $this->parent->getHelpBox( 'config-mssql-install-auth' )
00118             ) ) .
00119             Html::openElement( 'div', array( 'id' => 'dbCredentialBox', 'style' => $displayStyle ) ) .
00120             $this->getTextBox(
00121                 '_InstallUser',
00122                 'config-db-username',
00123                 array( 'dir' => 'ltr' ),
00124                 $this->parent->getHelpBox( 'config-db-install-username' )
00125             ) .
00126             $this->getPasswordBox(
00127                 '_InstallPassword',
00128                 'config-db-password',
00129                 array( 'dir' => 'ltr' ),
00130                 $this->parent->getHelpBox( 'config-db-install-password' )
00131             ) .
00132             Html::closeElement( 'div' ) .
00133             Html::closeElement( 'fieldset' );
00134     }
00135 
00136     public function submitConnectForm() {
00137         // Get variables from the request.
00138         $newValues = $this->setVarsFromRequest( array( 'wgDBserver', 'wgDBname', 'wgDBmwschema', 'wgDBprefix' ) );
00139 
00140         // Validate them.
00141         $status = Status::newGood();
00142         if ( !strlen( $newValues['wgDBserver'] ) ) {
00143             $status->fatal( 'config-missing-db-host' );
00144         }
00145         if ( !strlen( $newValues['wgDBname'] ) ) {
00146             $status->fatal( 'config-missing-db-name' );
00147         } elseif ( !preg_match( '/^[a-z0-9_]+$/i', $newValues['wgDBname'] ) ) {
00148             $status->fatal( 'config-invalid-db-name', $newValues['wgDBname'] );
00149         }
00150         if ( !preg_match( '/^[a-z0-9_]*$/i', $newValues['wgDBmwschema'] ) ) {
00151             $status->fatal( 'config-invalid-schema', $newValues['wgDBmwschema'] );
00152         }
00153         if ( !preg_match( '/^[a-z0-9_]*$/i', $newValues['wgDBprefix'] ) ) {
00154             $status->fatal( 'config-invalid-db-prefix', $newValues['wgDBprefix'] );
00155         }
00156         if ( !$status->isOK() ) {
00157             return $status;
00158         }
00159 
00160         // Check for blank schema and remap to dbo
00161         if ( $newValues['wgDBmwschema'] === '' ) {
00162             $this->setVar( 'wgDBmwschema', 'dbo' );
00163         }
00164 
00165         // User box
00166         $this->setVarsFromRequest( array( '_InstallUser', '_InstallPassword', '_InstallWindowsAuthentication' ) );
00167 
00168         // Try to connect
00169         $status = $this->getConnection();
00170         if ( !$status->isOK() ) {
00171             return $status;
00172         }
00176         $conn = $status->value;
00177 
00178         // Check version
00179         $version = $conn->getServerVersion();
00180         if ( version_compare( $version, $this->minimumVersion ) < 0 ) {
00181             return Status::newFatal( 'config-mssql-old', $this->minimumVersion, $version );
00182         }
00183 
00184         return $status;
00185     }
00186 
00190     public function openConnection() {
00191         global $wgDBWindowsAuthentication;
00192         $status = Status::newGood();
00193         $user = $this->getVar( '_InstallUser' );
00194         $password = $this->getVar( '_InstallPassword' );
00195 
00196         if ( $this->getVar( '_InstallWindowsAuthentication' ) == 'windowsauth' ) {
00197             // Use Windows authentication for this connection
00198             $wgDBWindowsAuthentication = true;
00199         } else {
00200             $wgDBWindowsAuthentication = false;
00201         }
00202 
00203         try {
00204             $db = DatabaseBase::factory( 'mssql', array(
00205                 'host' => $this->getVar( 'wgDBserver' ),
00206                 'user' => $user,
00207                 'password' => $password,
00208                 'dbname' => false,
00209                 'flags' => 0,
00210                 'tablePrefix' => $this->getVar( 'wgDBprefix' ) ) );
00211             $db->prepareStatements( false );
00212             $db->scrollableCursor( false );
00213             $status->value = $db;
00214         } catch ( DBConnectionError $e ) {
00215             $status->fatal( 'config-connection-error', $e->getMessage() );
00216         }
00217 
00218         return $status;
00219     }
00220 
00221     public function preUpgrade() {
00222         global $wgDBuser, $wgDBpassword;
00223 
00224         $status = $this->getConnection();
00225         if ( !$status->isOK() ) {
00226             $this->parent->showStatusError( $status );
00227 
00228             return;
00229         }
00233         $conn = $status->value;
00234         $conn->selectDB( $this->getVar( 'wgDBname' ) );
00235 
00236         # Normal user and password are selected after this step, so for now
00237         # just copy these two
00238         $wgDBuser = $this->getVar( '_InstallUser' );
00239         $wgDBpassword = $this->getVar( '_InstallPassword' );
00240     }
00241 
00247     public function canCreateAccounts() {
00248         $status = $this->getConnection();
00249         if ( !$status->isOK() ) {
00250             return false;
00251         }
00253         $conn = $status->value;
00254 
00255         // We need the server-level ALTER ANY LOGIN permission to create new accounts
00256         $res = $conn->query( "SELECT permission_name FROM sys.fn_my_permissions( NULL, 'SERVER' )" );
00257         $serverPrivs = array(
00258             'ALTER ANY LOGIN' => false,
00259             'CONTROL SERVER' => false,
00260         );
00261 
00262         foreach ( $res as $row ) {
00263             $serverPrivs[$row->permission_name] = true;
00264         }
00265 
00266         if ( !$serverPrivs['ALTER ANY LOGIN'] ) {
00267             return false;
00268         }
00269 
00270         // Check to ensure we can grant everything needed as well
00271         // We can't actually tell if we have WITH GRANT OPTION for a given permission, so we assume we do
00272         // and just check for the permission
00273         // http://technet.microsoft.com/en-us/library/ms178569.aspx
00274         // The following array sets up which permissions imply whatever permissions we specify
00275         $implied = array(
00276             // schema           database  server
00277             'DELETE'  => array( 'DELETE', 'CONTROL SERVER' ),
00278             'EXECUTE' => array( 'EXECUTE', 'CONTROL SERVER' ),
00279             'INSERT'  => array( 'INSERT', 'CONTROL SERVER' ),
00280             'SELECT'  => array( 'SELECT', 'CONTROL SERVER' ),
00281             'UPDATE'  => array( 'UPDATE', 'CONTROL SERVER' ),
00282         );
00283 
00284         $grantOptions = array_flip( $this->webUserPrivs );
00285 
00286         // Check for schema and db-level permissions, but only if the schema/db exists
00287         $schemaPrivs = $dbPrivs = array(
00288             'DELETE' => false,
00289             'EXECUTE' => false,
00290             'INSERT' => false,
00291             'SELECT' => false,
00292             'UPDATE' => false,
00293         );
00294 
00295         $dbPrivs['ALTER ANY USER'] = false;
00296 
00297         if ( $this->databaseExists( $this->getVar( 'wgDBname' ) ) ) {
00298             $conn->selectDB( $this->getVar( 'wgDBname' ) );
00299             $res = $conn->query( "SELECT permission_name FROM sys.fn_my_permissions( NULL, 'DATABASE' )" );
00300 
00301             foreach ( $res as $row ) {
00302                 $dbPrivs[$row->permission_name] = true;
00303             }
00304 
00305             // If the db exists, we need ALTER ANY USER privs on it to make a new user
00306             if ( !$dbPrivs['ALTER ANY USER'] ) {
00307                 return false;
00308             }
00309 
00310             if ( $this->schemaExists( $this->getVar( 'wgDBmwschema' ) ) ) {
00311                 // wgDBmwschema is validated to only contain alphanumeric + underscore, so this is safe
00312                 $res = $conn->query( "SELECT permission_name FROM sys.fn_my_permissions( '{$this->getVar( 'wgDBmwschema' )}', 'SCHEMA' )" );
00313 
00314                 foreach ( $res as $row ) {
00315                     $schemaPrivs[$row->permission_name] = true;
00316                 }
00317             }
00318         }
00319 
00320         // Now check all the grants we'll need to be doing to see if we can
00321         foreach ( $this->webUserPrivs as $permission ) {
00322             if ( ( isset( $schemaPrivs[$permission] ) && $schemaPrivs[$permission] )
00323                     || ( isset( $dbPrivs[$implied[$permission][0]] ) && $dbPrivs[$implied[$permission][0]] )
00324                     || ( isset( $serverPrivs[$implied[$permission][1]] ) && $serverPrivs[$implied[$permission][1]] ) ) {
00325 
00326                 unset( $grantOptions[$permission] );
00327             }
00328         }
00329 
00330         if ( count( $grantOptions ) ) {
00331             // Can't grant everything
00332             return false;
00333         }
00334 
00335         return true;
00336     }
00337 
00341     public function getSettingsForm() {
00342         if ( $this->canCreateAccounts() ) {
00343             $noCreateMsg = false;
00344         } else {
00345             $noCreateMsg = 'config-db-web-no-create-privs';
00346         }
00347         $wrapperStyle = $this->getVar( '_SameAccount' ) ? 'display: none' : '';
00348         $displayStyle = $this->getVar( '_WebWindowsAuthentication' ) == 'windowsauth' ? 'display: none' : '';
00349         $s = Html::openElement( 'fieldset' ) .
00350             Html::element( 'legend', array(), wfMessage( 'config-db-web-account' )->text() ) .
00351             $this->getCheckBox(
00352                 '_SameAccount', 'config-db-web-account-same',
00353                 array( 'class' => 'hideShowRadio', 'rel' => 'dbOtherAccount' )
00354             ) .
00355             Html::openElement( 'div', array( 'id' => 'dbOtherAccount', 'style' => $wrapperStyle ) ) .
00356             $this->getRadioSet( array(
00357                 'var' => '_WebWindowsAuthentication',
00358                 'label' => 'config-mssql-auth',
00359                 'itemLabelPrefix' => 'config-mssql-',
00360                 'values' => array( 'sqlauth', 'windowsauth' ),
00361                 'itemAttribs' => array(
00362                     'sqlauth' => array(
00363                         'class' => 'showHideRadio',
00364                         'rel' => 'dbCredentialBox',
00365                     ),
00366                     'windowsauth' => array(
00367                         'class' => 'hideShowRadio',
00368                         'rel' => 'dbCredentialBox',
00369                     )
00370                 ),
00371                 'help' => $this->parent->getHelpBox( 'config-mssql-web-auth' )
00372             ) ) .
00373             Html::openElement( 'div', array( 'id' => 'dbCredentialBox', 'style' => $displayStyle ) ) .
00374             $this->getTextBox( 'wgDBuser', 'config-db-username' ) .
00375             $this->getPasswordBox( 'wgDBpassword', 'config-db-password' ) .
00376             Html::closeElement( 'div' );
00377 
00378         if ( $noCreateMsg ) {
00379             $s .= $this->parent->getWarningBox( wfMessage( $noCreateMsg )->plain() );
00380         } else {
00381             $s .= $this->getCheckBox( '_CreateDBAccount', 'config-db-web-create' );
00382         }
00383 
00384         $s .= Html::closeElement( 'div' ) . Html::closeElement( 'fieldset' );
00385 
00386         return $s;
00387     }
00388 
00392     public function submitSettingsForm() {
00393         $this->setVarsFromRequest(
00394             array( 'wgDBuser', 'wgDBpassword', '_SameAccount', '_CreateDBAccount', '_WebWindowsAuthentication' )
00395         );
00396 
00397         if ( $this->getVar( '_SameAccount' ) ) {
00398             $this->setVar( '_WebWindowsAuthentication', $this->getVar( '_InstallWindowsAuthentication' ) );
00399             $this->setVar( 'wgDBuser', $this->getVar( '_InstallUser' ) );
00400             $this->setVar( 'wgDBpassword', $this->getVar( '_InstallPassword' ) );
00401         }
00402 
00403         if ( $this->getVar( '_WebWindowsAuthentication' ) == 'windowsauth' ) {
00404             $this->setVar( 'wgDBuser', '' );
00405             $this->setVar( 'wgDBpassword', '' );
00406             $this->setVar( 'wgDBWindowsAuthentication', true );
00407         } else {
00408             $this->setVar( 'wgDBWindowsAuthentication', false );
00409         }
00410 
00411         if ( $this->getVar( '_CreateDBAccount' ) && $this->getVar( '_WebWindowsAuthentication' ) == 'sqlauth' && strval( $this->getVar( 'wgDBpassword' ) ) == '' ) {
00412             return Status::newFatal( 'config-db-password-empty', $this->getVar( 'wgDBuser' ) );
00413         }
00414 
00415         // Validate the create checkbox
00416         $canCreate = $this->canCreateAccounts();
00417         if ( !$canCreate ) {
00418             $this->setVar( '_CreateDBAccount', false );
00419             $create = false;
00420         } else {
00421             $create = $this->getVar( '_CreateDBAccount' );
00422         }
00423 
00424         if ( !$create ) {
00425             // Test the web account
00426             $user = $this->getVar( 'wgDBuser' );
00427             $password = $this->getVar( 'wgDBpassword' );
00428 
00429             if ( $this->getVar( '_WebWindowsAuthentication' ) == 'windowsauth' ) {
00430                 $user = 'windowsauth';
00431                 $password = 'windowsauth';
00432             }
00433 
00434             try {
00435                 DatabaseBase::factory( 'mssql', array(
00436                     'host' => $this->getVar( 'wgDBserver' ),
00437                     'user' => $user,
00438                     'password' => $password,
00439                     'dbname' => false,
00440                     'flags' => 0,
00441                     'tablePrefix' => $this->getVar( 'wgDBprefix' ),
00442                     'schema' => $this->getVar( 'wgDBmwschema' ),
00443                 ) );
00444             } catch ( DBConnectionError $e ) {
00445                 return Status::newFatal( 'config-connection-error', $e->getMessage() );
00446             }
00447         }
00448 
00449         return Status::newGood();
00450     }
00451 
00452     public function preInstall() {
00453         # Add our user callback to installSteps, right before the tables are created.
00454         $callback = array(
00455             'name' => 'user',
00456             'callback' => array( $this, 'setupUser' ),
00457         );
00458         $this->parent->addInstallStep( $callback, 'tables' );
00459     }
00460 
00464     public function setupDatabase() {
00465         $status = $this->getConnection();
00466         if ( !$status->isOK() ) {
00467             return $status;
00468         }
00470         $conn = $status->value;
00471         $dbName = $this->getVar( 'wgDBname' );
00472         $schemaName = $this->getVar( 'wgDBmwschema' );
00473         if ( !$this->databaseExists( $dbName ) ) {
00474             $conn->query( "CREATE DATABASE " . $conn->addIdentifierQuotes( $dbName ), __METHOD__ );
00475             $conn->selectDB( $dbName );
00476             if ( !$this->schemaExists( $schemaName ) ) {
00477                 $conn->query( "CREATE SCHEMA " . $conn->addIdentifierQuotes( $schemaName ), __METHOD__ );
00478             }
00479             if ( !$this->catalogExists( $schemaName ) ) {
00480                 $conn->query( "CREATE FULLTEXT CATALOG " . $conn->addIdentifierQuotes( $schemaName ), __METHOD__ );
00481             }
00482         }
00483         $this->setupSchemaVars();
00484 
00485         return $status;
00486     }
00487 
00491     public function setupUser() {
00492         $dbUser = $this->getVar( 'wgDBuser' );
00493         if ( $dbUser == $this->getVar( '_InstallUser' )
00494                 || ( $this->getVar( '_InstallWindowsAuthentication' ) == 'windowsauth'
00495                     && $this->getVar( '_WebWindowsAuthentication' ) == 'windowsauth' ) ) {
00496             return Status::newGood();
00497         }
00498         $status = $this->getConnection();
00499         if ( !$status->isOK() ) {
00500             return $status;
00501         }
00502 
00503         $this->setupSchemaVars();
00504         $dbName = $this->getVar( 'wgDBname' );
00505         $this->db->selectDB( $dbName );
00506         $server = $this->getVar( 'wgDBserver' );
00507         $password = $this->getVar( 'wgDBpassword' );
00508         $schemaName = $this->getVar( 'wgDBmwschema' );
00509 
00510         if ( $this->getVar( '_WebWindowsAuthentication' ) == 'windowsauth' ) {
00511             $dbUser = 'windowsauth';
00512             $password = 'windowsauth';
00513         }
00514 
00515         if ( $this->getVar( '_CreateDBAccount' ) ) {
00516             $tryToCreate = true;
00517         } else {
00518             $tryToCreate = false;
00519         }
00520 
00521         $escUser = $this->db->addIdentifierQuotes( $dbUser );
00522         $escDb = $this->db->addIdentifierQuotes( $dbName );
00523         $escSchema = $this->db->addIdentifierQuotes( $schemaName );
00524         $grantableNames = array();
00525         if ( $tryToCreate ) {
00526             $escPass = $this->db->addQuotes( $password );
00527 
00528             if ( !$this->loginExists( $dbUser ) ) {
00529                 try {
00530                     $this->db->begin();
00531                     $this->db->selectDB( 'master' );
00532                     $logintype = $this->getVar( '_WebWindowsAuthentication' ) == 'windowsauth' ? 'FROM WINDOWS' : "WITH PASSWORD = $escPass";
00533                     $this->db->query( "CREATE LOGIN $escUser $logintype" );
00534                     $this->db->selectDB( $dbName );
00535                     $this->db->query( "CREATE USER $escUser FOR LOGIN $escUser WITH DEFAULT_SCHEMA = $escSchema" );
00536                     $this->db->commit();
00537                     $grantableNames[] = $dbUser;
00538                 } catch ( DBQueryError $dqe ) {
00539                     $this->db->rollback();
00540                     $status->warning( 'config-install-user-create-failed', $dbUser, $dqe->getText() );
00541                 }
00542             } elseif ( !$this->userExists( $dbUser ) ) {
00543                 try {
00544                     $this->db->begin();
00545                     $this->db->selectDB( $dbName );
00546                     $this->db->query( "CREATE USER $escUser FOR LOGIN $escUser WITH DEFAULT_SCHEMA = $escSchema" );
00547                     $this->db->commit();
00548                     $grantableNames[] = $dbUser;
00549                 } catch ( DBQueryError $dqe ) {
00550                     $this->db->rollback();
00551                     $status->warning( 'config-install-user-create-failed', $dbUser, $dqe->getText() );
00552                 }
00553             } else {
00554                 $status->warning( 'config-install-user-alreadyexists', $dbUser );
00555                 $grantableNames[] = $dbUser;
00556             }
00557         }
00558 
00559         // Try to grant to all the users we know exist or we were able to create
00560         $this->db->selectDB( $dbName );
00561         foreach ( $grantableNames as $name ) {
00562             try {
00563                 // First try to grant full permissions
00564                 $fullPrivArr = array(
00565                     'BACKUP DATABASE', 'BACKUP LOG', 'CREATE FUNCTION', 'CREATE PROCEDURE',
00566                     'CREATE TABLE', 'CREATE VIEW', 'CREATE FULLTEXT CATALOG', 'SHOWPLAN'
00567                 );
00568                 $fullPrivList = implode( ', ', $fullPrivArr );
00569                 $this->db->begin();
00570                 $this->db->query( "GRANT $fullPrivList ON DATABASE :: $escDb TO $escUser", __METHOD__ );
00571                 $this->db->query( "GRANT CONTROL ON SCHEMA :: $escSchema TO $escUser", __METHOD__ );
00572                 $this->db->commit();
00573             } catch ( DBQueryError $dqe ) {
00574                 // If that fails, try to grant the limited subset specified in $this->webUserPrivs
00575                 try {
00576                     $privList = implode( ', ', $this->webUserPrivs );
00577                     $this->db->rollback();
00578                     $this->db->begin();
00579                     $this->db->query( "GRANT $privList ON SCHEMA :: $escSchema TO $escUser", __METHOD__ );
00580                     $this->db->commit();
00581                 } catch ( DBQueryError $dqe ) {
00582                     $this->db->rollback();
00583                     $status->fatal( 'config-install-user-grant-failed', $dbUser, $dqe->getText() );
00584                 }
00585                 // Also try to grant SHOWPLAN on the db, but don't fail if we can't
00586                 // (just makes a couple things in mediawiki run slower since
00587                 // we have to run SELECT COUNT(*) instead of getting the query plan)
00588                 try {
00589                     $this->db->query( "GRANT SHOWPLAN ON DATABASE :: $escDb TO $escUser", __METHOD__ );
00590                 } catch ( DBQueryError $dqe ) {
00591                 }
00592             }
00593         }
00594 
00595         return $status;
00596     }
00597 
00598     public function createTables() {
00599         $status = parent::createTables();
00600 
00601         // Do last-minute stuff like fulltext indexes (since they can't be inside a transaction)
00602         if ( $status->isOk() ) {
00603             $searchindex = $this->db->tableName( 'searchindex' );
00604             $schema = $this->db->addIdentifierQuotes( $this->getVar( 'wgDBmwschema' ) );
00605             try {
00606                 $this->db->query( "CREATE FULLTEXT INDEX ON $searchindex (si_title, si_text) KEY INDEX si_page ON $schema" );
00607             } catch ( DBQueryError $dqe ) {
00608                 $status->fatal( 'config-install-tables-failed', $dqe->getText() );
00609             }
00610         }
00611 
00612         return $status;
00613     }
00614 
00620     private function loginExists( $user ) {
00621         $res = $this->db->selectField( 'sys.sql_logins', 1, array( 'name' => $user ) );
00622         return (bool)$res;
00623     }
00624 
00631     private function userExists( $user ) {
00632         $res = $this->db->selectField( 'sys.sysusers', 1, array( 'name' => $user ) );
00633         return (bool)$res;
00634     }
00635 
00641     private function databaseExists( $dbName ) {
00642         $res = $this->db->selectField( 'sys.databases', 1, array( 'name' => $dbName ) );
00643         return (bool)$res;
00644     }
00645 
00652     private function schemaExists( $schemaName ) {
00653         $res = $this->db->selectField( 'sys.schemas', 1, array( 'name' => $schemaName ) );
00654         return (bool)$res;
00655     }
00656 
00663     private function catalogExists( $catalogName ) {
00664         $res = $this->db->selectField( 'sys.fulltext_catalogs', 1, array( 'name' => $catalogName ) );
00665         return (bool)$res;
00666     }
00667 
00673     public function getSchemaVars() {
00674         return array(
00675             'wgDBname' => $this->getVar( 'wgDBname' ),
00676             'wgDBmwschema' => $this->getVar( 'wgDBmwschema' ),
00677             'wgDBuser' => $this->getVar( 'wgDBuser' ),
00678             'wgDBpassword' => $this->getVar( 'wgDBpassword' ),
00679         );
00680     }
00681 
00682     public function getLocalSettings() {
00683         $schema = LocalSettingsGenerator::escapePhpString( $this->getVar( 'wgDBmwschema' ) );
00684         $prefix = LocalSettingsGenerator::escapePhpString( $this->getVar( 'wgDBprefix' ) );
00685         $windowsauth = $this->getVar( 'wgDBWindowsAuthentication' ) ? 'true' : 'false';
00686 
00687         return "# MSSQL specific settings
00688 \$wgDBWindowsAuthentication = {$windowsauth};
00689 \$wgDBmwschema = \"{$schema}\";
00690 \$wgDBprefix = \"{$prefix}\";";
00691     }
00692 }