--conf option for specifying a different LocalSettings.php. This allows multiple...
[lhc/web/wiklou.git] / maintenance / updaters.inc
index 2676b35..bb681d6 100644 (file)
@@ -39,6 +39,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 +50,8 @@ $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' ),
 );
 
 function rename_table( $from, $to, $patch ) {
@@ -157,6 +159,20 @@ function do_index_update() {
        return false;
 }
 
+function do_image_index_update() {
+       global $wgDatabase;
+
+       $meta = $wgDatabase->fieldInfo( "image", "img_major_mime" );
+       if( $meta->multiple_key == 0 ) {
+               echo "Updating indexes to 20050912: ";
+               dbsource( archive("patch-mimesearch-indexes.sql") );
+               echo "ok\n";
+               return true;
+       }
+       echo "...indexes seem up to 20050912 standards\n";
+       return false;
+}
+
 function do_image_name_unique_update() {
        global $wgDatabase;
        if( $wgDatabase->indexExists( 'image', 'PRIMARY' ) ) {
@@ -168,6 +184,18 @@ 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;
        if( $wgDatabase->fieldExists( 'watchlist', 'wl_notificationtimestamp' ) ) {
@@ -363,7 +391,7 @@ function do_schema_restructuring() {
                echo "......Locking tables.\n";
                $wgDatabase->query( "LOCK TABLES $page WRITE, $revision WRITE, $old WRITE, $cur WRITE", $fname );
 
-               $maxold = $wgDatabase->selectField( 'old', 'max(old_id)', '', $fname );
+               $maxold = intval( $wgDatabase->selectField( 'old', 'max(old_id)', '', $fname ) );
                echo wfTimestamp();
                echo "......maxold is {$maxold}\n";
 
@@ -500,7 +528,7 @@ function do_pagelinks_update() {
 function do_pagelinks_namespace( $namespace ) {
        global $wgDatabase, $wgContLang;
 
-       $ns = IntVal( $namespace );
+       $ns = intval( $namespace );
        echo "Cleaning up broken links for namespace $ns... ";
 
        $pagelinks = $wgDatabase->tableName( 'pagelinks' );
@@ -629,6 +657,87 @@ function do_user_groups_reformat() {
 
 }
 
+function do_watchlist_null() {
+       # Make sure wl_notificationtimestamp can be 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 );
+               echo "ok\n";
+       } else {
+               echo "...wl_notificationtimestamp is already nullable.\n";
+       }
+
+}
+
+/**
+ * @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() {
        global $wgNewTables, $wgNewFields, $wgRenamedTables;
 
@@ -665,22 +774,31 @@ 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();
        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";
        }
 }
 ?>