Merge "Upgrade phan config to 0.7.1"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Wed, 4 Sep 2019 16:21:12 +0000 (16:21 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Wed, 4 Sep 2019 16:21:12 +0000 (16:21 +0000)
includes/EditPage.php
includes/api/ApiBase.php
includes/import/ImportableOldRevision.php
includes/import/ImportableOldRevisionImporter.php
includes/import/WikiRevision.php
tests/phpunit/includes/api/ApiBaseTest.php
tests/phpunit/includes/import/ImportableOldRevisionImporterTest.php [new file with mode: 0644]

index 541541a..6ae4371 100644 (file)
@@ -1799,8 +1799,11 @@ class EditPage {
                } elseif ( !$status->isOK() ) {
                        # ...or the hook could be expecting us to produce an error
                        // FIXME this sucks, we should just use the Status object throughout
+                       if ( !$status->getErrors() ) {
+                               // Provide a fallback error message if none was set
+                               $status->fatal( 'hookaborted' );
+                       }
                        $this->hookError = $this->formatStatusErrors( $status );
-                       $status->fatal( 'hookaborted' );
                        $status->value = self::AS_HOOK_ERROR_EXPECTED;
                        return false;
                }
index d8134bb..0cd9806 100644 (file)
@@ -1308,8 +1308,15 @@ abstract class ApiBase extends ContextSource {
                                                }
                                                break;
                                        case 'limit':
+                                               // Must be a number or 'max'
+                                               if ( $value !== 'max' ) {
+                                                       $value = (int)$value;
+                                               }
+                                               if ( $multi ) {
+                                                       self::dieDebug( __METHOD__, "Multi-values not supported for $encParamName" );
+                                               }
                                                if ( !$parseLimit ) {
-                                                       // Don't do any validation whatsoever
+                                                       // Don't do min/max validation and don't parse 'max'
                                                        break;
                                                }
                                                if ( !isset( $paramSettings[self::PARAM_MAX] )
@@ -1320,21 +1327,16 @@ abstract class ApiBase extends ContextSource {
                                                                "MAX1 or MAX2 are not defined for the limit $encParamName"
                                                        );
                                                }
-                                               if ( $multi ) {
-                                                       self::dieDebug( __METHOD__, "Multi-values not supported for $encParamName" );
-                                               }
-                                               $min = $paramSettings[self::PARAM_MIN] ?? 0;
-                                               if ( $value == 'max' ) {
+                                               if ( $value === 'max' ) {
                                                        $value = $this->getMain()->canApiHighLimits()
                                                                ? $paramSettings[self::PARAM_MAX2]
                                                                : $paramSettings[self::PARAM_MAX];
                                                        $this->getResult()->addParsedLimit( $this->getModuleName(), $value );
                                                } else {
-                                                       $value = (int)$value;
                                                        $this->validateLimit(
                                                                $paramName,
                                                                $value,
-                                                               $min,
+                                                               $paramSettings[self::PARAM_MIN] ?? 0,
                                                                $paramSettings[self::PARAM_MAX],
                                                                $paramSettings[self::PARAM_MAX2]
                                                        );
index 6d1e242..8cfb605 100644 (file)
@@ -65,4 +65,10 @@ interface ImportableOldRevision {
         */
        public function getSha1Base36();
 
+       /**
+        * @since 1.34
+        * @return string[]
+        */
+       public function getTags();
+
 }
index ad62e16..821d6f6 100644 (file)
@@ -129,6 +129,11 @@ class ImportableOldRevisionImporter implements OldRevisionImporter {
                $revision->insertOn( $dbw );
                $changed = $page->updateIfNewerOn( $dbw, $revision );
 
+               $tags = $importableRevision->getTags();
+               if ( $tags !== [] ) {
+                       ChangeTags::addTags( $tags, null, $revision->getId() );
+               }
+
                if ( $changed !== false && $this->doUpdates ) {
                        $this->logger->debug( __METHOD__ . ": running updates\n" );
                        // countable/oldcountable stuff is handled in WikiImporter::finishImportPage
index e36d673..c29ba21 100644 (file)
@@ -144,6 +144,12 @@ class WikiRevision implements ImportableUploadRevision, ImportableOldRevision {
         */
        public $sha1base36 = false;
 
+       /**
+        * @since 1.34
+        * @var string[]
+        */
+       protected $tags = [];
+
        /**
         * @since 1.17
         * @var string
@@ -310,6 +316,14 @@ class WikiRevision implements ImportableUploadRevision, ImportableOldRevision {
                $this->sha1base36 = $sha1base36;
        }
 
+       /**
+        * @since 1.34
+        * @param string[] $tags
+        */
+       public function setTags( array $tags ) {
+               $this->tags = $tags;
+       }
+
        /**
         * @since 1.12.2
         * @param string $filename
@@ -509,6 +523,14 @@ class WikiRevision implements ImportableUploadRevision, ImportableOldRevision {
                return false;
        }
 
+       /**
+        * @since 1.34
+        * @return string[]
+        */
+       public function getTags() {
+               return $this->tags;
+       }
+
        /**
         * @since 1.17
         * @return string
index 3adf1b6..ea0cb8a 100644 (file)
@@ -889,10 +889,24 @@ class ApiBaseTest extends ApiTestCase {
                                [],
                                [ 'internalmode' => false ],
                        ],
-                       'Limit with parseLimits false' => [
+                       'Limit with parseLimits false (numeric)' => [
                                '100',
                                [ ApiBase::PARAM_TYPE => 'limit' ],
-                               '100',
+                               100,
+                               [],
+                               [ 'parseLimits' => false ],
+                       ],
+                       'Limit with parseLimits false (max)' => [
+                               'max',
+                               [ ApiBase::PARAM_TYPE => 'limit' ],
+                               'max',
+                               [],
+                               [ 'parseLimits' => false ],
+                       ],
+                       'Limit with parseLimits false (invalid)' => [
+                               'kitten',
+                               [ ApiBase::PARAM_TYPE => 'limit' ],
+                               0,
                                [],
                                [ 'parseLimits' => false ],
                        ],
@@ -901,7 +915,6 @@ class ApiBaseTest extends ApiTestCase {
                                [
                                        ApiBase::PARAM_TYPE => 'limit',
                                        ApiBase::PARAM_MAX2 => 10,
-                                       ApiBase::PARAM_ISMULTI => true,
                                ],
                                new MWException(
                                        'Internal error in ApiBase::getParameterFromSettings: ' .
@@ -913,7 +926,6 @@ class ApiBaseTest extends ApiTestCase {
                                [
                                        ApiBase::PARAM_TYPE => 'limit',
                                        ApiBase::PARAM_MAX => 10,
-                                       ApiBase::PARAM_ISMULTI => true,
                                ],
                                new MWException(
                                        'Internal error in ApiBase::getParameterFromSettings: ' .
diff --git a/tests/phpunit/includes/import/ImportableOldRevisionImporterTest.php b/tests/phpunit/includes/import/ImportableOldRevisionImporterTest.php
new file mode 100644 (file)
index 0000000..a68ac83
--- /dev/null
@@ -0,0 +1,56 @@
+<?php
+
+use MediaWiki\MediaWikiServices;
+use Psr\Log\NullLogger;
+
+/**
+ * @group Database
+ * @coversDefaultClass ImportableOldRevisionImporter
+ */
+class ImportableOldRevisionImporterTest extends MediaWikiIntegrationTestCase {
+
+       public function setUp() {
+               parent::setUp();
+
+               $this->tablesUsed[] = 'change_tag';
+               $this->tablesUsed[] = 'change_tag_def';
+
+               ChangeTags::defineTag( 'tag1' );
+       }
+
+       public function provideTestCases() {
+               yield [ [] ];
+               yield [ [ "tag1" ] ];
+       }
+
+       /**
+        * @covers ::import
+        * @param $expectedTags
+        * @dataProvider provideTestCases
+        */
+       public function testImport( $expectedTags ) {
+               $services = MediaWikiServices::getInstance();
+
+               $title = Title::newFromText( __CLASS__ . rand() );
+               $revision = new WikiRevision( $services->getMainConfig() );
+               $revision->setTitle( $title );
+               $revision->setTags( $expectedTags );
+               $revision->setText( "dummy edit" );
+
+               $importer = new ImportableOldRevisionImporter(
+                       true,
+                       new NullLogger(),
+                       $services->getDBLoadBalancer()
+               );
+               $result = $importer->import( $revision );
+               $this->assertTrue( $result );
+
+               $page = WikiPage::factory( $title );
+               $tags = ChangeTags::getTags(
+                       $services->getDBLoadBalancer()->getConnection( DB_MASTER ),
+                       null,
+                       $page->getLatest()
+               );
+               $this->assertSame( $expectedTags, $tags );
+       }
+}