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 17:49:05 +0000 (17:49 +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

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 3e1909b..25571cc 100644 (file)
@@ -63,7 +63,6 @@ class BrokenRedirectsPage extends QueryPage {
                        'fields' => [
                                'namespace' => 'p1.page_namespace',
                                'title' => 'p1.page_title',
-                               'value' => 'p1.page_title',
                                'rd_namespace',
                                'rd_title',
                                'rd_fragment',
index 77c59f0..8bfc4a9 100644 (file)
@@ -64,7 +64,6 @@ class DoubleRedirectsPage 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 48f3640..d58097c 100644 (file)
@@ -53,7 +53,6 @@ class ListredirectsPage 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 ff76a4b..a387524 100644 (file)
@@ -79,7 +79,6 @@ class LonelyPagesPage extends PageQueryPage {
                        'fields' => [
                                'namespace' => 'page_namespace',
                                'title' => 'page_title',
-                               'value' => 'page_title'
                        ],
                        'conds' => $conds,
                        'join_conds' => $joinConds
index 1cb27a3..7e89389 100644 (file)
@@ -45,17 +45,28 @@ class UncategorizedImagesPage 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 30b33cc..d616f70 100644 (file)
@@ -52,7 +52,6 @@ class UncategorizedPagesPage 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 1469742..429a3b0 100644 (file)
@@ -37,13 +37,16 @@ class UnusedCategoriesPage extends QueryPage {
                return $this->msg( 'unusedcategoriestext' )->parseAsBlock();
        }
 
+       function getOrderFields() {
+               return [ 'title' ];
+       }
+
        public function getQueryInfo() {
                return [
                        'tables' => [ 'page', 'categorylinks' ],
                        'fields' => [
                                'namespace' => 'page_namespace',
                                'title' => 'page_title',
-                               'value' => 'page_title'
                        ],
                        'conds' => [
                                'cl_from IS NULL',
index f73be43..1ac5e7f 100644 (file)
@@ -46,13 +46,16 @@ class UnusedtemplatesPage 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 a1e5156..45dd5f5 100644 (file)
@@ -87,7 +87,6 @@ class WithoutInterwikiPage extends PageQueryPage {
                        'fields' => [
                                'namespace' => 'page_namespace',
                                'title' => 'page_title',
-                               'value' => 'page_title'
                        ],
                        'conds' => [
                                'll_title IS NULL',
index 80bd365..fb49e85 100644 (file)
@@ -21,7 +21,6 @@ class UncategorizedCategoriesPageTest extends MediaWikiTestCase {
                        'fields' => [
                                'namespace' => 'page_namespace',
                                'title' => 'page_title',
-                               'value' => 'page_title',
                        ],
                        'conds' => [
                                0 => 'cl_from IS NULL',