Do not insert page titles into querycache.qc_value
authormszabo-wikia <mszabo@wikia-inc.com>
Wed, 14 Mar 2018 14:38:14 +0000 (15:38 +0100)
committerReedy <reedy@wikimedia.org>
Mon, 4 Nov 2019 16:59:05 +0000 (16:59 +0000)
querycache.qc_value column is used to store a numeric value related
to the query results, generally a COUNT(*) aggregation or timestamp,
but some query pages insert the page title here after passing it through
PHP's intval() function to parse it into a number.
While this will cause 0 to be inserted for pages whose title is not numeric
(i.e. most titles), a DB error may occur for numeric page titles that exceed
the maximum value for unsigned integers, depending on relevant DB settings,
such as MySQL's strict mode.[1]

This patch changes query pages not to insert page titles into the qc_value
column. Also, it adds the getOrderFields() method to query pages that were
missing them, to ensure that the result set inserted into the querycache
table is correctly ordered by title.

---
[1] https://dev.mysql.com/doc/refman/8.0/en/sql-mode.html#sql-mode-strict

Bug: T181658
Change-Id: I1ef297257c6f419826ba4ffc6e875389ccec46db
(cherry picked from commit 335fabf5fba49fa43c0e876996baa165a7ff4350)

includes/specials/SpecialBrokenRedirects.php
includes/specials/SpecialDoubleRedirects.php
includes/specials/SpecialListRedirects.php
includes/specials/SpecialLonelyPages.php
includes/specials/SpecialUncategorizedImages.php
includes/specials/SpecialUncategorizedPages.php
includes/specials/SpecialUnusedCategories.php
includes/specials/SpecialUnusedTemplates.php
includes/specials/SpecialWithoutInterwiki.php
tests/phpunit/includes/specials/SpecialUncategorizedCategoriesTest.php

index 392b4e9..9382b5f 100644 (file)
@@ -64,7 +64,6 @@ class SpecialBrokenRedirects extends QueryPage {
                        'fields' => [
                                'namespace' => 'p1.page_namespace',
                                'title' => 'p1.page_title',
-                               'value' => 'p1.page_title',
                                'rd_namespace',
                                'rd_title',
                                'rd_fragment',
index 540ac5a..d0d8322 100644 (file)
@@ -65,7 +65,6 @@ class SpecialDoubleRedirects extends QueryPage {
                        'fields' => [
                                'namespace' => 'pa.page_namespace',
                                'title' => 'pa.page_title',
-                               'value' => 'pa.page_title',
 
                                'b_namespace' => 'pb.page_namespace',
                                'b_title' => 'pb.page_title',
index e686273..e73c871 100644 (file)
@@ -53,7 +53,6 @@ class SpecialListRedirects extends QueryPage {
                        'tables' => [ 'p1' => 'page', 'redirect', 'p2' => 'page' ],
                        'fields' => [ 'namespace' => 'p1.page_namespace',
                                'title' => 'p1.page_title',
-                               'value' => 'p1.page_title',
                                'rd_namespace',
                                'rd_title',
                                'rd_fragment',
index 14f9435..d1c83af 100644 (file)
@@ -82,7 +82,6 @@ class SpecialLonelyPages extends PageQueryPage {
                        'fields' => [
                                'namespace' => 'page_namespace',
                                'title' => 'page_title',
-                               'value' => 'page_title'
                        ],
                        'conds' => $conds,
                        'join_conds' => $joinConds
index 9dcd1bd..67a2edb 100644 (file)
@@ -46,17 +46,28 @@ class SpecialUncategorizedImages extends ImageQueryPage {
                return false;
        }
 
+       function getOrderFields() {
+               return [ 'title' ];
+       }
+
        function getQueryInfo() {
                return [
                        'tables' => [ 'page', 'categorylinks' ],
-                       'fields' => [ 'namespace' => 'page_namespace',
+                       'fields' => [
+                               'namespace' => 'page_namespace',
                                'title' => 'page_title',
-                               'value' => 'page_title' ],
-                       'conds' => [ 'cl_from IS NULL',
+                       ],
+                       'conds' => [
+                               'cl_from IS NULL',
                                'page_namespace' => NS_FILE,
-                               'page_is_redirect' => 0 ],
-                       'join_conds' => [ 'categorylinks' => [
-                               'LEFT JOIN', 'cl_from=page_id' ] ]
+                               'page_is_redirect' => 0,
+                       ],
+                       'join_conds' => [
+                               'categorylinks' => [
+                                       'LEFT JOIN',
+                                       'cl_from=page_id',
+                               ],
+                       ],
                ];
        }
 
index 3610c01..2ec020a 100644 (file)
@@ -56,7 +56,6 @@ class SpecialUncategorizedPages extends PageQueryPage {
                        'fields' => [
                                'namespace' => 'page_namespace',
                                'title' => 'page_title',
-                               'value' => 'page_title'
                        ],
                        // default for page_namespace is all content namespaces (if requestedNamespace is false)
                        // otherwise, page_namespace is requestedNamespace
index 36367d2..f8c9360 100644 (file)
@@ -37,13 +37,16 @@ class SpecialUnusedCategories extends QueryPage {
                return $this->msg( 'unusedcategoriestext' )->parseAsBlock();
        }
 
+       function getOrderFields() {
+               return [ 'title' ];
+       }
+
        public function getQueryInfo() {
                return [
                        'tables' => [ 'page', 'categorylinks', 'page_props' ],
                        'fields' => [
                                'namespace' => 'page_namespace',
                                'title' => 'page_title',
-                               'value' => 'page_title'
                        ],
                        'conds' => [
                                'cl_from IS NULL',
index 119ef87..89468d2 100644 (file)
@@ -46,13 +46,16 @@ class SpecialUnusedTemplates extends QueryPage {
                return false;
        }
 
+       function getOrderFields() {
+               return [ 'title' ];
+       }
+
        public function getQueryInfo() {
                return [
                        'tables' => [ 'page', 'templatelinks' ],
                        'fields' => [
                                'namespace' => 'page_namespace',
                                'title' => 'page_title',
-                               'value' => 'page_title'
                        ],
                        'conds' => [
                                'page_namespace' => NS_TEMPLATE,
index 36aea75..3ab0ef9 100644 (file)
@@ -89,7 +89,6 @@ class SpecialWithoutInterwiki extends PageQueryPage {
                        'fields' => [
                                'namespace' => 'page_namespace',
                                'title' => 'page_title',
-                               'value' => 'page_title'
                        ],
                        'conds' => [
                                'll_title IS NULL',
index daccd27..d151f59 100644 (file)
@@ -21,7 +21,6 @@ class SpecialUncategorizedCategoriesTest extends MediaWikiTestCase {
                        'fields' => [
                                'namespace' => 'page_namespace',
                                'title' => 'page_title',
-                               'value' => 'page_title',
                        ],
                        'conds' => [
                                0 => 'cl_from IS NULL',