mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-11-28 02:00:57 +00:00
Merge "Check if you can edit the page before opening the tools"
This commit is contained in:
commit
c27071a2e7
|
@ -48,21 +48,6 @@ NewTopicController.static.initType = 'section';
|
|||
|
||||
/* Methods */
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
NewTopicController.prototype.getTranscludedFromSource = function () {
|
||||
var
|
||||
pageName = mw.config.get( 'wgRelevantPageName' ),
|
||||
oldId = mw.config.get( 'wgCurRevisionId' );
|
||||
|
||||
// Always post on the current page
|
||||
return $.Deferred().resolve( {
|
||||
pageName: pageName,
|
||||
oldId: oldId
|
||||
} ).promise();
|
||||
};
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
|
@ -111,7 +96,9 @@ NewTopicController.prototype.focus = function () {
|
|||
NewTopicController.prototype.teardown = function ( abandoned ) {
|
||||
NewTopicController.super.prototype.teardown.call( this, abandoned );
|
||||
|
||||
this.replyWidget.storage.remove( this.replyWidget.storagePrefix + '/title' );
|
||||
if ( this.replyWidget ) {
|
||||
this.replyWidget.storage.remove( this.replyWidget.storagePrefix + '/title' );
|
||||
}
|
||||
this.sectionTitle.setValue( '' );
|
||||
this.sectionTitleField.setWarnings( [] );
|
||||
this.container.$element.detach();
|
||||
|
|
|
@ -66,9 +66,10 @@ function highlight( comment ) {
|
|||
*
|
||||
* @param {string} pageName Page title
|
||||
* @param {number} oldId Revision ID
|
||||
* @param {boolean} [isNewTopic=false]
|
||||
* @return {jQuery.Promise}
|
||||
*/
|
||||
function getPageData( pageName, oldId ) {
|
||||
function getPageData( pageName, oldId, isNewTopic ) {
|
||||
var lintPromise, transcludedFromPromise, veMetadataPromise,
|
||||
api = getApi();
|
||||
|
||||
|
@ -77,7 +78,7 @@ function getPageData( pageName, oldId ) {
|
|||
return pageDataCache[ pageName ][ oldId ];
|
||||
}
|
||||
|
||||
if ( oldId ) {
|
||||
if ( oldId && !isNewTopic ) {
|
||||
lintPromise = api.get( {
|
||||
action: 'query',
|
||||
list: 'linterrors',
|
||||
|
@ -135,59 +136,71 @@ function getPageData( pageName, oldId ) {
|
|||
* Rejects with error data if the comment is transcluded, or there are lint errors on the page.
|
||||
*/
|
||||
function checkCommentOnPage( pageName, oldId, commentId ) {
|
||||
return getPageData( pageName, oldId )
|
||||
var isNewTopic = commentId.slice( 0, 4 ) === 'new|';
|
||||
|
||||
return getPageData( pageName, oldId, isNewTopic )
|
||||
.then( function ( response ) {
|
||||
var isTranscludedFrom, transcludedErrMsg, mwTitle, follow,
|
||||
lintType,
|
||||
metadata = response.metadata,
|
||||
lintErrors = response.linterrors,
|
||||
transcludedFrom = response.transcludedfrom;
|
||||
|
||||
isTranscludedFrom = transcludedFrom[ commentId ];
|
||||
if ( isTranscludedFrom === undefined ) {
|
||||
// The comment wasn't found when generating the "transcludedfrom" data,
|
||||
// so we don't know where the reply should be posted. Just give up.
|
||||
return $.Deferred().reject( 'discussiontools-commentid-notfound-transcludedfrom', { errors: [ {
|
||||
code: 'discussiontools-commentid-notfound-transcludedfrom',
|
||||
html: mw.message( 'discussiontools-error-comment-disappeared' ).parse()
|
||||
} ] } ).promise();
|
||||
} else if ( isTranscludedFrom ) {
|
||||
mwTitle = isTranscludedFrom === true ? null : mw.Title.newFromText( isTranscludedFrom );
|
||||
// If this refers to a template rather than a subpage, we never want to edit it
|
||||
follow = mwTitle && mwTitle.getNamespaceId() !== mw.config.get( 'wgNamespaceIds' ).template;
|
||||
if ( !isNewTopic ) {
|
||||
isTranscludedFrom = transcludedFrom[ commentId ];
|
||||
if ( isTranscludedFrom === undefined ) {
|
||||
// The comment wasn't found when generating the "transcludedfrom" data,
|
||||
// so we don't know where the reply should be posted. Just give up.
|
||||
return $.Deferred().reject( 'discussiontools-commentid-notfound-transcludedfrom', { errors: [ {
|
||||
code: 'discussiontools-commentid-notfound-transcludedfrom',
|
||||
html: mw.message( 'discussiontools-error-comment-disappeared' ).parse()
|
||||
} ] } ).promise();
|
||||
} else if ( isTranscludedFrom ) {
|
||||
mwTitle = isTranscludedFrom === true ? null : mw.Title.newFromText( isTranscludedFrom );
|
||||
// If this refers to a template rather than a subpage, we never want to edit it
|
||||
follow = mwTitle && mwTitle.getNamespaceId() !== mw.config.get( 'wgNamespaceIds' ).template;
|
||||
|
||||
if ( follow ) {
|
||||
transcludedErrMsg = mw.message(
|
||||
'discussiontools-error-comment-is-transcluded-title',
|
||||
mwTitle.getPrefixedText()
|
||||
).parse();
|
||||
} else {
|
||||
transcludedErrMsg = mw.message(
|
||||
'discussiontools-error-comment-is-transcluded',
|
||||
// eslint-disable-next-line no-jquery/no-global-selector
|
||||
$( '#ca-edit' ).text()
|
||||
).parse();
|
||||
if ( follow ) {
|
||||
transcludedErrMsg = mw.message(
|
||||
'discussiontools-error-comment-is-transcluded-title',
|
||||
mwTitle.getPrefixedText()
|
||||
).parse();
|
||||
} else {
|
||||
transcludedErrMsg = mw.message(
|
||||
'discussiontools-error-comment-is-transcluded',
|
||||
// eslint-disable-next-line no-jquery/no-global-selector
|
||||
$( '#ca-edit' ).text()
|
||||
).parse();
|
||||
}
|
||||
|
||||
return $.Deferred().reject( 'comment-is-transcluded', { errors: [ {
|
||||
data: {
|
||||
transcludedFrom: isTranscludedFrom,
|
||||
follow: follow
|
||||
},
|
||||
code: 'comment-is-transcluded',
|
||||
html: transcludedErrMsg
|
||||
} ] } ).promise();
|
||||
}
|
||||
|
||||
return $.Deferred().reject( 'comment-is-transcluded', { errors: [ {
|
||||
data: {
|
||||
transcludedFrom: isTranscludedFrom,
|
||||
follow: follow
|
||||
},
|
||||
code: 'comment-is-transcluded',
|
||||
html: transcludedErrMsg
|
||||
} ] } ).promise();
|
||||
if ( lintErrors.length ) {
|
||||
// We currently only request the first error
|
||||
lintType = lintErrors[ 0 ].category;
|
||||
|
||||
return $.Deferred().reject( 'lint', { errors: [ {
|
||||
code: 'lint',
|
||||
html: mw.message( 'discussiontools-error-lint',
|
||||
'https://www.mediawiki.org/wiki/Special:MyLanguage/Help:Lint_errors/' + lintType,
|
||||
'https://www.mediawiki.org/wiki/Special:MyLanguage/Help_talk:Lint_errors/' + lintType,
|
||||
mw.util.getUrl( pageName, { action: 'edit', lintid: lintErrors[ 0 ].lintId } ) ).parse()
|
||||
} ] } ).promise();
|
||||
}
|
||||
}
|
||||
|
||||
if ( lintErrors.length ) {
|
||||
// We currently only request the first error
|
||||
lintType = lintErrors[ 0 ].category;
|
||||
|
||||
return $.Deferred().reject( 'lint', { errors: [ {
|
||||
code: 'lint',
|
||||
html: mw.message( 'discussiontools-error-lint',
|
||||
'https://www.mediawiki.org/wiki/Special:MyLanguage/Help:Lint_errors/' + lintType,
|
||||
'https://www.mediawiki.org/wiki/Special:MyLanguage/Help_talk:Lint_errors/' + lintType,
|
||||
mw.util.getUrl( pageName, { action: 'edit', lintid: lintErrors[ 0 ].lintId } ) ).parse()
|
||||
if ( !metadata.canEdit ) {
|
||||
return $.Deferred().reject( 'permissions-error', { errors: [ {
|
||||
code: 'permissions-error',
|
||||
html: metadata.notices[ 'permissions-error' ]
|
||||
} ] } ).promise();
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ mw.dt.init = function ( $container ) {
|
|||
|
||||
if ( uri.query.dtdebug ) {
|
||||
mw.loader.load( 'ext.discussionTools.debug' );
|
||||
} else if ( mw.config.get( 'wgIsProbablyEditable' ) ) {
|
||||
} else {
|
||||
// Don't use an anonymous function, because ReplyWidget needs to be able to remove this handler
|
||||
mw.hook( 'wikipage.content' ).add( mw.dt.init );
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue