Merge "EditPage: Try to avoid using $wgTitle"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Wed, 20 Sep 2017 15:59:47 +0000 (15:59 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Wed, 20 Sep 2017 15:59:47 +0000 (15:59 +0000)
14 files changed:
autoload.php
includes/EditPage.php
includes/GlobalFunctions.php
includes/MagicWordArray.php
includes/filerepo/file/LocalFile.php
includes/libs/HashRing.php
includes/libs/rdbms/database/Database.php
includes/libs/rdbms/database/DatabaseMysqlBase.php
includes/libs/rdbms/exception/DBQueryError.php
includes/libs/rdbms/exception/DBQueryTimeoutError.php [new file with mode: 0644]
includes/media/FormatMetadata.php
includes/pager/IndexPager.php
maintenance/populateIpChanges.php
tests/phpunit/includes/http/HttpTest.php

index 61fd192..4dd5f12 100644 (file)
@@ -1636,6 +1636,7 @@ $wgAutoloadLocalClasses = [
        'Wikimedia\\Rdbms\\DBExpectedError' => __DIR__ . '/includes/libs/rdbms/exception/DBExpectedError.php',
        'Wikimedia\\Rdbms\\DBMasterPos' => __DIR__ . '/includes/libs/rdbms/database/position/DBMasterPos.php',
        'Wikimedia\\Rdbms\\DBQueryError' => __DIR__ . '/includes/libs/rdbms/exception/DBQueryError.php',
+       'Wikimedia\\Rdbms\\DBQueryTimeoutError' => __DIR__ . '/includes/libs/rdbms/exception/DBQueryTimeoutError.php',
        'Wikimedia\\Rdbms\\DBReadOnlyError' => __DIR__ . '/includes/libs/rdbms/exception/DBReadOnlyError.php',
        'Wikimedia\\Rdbms\\DBReplicationWaitError' => __DIR__ . '/includes/libs/rdbms/exception/DBReplicationWaitError.php',
        'Wikimedia\\Rdbms\\DBTransactionError' => __DIR__ . '/includes/libs/rdbms/exception/DBTransactionError.php',
index 7750b10..0ea61c0 100644 (file)
@@ -4188,8 +4188,6 @@ class EditPage {
         * @return array
         */
        public function getCheckboxes( &$tabindex, $checked ) {
-               global $wgUseMediaWikiUIEverywhere;
-
                $checkboxes = [];
                $checkboxesDef = $this->getCheckboxesDefinition( $checked );
 
@@ -4224,10 +4222,6 @@ class EditPage {
                                '&#160;' .
                                Xml::tags( 'label', $labelAttribs, $label );
 
-                       if ( $wgUseMediaWikiUIEverywhere ) {
-                               $checkboxHtml = Html::rawElement( 'div', [ 'class' => 'mw-ui-checkbox' ], $checkboxHtml );
-                       }
-
                        $checkboxes[ $legacyName ] = $checkboxHtml;
                }
 
index e80ecf1..484dfe8 100644 (file)
@@ -195,11 +195,15 @@ function wfArrayDiff2_cmp( $a, $b ) {
        } else {
                reset( $a );
                reset( $b );
-               while ( ( list( , $valueA ) = each( $a ) ) && ( list( , $valueB ) = each( $b ) ) ) {
+               while ( key( $a ) !== null && key( $b ) !== null ) {
+                       $valueA = current( $a );
+                       $valueB = current( $b );
                        $cmp = strcmp( $valueA, $valueB );
                        if ( $cmp !== 0 ) {
                                return $cmp;
                        }
+                       next( $a );
+                       next( $b );
                }
                return 0;
        }
index 5856e21..4010ec7 100644 (file)
@@ -203,7 +203,9 @@ class MagicWordArray {
         */
        public function parseMatch( $m ) {
                reset( $m );
-               while ( list( $key, $value ) = each( $m ) ) {
+               while ( ( $key = key( $m ) ) !== null ) {
+                       $value = current( $m );
+                       next( $m );
                        if ( $key === 0 || $value === '' ) {
                                continue;
                        }
index fd0f3f3..133f797 100644 (file)
@@ -43,7 +43,7 @@ use Wikimedia\Rdbms\IDatabase;
  * @ingroup FileAbstraction
  */
 class LocalFile extends File {
-       const VERSION = 10; // cache version
+       const VERSION = 11; // cache version
 
        const CACHE_FIELD_MAX_LEN = 1000;
 
index be40965..f61c139 100644 (file)
@@ -116,11 +116,12 @@ class HashRing {
                // If more locations are requested, wrap-around and keep adding them
                reset( $this->ring );
                while ( count( $locations ) < $limit ) {
-                       list( $location, ) = each( $this->ring );
+                       $location = key( $this->ring );
                        if ( $location === $primaryLocation ) {
                                break; // don't go in circles
                        }
                        $locations[] = $location;
+                       next( $this->ring );
                }
 
                return $locations;
index c904092..e7417eb 100644 (file)
@@ -1130,6 +1130,19 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware
                }
        }
 
+       /**
+        * Checks whether the cause of the error is detected to be a timeout.
+        *
+        * It returns false by default, and not all engines support detecting this yet.
+        * If this returns false, it will be treated as a generic query error.
+        *
+        * @param string $error Error text
+        * @param int $errno Error number
+        */
+       protected function wasQueryTimeout( $error, $errno ) {
+               return false;
+       }
+
        public function reportQueryError( $error, $errno, $sql, $fname, $tempIgnore = false ) {
                if ( $this->ignoreErrors() || $tempIgnore ) {
                        $this->queryLogger->debug( "SQL ERROR (ignored): $error\n" );
@@ -1146,7 +1159,12 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware
                                ] )
                        );
                        $this->queryLogger->debug( "SQL ERROR: " . $error . "\n" );
-                       throw new DBQueryError( $this, $error, $errno, $sql, $fname );
+                       $wasQueryTimeout = $this->wasQueryTimeout( $error, $errno );
+                       if ( $wasQueryTimeout ) {
+                               throw new DBQueryTimeoutError( $this, $error, $errno, $sql, $fname );
+                       } else {
+                               throw new DBQueryError( $this, $error, $errno, $sql, $fname );
+                       }
                }
        }
 
index 3c4cda5..5312a3d 100644 (file)
@@ -486,6 +486,10 @@ abstract class DatabaseMysqlBase extends Database {
         */
        abstract protected function mysqlError( $conn = null );
 
+       protected function wasQueryTimeout( $error, $errno ) {
+               return $errno == 2062;
+       }
+
        /**
         * @param string $table
         * @param array $uniqueIndexes
index a8ea3ad..e6870a7 100644 (file)
@@ -40,19 +40,22 @@ class DBQueryError extends DBExpectedError {
         * @param int|string $errno
         * @param string $sql
         * @param string $fname
+        * @param string $message Optional message, intended for subclases (optional)
         */
-       public function __construct( IDatabase $db, $error, $errno, $sql, $fname ) {
-               if ( $db instanceof Database && $db->wasConnectionError( $errno ) ) {
-                       $message = "A connection error occured. \n" .
-                               "Query: $sql\n" .
-                               "Function: $fname\n" .
-                               "Error: $errno $error\n";
-               } else {
-                       $message = "A database query error has occurred. Did you forget to run " .
-                               "your application's database schema updater after upgrading? \n" .
-                               "Query: $sql\n" .
-                               "Function: $fname\n" .
-                               "Error: $errno $error\n";
+       public function __construct( IDatabase $db, $error, $errno, $sql, $fname, $message = null ) {
+               if ( $message === null ) {
+                       if ( $db instanceof Database && $db->wasConnectionError( $errno ) ) {
+                               $message = "A connection error occured. \n" .
+                                        "Query: $sql\n" .
+                                        "Function: $fname\n" .
+                                        "Error: $errno $error\n";
+                       } else {
+                               $message = "A database query error has occurred. Did you forget to run " .
+                                        "your application's database schema updater after upgrading? \n" .
+                                        "Query: $sql\n" .
+                                        "Function: $fname\n" .
+                                        "Error: $errno $error\n";
+                       }
                }
 
                parent::__construct( $db, $message );
diff --git a/includes/libs/rdbms/exception/DBQueryTimeoutError.php b/includes/libs/rdbms/exception/DBQueryTimeoutError.php
new file mode 100644 (file)
index 0000000..ea91d95
--- /dev/null
@@ -0,0 +1,38 @@
+<?php
+/**
+ * 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @ingroup Database
+ */
+
+namespace Wikimedia\Rdbms;
+
+/**
+ * Error thrown when a query times out
+ *
+ * @ingroup Database
+ */
+class DBQueryTimeoutError extends DBQueryError {
+       public function __construct( IDatabase $db, $error, $errno, $sql, $fname ) {
+               $message = "A database query timeout has occurred. \n" .
+                        "Query: $sql\n" .
+                        "Function: $fname\n" .
+                        "Error: $errno $error\n";
+
+               parent::__construct( $db, $error, $errno, $sql, $fname, $message );
+       }
+}
index 6cac126..6661965 100644 (file)
@@ -1761,9 +1761,9 @@ class FormatMetadata extends ContextSource {
                        }
                        return $newValue;
                } else { // _type is 'ul' or 'ol' or missing in which case it defaults to 'ul'
-                       list( $k, $v ) = each( $value );
-                       if ( $k === '_type' ) {
-                               $v = current( $value );
+                       $v = reset( $value );
+                       if ( key( $value ) === '_type' ) {
+                               $v = next( $value );
                        }
                        return $v;
                }
index 6620c47..d1c98f2 100644 (file)
@@ -162,8 +162,8 @@ abstract class IndexPager extends ContextSource implements Pager {
                                : [];
                } elseif ( is_array( $index ) ) {
                        # First element is the default
-                       reset( $index );
-                       list( $this->mOrderType, $this->mIndexField ) = each( $index );
+                       $this->mIndexField = reset( $index );
+                       $this->mOrderType = key( $index );
                        $this->mExtraSortFields = isset( $extraSort[$this->mOrderType] )
                                ? (array)$extraSort[$this->mOrderType]
                                : [];
index f7bcc12..2b2a2b4 100644 (file)
@@ -72,7 +72,8 @@ TEXT
                        ? $maxRevId
                        : $dbw->selectField( 'revision', 'MAX(rev_id)', false, __METHOD__ );
                $blockStart = $start;
-               $revCount = 0;
+               $attempted = 0;
+               $inserted = 0;
 
                $this->output( "Copying IP revisions to ip_changes, from rev_id $start to rev_id $end\n" );
 
@@ -105,7 +106,7 @@ TEXT
                                                'ipc_hex' => IP::toHex( $row->rev_user_text ),
                                        ];
 
-                                       $revCount++;
+                                       $attempted++;
                                }
                        }
 
@@ -116,13 +117,15 @@ TEXT
                                'IGNORE'
                        );
 
+                       $inserted += $dbw->affectedRows();
+
                        $lbFactory->waitForReplication();
                        usleep( $throttle * 1000 );
 
                        $blockStart = $blockEnd + 1;
                }
 
-               $this->output( "$revCount IP revisions copied.\n" );
+               $this->output( "Attempted to insert $attempted IP revisions, $inserted actually done.\n" );
 
                return true;
        }
index 3693a27..3790e3a 100644 (file)
@@ -497,6 +497,10 @@ class HttpTest extends MediaWikiTestCase {
         * @dataProvider provideCurlConstants
         */
        public function testCurlConstants( $value ) {
+               if ( !extension_loaded( 'curl' ) ) {
+                       $this->markTestSkipped( "PHP extension 'curl' is not loaded, skipping." );
+               }
+
                $this->assertTrue( defined( $value ), $value . ' not defined' );
        }
 }