index.php
来自「php 开发的内容管理系统」· PHP 代码 · 共 1,666 行 · 第 1/4 页
PHP
1,666 行
}$conf->diff3 = false;$diff3locations = array("/usr/bin", "/usr/local/bin", "/opt/csw/bin", "/usr/gnu/bin", "/usr/sfw/bin") + explode($sep, getenv("PATH"));$diff3names = array("gdiff3", "diff3", "diff3.exe");$diff3versioninfo = array('$1 --version 2>&1', 'diff3 (GNU diffutils)');foreach ($diff3locations as $loc) { $exe = locate_executable($loc, $diff3names, $diff3versioninfo); if ($exe !== false) { $conf->diff3 = $exe; break; }}if ($conf->diff3) print "<li>Found GNU diff3: <tt>$conf->diff3</tt>.</li>";else print "<li>GNU diff3 not found.</li>";$conf->ImageMagick = false;$imcheck = array( "/usr/bin", "/opt/csw/bin", "/usr/local/bin", "/sw/bin", "/opt/local/bin" );foreach( $imcheck as $dir ) { $im = "$dir/convert"; if( file_exists( $im ) ) { print "<li>Found ImageMagick: <tt>$im</tt>; image thumbnailing will be enabled if you enable uploads.</li>\n"; $conf->ImageMagick = $im; break; }}$conf->HaveGD = function_exists( "imagejpeg" );if( $conf->HaveGD ) { print "<li>Found GD graphics library built-in"; if( !$conf->ImageMagick ) { print ", image thumbnailing will be enabled if you enable uploads"; } print ".</li>\n";} else { if( !$conf->ImageMagick ) { print "<li>Couldn't find GD library or ImageMagick; image thumbnailing disabled.</li>\n"; }}$conf->UseImageResize = $conf->HaveGD || $conf->ImageMagick;$conf->IP = dirname( dirname( __FILE__ ) );print "<li>Installation directory: <tt>" . htmlspecialchars( $conf->IP ) . "</tt></li>\n";$conf->ScriptPath = preg_replace( '{^(.*)/config.*$}', '$1', $_SERVER["PHP_SELF"] ); # was SCRIPT_NAMEprint "<li>Script URI path: <tt>" . htmlspecialchars( $conf->ScriptPath ) . "</tt></li>\n";print "<li style='font-weight:bold;color:green;font-size:110%'>Environment checked. You can install MediaWiki.</li>\n"; $conf->posted = ($_SERVER["REQUEST_METHOD"] == "POST"); $conf->Sitename = ucfirst( importPost( "Sitename", "" ) ); $defaultEmail = empty( $_SERVER["SERVER_ADMIN"] ) ? 'root@localhost' : $_SERVER["SERVER_ADMIN"]; $conf->EmergencyContact = importPost( "EmergencyContact", $defaultEmail ); $conf->DBtype = importPost( "DBtype", $DefaultDBtype );?><?php $conf->DBserver = importPost( "DBserver", "localhost" ); $conf->DBname = importPost( "DBname", "wikidb" ); $conf->DBuser = importPost( "DBuser", "wikiuser" ); $conf->DBpassword = importPost( "DBpassword" ); $conf->DBpassword2 = importPost( "DBpassword2" ); $conf->SysopName = importPost( "SysopName", "WikiSysop" ); $conf->SysopPass = importPost( "SysopPass" ); $conf->SysopPass2 = importPost( "SysopPass2" ); ## MySQL specific: $conf->DBprefix = importPost( "DBprefix" ); $conf->DBmysql5 = (importPost( "DBmysql5" ) == "true") ? "true" : "false"; $conf->RootUser = importPost( "RootUser", "root" ); $conf->RootPW = importPost( "RootPW", "-" ); $conf->LanguageCode = importPost( "LanguageCode", "en" ); ## Postgres specific: $conf->DBport = importPost( "DBport", "5432" ); $conf->DBmwschema = importPost( "DBmwschema", "mediawiki" ); $conf->DBts2schema = importPost( "DBts2schema", "public" );/* Check for validity */$errs = array();if( $conf->Sitename == "" || $conf->Sitename == "MediaWiki" || $conf->Sitename == "Mediawiki" ) { $errs["Sitename"] = "Must not be blank or \"MediaWiki\"";}if( $conf->DBuser == "" ) { $errs["DBuser"] = "Must not be blank";}if( $conf->DBpassword == "" ) { $errs["DBpassword"] = "Must not be blank";}if( $conf->DBpassword != $conf->DBpassword2 ) { $errs["DBpassword2"] = "Passwords don't match!";}if( !preg_match( '/^[A-Za-z_0-9]*$/', $conf->DBprefix ) ) { $errs["DBprefix"] = "Invalid table prefix";}if( $conf->SysopPass == "" ) { $errs["SysopPass"] = "Must not be blank";}if( $conf->SysopPass != $conf->SysopPass2 ) { $errs["SysopPass2"] = "Passwords don't match!";}$conf->License = importRequest( "License", "none" );if( $conf->License == "gfdl" ) { $conf->RightsUrl = "http://www.gnu.org/copyleft/fdl.html"; $conf->RightsText = "GNU Free Documentation License 1.2"; $conf->RightsCode = "gfdl"; $conf->RightsIcon = '${wgStylePath}/common/images/gnu-fdl.png';} elseif( $conf->License == "none" ) { $conf->RightsUrl = $conf->RightsText = $conf->RightsCode = $conf->RightsIcon = "";} else { $conf->RightsUrl = importRequest( "RightsUrl", "" ); $conf->RightsText = importRequest( "RightsText", "" ); $conf->RightsCode = importRequest( "RightsCode", "" ); $conf->RightsIcon = importRequest( "RightsIcon", "" );}$conf->Shm = importRequest( "Shm", "none" );$conf->MCServers = importRequest( "MCServers" );/* Test memcached servers */if ( $conf->Shm == 'memcached' && $conf->MCServers ) { $conf->MCServerArray = array_map( 'trim', explode( ',', $conf->MCServers ) ); foreach ( $conf->MCServerArray as $server ) { $error = testMemcachedServer( $server ); if ( $error ) { $errs["MCServers"] = $error; break; } }} else if ( $conf->Shm == 'memcached' ) { $errs["MCServers"] = "Please specify at least one server if you wish to use memcached";}/* default values for installation */$conf->Email =importRequest("Email", "email_enabled");$conf->Emailuser=importRequest("Emailuser", "emailuser_enabled");$conf->Enotif =importRequest("Enotif", "enotif_allpages");$conf->Eauthent =importRequest("Eauthent", "eauthent_enabled");if( $conf->posted && ( 0 == count( $errs ) ) ) { do { /* So we can 'continue' to end prematurely */ $conf->Root = ($conf->RootPW != ""); /* Load up the settings and get installin' */ $local = writeLocalSettings( $conf ); echo "<p><b>Generating configuration file...</b></p>\n"; // for debugging: // echo "<pre>" . htmlspecialchars( $local ) . "</pre>\n"; $wgCommandLineMode = false; chdir( ".." ); eval($local); $conf->DBtypename = ''; foreach (array_keys($ourdb) as $db) { if ($conf->DBtype === $db) $conf->DBtypename = $ourdb[$db]['fullname']; } if (! $conf->DBtypename) { $errs["DBtype"] = "Unknown database type '$conf->DBtype'"; continue; } print "<li>Database type: {$conf->DBtypename}</li>\n"; $dbclass = 'Database'.ucfirst($conf->DBtype); $wgDBtype = $conf->DBtype; $wgDBadminuser = "root"; $wgDBadminpassword = $conf->RootPW; ## Mysql specific: $wgDBprefix = $conf->DBprefix; ## Postgres specific: $wgDBport = $conf->DBport; $wgDBmwschema = $conf->DBmwschema; $wgDBts2schema = $conf->DBts2schema; $wgCommandLineMode = true; $wgUseDatabaseMessages = false; /* FIXME: For database failure */ require_once( "includes/Setup.php" ); chdir( "config" ); require_once( "maintenance/InitialiseMessages.inc" ); $wgTitle = Title::newFromText( "Installation script" );error_reporting( E_ALL ); print "<li>Loading class: $dbclass"; $dbc = new $dbclass; if( $conf->DBtype == 'mysql' ) { $mysqlOldClient = version_compare( mysql_get_client_info(), "4.1.0", "lt" ); if( $mysqlOldClient ) { print "<li><b>PHP is linked with old MySQL client libraries. If you are using a MySQL 4.1 server and have problems connecting to the database, see <a href='http://dev.mysql.com/doc/mysql/en/old-client.html' >http://dev.mysql.com/doc/mysql/en/old-client.html</a> for help.</b></li>\n"; } $ok = true; # Let's be optimistic # Decide if we're going to use the superuser or the regular database user if( $conf->RootPW == '-' ) { # Regular user $conf->Root = false; $db_user = $wgDBuser; $db_pass = $wgDBpassword; } else { # Superuser $conf->Root = true; $db_user = $conf->RootUser; $db_pass = $conf->RootPW; } # Attempt to connect echo( "<li>Attempting to connect to database server as $db_user..." ); $wgDatabase = Database::newFromParams( $wgDBserver, $db_user, $db_pass, '', 1 ); # Check the connection and respond to errors if( $wgDatabase->isOpen() ) { # Seems OK $ok = true; $wgDBadminuser = $db_user; $wgDBadminpassword = $db_pass; echo( "success.</li>\n" ); $wgDatabase->ignoreErrors( true ); $myver = $wgDatabase->getServerVersion(); } else { # There were errors, report them and back out $ok = false; $errno = mysql_errno(); $errtx = htmlspecialchars( mysql_error() ); switch( $errno ) { case 1045: case 2000: echo( "failed due to authentication errors. Check passwords.</li>" ); if( $conf->Root ) { # The superuser details are wrong $errs["RootUser"] = "Check username"; $errs["RootPW"] = "and password"; } else { # The regular user details are wrong $errs["DBuser"] = "Check username"; $errs["DBpassword"] = "and password"; } break; case 2002: case 2003: default: # General connection problem echo( "failed with error [$errno] $errtx.</li>\n" ); $errs["DBserver"] = "Connection failed"; break; } # switch } #conn. att. if( !$ok ) { continue; } } else /* not mysql */ { echo( "<li>Attempting to connect to database server as $wgDBuser..." ); $wgDatabase = $dbc->newFromParams($wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, 1); if (!$wgDatabase->isOpen()) { print " error: " . $wgDatabase->lastError() . "</li>\n"; } else { $wgDatabase->ignoreErrors(true); $myver = $wgDatabase->getServerVersion(); } } if ( !$wgDatabase->isOpen() ) { $errs["DBserver"] = "Couldn't connect to database"; continue; } print "<li>Connected to $myver"; if ($conf->DBtype == 'mysql') { if( version_compare( $myver, "4.0.14" ) < 0 ) { die( " -- mysql 4.0.14 or later required. Aborting." ); } $mysqlNewAuth = version_compare( $myver, "4.1.0", "ge" ); if( $mysqlNewAuth && $mysqlOldClient ) { print "; <b class='error'>You are using MySQL 4.1 server, but PHP is linked to old client libraries; if you have trouble with authentication, see <a href='http://dev.mysql.com/doc/mysql/en/old-client.html' >http://dev.mysql.com/doc/mysql/en/old-client.html</a> for help.</b>"; } if( $wgDBmysql5 ) { if( $mysqlNewAuth ) { print "; enabling MySQL 4.1/5.0 charset mode"; } else { print "; <b class='error'>MySQL 4.1/5.0 charset mode enabled, but older version detected; will likely fail.</b>"; } } print "</li>\n"; @$sel = $wgDatabase->selectDB( $wgDBname ); if( $sel ) { print "<li>Database <tt>" . htmlspecialchars( $wgDBname ) . "</tt> exists</li>\n"; } else { $err = mysql_errno(); if ( $err != 1049 ) { print "<ul><li>Error selecting database $wgDBname: $err " . htmlspecialchars( mysql_error() ) . "</li></ul>"; continue; } $res = $wgDatabase->query( "CREATE DATABASE `$wgDBname`" ); if( !$res ) { print "<li>Couldn't create database <tt>" . htmlspecialchars( $wgDBname ) . "</tt>; try with root access or check your username/pass.</li>\n"; $errs["RootPW"] = "<- Enter"; continue; } print "<li>Created database <tt>" . htmlspecialchars( $wgDBname ) . "</tt></li>\n"; } $wgDatabase->selectDB( $wgDBname ); } if( $wgDatabase->tableExists( "cur" ) || $wgDatabase->tableExists( "revision" ) ) { print "<li>There are already MediaWiki tables in this database. Checking if updates are needed...</li>\n"; # Create user if required (todo: other databases) if ( $conf->Root && $conf->DBtype == 'mysql') { $conn = $dbc->newFromParams( $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, 1 ); if ( $conn->isOpen() ) { print "<li>DB user account ok</li>\n"; $conn->close(); } else { print "<li>Granting user permissions..."; if( $mysqlOldClient && $mysqlNewAuth ) { print " <b class='error'>If the next step fails, see <a href='http://dev.mysql.com/doc/mysql/en/old-client.html'>http://dev.mysql.com/doc/mysql/en/old-client.html</a> for help.</b>"; } print "</li>\n"; dbsource( "../maintenance/users.sql", $wgDatabase ); } } if ( $conf->DBtype == 'mysql') { print "<pre>\n"; chdir( ".." ); flush(); do_all_updates(); chdir( "config" ); print "</pre>\n"; } print "<li>Finished update checks.</li>\n"; } else { # FIXME: Check for errors print "<li>Creating tables..."; if ($conf->DBtype == 'mysql') { if( $wgDBmysql5 ) { print " using MySQL 5 table defs..."; dbsource( "../maintenance/mysql5/tables.sql", $wgDatabase ); } else { print " using MySQL 4 table defs..."; dbsource( "../maintenance/tables.sql", $wgDatabase ); } dbsource( "../maintenance/interwiki.sql", $wgDatabase ); } else if ($conf->DBtype == 'postgres') { dbsource( "../maintenance/postgres/tables.sql", $wgDatabase ); $wgDatabase->update_interwiki(); } else if ($conf->DBtype == 'oracle') { dbsource( "../maintenance/oracle/tables.sql", $wgDatabase ); dbsource( "../maintenance/oracle/interwiki.sql", $wgDatabase ); } else { $errs["DBtype"] = "Do not know how to handle database type '$conf->DBtype'"; continue; } print " done.</li>\n"; print "<li>Initializing data..."; $wgDatabase->insert( 'site_stats', array( 'ss_row_id' => 1, 'ss_total_views' => 0, 'ss_total_edits' => 0, 'ss_good_articles' => 0 ) ); # Set up the "regular user" account *if we can, and if we need to* if( $conf->Root ) { # See if we need to $wgDatabase2 = $dbc->newFromParams( $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, 1 ); if( $wgDatabase2->isOpen() ) { # Nope, just close the test connection and continue $wgDatabase2->close(); echo( "<li>User $wgDBuser exists. Skipping grants.</li>" ); } else { # Yes, so run the grants echo( "<li>Granting user permissions to $wgDBuser on $wgDBname..." ); dbsource( "../maintenance/users.sql", $wgDatabase ); echo( "success.</li>" ); } } if( $conf->SysopName ) { $u = User::newFromName( $conf->getSysopName() ); if ( 0 == $u->idForName() ) { $u->addToDatabase(); $u->setPassword( $conf->getSysopPass() ); $u->saveSettings(); $u->addGroup( "sysop" ); $u->addGroup( "bureaucrat" ); print "<li>Created sysop account <tt>" . htmlspecialchars( $conf->SysopName ) . "</tt>.</li>\n"; } else { print "<li>Could not create user - already exists!</li>\n"; } } else {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?