Remove all custom plural rules and use CLDR plural rule system
[lhc/web/wiklou.git] / maintenance / convertLinks.php
index f13681b..5f7b02e 100644 (file)
@@ -1,7 +1,6 @@
 <?php
 /**
- * Convert from the old links schema (string->ID) to the new schema (ID->ID)
- * The wiki should be put into read-only mode while this script executes
+ * Convert from the old links schema (string->ID) to the new schema (ID->ID).
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * @ingroup Maintenance
  */
 
-require_once( dirname( __FILE__ ) . '/Maintenance.php' );
+require_once( __DIR__ . '/Maintenance.php' );
 
+/**
+ * Maintenance script to convert from the old links schema (string->ID)
+ * to the new schema (ID->ID).
+ *
+ * The wiki should be put into read-only mode while this script executes.
+ *
+ * @ingroup Maintenance
+ */
 class ConvertLinks extends Maintenance {
        private $logPerformance;
 
        public function __construct() {
                parent::__construct();
-               $this->mDescription = "Convert from the old links schema (string->ID) to the new schema (ID->ID)
+               $this->mDescription = "Convert from the old links schema (string->ID) to the new schema (ID->ID).
 The wiki should be put into read-only mode while this script executes";
 
                $this->addArg( 'logperformance', "Log performance to perfLogFilename.", false );
@@ -53,7 +60,7 @@ This gives a huge speed improvement for very large links tables which are MyISAM
                }
 
                global $wgContLang;
-       
+
                $numBadLinks = $curRowsRead = 0; # counters etc
                $totalTuplesInserted = 0; # total tuples INSERTed into links_temp
 
@@ -68,7 +75,7 @@ This gives a huge speed improvement for very large links tables which are MyISAM
 
                $overwriteLinksTable = !$this->hasOption( 'keep-links-table' );
                $noKeys = $this->hasOption( 'noKeys' );
-               $this->logPerformance = $this->hasOption( 'logperformance' ); 
+               $this->logPerformance = $this->hasOption( 'logperformance' );
                $perfLogFilename = $this->getArg( 'perfLogFilename', "convLinksPerf.txt" );
 
                # --------------------------------------------------------------------
@@ -79,18 +86,18 @@ This gives a huge speed improvement for very large links tables which are MyISAM
                        $this->output( "...have pagelinks; skipping old links table updates\n" );
                        return;
                }
-       
+
                $res = $dbw->query( "SELECT l_from FROM $links LIMIT 1" );
                if ( $dbw->fieldType( $res, 0 ) == "int" ) {
                        $this->output( "Schema already converted\n" );
                        return;
                }
-       
+
                $res = $dbw->query( "SELECT COUNT(*) AS count FROM $links" );
                $row = $dbw->fetchObject( $res );
                $numRows = $row->count;
                $dbw->freeResult( $res );
-       
+
                if ( $numRows == 0 ) {
                        $this->output( "Updating schema (no rows to convert)...\n" );
                        $this->createTempTable();
@@ -142,7 +149,7 @@ This gives a huge speed improvement for very large links tables which are MyISAM
                        $this->output( "Processing $numRows rows from $links table...\n" );
                        $this->performanceLog( $fh, "Processing $numRows rows from $links table...\n" );
                        $this->performanceLog( $fh, "rows inserted vs seconds elapsed:\n" );
-       
+
                        for ( $rowOffset = $initialRowOffset; $rowOffset < $numRows; $rowOffset += $linksConvInsertInterval ) {
                                $sqlRead = "SELECT * FROM $links ";
                                $sqlRead = $dbw->limitResult( $sqlRead, $linksConvInsertInterval, $rowOffset );
@@ -152,7 +159,7 @@ This gives a huge speed improvement for very large links tables which are MyISAM
                                } else {
                                        $sqlWrite = array( "INSERT IGNORE INTO $links_temp (l_from,l_to) VALUES " );
                                }
-       
+
                                $tuplesAdded = 0; # no tuples added to INSERT yet
                                foreach ( $res as $row ) {
                                        $fromTitle = $row->l_from;
@@ -193,14 +200,14 @@ This gives a huge speed improvement for very large links tables which are MyISAM
                if ( $overwriteLinksTable ) {
                        # Check for existing links_backup, and delete it if it exists.
                        $this->output( "Dropping backup links table if it exists..." );
-                       $dbw->query( "DROP TABLE IF EXISTS $links_backup", DB_MASTER );
+                       $dbw->query( "DROP TABLE IF EXISTS $links_backup", __METHOD__ );
                        $this->output( " done.\n" );
-       
+
                        # Swap in the new table, and move old links table to links_backup
                        $this->output( "Swapping tables '$links' to '$links_backup'; '$links_temp' to '$links'..." );
-                       $dbw->query( "RENAME TABLE links TO $links_backup, $links_temp TO $links", DB_MASTER );
+                       $dbw->query( "RENAME TABLE links TO $links_backup, $links_temp TO $links", __METHOD__ );
                        $this->output( " done.\n\n" );
-       
+
                        $dbw->close();
                        $this->output( "Conversion complete. The old table remains at $links_backup;\n" );
                        $this->output( "delete at your leisure.\n" );
@@ -251,4 +258,4 @@ This gives a huge speed improvement for very large links tables which are MyISAM
 }
 
 $maintClass = "ConvertLinks";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );