--conf option for specifying a different LocalSettings.php. This allows multiple...
[lhc/web/wiklou.git] / maintenance / updaters.inc
index baadae3..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 ) {
@@ -159,7 +161,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: ";
@@ -660,7 +662,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 );
@@ -671,6 +673,71 @@ function do_watchlist_null() {
 
 }
 
+/**
+ * @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;
 
@@ -707,28 +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";
        }
 }
 ?>