mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-11-12 01:16:19 +00:00
Merge "Don't allow switching when unsupported content used"
This commit is contained in:
commit
3db53080e8
|
@ -67,10 +67,15 @@
|
|||
"ext.visualEditor.core.utils.parsing"
|
||||
],
|
||||
"messages": [
|
||||
"discussiontools-error-lint",
|
||||
"discussiontools-error-comment-disappeared",
|
||||
"discussiontools-error-comment-is-transcluded",
|
||||
"discussiontools-error-comment-is-transcluded-title",
|
||||
"discussiontools-error-lint",
|
||||
"discussiontools-error-noswitchtove",
|
||||
"discussiontools-error-noswitchtove-extension",
|
||||
"discussiontools-error-noswitchtove-table",
|
||||
"discussiontools-error-noswitchtove-template",
|
||||
"discussiontools-error-noswitchtove-title",
|
||||
"discussiontools-replylink",
|
||||
"discussiontools-replywidget-loading"
|
||||
]
|
||||
|
|
|
@ -32,6 +32,11 @@
|
|||
"discussiontools-error-comment-is-transcluded": "The \"{{int:discussiontools-replylink}}\" link cannot be used to reply to this comment. To reply, please use the full page editor by clicking \"$1\".",
|
||||
"discussiontools-error-comment-is-transcluded-title": "The \"{{int:discussiontools-replylink}}\" link cannot be used to reply to this comment because it is loaded from another page. To reply, please go here: [[$1]].",
|
||||
"discussiontools-error-lint": "Comments on this page can't be replied to because of an error in the wikitext. You can learn about this error by [$1 reading the documentation], ask for help by [$2 posting here] or fix the error by [$3 opening the full page editor].",
|
||||
"discussiontools-error-noswitchtove": "Sorry, switching to visual mode is disabled because <b>$1</b> was detected in the comment you have written. [https:\/\/mediawiki.org\/wiki\/Special:MyLanguage\/Extension:DiscussionTools/Reply_tool_visual_mode_limitations Learn more].",
|
||||
"discussiontools-error-noswitchtove-extension": "extension or reference syntax",
|
||||
"discussiontools-error-noswitchtove-table": "table syntax",
|
||||
"discussiontools-error-noswitchtove-template": "template syntax",
|
||||
"discussiontools-error-noswitchtove-title": "Visual mode disabled",
|
||||
"tag-discussiontools": "-",
|
||||
"tag-discussiontools-description": "Edit made using DiscussionTools",
|
||||
"tag-discussiontools-edit": "Edit comment",
|
||||
|
|
|
@ -37,6 +37,11 @@
|
|||
"discussiontools-error-comment-is-transcluded": "Error message. Parameter: $1 – text of the 'Edit'/'Edit source' tab",
|
||||
"discussiontools-error-comment-is-transcluded-title": "Error message. Parameter: $1 – page name",
|
||||
"discussiontools-error-lint": "Error message. Parameters:\n* $1 – URL to documentation on mediawiki.org\n* $2 – URL to talk page on mediawiki.org\n* $3 – URL to the editor (action=edit)",
|
||||
"discussiontools-error-noswitchtove": "Error message. Parameters: $1 – type of syntax detected",
|
||||
"discussiontools-error-noswitchtove-extension": "Type of syntax detected, used my {{msg-mw|discussiontools-error-noswitchtove}}",
|
||||
"discussiontools-error-noswitchtove-table": "Type of syntax detected, used my {{msg-mw|discussiontools-error-noswitchtove}}",
|
||||
"discussiontools-error-noswitchtove-template": "Type of syntax detected, used my {{msg-mw|discussiontools-error-noswitchtove}}",
|
||||
"discussiontools-error-noswitchtove-title": "Title for switching error message {{msg-mw|discussiontools-error-noswitchtove}}",
|
||||
"tag-discussiontools": "{{ignored}}Short description of the discussiontools tag.\n\nShown on lists of changes (history, recentchanges, etc.) for each edit made using DiscussionTools.\n\nSee also:\n* {{msg-mw|Tag-discussiontools-description}}\n{{Related|tag-discussiontools}}",
|
||||
"tag-discussiontools-description": "Long description of the discussiontools tag ({{msg-mw|Tag-discussiontools}}).\n\nShown on [[Special:Tags]].\n\nSee also:\n* {{msg-mw|Tag-discussiontools}}\n{{Related|tag-discussiontools}}",
|
||||
"tag-discussiontools-edit": "Short description of the discussiontools-edit tag.\n\nShown on lists of changes (history, recentchanges, etc.) for each edit to an existing comment made using DiscussionTools.\n\nThis message is always shown directly after {{msg-mw|tag-discussiontools}} and a comma.\n\nSee also:\n* {{msg-mw|Tag-discussiontools-edit-description}}\n{{Related|tag-discussiontools}}",
|
||||
|
|
|
@ -411,19 +411,52 @@ CommentController.prototype.switchToVisual = function () {
|
|||
this.replyWidgetPromise = this.createReplyWidget( oldWidget.parsoidData, true );
|
||||
|
||||
return $.when( parsePromise, this.replyWidgetPromise ).then( function ( html, replyWidget ) {
|
||||
var doc, bodyChildren;
|
||||
|
||||
// Swap out the DOM nodes
|
||||
oldWidget.$element.replaceWith( replyWidget.$element );
|
||||
|
||||
// Teardown the old widget
|
||||
oldWidget.disconnect( commentController );
|
||||
oldWidget.teardown();
|
||||
var doc, bodyChildren, type, $msg,
|
||||
unsupportedSelectors = {
|
||||
// Tables are almost always multi-line
|
||||
table: 'table',
|
||||
// Headings are converted to plain text before we can detect them:
|
||||
// `:==h2==` -> `<p>==h2==</p>`
|
||||
// heading: 'h1, h2, h3, h4, h5, h6',
|
||||
// Templates can be multiline
|
||||
template: '[typeof*="mw:Transclusion"]',
|
||||
// Extensions (includes references) can be multiline, could be supported later (T251633)
|
||||
extension: '[typeof*="mw:Extension"]'
|
||||
// Images are probably fine unless a multi-line caption was used (rare)
|
||||
// image: 'figure, figure-inline'
|
||||
};
|
||||
|
||||
if ( html ) {
|
||||
doc = replyWidget.replyBodyWidget.target.parseDocument( html );
|
||||
// Remove RESTBase IDs (T253584)
|
||||
mw.libs.ve.stripRestbaseIds( doc );
|
||||
for ( type in unsupportedSelectors ) {
|
||||
if ( doc.querySelector( unsupportedSelectors[ type ] ) ) {
|
||||
$msg = $( '<div>' ).html(
|
||||
mw.message(
|
||||
'discussiontools-error-noswitchtove',
|
||||
// The following messages are used here:
|
||||
// * discussiontools-error-noswitchtove-extension
|
||||
// * discussiontools-error-noswitchtove-table
|
||||
// * discussiontools-error-noswitchtove-template
|
||||
mw.msg( 'discussiontools-error-noswitchtove-' + type )
|
||||
).parse()
|
||||
);
|
||||
$msg.find( 'a' ).attr( {
|
||||
target: '_blank',
|
||||
rel: 'noopener'
|
||||
} );
|
||||
OO.ui.alert(
|
||||
$msg.contents(),
|
||||
{
|
||||
title: mw.msg( 'discussiontools-error-noswitchtove-title' ),
|
||||
size: 'medium'
|
||||
}
|
||||
);
|
||||
return $.Deferred().reject().promise();
|
||||
}
|
||||
}
|
||||
// Check for tables, headings, images, templates
|
||||
bodyChildren = Array.prototype.slice.call( doc.body.childNodes );
|
||||
// There may be multiple lists when some lines are template generated
|
||||
bodyChildren.forEach( function ( child ) {
|
||||
|
@ -434,6 +467,13 @@ CommentController.prototype.switchToVisual = function () {
|
|||
} );
|
||||
}
|
||||
|
||||
// Swap out the DOM nodes
|
||||
oldWidget.$element.replaceWith( replyWidget.$element );
|
||||
|
||||
// Teardown the old widget
|
||||
oldWidget.disconnect( commentController );
|
||||
oldWidget.teardown();
|
||||
|
||||
commentController.setupReplyWidget( replyWidget, doc );
|
||||
} );
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue