-<?
+<?php
-if( !function_exists( "version_compare" ) ) {
- # version_compare was introduced in 4.1.0
- die( "Your PHP version is much too old; 4.0.x will _not_ work. 4.3.2 or higher is recommended. ABORTING.\n" );
-}
-if( version_compare( phpversion(), "4.3.2" ) < 0 ) {
- echo "WARNING: PHP 4.3.2 or higher is recommended. Older versions from 4.1.x up may work but are not actively supported.\n\n";
-}
-if( !ini_get( "register_globals" ) ) {
- echo "WARNING: register_globals is not on; MediaWiki currently relies on this option.\n\n";
-}
+die("obsolete; remove this file befor 1.3.0 release\n");
-if (!extension_loaded('mysql')) {
- if (!dl('mysql.so')) {
- print "Could not load MySQL driver! Please compile ".
- "php --with-mysql or install the mysql.so module.\n";
- exit;
- }
-}
# Install software and create new empty database.
#
+include( "./install-utils.inc" );
+install_version_checks();
+
if ( ! ( is_readable( "./LocalSettings.php" )
&& is_readable( "./AdminSettings.php" ) ) ) {
print "You must first create the files LocalSettings.php\n" .
}
$DP = "./includes";
-include_once( "./LocalSettings.php" );
-include_once( "./AdminSettings.php" );
-include_once( "./maintenance/InitialiseMessages.inc" );
+require_once( "./LocalSettings.php" );
+require_once( "./AdminSettings.php" );
+require_once( "./maintenance/InitialiseMessages.inc" );
+
+if( $wgSitename == "MediaWiki" ) {
+ die( "You must set the site name in \$wgSitename before installation.\n\n" );
+}
if ( $wgUseTeX && ( ! is_executable( "./math/texvc" ) ) ) {
print "To use math functions, you must first compile texvc by\n" .
if ( ! ( "Y" == $response{0} || "y" == $response{0} ) ) { exit(); }
}
-$wgCommandLineMode = true;
-umask( 000 );
-set_time_limit( 0 );
-
#
# Make the necessary directories
#
copyfile( ".", "LocalSettings.php", $IP );
copyfile( ".", "Version.php", $IP );
+copyfile( ".", "index.php", $IP );
+copyfile( ".", "redirect.php", $IP );
+
+# compatibility with older versions, can be removed in a year or so
+# (written in Feb 2004)
copyfile( ".", "wiki.phtml", $IP );
copyfile( ".", "redirect.phtml", $IP );
-copyfile( ".", "texvc.phtml", $IP );
copydirectory( "./includes", $IP );
copydirectory( "./stylesheets", $wgStyleSheetDirectory );
copyfile( "./images", "wiki.png", $wgUploadDirectory );
+copyfile( "./images", "button_bold.png", $wgUploadDirectory );
+copyfile( "./images", "button_extlink.png", $wgUploadDirectory );
+copyfile( "./images", "button_headline.png", $wgUploadDirectory );
+copyfile( "./images", "button_hr.png", $wgUploadDirectory );
+copyfile( "./images", "button_image.png", $wgUploadDirectory );
+copyfile( "./images", "button_italic.png", $wgUploadDirectory );
+copyfile( "./images", "button_link.png", $wgUploadDirectory );
+copyfile( "./images", "button_math.png", $wgUploadDirectory );
+copyfile( "./images", "button_media.png", $wgUploadDirectory );
+copyfile( "./images", "button_nowiki.png", $wgUploadDirectory );
+copyfile( "./images", "button_sig.png", $wgUploadDirectory );
+copyfile( "./images", "button_template.png", $wgUploadDirectory );
+copyfile( "./images", "magnify-clip.png", $wgUploadDirectory );
+copyfile( "./images", "Arr_.png", $wgUploadDirectory );
+copyfile( "./images", "Arr_r.png", $wgUploadDirectory );
+copyfile( "./images", "Arr_d.png", $wgUploadDirectory );
+copyfile( "./images", "Arr_l.png", $wgUploadDirectory );
+
copyfile( "./languages", "Language.php", $IP );
+copyfile( "./languages", "LanguageUtf8.php", $IP );
copyfile( "./languages", "Language" . ucfirst( $wgLanguageCode ) . ".php", $IP );
-$fp = fopen( $wgDebugLogFile, "w" );
-if ( false === $fp ) {
- print "Could not create log file \"{$wgDebugLogFile}\".\n";
- exit();
+if ( $wgDebugLogFile ) {
+ $fp = fopen( $wgDebugLogFile, "w" );
+ if ( false === $fp ) {
+ print "Could not create log file \"{$wgDebugLogFile}\".\n";
+ exit();
+ }
+ $d = date( "Y-m-d H:i:s" );
+ fwrite( $fp, "Wiki debug log file created {$d}\n\n" );
+ fclose( $fp );
}
-$d = date( "Y-m-d H:i:s" );
-fwrite( $fp, "Wiki debug log file created {$d}\n\n" );
-fclose( $fp );
if ( $wgUseTeX ) {
makedirectory( "{$IP}/math" );
#
# Make and initialize database
#
-print "\n* * *\nWarning! This script will completely erase the\n" .
+print "\n* * *\nWarning! This script will completely erase any\n" .
"existing database \"{$wgDBname}\" and all its contents.\n" .
"Are you sure you want to do this? (yes/no) ";
$response = readconsole();
if ( ! ( "Y" == $response{0} || "y" == $response{0} ) ) { exit(); }
-print "\nYou should have already created a root password for the database.\n" .
- "Enter the root password here: ";
+print "Please enter your root password for the database server now.\n";
+print "It is used to do the following:\n";
+print "1) Create the database\n";
+print "2) Create the users specified in AdminSettings.php and LocalSettings.php\n\n";
+print "You do not need to create any user accounts yourself!\n\n";
+print "MySQL root password (typing will be visible): ";
+$rootpw=readconsole();
-$rootpw = readconsole();
+# Include rest of code to get things like internationalized messages.
+#
+$wgUseDatabaseMessages = false; # no DB yet
-$rconn = mysql_connect( $wgDBserver, "root", $rootpw );
-if ( false === $rconn ) {
+require_once( "{$IP}/Setup.php" );
+$wgTitle = Title::newFromText( "Installation script" );
+
+$wgDatabase = Database::newFromParams( $wgDBserver, "root", $rootpw, "", 1 );
+if ( !$wgDatabase->isOpen() ) {
print "Could not connect to database on \"{$wgDBserver}\" as root.\n";
exit();
}
-# Include rest of code to get things like internationalized messages.
-#
-include_once( "{$IP}/Setup.php" );
-$wgTitle = Title::newFromText( "Installation script" );
-
# Now do the actual database creation
#
print "Creating database...\n";
-dbsource( $rconn, "./maintenance/database.sql" );
+dbsource( "./maintenance/database.sql", $wgDatabase );
-mysql_select_db( $wgDBname, $rconn );
-dbsource( $rconn, "./maintenance/tables.sql" );
-dbsource( $rconn, "./maintenance/users.sql" );
-dbsource( $rconn, "./maintenance/initialdata.sql" );
-dbsource( $rconn, "./maintenance/interwiki.sql" );
+$wgDatabase->selectDB( $wgDBname );
+dbsource( "./maintenance/tables.sql", $wgDatabase );
+dbsource( "./maintenance/users.sql", $wgDatabase );
+dbsource( "./maintenance/initialdata.sql", $wgDatabase );
+dbsource( "./maintenance/interwiki.sql", $wgDatabase );
populatedata(); # Needs internationalized messages
print "Adding indexes...\n";
-dbsource( $rconn, "./maintenance/indexes.sql" );
+dbsource( "./maintenance/indexes.sql", $wgDatabase );
-print "Done.\nBrowse \"{$wgServer}{$wgScript}\" to test,\n" .
- "or \"run WikiSuite -b -o\" in test suite.\n";
+print "Done.\nBrowse \"{$wgServer}{$wgScript}\" to test.\n";
exit();
#
}
}
-function copyfile( $sdir, $name, $ddir, $perms = 0664 ) {
- global $wgInstallOwner, $wgInstallGroup;
-
- $d = "{$ddir}/{$name}";
- if ( copy( "{$sdir}/{$name}", $d ) ) {
- if ( isset( $wgInstallOwner ) ) { chown( $d, $wgInstallOwner ); }
- if ( isset( $wgInstallGroup ) ) { chgrp( $d, $wgInstallGroup ); }
- chmod( $d, $perms );
- # print "Copied \"{$name}\" to \"{$ddir}\".\n";
- } else {
- print "Failed to copy file \"{$name}\" to \"{$ddir}\".\n";
- exit();
- }
-}
-
-function copydirectory( $source, $dest ) {
- $handle = opendir( $source );
- while ( false !== ( $f = readdir( $handle ) ) ) {
- if ( "." == $f{0} ) continue;
- # Something made all my "CVSs" go lowercase :(
- if ( !strcasecmp( "CVS", $f ) ) continue;
- copyfile( $source, $f, $dest );
- }
-}
-
-function readconsole() {
- $fp = fopen( "php://stdin", "r" );
- $resp = trim( fgets( $fp, 1024 ) );
- fclose( $fp );
- return $resp;
-}
-
-#
-# Read and execute SQL commands from a file
-#
-function dbsource( $conn, $fname ) {
- $fp = fopen( $fname, "r" );
- if ( false === $fp ) {
- print "Could not open \"{$fname}\".\n";
- exit();
- }
-
- $cmd = "";
- $done = false;
-
- while ( ! feof( $fp ) ) {
- $line = trim( fgets( $fp, 1024 ) );
- $sl = strlen( $line ) - 1;
-
- if ( $sl < 0 ) { continue; }
- if ( "-" == $line{0} && "-" == $line{1} ) { continue; }
-
- if ( ";" == $line{$sl} ) {
- $done = true;
- $line = substr( $line, 0, $sl );
- }
-
- if ( "" != $cmd ) { $cmd .= " "; }
- $cmd .= $line;
-
- if ( $done ) {
- $cmd = replacevars( $cmd );
- $res = mysql_query( $cmd, $conn );
-
- if ( false === $res ) {
- print "Query \"{$cmd}\" failed.\n";
- exit();
- }
-
- $cmd = "";
- $done = false;
- }
- }
- fclose( $fp );
-}
-
-function replacevars( $ins ) {
- $varnames = array(
- "wgDBserver", "wgDBname", "wgDBintlname", "wgDBuser",
- "wgDBpassword", "wgDBsqluser", "wgDBsqlpassword",
- "wgDBadminuser", "wgDBadminpassword"
- );
-
- foreach ( $varnames as $var ) {
- global $$var;
- $ins = str_replace( '{$' . $var . '}', $$var, $ins );
- }
- return $ins;
-}
function populatedata() {
- global $wgDBadminpassword;
+ global $wgDBadminpassword, $wgDatabase;
$fname = "Installation script: populatedata()";
$sql = "DELETE FROM site_stats";
- wfQuery( $sql, DB_WRITE, $fname );
+ $wgDatabase->query( $sql, $fname );
$sql = "INSERT INTO site_stats (ss_row_id,ss_total_views," .
"ss_total_edits,ss_good_articles) VALUES (1,0,0,0)";
- wfQuery( $sql, DB_WRITE, $fname );
+ $wgDatabase->query( $sql, $fname );
$sql = "DELETE FROM user";
- wfQuery( $sql, DB_WRITE, $fname );
-
- $u = User::newFromName( "WikiSysop" );
- if ( 0 == $u->idForName() ) {
- $u->addToDatabase();
- $u->setPassword( $wgDBadminpassword );
- $u->addRight( "sysop" );
- $u->saveSettings();
+ $wgDatabase->query( $sql, $fname );
+
+ print "Do you want to create a sysop account? A sysop can protect,\n";
+ print "delete and undelete pages and ban users. Recomended. [Y/n] ";
+ $response = readconsole();
+ if(strtolower($response)!="n") {
+ print "Enter the username [Sysop]: ";
+ $sysop_user=readconsole();
+ if(!$sysop_user) { $sysop_user="Sysop"; }
+ while(!$sysop_password) {
+ print "Enter the password: ";
+ $sysop_password=readconsole();
+ }
+ $u = User::newFromName( $sysop_user );
+ if ( 0 == $u->idForName() ) {
+ $u->addToDatabase();
+ $u->setPassword( $sysop_password );
+ $u->addRight( "sysop" );
+ $u->saveSettings();
+ } else {
+ print "Could not create user - already exists!\n";
+ }
}
- $u = User::newFromName( "WikiDeveloper" );
- if ( 0 == $u->idForName() ) {
- $u->addToDatabase();
- $u->setPassword( $wgDBadminpassword );
- $u->addRight( "sysop" );
- $u->addRight( "developer" );
- $u->saveSettings();
+ print "Do you want to create a sysop+developer account? A developer\n";
+ print "can switch the database to read-only mode and run any type of\n";
+ print "query through a web interface. [Y/n] ";
+ $response=readconsole();
+ if(strtolower($response)!="n") {
+ print "Enter the username [Developer]: ";
+ $developer_user=readconsole();
+ if(!$developer_user) { $developer_user="Developer"; }
+ while (!$developer_password) {
+ print "Enter the password: ";
+ $developer_password=readconsole();
+ }
+ $u = User::newFromName( $developer_user );
+ if ( 0 == $u->idForName() ) {
+ $u->addToDatabase();
+ $u->setPassword( $developer_password );
+ $u->addRight( "sysop" );
+ $u->addRight( "developer" );
+ $u->saveSettings();
+ } else {
+ print "Could not create user - already exists!\n";
+ }
}
$wns = Namespace::getWikipedia();
$dlp = addslashes( wfMsgNoDB( "dellogpage" ) );
$sql = "DELETE FROM cur";
- wfQuery( $sql, DB_WRITE, $fname );
+ $wgDatabase->query( $sql, $fname );
+ $now = wfTimestampNow();
+ $won = wfInvertTimestamp( $now );
+
$sql = "INSERT INTO cur (cur_namespace,cur_title,cur_text," .
- "cur_restrictions) VALUES ({$wns},'{$ulp}','" .
- wfStrencode( wfMsgNoDB( "uploadlogpagetext" ) ) . "','sysop')";
- wfQuery( $sql, DB_WRITE, $fname );
+ "cur_restrictions,cur_timestamp,inverse_timestamp,cur_touched) VALUES ({$wns},'{$ulp}','" .
+ wfStrencode( wfMsg( "uploadlogpagetext" ) ) . "','sysop','$now','$won','$now')";
+ $wgDatabase->query( $sql, $fname );
$sql = "INSERT INTO cur (cur_namespace,cur_title,cur_text," .
- "cur_restrictions) VALUES ({$wns},'{$dlp}','" .
- wfStrencode( wfMsgNoDB( "dellogpagetext" ) ) . "','sysop')";
- wfQuery( $sql, DB_WRITE, $fname );
+ "cur_restrictions,cur_timestamp,inverse_timestamp,cur_touched) VALUES ({$wns},'{$dlp}','" .
+ wfStrencode( wfMsg( "dellogpagetext" ) ) . "','sysop','$now','$won','$now')";
+ $wgDatabase->query( $sql, $fname );
$titleobj = Title::newFromText( wfMsgNoDB( "mainpage" ) );
$title = $titleobj->getDBkey();
- $sql = "INSERT INTO cur (cur_namespace,cur_title,cur_text) " .
+ $sql = "INSERT INTO cur (cur_namespace,cur_title,cur_text,cur_timestamp,inverse_timestamp,cur_touched) " .
"VALUES (0,'$title','" .
- wfStrencode( wfMsgNoDB( "mainpagetext" ) ) . "')";
- wfQuery( $sql, DB_WRITE, $fname );
+ wfStrencode( wfMsg( "mainpagetext" ) ) . "','$now','$won','$now')";
+ $wgDatabase->query( $sql, $fname );
initialiseMessages();
}