Fix NS_PROJECT_TALK (bug #7792)
[lhc/web/wiklou.git] / maintenance / updaters.inc
index 400da7e..7909b13 100644 (file)
@@ -6,9 +6,14 @@
 
  /** */
 
+if ( !defined( 'MEDIAWIKI' ) ) {
+       echo "This file is not a valid entry point\n";
+       exit( 1 );
+}
+
 require_once 'convertLinks.inc';
-require_once 'InitialiseMessages.inc';
 require_once 'userDupes.inc';
+require_once 'deleteDefaultMessages.php';
 
 $wgRenamedTables = array(
 #           from             to                  patch file
@@ -43,8 +48,7 @@ $wgNewFields = array(
        array( 'recentchanges', 'rc_ip',            'patch-rc_ip.sql' ),
        array( 'recentchanges', 'rc_id',            'patch-rc_id.sql' ),
        array( 'recentchanges', 'rc_patrolled',     'patch-rc-patrol.sql' ),
-       array( 'recentchanges', 'rc_old_len',       'patch-rc_old_len.sql' ),
-       array( 'recentchanges', 'rc_new_len',       'patch-rc_new_len.sql' ),
+       array( 'recentchanges', 'rc_old_len',       'patch-rc_len.sql' ),
        array( 'user',          'user_real_name',   'patch-user-realname.sql' ),
        array( 'user',          'user_token',       'patch-user_token.sql' ),
        array( 'user',          'user_email_token', 'patch-user_email_token.sql' ),
@@ -63,6 +67,7 @@ $wgNewFields = array(
        array( 'site_stats',    'ss_images',        'patch-ss_images.sql' ),
        array( 'ipblocks',      'ipb_anon_only',    'patch-ipb_anon_only.sql' ),
        array( 'user',          'user_newpass_time','patch-user_newpass_time.sql' ),
+       array( 'user',          'user_editcount',   'patch-user_editcount.sql' ),
 );
 
 function rename_table( $from, $to, $patch ) {
@@ -385,7 +390,7 @@ function do_schema_restructuring() {
                        page_id int(8) unsigned NOT NULL auto_increment,
                        page_namespace int NOT NULL,
                        page_title varchar(255) binary NOT NULL,
-                       page_restrictions tinyblob NOT NULL default '',
+                       page_restrictions tinyblob NOT NULL,
                        page_counter bigint(20) unsigned NOT NULL default '0',
                        page_is_redirect tinyint(1) unsigned NOT NULL default '0',
                        page_is_new tinyint(1) unsigned NOT NULL default '0',
@@ -402,7 +407,7 @@ function do_schema_restructuring() {
                $wgDatabase->query("CREATE TABLE $revision (
                        rev_id int(8) unsigned NOT NULL auto_increment,
                        rev_page int(8) unsigned NOT NULL,
-                       rev_comment tinyblob NOT NULL default '',
+                       rev_comment tinyblob NOT NULL,
                        rev_user int(5) unsigned NOT NULL default '0',
                        rev_user_text varchar(255) binary NOT NULL default '',
                        rev_timestamp char(14) binary NOT NULL default '',
@@ -823,8 +828,17 @@ function do_backlinking_indices_update() {
        }
 }
 
-function do_all_updates( $doShared = false ) {
-       global $wgNewTables, $wgNewFields, $wgRenamedTables, $wgSharedDB, $wgDatabase, $wgDBtype;
+function purge_cache() {
+       global $wgDatabase;
+       # We can't guarantee that the user will be able to use TRUNCATE,
+       # but we know that DELETE is available to us
+       echo( "Purging caches..." );
+       $wgDatabase->delete( 'objectcache', '*', __METHOD__ );
+       echo( "done.\n" );
+}
+
+function do_all_updates( $shared = false, $purge = true ) {
+       global $wgNewTables, $wgNewFields, $wgRenamedTables, $wgSharedDB, $wgDatabase, $wgDBtype, $IP;
 
        $doUser = !$wgSharedDB || $doShared;
 
@@ -891,7 +905,14 @@ function do_all_updates( $doShared = false ) {
        
        do_backlinking_indices_update(); flush();
 
-       initialiseMessages(); flush();
+       echo "Deleting old default messages..."; flush();
+       deleteDefaultMessages();
+       echo "Done\n"; flush();
+       
+       if( $purge ) {
+               purge_cache();
+               flush();
+       }
 }
 
 function archive($name) {
@@ -907,20 +928,28 @@ function archive($name) {
 function do_postgres_updates() {
        global $wgDatabase, $wgVersion, $wgDBmwschema;
 
-       $version = "1.7.1";
-
        # Just in case their LocalSetings.php does not have this:
        if ( !isset( $wgDBmwschema ))
                $wgDBmwschema = 'mediawiki';
 
+       ## Default to the oldest supported version
+       $version = 1.7;
+
        if ($wgDatabase->tableExists("mediawiki_version")) {
                $version = "1.8";
+               $sql = "SELECT mw_version FROM mediawiki_version ORDER BY cdate DESC LIMIT 1";
+               $tempversion = pg_fetch_result($wgDatabase->doQuery($sql),0,0);
+               $thisver = array();
+               if (preg_match('/(\d+\.\d+)/', $tempversion, $thisver)) {
+                       $version = $thisver[1];
+               }
        }
 
-       if ($version == '1.7.1') {
-               $upgrade = <<<PGEND
+       print " Detected version: $version ";
+       $upgrade = '';
 
-BEGIN;
+       if ($version <= 1.7) {
+               $upgrade = <<<PGEND
 
 -- Type tweaking:
 ALTER TABLE oldimage ALTER oi_size TYPE INTEGER;
@@ -973,9 +1002,6 @@ CREATE TABLE mediawiki_version (
   cdate        TIMESTAMPTZ  NOT NULL DEFAULT now()
 );
 
-INSERT INTO mediawiki_version (type,mw_version,notes)
-VALUES ('Upgrade','MWVERSION','Upgrade from older version 1.7.1');
-
 -- Special modifications
 ALTER TABLE archive RENAME to archive2;
 CREATE VIEW archive AS 
@@ -1003,23 +1029,21 @@ END;
 CREATE TRIGGER page_deleted AFTER DELETE ON page
   FOR EACH ROW EXECUTE PROCEDURE page_deleted();
 
-COMMIT;
-
 PGEND;
 
-       } ## end version 1.7.1 upgrade
-       else if ($version == '1.8') {
-               $upgrade = <<<PGEND
+       } ## end version 1.7
 
-BEGIN;
+       else if ($version <= 1.8) {
+               $upgrade = <<<PGEND
 
 -- Tighten up restrictions on the revision table so we don't lose data:
 ALTER TABLE revision DROP CONSTRAINT revision_rev_user_fkey;
 ALTER TABLE revision ADD CONSTRAINT revision_rev_user_fkey
   FOREIGN KEY (rev_user) REFERENCES mwuser(user_id) ON DELETE RESTRICT;
 
--- New column for better password tracking:
+-- New columns for better password tracking:
 ALTER TABLE mwuser ADD user_newpass_time TIMESTAMPTZ;
+ALTER TABLE mwuser ADD user_editcount INTEGER;
 
 -- New column for autoblocking problem users
 ALTER TABLE ipblocks ADD ipb_enable_autoblock CHAR NOT NULL DEFAULT '1';
@@ -1048,27 +1072,25 @@ CREATE INDEX querycachetwo_title      ON querycachetwo (qcc_type,qcc_namespace,q
 CREATE INDEX querycachetwo_titletwo   ON querycachetwo (qcc_type,qcc_namespacetwo,qcc_titletwo);
 
 -- New columns for fancy recentchanges display
-ALTER TABLE recentchanges ADD rc_old_len INT DEFAULT 0;
-ALTER TABLE recentchanges ADD rc_new_len INT DEFAULT 0;
+ALTER TABLE recentchanges ADD rc_old_len INT;
+ALTER TABLE recentchanges ADD rc_new_len INT;
 
 -- Note this upgrade
 INSERT INTO mediawiki_version (type,mw_version,notes)
-VALUES ('Upgrade','MWVERSION','Upgrade from older version 1.8');
-
-COMMIT;
+VALUES ('Upgrade','MWVERSION','Upgrade from older version THISVERSION');
 
 PGEND;
 
        }
 
-       else {
+       if ( !strlen($upgrade)) {
                print "No updates needed for version $version\n";
                return;
        }
 
        $upgrade = str_replace( 'MWVERSION', $wgVersion, $upgrade );
-       $res = $wgDatabase->query($upgrade);
-
+       $upgrade = str_replace( 'THISVERSION', $version, $upgrade );
+       $res = $wgDatabase->query("BEGIN;\n\n $upgrade\n\nCOMMIT;\n");
 
        return;
 }