Merge "Fix API message maps for block errors"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Wed, 3 Jul 2019 14:49:05 +0000 (14:49 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Wed, 3 Jul 2019 14:49:05 +0000 (14:49 +0000)
.phpcs.xml
includes/export/XmlDumpWriter.php
includes/libs/rdbms/database/DatabaseSqlite.php
tests/phpunit/MediaWikiIntegrationTestCase.php

index 76234a2..8f3bd8c 100644 (file)
@@ -60,6 +60,7 @@
                <exclude-pattern>maintenance/doMaintenance\.php</exclude-pattern>
                <exclude-pattern>maintenance/mergeMessageFileList\.php</exclude-pattern>
                <exclude-pattern>maintenance/commandLine\.inc</exclude-pattern>
+               <exclude-pattern>tests/phpunit/MediaWikiIntegrationTestCase\.php</exclude-pattern>
        </rule>
        <rule ref="Generic.Files.LineLength">
                <exclude-pattern>*/languages/messages/Messages*\.php</exclude-pattern>
index bedfe13..f71b0d5 100644 (file)
@@ -337,9 +337,11 @@ class XmlDumpWriter {
                if ( $rev->isDeleted( Revision::DELETED_COMMENT ) ) {
                        $out .= "      " . Xml::element( 'comment', [ 'deleted' => 'deleted' ] ) . "\n";
                } else {
-                       $out .= "      "
-                               . Xml::elementClean( 'comment', [], strval( $rev->getComment()->text ) )
-                               . "\n";
+                       if ( $rev->getComment()->text != '' ) {
+                               $out .= "      "
+                                       . Xml::elementClean( 'comment', [], strval( $rev->getComment()->text ) )
+                                       . "\n";
+                       }
                }
 
                $contentMode = $rev->isDeleted( Revision::DELETED_TEXT ) ? self::WRITE_STUB_DELETED
index 17f12d3..c1a3ab5 100644 (file)
@@ -23,6 +23,7 @@
  */
 namespace Wikimedia\Rdbms;
 
+use NullLockManager;
 use PDO;
 use PDOException;
 use Exception;
@@ -39,7 +40,7 @@ class DatabaseSqlite extends Database {
        /** @var bool Whether full text is enabled */
        private static $fulltextEnabled = null;
 
-       /** @var string Directory */
+       /** @var string|null Directory */
        protected $dbDir;
        /** @var string File name for SQLite database file */
        protected $dbPath;
@@ -91,10 +92,16 @@ class DatabaseSqlite extends Database {
                        $this->queryLogger->warning( "Invalid SQLite transaction mode provided." );
                }
 
-               $this->lockMgr = new FSLockManager( [
-                       'domain' => $lockDomain,
-                       'lockDirectory' => "{$this->dbDir}/locks"
-               ] );
+               if ( $this->hasProcessMemoryPath() ) {
+                       $this->lockMgr = new NullLockManager( [ 'domain' => $lockDomain ] );
+               } else {
+                       $this->lockMgr = new FSLockManager( [
+                               'domain' => $lockDomain,
+                               'lockDirectory' => is_string( $this->dbDir )
+                                       ? "{$this->dbDir}/locks"
+                                       : dirname( $this->dbPath ) . "/locks"
+                       ] );
+               }
 
                parent::__construct( $p );
        }
@@ -186,7 +193,7 @@ class DatabaseSqlite extends Database {
         * @throws DBConnectionError
         */
        protected function openFile( $fileName, $dbName, $tablePrefix ) {
-               if ( !$this->hasMemoryPath() && !is_readable( $fileName ) ) {
+               if ( !$this->hasProcessMemoryPath() && !is_readable( $fileName ) ) {
                        $error = "SQLite database file not readable";
                        $this->connLogger->error(
                                "Error connecting to {db_server}: {error}",
@@ -772,13 +779,13 @@ class DatabaseSqlite extends Database {
        }
 
        public function serverIsReadOnly() {
-               return ( !$this->hasMemoryPath() && !is_writable( $this->dbPath ) );
+               return ( !$this->hasProcessMemoryPath() && !is_writable( $this->dbPath ) );
        }
 
        /**
         * @return bool
         */
-       private function hasMemoryPath() {
+       private function hasProcessMemoryPath() {
                return ( strpos( $this->dbPath, ':memory:' ) === 0 );
        }
 
@@ -974,17 +981,19 @@ class DatabaseSqlite extends Database {
        }
 
        public function lock( $lockName, $method, $timeout = 5 ) {
-               if ( !is_dir( "{$this->dbDir}/locks" ) ) { // create dir as needed
-                       if ( !is_writable( $this->dbDir ) || !mkdir( "{$this->dbDir}/locks" ) ) {
-                               throw new DBError( $this, "Cannot create directory \"{$this->dbDir}/locks\"." );
-                       }
+               // Give better error message for permission problems than just returning false
+               if (
+                       !is_dir( "{$this->dbDir}/locks" ) &&
+                       ( !is_writable( $this->dbDir ) || !mkdir( "{$this->dbDir}/locks" ) )
+               ) {
+                       throw new DBError( $this, "Cannot create directory \"{$this->dbDir}/locks\"." );
                }
 
                return $this->lockMgr->lock( [ $lockName ], LockManager::LOCK_EX, $timeout )->isOK();
        }
 
        public function unlock( $lockName, $method ) {
-               return $this->lockMgr->unlock( [ $lockName ], LockManager::LOCK_EX )->isOK();
+               return $this->lockMgr->unlock( [ $lockName ], LockManager::LOCK_EX )->isGood();
        }
 
        /**
index 536de24..bba9d5a 100644 (file)
@@ -180,7 +180,13 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
        }
 
        public static function setUpBeforeClass() {
+               global $IP;
                parent::setUpBeforeClass();
+               if ( !file_exists( "$IP/LocalSettings.php" ) ) {
+                       echo 'A working MediaWiki installation with a configured LocalSettings.php file is'
+                       . ' required for tests that extend ' . self::class;
+                       die();
+               }
                self::initializeForStandardPhpunitEntrypointIfNeeded();
 
                // Get the original service locator