} 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;
}
}
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] )
"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]
);
*/
public function getSha1Base36();
+ /**
+ * @since 1.34
+ * @return string[]
+ */
+ public function getTags();
+
}
$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
*/
public $sha1base36 = false;
+ /**
+ * @since 1.34
+ * @var string[]
+ */
+ protected $tags = [];
+
/**
* @since 1.17
* @var string
$this->sha1base36 = $sha1base36;
}
+ /**
+ * @since 1.34
+ * @param string[] $tags
+ */
+ public function setTags( array $tags ) {
+ $this->tags = $tags;
+ }
+
/**
* @since 1.12.2
* @param string $filename
return false;
}
+ /**
+ * @since 1.34
+ * @return string[]
+ */
+ public function getTags() {
+ return $this->tags;
+ }
+
/**
* @since 1.17
* @return string
[],
[ '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 ],
],
[
ApiBase::PARAM_TYPE => 'limit',
ApiBase::PARAM_MAX2 => 10,
- ApiBase::PARAM_ISMULTI => true,
],
new MWException(
'Internal error in ApiBase::getParameterFromSettings: ' .
[
ApiBase::PARAM_TYPE => 'limit',
ApiBase::PARAM_MAX => 10,
- ApiBase::PARAM_ISMULTI => true,
],
new MWException(
'Internal error in ApiBase::getParameterFromSettings: ' .
--- /dev/null
+<?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 );
+ }
+}