Rename the iwl_prefix_from_title index (again) to iwl_prefix_title_from and change...
authorRoan Kattouw <catrope@users.mediawiki.org>
Thu, 22 Jul 2010 08:52:58 +0000 (08:52 +0000)
committerRoan Kattouw <catrope@users.mediawiki.org>
Thu, 22 Jul 2010 08:52:58 +0000 (08:52 +0000)
16 files changed:
includes/api/ApiQueryIWBacklinks.php
includes/installer/MysqlUpdater.php
includes/installer/SqliteUpdater.php
maintenance/archives/patch-iwlinks.sql
maintenance/archives/patch-kill-iwl_pft.sql [new file with mode: 0644]
maintenance/archives/patch-kill-iwl_prefix.sql [new file with mode: 0644]
maintenance/archives/patch-rename-iwl_prefix.sql
maintenance/postgres/archives/patch-iwlinks.sql
maintenance/postgres/archives/patch-kill-iwl_pft.sql [new file with mode: 0644]
maintenance/postgres/archives/patch-kill-iwl_prefix.sql [new file with mode: 0644]
maintenance/postgres/archives/patch-rename-iwl_prefix.sql
maintenance/postgres/tables.sql
maintenance/sqlite/archives/patch-kill-iwl_pft.sql [new file with mode: 0644]
maintenance/sqlite/archives/patch-kill-iwl_prefix.sql [new file with mode: 0644]
maintenance/tables.sql
maintenance/updaters.inc

index ad4e7c1..fa41f97 100644 (file)
@@ -53,15 +53,15 @@ class ApiQueryIWBacklinks extends ApiQueryBase {
                                        'original value returned by the previous query', '_badcontinue' );
                        }
 
-                       $from = intval( $cont[0] );
-                       $prefix = $this->getDB()->strencode( $cont[1] );
-                       $title = $this->getDB()->strencode( $this->titleToKey( $cont[2] ) );
+                       $prefix = $this->getDB()->strencode( $cont[0] );
+                       $title = $this->getDB()->strencode( $this->titleToKey( $cont[1] ) );
+                       $from = intval( $cont[2] );
                        $this->addWhere(
-                               "iwl_from > $from OR " .
-                               "(iwl_from = $from AND " .
-                               "(iwl_prefix > '$prefix' OR " .
+                               "iwl_prefix > '$prefix' OR " .
                                "(iwl_prefix = '$prefix' AND " .
-                               "iwl_title >= '$title')))"
+                               "(iwl_title > '$title' OR " .
+                               "(iwl_title = '$title' AND " .
+                               "iwl_from >= $from)))"
                        );
                }
 
@@ -73,14 +73,17 @@ class ApiQueryIWBacklinks extends ApiQueryBase {
 
                if ( isset( $params['prefix'] ) ) {
                        $this->addWhereFld( 'iwl_prefix', $params['prefix'] );
-               }
-               
-               if ( isset( $params['title'] ) ) {
-                       $this->addWhereFld( 'iwl_title', $params['title'] );
+                       if ( isset( $params['title'] ) ) {
+                               $this->addWhereFld( 'iwl_title', $params['title'] );
+                               $this->addOption( 'ORDER BY', 'iwl_from' );
+                       } else {
+                               $this->addOption( 'ORDER BY', 'iwl_title, iwl_from' );
+                       }
+               } else {
+                       $this->addOption( 'ORDER BY', 'iwl_prefix, iwl_title, iwl_from' );
                }
 
                $this->addOption( 'LIMIT', $params['limit'] + 1 );
-               $this->addOption( 'ORDER BY', 'iwl_from' );
 
                $db = $this->getDB();
                $res = $this->select( __METHOD__ );
@@ -91,7 +94,7 @@ class ApiQueryIWBacklinks extends ApiQueryBase {
                        if ( ++ $count > $params['limit'] ) {
                                // We've reached the one extra which shows that there are additional pages to be had. Stop here...
                                // Continue string preserved in case the redirect query doesn't pass the limit
-                               $this->setContinueEnumParameter( 'continue', "{$row->iwl_from}|{$row->iwl_prefix}|{$row->iwl_title}" );
+                               $this->setContinueEnumParameter( 'continue', "{$row->iwl_prefix}|{$row->iwl_title}|{$row->iwl_from}" );
                                break;
                        }
                        
@@ -107,7 +110,7 @@ class ApiQueryIWBacklinks extends ApiQueryBase {
 
                        $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $entry );
                        if ( !$fit ) {
-                               $this->setContinueEnumParameter( 'continue', "{$row->iwl_from}|{$row->iwl_prefix}|{$row->iwl_title}" );
+                               $this->setContinueEnumParameter( 'continue', "{$row->iwl_prefix}|{$row->iwl_title}|{$row->iwl_from}" );
                                break;
                        }
                }
@@ -145,9 +148,9 @@ class ApiQueryIWBacklinks extends ApiQueryBase {
        public function getDescription() {
                return array( 'Find all pages that link to the given interwiki link.',
                        'Can be used to find all links with a prefix, or',
-                       'all links to a title (any prefix).',
+                       'all links to a title (with a given prefix).',
                        'Using neither parameter is effectively "All IW Links"',
-                       );
+               );
        }
 
        public function getPossibleErrors() {
index 07dad0c..f6db9f7 100644 (file)
@@ -149,9 +149,11 @@ class MysqlUpdater extends DatabaseUpdater {
                        ),
                        '1.17' => array(
                                array( 'add_table', 'iwlinks',                           'patch-iwlinks.sql' ),
-                               array( 'add_index', 'iwlinks', 'iwl_prefix_from_title',  'patch-rename-iwl_prefix.sql' ),
+                               array( 'add_index', 'iwlinks', 'iwl_prefix_title_from',  'patch-rename-iwl_prefix.sql' ),
                                array( 'add_field', 'updatelog', 'ul_value',              'patch-ul_value.sql' ),
                                array( 'add_field', 'interwiki',     'iw_api',           'patch-iw_api_and_wikiid.sql' ),
+                               array( 'drop_index_if_exists', 'iwlinks', 'iwl_prefix',  'patch-kill-iwl_prefix.sql' ),
+                               array( 'drop_index_if_exists', 'iwlinks', 'iwl_prefix_from_title', 'patch-kill-iwl_pft.sql' ),
                        ),
                );
        }
index 2bace6e..99a8f12 100644 (file)
@@ -31,9 +31,11 @@ class SqliteUpdater extends DatabaseUpdater {
                        ),
                        '1.17' => array(
                                array( 'add_table', 'iwlinks',                            'patch-iwlinks.sql' ),
-                               array( 'add_index', 'iwlinks',   'iwl_prefix_from_title', 'patch-rename-iwl_prefix.sql' ),
+                               array( 'add_index', 'iwlinks',   'iwl_prefix_title_from', 'patch-rename-iwl_prefix.sql' ),
                                array( 'add_field', 'updatelog', 'ul_value',              'patch-ul_value.sql' ),
                                array( 'add_field', 'interwiki',     'iw_api',           'patch-iw_api_and_wikiid.sql' ),
+                               array( 'drop_index_if_exists', 'iwlinks', 'iwl_prefix',  'patch-kill-iwl_prefix.sql' ),
+                               array( 'drop_index_if_exists', 'iwlinks', 'iwl_prefix_from_title', 'patch-kill-iwl_pft.sql' ),
                        ),
                );
        }
index c1c2595..89b34cb 100644 (file)
@@ -13,4 +13,4 @@ CREATE TABLE /*_*/iwlinks (
 ) /*$wgDBTableOptions*/;
 
 CREATE UNIQUE INDEX /*i*/iwl_from ON /*_*/iwlinks (iwl_from, iwl_prefix, iwl_title);
-CREATE INDEX /*i*/iwl_prefix_from_title ON /*_*/iwlinks (iwl_prefix, iwl_from, iwl_title);
+CREATE UNIQUE INDEX /*i*/iwl_prefix_title_from ON /*_*/iwlinks (iwl_prefix, iwl_title, iwl_from);
diff --git a/maintenance/archives/patch-kill-iwl_pft.sql b/maintenance/archives/patch-kill-iwl_pft.sql
new file mode 100644 (file)
index 0000000..96e1435
--- /dev/null
@@ -0,0 +1,7 @@
+--
+-- Kill the old iwl_prefix_from_title index, which may be present on some
+-- installs if they ran update.php between it being added and being renamed
+--
+
+DROP INDEX /*i*/iwl_prefix_from_title ON /*_*/iwlinks;
+
diff --git a/maintenance/archives/patch-kill-iwl_prefix.sql b/maintenance/archives/patch-kill-iwl_prefix.sql
new file mode 100644 (file)
index 0000000..1cd9b45
--- /dev/null
@@ -0,0 +1,7 @@
+--
+-- Kill the old iwl_prefix index, which may be present on some
+-- installs if they ran update.php between it being added and being renamed
+--
+
+DROP INDEX /*i*/iwl_prefix ON /*_*/iwlinks;
+
index df36029..4b11b36 100644 (file)
@@ -1,5 +1,4 @@
 -- 
--- Recreates the iwl_prefix for the iwlinks table
+-- Recreates the iwl_prefix index for the iwlinks table
 --
-DROP INDEX /*i*/iwl_prefix ON /*_*/iwlinks;
-CREATE INDEX /*i*/iwl_prefix_from_title ON /*_*/iwlinks (iwl_prefix, iwl_from, iwl_title);
\ No newline at end of file
+CREATE UNIQUE INDEX /*i*/iwl_prefix_title_from ON /*_*/iwlinks (iwl_prefix, iwl_title, iwl_from);
index a24154f..db26eae 100644 (file)
@@ -5,4 +5,4 @@ CREATE TABLE iwlinks (
        iwl_title TEXT NOT NULL DEFAULT ''
 );
 CREATE UNIQUE INDEX iwl_from ON iwlinks (iwl_from, iwl_prefix, iwl_title);
-CREATE INDEX iwl_prefix ON iwlinks (iwl_prefix, iwl_title);
+CREATE UNIQUE INDEX iwl_prefix_title_from ON iwlinks (iwl_prefix, iwl_title, iwl_from);
diff --git a/maintenance/postgres/archives/patch-kill-iwl_pft.sql b/maintenance/postgres/archives/patch-kill-iwl_pft.sql
new file mode 100644 (file)
index 0000000..4419d9e
--- /dev/null
@@ -0,0 +1,7 @@
+--
+-- Kill the old iwl_prefix_from_title index, which may be present on some
+-- installs if they ran update.php between it being added and being renamed
+--
+
+DROP INDEX iwl_prefix_from_title;
+
diff --git a/maintenance/postgres/archives/patch-kill-iwl_prefix.sql b/maintenance/postgres/archives/patch-kill-iwl_prefix.sql
new file mode 100644 (file)
index 0000000..8b6d108
--- /dev/null
@@ -0,0 +1,7 @@
+--
+-- Kill the old iwl_prefix index, which may be present on some
+-- installs if they ran update.php between it being added and being renamed
+--
+
+DROP INDEX iwl_prefix;
+
index ebe0abc..a4bdb6a 100644 (file)
@@ -1,2 +1,2 @@
 DROP INDEX iwl_prefix;
-CREATE INDEX iwl_prefix_from_title ON iwlinks (iwl_prefix, iwl_from, iwl_title);
\ No newline at end of file
+CREATE UNIQUE INDEX iwl_prefix_title_from ON iwlinks (iwl_prefix, iwl_from, iwl_title);
index 5b100ee..c38a56a 100644 (file)
@@ -625,4 +625,4 @@ CREATE TABLE iwlinks (
   iwl_title   TEXT     NOT NULL DEFAULT ''
 );
 CREATE UNIQUE INDEX iwl_from ON iwlinks (iwl_from, iwl_prefix, iwl_title);
-CREATE INDEX iwl_prefix_from_title ON iwlinks (iwl_prefix, iwl_from, iwl_title);
+CREATE UNIQUE INDEX iwl_prefix_title_from ON iwlinks (iwl_prefix, iwl_title, iwl_from);
diff --git a/maintenance/sqlite/archives/patch-kill-iwl_pft.sql b/maintenance/sqlite/archives/patch-kill-iwl_pft.sql
new file mode 100644 (file)
index 0000000..96e1435
--- /dev/null
@@ -0,0 +1,7 @@
+--
+-- Kill the old iwl_prefix_from_title index, which may be present on some
+-- installs if they ran update.php between it being added and being renamed
+--
+
+DROP INDEX /*i*/iwl_prefix_from_title ON /*_*/iwlinks;
+
diff --git a/maintenance/sqlite/archives/patch-kill-iwl_prefix.sql b/maintenance/sqlite/archives/patch-kill-iwl_prefix.sql
new file mode 100644 (file)
index 0000000..1cd9b45
--- /dev/null
@@ -0,0 +1,7 @@
+--
+-- Kill the old iwl_prefix index, which may be present on some
+-- installs if they ran update.php between it being added and being renamed
+--
+
+DROP INDEX /*i*/iwl_prefix ON /*_*/iwlinks;
+
index d3a12bd..1e04c9b 100644 (file)
@@ -623,7 +623,7 @@ CREATE TABLE /*_*/iwlinks (
 ) /*$wgDBTableOptions*/;
 
 CREATE UNIQUE INDEX /*i*/iwl_from ON /*_*/iwlinks (iwl_from, iwl_prefix, iwl_title);
-CREATE INDEX /*i*/iwl_prefix_from_title ON /*_*/iwlinks (iwl_prefix, iwl_from, iwl_title);
+CREATE UNIQUE INDEX /*i*/iwl_prefix_title_from ON /*_*/iwlinks (iwl_prefix, iwl_title, iwl_from);
 
 
 --
index 246d6d6..d81c3b1 100644 (file)
@@ -1508,6 +1508,7 @@ function do_postgres_updates() {
                array( "watchlist",     "wl_user",            "(wl_user)" ),
                array( "logging",       "logging_user_type_time", "(log_user, log_type, log_timestamp)" ),
                array( "logging",       "logging_page_id_time",   "(log_page,log_timestamp)" ),
+               array( "iwlinks",       "iwl_prefix_title_from",  "(iwl_prefix, iwl_title, iwl_from)" ),
        );
 
        $newrules = array(