Tag VE edits from the client-side

This opens up the API so that other tools can use it without being
forced to tag those edits as being from VE.

Also, document that tags is a working parameter that can be passed
through to the edit API.

Bug: T242184
Change-Id: I2c1d0f8d69bc03e5c1877c790247e165f160e966
This commit is contained in:
David Lynch 2020-01-24 13:14:32 -06:00
parent 37ba2c223a
commit d85d30f9b3
6 changed files with 18 additions and 10 deletions

View file

@ -133,6 +133,7 @@
"PreferencesFormPreSave": "VisualEditorHooks::onPreferencesFormPreSave",
"ListDefinedTags": "VisualEditorHooks::onListDefinedTags",
"ChangeTagsListActive": "VisualEditorHooks::onListDefinedTags",
"ChangeTagsAllowedAdd": "VisualEditorHooks::onListDefinedTags",
"MakeGlobalVariablesScript": "VisualEditorHooks::onMakeGlobalVariablesScript",
"RedirectSpecialArticleRedirectParams": "VisualEditorHooks::onRedirectSpecialArticleRedirectParams",
"ResourceLoaderGetConfigVars": "VisualEditorHooks::onResourceLoaderGetConfigVars",

View file

@ -63,6 +63,7 @@
"apihelp-visualeditoredit-param-sectiontitle": "Title for new section.",
"apihelp-visualeditoredit-param-starttimestamp": "When saving, set this to the timestamp of when the page was loaded. Used to detect edit conflicts.",
"apihelp-visualeditoredit-param-summary": "Edit summary.",
"apihelp-visualeditoredit-param-tags": "Change tags to apply to the edit. If provided, suppresses the normal visualeditor change tagging.",
"apihelp-visualeditoredit-param-watch": "Add the page to the current user's watchlist.",
"apihelp-visualeditoredit-param-wikitext": "The wikitext to act with.",
"apihelp-visualeditoredit-summary": "Save an HTML5 page to MediaWiki (converted to wikitext via the Parsoid service)."

View file

@ -72,6 +72,7 @@
"apihelp-visualeditoredit-param-sectiontitle": "{{doc-apihelp-param|visualeditoredit|sectiontitle}}",
"apihelp-visualeditoredit-param-starttimestamp": "{{doc-apihelp-param|visualeditoredit|starttimestamp}}",
"apihelp-visualeditoredit-param-summary": "{{doc-apihelp-param|visualeditoredit|summary}}\n{{Identical|Edit summary}}",
"apihelp-visualeditoredit-param-tags": "{{doc-apihelp-param|visualeditoredit|tags}}",
"apihelp-visualeditoredit-param-watch": "{{doc-apihelp-param|visualeditoredit|watch}}",
"apihelp-visualeditoredit-param-wikitext": "{{doc-apihelp-param|visualeditoredit|wikitext}}",
"apihelp-visualeditoredit-summary": "{{doc-apihelp-summary|visualeditoredit}}"

View file

@ -426,14 +426,6 @@ class ApiVisualEditorEdit extends ApiVisualEditor {
} else {
if ( isset( $saveresult['edit']['newrevid'] ) ) {
$newRevId = intval( $saveresult['edit']['newrevid'] );
if ( $this->veConfig->get( 'VisualEditorUseChangeTagging' ) ) {
// Defer till after the RC row is inserted
// @TODO: doEditContent should let callers specify desired tags
$tag = isset( $params['wikitext'] ) ? 'visualeditor-wikitext' : 'visualeditor';
DeferredUpdates::addCallableUpdate( function () use ( $tag, $newRevId ) {
ChangeTags::addTags( $tag, null, $newRevId, null );
} );
}
} else {
$newRevId = $title->getLatestRevId();
}
@ -547,6 +539,9 @@ class ApiVisualEditorEdit extends ApiVisualEditor {
'captchaid' => null,
'captchaword' => null,
'cachekey' => null,
'tags' => [
ApiBase::PARAM_ISMULTI => true,
],
];
}

View file

@ -896,8 +896,9 @@ class VisualEditorHooks {
}
/**
* Implements the ListDefinedTags and ChangeTagsListActive hooks, to populate
* core Special:Tags with the change tags in use by VisualEditor.
* Implements the ListDefinedTags, ChangeTagsListActive, and
* ChangeTagsAllowedAdd hooks, to populate core Special:Tags with the change
* tags in use by VisualEditor.
*
* @param array &$tags Available change tags.
*/
@ -973,6 +974,7 @@ class VisualEditorHooks {
$veConfig->get( 'VisualEditorEnableWikitext' ) ||
$veConfig->get( 'VisualEditorEnableWikitextBetaFeature' )
),
'useChangeTagging' => $veConfig->get( 'VisualEditorUseChangeTagging' ),
'svgMaxSize' => $coreConfig->get( 'SVGMaxSize' ),
'namespacesWithSubpages' => $coreConfig->get( 'NamespacesWithSubpages' ),
'specialBooksources' => urldecode( SpecialPage::getTitleFor( 'Booksources' )->getPrefixedURL() ),

View file

@ -1475,6 +1475,14 @@ ve.init.mw.ArticleTarget.prototype.save = function ( doc, options, isRetry ) {
token: this.editToken
} );
if ( mw.config.get( 'wgVisualEditorConfig' ).useChangeTagging && !data.tags ) {
if ( this.getSurface().getMode() === 'source' ) {
data.tags = [ 'visualeditor-wikitext' ];
} else {
data.tags = [ 'visualeditor' ];
}
}
promise = this.saving = this.tryWithPreparedCacheKey( doc, data, 'save' )
.done( this.saveComplete.bind( this ) )
.fail( this.saveFail.bind( this, doc, data, !!isRetry ) )