* (bug 5195) rebuildrecentchanges.php works again; Database::insertSelect now has...
[lhc/web/wiklou.git] / maintenance / updaters.inc
index ace5b2f..6f33841 100644 (file)
@@ -26,6 +26,8 @@ $wgNewTables = array(
        array( 'user_newtalk',  'patch-usernewtalk2.sql' ),
        array( 'transcache',    'patch-transcache.sql' ),
        array( 'trackbacks',    'patch-trackbacks.sql' ),
+       array( 'externallinks', 'patch-externallinks.sql' ),
+       array( 'job',           'patch-job.sql' ),
 );
 
 $wgNewFields = array(
@@ -39,6 +41,7 @@ $wgNewFields = array(
        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' ),
+       array( 'user',          'user_registration','patch-user_registration.sql' ),
        array( 'logging',       'log_params',       'patch-log_params.sql' ),
        array( 'archive',       'ar_rev_id',        'patch-archive-rev_id.sql' ),
        array( 'archive',       'ar_text_id',       'patch-archive-text_id.sql' ),
@@ -49,7 +52,9 @@ $wgNewFields = array(
        array( 'image',         'img_media_type',   'patch-img_media_type.sql' ),
        array( 'validate',      'val_ip',           'patch-val_ip.sql' ),
        array( 'site_stats',    'ss_total_pages',   'patch-ss_total_articles.sql' ),
-       array( 'interwiki',     'iw_trans',         'patch-interwiki-trans.sql' ),
+       array( 'interwiki',     'iw_trans',         'patch-interwiki-trans.sql' ),
+       array( 'ipblocks',      'ipb_range_start',  'patch-ipb_range_start.sql' ),
+       array( 'site_stats',    'ss_images',        'patch-ss_images.sql' ),
 );
 
 function rename_table( $from, $to, $patch ) {
@@ -159,7 +164,7 @@ function do_index_update() {
 
 function do_image_index_update() {
        global $wgDatabase;
-       
+
        $meta = $wgDatabase->fieldInfo( "image", "img_major_mime" );
        if( $meta->multiple_key == 0 ) {
                echo "Updating indexes to 20050912: ";
@@ -182,8 +187,21 @@ function do_image_name_unique_update() {
        }
 }
 
+function do_logging_timestamp_index() {
+       global $wgDatabase;
+       if( $wgDatabase->indexExists( 'logging', 'times' ) ) {
+               echo "...timestamp key on logging already exists.\n";
+       } else {
+               echo "Adding timestamp key on logging table... ";
+               dbsource( archive("patch-logging-times-index.sql"), $wgDatabase );
+               echo "ok\n";
+       }
+}
+
+
 function do_watchlist_update() {
        global $wgDatabase;
+       $fname = 'do_watchlist_update';
        if( $wgDatabase->fieldExists( 'watchlist', 'wl_notificationtimestamp' ) ) {
                echo "The watchlist table is already set up for email notification.\n";
        } else {
@@ -192,6 +210,24 @@ function do_watchlist_update() {
                dbsource( "maintenance/archives/patch-email-notification.sql", $wgDatabase );
                echo "ok\n";
        }
+       # Check if we need to add talk page rows to the watchlist
+       $talk = $wgDatabase->selectField( 'watchlist', 'count(*)', 'wl_namespace & 1', $fname );
+       $nontalk = $wgDatabase->selectField( 'watchlist', 'count(*)', 'NOT (wl_namespace & 1)', $fname );
+       if ( $talk != $nontalk ) {
+               echo "Adding missing watchlist talk page rows... ";
+               flush();
+
+               $wgDatabase->insertSelect( 'watchlist', 'watchlist', 
+                       array(
+                               'wl_user' => 'wl_user',
+                               'wl_namespace' => 'wl_namespace | 1',
+                               'wl_title' => 'wl_title',
+                               'wl_notificationtimestamp' => 'wl_notificationtimestamp'
+                       ), array( 'NOT (wl_namespace & 1)' ), $fname, 'IGNORE' );
+               echo "ok\n";
+       } else {
+               echo "...watchlist talk page rows already present\n";
+       }
 }
 
 function do_copy_newtalk_to_watchlist() {
@@ -354,7 +390,7 @@ function do_schema_restructuring() {
                        UNIQUE INDEX name_title (page_namespace,page_title),
                        INDEX (page_random),
                        INDEX (page_len)
-                       ) TYPE=InnoDB", $fname );
+                       ) ENGINE=InnoDB", $fname );
                $wgDatabase->query("CREATE TABLE $revision (
                        rev_id int(8) unsigned NOT NULL auto_increment,
                        rev_page int(8) unsigned NOT NULL,
@@ -371,7 +407,7 @@ function do_schema_restructuring() {
                        INDEX page_timestamp (rev_page,rev_timestamp),
                        INDEX user_timestamp (rev_user,rev_timestamp),
                        INDEX usertext_timestamp (rev_user_text,rev_timestamp)
-                       ) TYPE=InnoDB", $fname );
+                       ) ENGINE=InnoDB", $fname );
 
                echo wfTimestamp();
                echo "......Locking tables.\n";
@@ -648,7 +684,7 @@ function do_watchlist_null() {
        # and update old broken items.
        global $wgDatabase;
        $info = $wgDatabase->fieldInfo( 'watchlist', 'wl_notificationtimestamp' );
-       
+
        if( $info->not_null ) {
                echo "Making wl_notificationtimestamp nullable... ";
                dbsource( 'maintenance/archives/patch-watchlist-null.sql', $wgDatabase );
@@ -659,8 +695,75 @@ function do_watchlist_null() {
 
 }
 
-function do_all_updates() {
-       global $wgNewTables, $wgNewFields, $wgRenamedTables;
+/**
+ * @bug 3946
+ */
+function do_page_random_update() {
+       global $wgDatabase;
+
+       echo "Setting page_random to a random value on rows where it equals 0...";
+
+       $page = $wgDatabase->tableName( 'page' );
+       $wgDatabase->query( "UPDATE $page SET page_random = RAND() WHERE page_random = 0", 'do_page_random_update' );
+       $rows = $wgDatabase->affectedRows();
+
+       echo "changed $rows rows\n";
+}
+
+function do_templatelinks_update() {
+       global $wgDatabase, $wgLoadBalancer;
+       $fname = 'do_templatelinks_update';
+
+       if ( $wgDatabase->tableExists( 'templatelinks' ) ) {
+               echo "...templatelinks table already exists\n";
+               return;
+       }
+       echo "Creating templatelinks table...\n";
+       dbsource( archive('patch-templatelinks.sql'), $wgDatabase );
+       echo "Populating...\n";
+       if ( isset( $wgLoadBalancer ) && $wgLoadBalancer->getServerCount() > 1 ) {
+               // Slow, replication-friendly update
+               $res = $wgDatabase->select( 'pagelinks', array( 'pl_from', 'pl_namespace', 'pl_title' ),
+                       array( 'pl_namespace' => NS_TEMPLATE ), $fname );
+               $count = 0;
+               while ( $row = $wgDatabase->fetchObject( $res ) ) {
+                       $count = ($count + 1) % 100;
+                       if ( $count == 0 ) {
+                               if ( function_exists( 'wfWaitForSlaves' ) ) {
+                                       wfWaitForSlaves( 10 );
+                               } else {
+                                       sleep( 1 );
+                               }
+                       }
+                       $wgDatabase->insert( 'templatelinks',
+                               array(
+                                       'tl_from' => $row->pl_from,
+                                       'tl_namespace' => $row->pl_namespace,
+                                       'tl_title' => $row->pl_title,
+                               ), $fname
+                       );
+
+               }
+               $wgDatabase->freeResult( $res );
+       } else {
+               // Fast update
+               $wgDatabase->insertSelect( 'templatelinks', 'pagelinks',
+                       array(
+                               'tl_from' => 'pl_from',
+                               'tl_namespace' => 'pl_namespace',
+                               'tl_title' => 'pl_title'
+                       ), array(
+                               'pl_namespace' => 10
+                       ), $fname
+               );
+       }
+       echo "Done. Please run maintenance/refreshLinks.php for a more thorough templatelinks update.\n";
+}
+
+function do_all_updates( $doShared = false ) {
+       global $wgNewTables, $wgNewFields, $wgRenamedTables, $wgSharedDB, $wgDatabase;
+
+       $doUser = !$wgSharedDB || $doShared;
 
        # Rename tables
        foreach ( $wgRenamedTables as $tableRecord ) {
@@ -675,7 +778,9 @@ function do_all_updates() {
 
        # Add missing fields
        foreach ( $wgNewFields as $fieldRecord ) {
-               add_field( $fieldRecord[0], $fieldRecord[1], $fieldRecord[2] );
+               if ( $fieldRecord[0] != 'user' || $doUser ) {
+                       add_field( $fieldRecord[0], $fieldRecord[1], $fieldRecord[2] );
+               }
                flush();
        }
 
@@ -685,7 +790,9 @@ function do_all_updates() {
        do_old_links_update(); flush();
        do_image_name_unique_update(); flush();
        do_watchlist_update(); flush();
-       do_user_update(); flush();
+       if ( $doUser ) {
+               do_user_update(); flush();
+       }
 ###### do_copy_newtalk_to_watchlist(); flush();
        do_logging_encoding(); flush();
 
@@ -695,26 +802,33 @@ function do_all_updates() {
        do_namespace_size(); flush();
 
        do_pagelinks_update(); flush();
+       do_templatelinks_update(); flush(); // after pagelinks
 
        do_drop_img_type(); flush();
 
-       do_user_unique_update(); flush();
+       if ( $doUser ) {
+               do_user_unique_update(); flush();
+       }
        do_user_groups_update(); flush();
-       
+
        do_watchlist_null(); flush();
 
        //do_image_index_update(); flush();
 
+       do_logging_timestamp_index(); flush();
+
+       do_page_random_update(); flush();
+
        initialiseMessages(); flush();
 }
 
 function archive($name) {
-       global $wgDBtype;
+       global $wgDBtype, $IP;
        switch ($wgDBtype) {
        case "oracle":
-               return "maintenance/oracle/archives/$name";
+               return "$IP/maintenance/oracle/archives/$name";
        default:
-               return "maintenance/archives/$name";
+               return "$IP/maintenance/archives/$name";
        }
 }
 ?>