Merge "Database: Remove unused errorCount() method"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Fri, 18 Sep 2015 09:10:27 +0000 (09:10 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Fri, 18 Sep 2015 09:10:27 +0000 (09:10 +0000)
14 files changed:
includes/MagicWord.php
includes/User.php
includes/api/ApiFormatBase.php
includes/api/ApiFormatFeedWrapper.php
includes/api/ApiFormatJson.php
includes/api/ApiFormatXml.php
includes/api/ApiMain.php
includes/api/ApiResult.php
includes/exception/HttpError.php
includes/installer/MssqlInstaller.php
includes/libs/objectcache/WANObjectCache.php
includes/skins/Skin.php
tests/phpunit/README
tests/phpunit/includes/api/ApiResultTest.php

index 833f852..2c7ba91 100644 (file)
@@ -950,10 +950,12 @@ class MagicWordArray {
                        if ( $regex === '' ) {
                                continue;
                        }
-                       preg_match_all( $regex, $text, $matches, PREG_SET_ORDER );
-                       foreach ( $matches as $m ) {
-                               list( $name, $param ) = $this->parseMatch( $m );
-                               $found[$name] = $param;
+                       $matches = array();
+                       if ( preg_match_all( $regex, $text, $matches, PREG_SET_ORDER ) ) {
+                               foreach ( $matches as $m ) {
+                                       list( $name, $param ) = $this->parseMatch( $m );
+                                       $found[$name] = $param;
+                               }
                        }
                        $text = preg_replace( $regex, '', $text );
                }
index dbcbe31..6df41ee 100644 (file)
@@ -1591,7 +1591,7 @@ class User implements IDBAccessObject {
                # We only need to worry about passing the IP address to the Block generator if the
                # user is not immune to autoblocks/hardblocks, and they are the current user so we
                # know which IP address they're actually coming from
-               if ( !$this->isAllowed( 'ipblock-exempt' ) && $this->getID() == $wgUser->getID() ) {
+               if ( !$this->isAllowed( 'ipblock-exempt' ) && $this->equals( $wgUser ) ) {
                        $ip = $this->getRequest()->getIP();
                } else {
                        $ip = null;
index f54f20f..e522d70 100644 (file)
@@ -387,10 +387,11 @@ abstract class ApiFormatBase extends ApiBase {
         * are required to ignore it or filter it out.
         *
         * @deprecated since 1.25
-        * @return bool
+        * @return bool Always true
         */
        public function getNeedsRawData() {
-               return false;
+               wfDeprecated( __METHOD__, '1.25' );
+               return true;
        }
 
        /**@}*/
index 00747ee..d2bfd48 100644 (file)
@@ -59,15 +59,6 @@ class ApiFormatFeedWrapper extends ApiFormatBase {
                return null;
        }
 
-       /**
-        * Optimization - no need to sanitize data that will not be needed
-        *
-        * @return bool
-        */
-       public function getNeedsRawData() {
-               return true;
-       }
-
        /**
         * ChannelFeed doesn't give us a method to print errors in a friendly
         * manner, so just punt errors to the default printer.
index 9538842..be1b12c 100644 (file)
@@ -56,13 +56,6 @@ class ApiFormatJson extends ApiFormatBase {
                return 'application/json';
        }
 
-       /**
-        * @deprecated since 1.25
-        */
-       public function getNeedsRawData() {
-               return $this->isRaw;
-       }
-
        /**
         * @deprecated since 1.25
         */
index 4be7d93..e8ad387 100644 (file)
@@ -39,13 +39,6 @@ class ApiFormatXml extends ApiFormatBase {
                return 'text/xml';
        }
 
-       /**
-        * @deprecated since 1.25
-        */
-       public function getNeedsRawData() {
-               return true;
-       }
-
        public function setRootElement( $rootElemName ) {
                $this->mRootElemName = $rootElemName;
        }
index c558c2b..d943c86 100644 (file)
@@ -1203,10 +1203,6 @@ class ApiMain extends ApiBase {
                        // Create an appropriate printer
                        $this->mPrinter = $this->createPrinterByName( $params['format'] );
                }
-
-               if ( $this->mPrinter->getNeedsRawData() ) {
-                       $this->getResult()->setRawMode();
-               }
        }
 
        /**
index 142a780..cd4165b 100644 (file)
@@ -144,7 +144,7 @@ class ApiResult implements ApiSerializable {
        private $errorFormatter;
 
        // Deprecated fields
-       private $isRawMode, $checkingSize, $mainForContinuation;
+       private $checkingSize, $mainForContinuation;
 
        /**
         * @param int|bool $maxSize Maximum result "size", or false for no limit
@@ -159,7 +159,6 @@ class ApiResult implements ApiSerializable {
                }
 
                $this->maxSize = $maxSize;
-               $this->isRawMode = false;
                $this->checkingSize = true;
                $this->reset();
        }
@@ -1205,27 +1204,23 @@ class ApiResult implements ApiSerializable {
         */
 
        /**
-        * Call this function when special elements such as '_element'
-        * are needed by the formatter, for example in XML printing.
+        * Formerly used to enable/disable "raw mode".
         * @deprecated since 1.25, you shouldn't have been using it in the first place
         * @since 1.23 $flag parameter added
         * @param bool $flag Set the raw mode flag to this state
         */
        public function setRawMode( $flag = true ) {
-               // Can't wfDeprecated() here, since we need to set this flag from
-               // ApiMain for BC with stuff using self::getIsRawMode as
-               // "self::getIsXMLMode".
-               $this->isRawMode = $flag;
+               wfDeprecated( __METHOD__, '1.25' );
        }
 
        /**
-        * Returns true whether the formatter requested raw data.
+        * Returns true, the equivalent of "raw mode" is always enabled now
         * @deprecated since 1.25, you shouldn't have been using it in the first place
         * @return bool
         */
        public function getIsRawMode() {
-               /// @todo: After Wikibase stops calling this, warn
-               return $this->isRawMode;
+               wfDeprecated( __METHOD__, '1.25' );
+               return true;
        }
 
        /**
@@ -1238,7 +1233,7 @@ class ApiResult implements ApiSerializable {
                return $this->getResultData( null, array(
                        'BC' => array(),
                        'Types' => array(),
-                       'Strip' => $this->isRawMode ? 'bc' : 'all',
+                       'Strip' => 'all',
                ) );
        }
 
index b910ec6..9211bf8 100644 (file)
@@ -121,7 +121,7 @@ class HttpError extends MWException {
                if ( $this->content instanceof Message ) {
                        $contentHtml = $this->content->escaped();
                } else {
-                       $contentHtml = htmlspecialchars( $this->content );
+                       $contentHtml = nl2br( htmlspecialchars( $this->content ) );
                }
 
                return "<!DOCTYPE html>\n" .
index 5a8403f..4d79d96 100644 (file)
@@ -537,7 +537,6 @@ class MssqlInstaller extends DatabaseInstaller {
                $this->setupSchemaVars();
                $dbName = $this->getVar( 'wgDBname' );
                $this->db->selectDB( $dbName );
-               $server = $this->getVar( 'wgDBserver' );
                $password = $this->getVar( 'wgDBpassword' );
                $schemaName = $this->getVar( 'wgDBmwschema' );
 
index 56c544f..130caeb 100644 (file)
@@ -260,9 +260,10 @@ class WANObjectCache {
        /**
         * Purge a key from all clusters
         *
-        * This deletes the key and instantiates a hold-off period where the key
-        * cannot be written to for the next few seconds (HOLDOFF_TTL). This is to
-        * avoid the following race condition:
+        * This should only be called when the underlying data (being cached)
+        * changes in a significant way. This deletes the key and starts a hold-off
+        * period where the key cannot be written to for a few seconds (HOLDOFF_TTL).
+        * This is done to avoid the following race condition:
         *   a) Some DB data changes and delete() is called on a corresponding key
         *   b) A request refills the key with a stale value from a lagged DB
         *   c) The stale value is stuck there until the key is expired/evicted
@@ -274,9 +275,10 @@ class WANObjectCache {
         *   a) Replication lag is bounded to being less than HOLDOFF_TTL; or
         *   b) If lag is higher, the DB will have gone into read-only mode already
         *
-        * This should only be called when the underlying data (being cached)
-        * changes in a significant way. If called twice on the same key, then
-        * the last TTL takes precedence.
+        * If called twice on the same key, then the last hold-off TTL takes
+        * precedence. For idempotence, the $ttl should not vary for different
+        * delete() calls on the same key. Also note that lowering $ttl reduces
+        * the effective range of the 'lockTSE' parameter to getWithSetCallback().
         *
         * @param string $key Cache key
         * @param integer $ttl How long to block writes to the key [seconds]
@@ -469,6 +471,7 @@ class WANObjectCache {
         *               Other threads will try to use stale values if possible.
         *               If, on miss, the time since expiration is low, the assumption
         *               is that the key is hot and that a stampede is worth avoiding.
+        *               Setting this above WANObjectCache::HOLDOFF_TTL makes no difference.
         *   - tempTTL : TTL of the temp key used to cache values while a key is tombstoned.
         *               This avoids excessive regeneration of hot keys on delete() but may
         *               result in stale values.
@@ -491,23 +494,24 @@ class WANObjectCache {
                        return $value;
                }
 
+               // A deleted key with a negative TTL left must be tombstoned
                $isTombstone = ( $curTTL !== null && $value === false );
                // Assume a key is hot if requested soon after invalidation
                $isHot = ( $curTTL !== null && $curTTL <= 0 && abs( $curTTL ) <= $lockTSE );
 
-               $locked = false;
+               $lockAcquired = false;
                if ( $isHot ) {
                        // Acquire a cluster-local non-blocking lock
                        if ( $this->cache->lock( $key, 0, self::LOCK_TTL ) ) {
                                // Lock acquired; this thread should update the key
-                               $locked = true;
+                               $lockAcquired = true;
                        } elseif ( $value !== false ) {
                                // If it cannot be acquired; then the stale value can be used
                                return $value;
                        }
                }
 
-               if ( !$locked && ( $isTombstone || $isHot ) ) {
+               if ( !$lockAcquired && ( $isTombstone || $isHot ) ) {
                        // Use the stash value for tombstoned keys to reduce regeneration load.
                        // For hot keys, either another thread has the lock or the lock failed;
                        // use the stash value from the last thread that regenerated it.
@@ -529,7 +533,7 @@ class WANObjectCache {
                        $this->cache->set( self::STASH_KEY_PREFIX . $key, $value, $tempTTL );
                }
 
-               if ( $locked ) {
+               if ( $lockAcquired ) {
                        $this->cache->unlock( $key );
                }
 
index be08e4c..4e6201c 100644 (file)
@@ -237,8 +237,8 @@ abstract class Skin extends ContextSource {
                        $titles[] = $user->getTalkPage();
                }
 
-               // Other tab link
-               if ( $title->isSpecialPage() ) {
+               // Check, if the page can hold some kind of content, otherwise do nothing
+               if ( !$title->canExist() ) {
                        // nothing
                } elseif ( $title->isTalkPage() ) {
                        $titles[] = $title->getSubjectPage();
index 0a32ba1..f555812 100644 (file)
@@ -14,16 +14,13 @@ TO RETAIN YOUR DATA.
 
 == Installation ==
 
-If PHPUnit is not installed, follow the installation instructions in the
-PHPUnit Manual at:
-
-  http://www.phpunit.de/manual/current/en/installation.html
+If you used composer to install MediaWiki's dependencies PHPUnit will already be available, unless
+you explicitly specified the --no-dev flag during the install. In this case just run "composer update".
 
-- or -
-
-On Unix-like operating systems, run:
+Otherwise follow the installation instructions in the
+PHPUnit Manual at:
 
-  make install
+  https://phpunit.de/manual/current/en/installation.html
 
 
 == Running tests ==
@@ -47,7 +44,7 @@ On Windows-family operating systems, run the 'run-tests.bat' batch file.
 
 === Writing tests ===
 
-A guide to writing unit tests for MediaWiki can be found at:
+A guide to writing PHP unit tests for MediaWiki can be found at:
 
-       http://mediawiki.org/wiki/Unit_Testing
+       https://www.mediawiki.org/wiki/Manual:PHP_unit_testing
 
index cff2328..2f31677 100644 (file)
@@ -1321,17 +1321,6 @@ class ApiResultTest extends MediaWikiTestCase {
                        ),
                        '*' => 'content',
                ), $result->getData() );
-               $result->setRawMode();
-               $this->assertSame( array(
-                       'foo' => array(
-                               'bar' => array(
-                                       '*' => 'content',
-                               ),
-                       ),
-                       '*' => 'content',
-                       '_element' => 'itn',
-                       '_subelements' => array( 'sub' ),
-               ), $result->getData() );
 
                $arr = array();
                ApiResult::setContent( $arr, 'value' );