mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-09-24 10:58:20 +00:00
Merge "controller: Move code for transcluded comment errors"
This commit is contained in:
commit
c5763bc2bd
|
@ -120,29 +120,8 @@ function autoSignWikitext( wikitext ) {
|
||||||
function postReply( widget, parsoidData ) {
|
function postReply( widget, parsoidData ) {
|
||||||
var wikitext,
|
var wikitext,
|
||||||
comment = parsoidData.comment,
|
comment = parsoidData.comment,
|
||||||
transcludedFrom, transcludedErrMsg, mwTitle, newParsoidItem;
|
newParsoidItem = modifier.addListItem( comment );
|
||||||
|
|
||||||
transcludedFrom = parser.getTranscludedFrom( comment );
|
|
||||||
if ( transcludedFrom ) {
|
|
||||||
mwTitle = transcludedFrom === true ? null : mw.Title.newFromText( transcludedFrom );
|
|
||||||
|
|
||||||
// If this refers to a template rather than a subpage, we never want to edit it
|
|
||||||
if ( mwTitle && mwTitle.getNamespaceId() !== mw.config.get( 'wgNamespaceIds' ).template ) {
|
|
||||||
// TODO: Post the reply to the target page instead
|
|
||||||
transcludedErrMsg = mw.message( 'discussiontools-error-comment-is-transcluded-title',
|
|
||||||
mwTitle.getPrefixedText() ).parse();
|
|
||||||
} else {
|
|
||||||
transcludedErrMsg = mw.message( 'discussiontools-error-comment-is-transcluded' ).parse();
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: This should be shown immediately, rather than after trying to post
|
|
||||||
return $.Deferred().reject( 'comment-is-transcluded', { errors: [ {
|
|
||||||
code: 'comment-is-transcluded',
|
|
||||||
html: transcludedErrMsg
|
|
||||||
} ] } ).promise();
|
|
||||||
}
|
|
||||||
|
|
||||||
newParsoidItem = modifier.addListItem( comment );
|
|
||||||
if ( widget.getMode() === 'source' ) {
|
if ( widget.getMode() === 'source' ) {
|
||||||
wikitext = widget.getValue();
|
wikitext = widget.getValue();
|
||||||
wikitext = autoSignWikitext( wikitext );
|
wikitext = autoSignWikitext( wikitext );
|
||||||
|
@ -306,7 +285,9 @@ function getParsoidCommentData( commentId ) {
|
||||||
|
|
||||||
return getPageData( pageName, oldId )
|
return getPageData( pageName, oldId )
|
||||||
.then( function ( response ) {
|
.then( function ( response ) {
|
||||||
var data = response.visualeditor;
|
var data, comment, transcludedFrom, transcludedErrMsg, mwTitle;
|
||||||
|
|
||||||
|
data = response.visualeditor;
|
||||||
// TODO: error handling
|
// TODO: error handling
|
||||||
parsoidDoc = ve.parseXhtml( data.content );
|
parsoidDoc = ve.parseXhtml( data.content );
|
||||||
// Mirror VE's ve.init.mw.Target.prototype.fixBase behavior:
|
// Mirror VE's ve.init.mw.Target.prototype.fixBase behavior:
|
||||||
|
@ -326,18 +307,38 @@ function getParsoidCommentData( commentId ) {
|
||||||
etag: data.etag
|
etag: data.etag
|
||||||
};
|
};
|
||||||
|
|
||||||
// getThreads build the tree structure, currently only
|
// getThreads builds the tree structure, currently only
|
||||||
// used to set 'replies'
|
// used to set 'replies' and 'id'
|
||||||
parser.groupThreads( parsoidComments );
|
parser.groupThreads( parsoidComments );
|
||||||
parsoidCommentsById = commentsById( parsoidComments );
|
parsoidCommentsById = commentsById( parsoidComments );
|
||||||
|
comment = parsoidCommentsById[ commentId ];
|
||||||
|
|
||||||
if ( !parsoidCommentsById[ commentId ] ) {
|
if ( !comment ) {
|
||||||
return $.Deferred().reject( 'comment-disappeared', { errors: [ {
|
return $.Deferred().reject( 'comment-disappeared', { errors: [ {
|
||||||
code: 'comment-disappeared',
|
code: 'comment-disappeared',
|
||||||
html: mw.message( 'discussiontools-error-comment-disappeared' ).parse()
|
html: mw.message( 'discussiontools-error-comment-disappeared' ).parse()
|
||||||
} ] } ).promise();
|
} ] } ).promise();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
transcludedFrom = parser.getTranscludedFrom( comment );
|
||||||
|
if ( transcludedFrom ) {
|
||||||
|
mwTitle = transcludedFrom === true ? null : mw.Title.newFromText( transcludedFrom );
|
||||||
|
|
||||||
|
// If this refers to a template rather than a subpage, we never want to edit it
|
||||||
|
if ( mwTitle && mwTitle.getNamespaceId() !== mw.config.get( 'wgNamespaceIds' ).template ) {
|
||||||
|
// TODO: Post the reply to the target page instead
|
||||||
|
transcludedErrMsg = mw.message( 'discussiontools-error-comment-is-transcluded-title',
|
||||||
|
mwTitle.getPrefixedText() ).parse();
|
||||||
|
} else {
|
||||||
|
transcludedErrMsg = mw.message( 'discussiontools-error-comment-is-transcluded' ).parse();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $.Deferred().reject( 'comment-is-transcluded', { errors: [ {
|
||||||
|
code: 'comment-is-transcluded',
|
||||||
|
html: transcludedErrMsg
|
||||||
|
} ] } ).promise();
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
comment: parsoidCommentsById[ commentId ],
|
comment: parsoidCommentsById[ commentId ],
|
||||||
doc: parsoidDoc,
|
doc: parsoidDoc,
|
||||||
|
|
Loading…
Reference in a new issue