[MediaWiki-commits] [Gerrit] mediawiki/core[master]: ApiComparePages: Add 'fromsection' and 'tosection' parameters
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/401090 ) Change subject: ApiComparePages: Add 'fromsection' and 'tosection' parameters .. ApiComparePages: Add 'fromsection' and 'tosection' parameters The deprecated diffing in prop=revisions and such used a 'rvsection' parameter. To enable migration of things using that, action=compare needs corresponding section parameters. Bug: T183823 Change-Id: If1a0e2df614c083b37640418c69cca367ce0e895 --- M includes/api/ApiComparePages.php M includes/api/i18n/en.json M includes/api/i18n/qqq.json M tests/phpunit/includes/api/ApiComparePagesTest.php 4 files changed, 72 insertions(+), 0 deletions(-) Approvals: Legoktm: Looks good to me, approved jenkins-bot: Verified diff --git a/includes/api/ApiComparePages.php b/includes/api/ApiComparePages.php index eb67bab..5486594 100644 --- a/includes/api/ApiComparePages.php +++ b/includes/api/ApiComparePages.php @@ -94,6 +94,26 @@ $this->dieWithError( 'apierror-baddiff' ); } + // Extract sections, if told to + if ( isset( $params['fromsection'] ) ) { + $fromContent = $fromContent->getSection( $params['fromsection'] ); + if ( !$fromContent ) { + $this->dieWithError( + [ 'apierror-compare-nosuchfromsection', wfEscapeWikiText( $params['fromsection'] ) ], + 'nosuchfromsection' + ); + } + } + if ( isset( $params['tosection'] ) ) { + $toContent = $toContent->getSection( $params['tosection'] ); + if ( !$toContent ) { + $this->dieWithError( + [ 'apierror-compare-nosuchtosection', wfEscapeWikiText( $params['tosection'] ) ], + 'nosuchtosection' + ); + } + } + // Get the diff $context = new DerivativeContext( $this->getContext() ); if ( $relRev && $relRev->getTitle() ) { @@ -444,6 +464,7 @@ 'text' => [ ApiBase::PARAM_TYPE => 'text' ], + 'section' => null, 'pst' => false, 'contentformat' => [ ApiBase::PARAM_TYPE => ContentHandler::getAllContentFormats(), diff --git a/includes/api/i18n/en.json b/includes/api/i18n/en.json index e1360c8..cceed01 100644 --- a/includes/api/i18n/en.json +++ b/includes/api/i18n/en.json @@ -64,6 +64,7 @@ "apihelp-compare-param-fromid": "First page ID to compare.", "apihelp-compare-param-fromrev": "First revision to compare.", "apihelp-compare-param-fromtext": "Use this text instead of the content of the revision specified by fromtitle, fromid or fromrev.", + "apihelp-compare-param-fromsection": "Only use the specified section of the specified 'from' content.", "apihelp-compare-param-frompst": "Do a pre-save transform on fromtext.", "apihelp-compare-param-fromcontentmodel": "Content model of fromtext. If not supplied, it will be guessed based on the other parameters.", "apihelp-compare-param-fromcontentformat": "Content serialization format of fromtext.", @@ -72,6 +73,7 @@ "apihelp-compare-param-torev": "Second revision to compare.", "apihelp-compare-param-torelative": "Use a revision relative to the revision determined from fromtitle, fromid or fromrev. All of the other 'to' options will be ignored.", "apihelp-compare-param-totext": "Use this text instead of the content of the revision specified by totitle, toid or torev.", + "apihelp-compare-param-tosection": "Only use the specified section of the specified 'to' content.", "apihelp-compare-param-topst": "Do a pre-save transform on totext.", "apihelp-compare-param-tocontentmodel": "Content model of totext. If not supplied, it will be guessed based on the other parameters.", "apihelp-compare-param-tocontentformat": "Content serialization format of totext.", @@ -1675,6 +1677,8 @@ "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-no-title": "Cannot pre-save transform without a title. Try specifying fromtitle or totitle.", + "apierror-compare-nosuchfromsection": "There is no section $1 in the 'from' content.", + "apierror-compare-nosuchtosection": "There is no section $1 in the 'to' content.",
[MediaWiki-commits] [Gerrit] mediawiki/core[master]: ApiComparePages: Add 'fromsection' and 'tosection' parameters
Anomie has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/401090 ) Change subject: ApiComparePages: Add 'fromsection' and 'tosection' parameters .. ApiComparePages: Add 'fromsection' and 'tosection' parameters The deprecated diffing in prop=revisions and such used a 'rvsection' parameter. To enable migration of things using that, action=compare needs corresponding section parameters. Bug: T183823 Change-Id: If1a0e2df614c083b37640418c69cca367ce0e895 --- M includes/api/ApiComparePages.php M includes/api/i18n/en.json M includes/api/i18n/qqq.json M tests/phpunit/includes/api/ApiComparePagesTest.php 4 files changed, 72 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/90/401090/1 diff --git a/includes/api/ApiComparePages.php b/includes/api/ApiComparePages.php index eb67bab..5486594 100644 --- a/includes/api/ApiComparePages.php +++ b/includes/api/ApiComparePages.php @@ -94,6 +94,26 @@ $this->dieWithError( 'apierror-baddiff' ); } + // Extract sections, if told to + if ( isset( $params['fromsection'] ) ) { + $fromContent = $fromContent->getSection( $params['fromsection'] ); + if ( !$fromContent ) { + $this->dieWithError( + [ 'apierror-compare-nosuchfromsection', wfEscapeWikiText( $params['fromsection'] ) ], + 'nosuchfromsection' + ); + } + } + if ( isset( $params['tosection'] ) ) { + $toContent = $toContent->getSection( $params['tosection'] ); + if ( !$toContent ) { + $this->dieWithError( + [ 'apierror-compare-nosuchtosection', wfEscapeWikiText( $params['tosection'] ) ], + 'nosuchtosection' + ); + } + } + // Get the diff $context = new DerivativeContext( $this->getContext() ); if ( $relRev && $relRev->getTitle() ) { @@ -444,6 +464,7 @@ 'text' => [ ApiBase::PARAM_TYPE => 'text' ], + 'section' => null, 'pst' => false, 'contentformat' => [ ApiBase::PARAM_TYPE => ContentHandler::getAllContentFormats(), diff --git a/includes/api/i18n/en.json b/includes/api/i18n/en.json index e1360c8..cceed01 100644 --- a/includes/api/i18n/en.json +++ b/includes/api/i18n/en.json @@ -64,6 +64,7 @@ "apihelp-compare-param-fromid": "First page ID to compare.", "apihelp-compare-param-fromrev": "First revision to compare.", "apihelp-compare-param-fromtext": "Use this text instead of the content of the revision specified by fromtitle, fromid or fromrev.", + "apihelp-compare-param-fromsection": "Only use the specified section of the specified 'from' content.", "apihelp-compare-param-frompst": "Do a pre-save transform on fromtext.", "apihelp-compare-param-fromcontentmodel": "Content model of fromtext. If not supplied, it will be guessed based on the other parameters.", "apihelp-compare-param-fromcontentformat": "Content serialization format of fromtext.", @@ -72,6 +73,7 @@ "apihelp-compare-param-torev": "Second revision to compare.", "apihelp-compare-param-torelative": "Use a revision relative to the revision determined from fromtitle, fromid or fromrev. All of the other 'to' options will be ignored.", "apihelp-compare-param-totext": "Use this text instead of the content of the revision specified by totitle, toid or torev.", + "apihelp-compare-param-tosection": "Only use the specified section of the specified 'to' content.", "apihelp-compare-param-topst": "Do a pre-save transform on totext.", "apihelp-compare-param-tocontentmodel": "Content model of totext. If not supplied, it will be guessed based on the other parameters.", "apihelp-compare-param-tocontentformat": "Content serialization format of totext.", @@ -1675,6 +1677,8 @@ "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-no-title": "Cannot pre-save transform without a title. Try specifying fromtitle or totitle.", + "apierror-compare-nosuchfromsection": "There is no section $1 in the 'from' content.", + "apierror-compare-nosuchtosection": "There is no section $1 in the 'to' content.",