foreach ( $params["{$prefix}slots"] as $role ) {
$text = $params["{$prefix}text-{$role}"];
if ( $text === null ) {
+ // The 'main' role can't be deleted
+ if ( $role === 'main' ) {
+ $this->dieWithError( [ 'apierror-compare-maintextrequired', $prefix ] );
+ }
+
+ // These parameters make no sense without text. Reject them to avoid
+ // confusion.
+ foreach ( [ 'section', 'contentmodel', 'contentformat' ] as $param ) {
+ if ( isset( $params["{$prefix}{$param}-{$role}"] ) ) {
+ $this->dieWithError( [
+ 'apierror-compare-notext',
+ wfEscapeWikiText( "{$prefix}{$param}-{$role}" ),
+ wfEscapeWikiText( "{$prefix}text-{$role}" ),
+ ] );
+ }
+ }
+
$newRev->removeSlot( $role );
continue;
}
"apierror-changeauth-norequest": "Failed to create change request.",
"apierror-chunk-too-small": "Minimum chunk size is $1 {{PLURAL:$1|byte|bytes}} for non-final chunks.",
"apierror-cidrtoobroad": "$1 CIDR ranges broader than /$2 are not accepted.",
+ "apierror-compare-maintextrequired": "Parameter <var>$1text-main</var> is required when <var>$1slots</var> contains <kbd>main</kbd> (cannot delete the main slot).",
"apierror-compare-no-title": "Cannot pre-save transform without a title. Try specifying <var>fromtitle</var> or <var>totitle</var>.",
"apierror-compare-nosuchfromsection": "There is no section $1 in the 'from' content.",
"apierror-compare-nosuchtosection": "There is no section $1 in the 'to' content.",
"apierror-compare-nofromrevision": "No 'from' revision. Specify <var>fromrev</var>, <var>fromtitle</var>, or <var>fromid</var>.",
+ "apierror-compare-notext": "Parameter <var>$1</var> cannot be used without <var>$2</var>.",
"apierror-compare-notorevision": "No 'to' revision. Specify <var>torev</var>, <var>totitle</var>, or <var>toid</var>.",
"apierror-compare-relative-to-nothing": "No 'from' revision for <var>torelative</var> to be relative to.",
"apierror-contentserializationexception": "Content serialization failed: $1",
"apierror-changeauth-norequest": "{{doc-apierror}}",
"apierror-chunk-too-small": "{{doc-apierror}}\n\nParameters:\n* $1 - Minimum size in bytes.",
"apierror-cidrtoobroad": "{{doc-apierror}}\n\nParameters:\n* $1 - \"IPv4\" or \"IPv6\"\n* $2 - Minimum CIDR mask length.",
+ "apierror-compare-maintextrequired": "{{doc-apierror}}\n\nParameters:\n* $1 - Parameter name prefix, 'to' or 'from'.",
"apierror-compare-no-title": "{{doc-apierror}}",
"apierror-compare-nosuchfromsection": "{{doc-apierror}}\n\nParameters:\n* $1 - Section identifier. Probably a number or \"T-\" followed by a number.",
"apierror-compare-nosuchtosection": "{{doc-apierror}}\n\nParameters:\n* $1 - Section identifier. Probably a number or \"T-\" followed by a number.",
"apierror-compare-nofromrevision": "{{doc-apierror}}",
+ "apierror-compare-notext": "{{doc-apierror}}\n\nParameters:\n* $1 - Parameter that is not allowed without <var>totext-{role}</var>/<var>fromtext-{role}</var>.\n* $2 - The specific <var>totext-{role}</var>/<var>fromtext-{role}</var> parameter that must be present.",
"apierror-compare-notorevision": "{{doc-apierror}}",
"apierror-compare-relative-to-nothing": "{{doc-apierror}}",
"apierror-contentserializationexception": "{{doc-apierror}}\n\nParameters:\n* $1 - Exception text, may end with punctuation. Currently this is probably English, hopefully we'll fix that in the future.",
[],
'sectionreplacefailed',
],
+ 'Error, deleting the main slot' => [
+ [
+ 'fromtitle' => 'ApiComparePagesTest A',
+ 'totitle' => 'ApiComparePagesTest A',
+ 'toslots' => 'main',
+ ],
+ [],
+ 'compare-maintextrequired',
+ ],
+ // @todo Add a test for using 'tosection-foo' without 'totext-foo' (can't do it with main)
];
// phpcs:enable
}