mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/TemplateData
synced 2024-11-23 23:43:54 +00:00
Warn if a TemplateData block already exists in related page
Check if there already is a TemplateData block in a related page and warn the user if that is the case. Related pages are either the /doc page or, if we are already in a /doc page, its immediate parent. Bug: T74062 Change-Id: I83212f14ecd2dcc18970d21ad0d833b461405390
This commit is contained in:
parent
c087fe89c7
commit
d59d517339
|
@ -107,6 +107,7 @@ $wgResourceModules['ext.templateDataGenerator.ui'] = array(
|
|||
'messages' => array(
|
||||
'comma-separator',
|
||||
'templatedata-doc-no-params-set',
|
||||
'templatedata-exists-on-related-page',
|
||||
'templatedata-modal-button-add-language',
|
||||
'templatedata-modal-button-addparam',
|
||||
'templatedata-modal-button-apply',
|
||||
|
@ -157,7 +158,7 @@ $wgResourceModules['ext.templateDataGenerator.ui'] = array(
|
|||
'templatedata-modal-title-paramorder',
|
||||
'templatedata-modal-title-templatedesc',
|
||||
'templatedata-modal-title-templateparam-details',
|
||||
'templatedata-modal-title-templateparams',
|
||||
'templatedata-modal-title-templateparams'
|
||||
)
|
||||
);
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
"templatedata-doc-params": "Template parameters",
|
||||
"templatedata-editbutton": "Manage TemplateData",
|
||||
"templatedata-errormsg-jsonbadformat": "Bad JSON format. Either correct it, or delete the current <templatedata> tags and try again.",
|
||||
"templatedata-exists-on-related-page": "Please note: there is already a TemplateData block on the related page '[[$1]]'.",
|
||||
"templatedata-helplink": "Information about TemplateData",
|
||||
"templatedata-helplink-target": "//www.mediawiki.org/wiki/Special:MyLanguage/Help:TemplateData",
|
||||
"templatedata-invalid-duplicate-value": "Property \"$1\" (\"$3\") is a duplicate of \"$2\".",
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
"templatedata-doc-params": "Used as caption for the table which has the following headings:\n* {{msg-mw|Templatedata-doc-param-name}}\n* {{msg-mw|Templatedata-doc-param-desc}}\n* {{msg-mw|Templatedata-doc-param-default}}\n* {{msg-mw|Templatedata-doc-param-status}}\n{{Identical|Template parameter}}",
|
||||
"templatedata-editbutton": "The label of the button to manage templatedata, appearing above the editor field.",
|
||||
"templatedata-errormsg-jsonbadformat": "Error message that appears in case the JSON string is not possible to parse. The user is asked to either correct the json syntax or delete the values between the <templatedata> tags and try again.",
|
||||
"templatedata-exists-on-related-page": "A messaged that is displayed when there already is a templatedata string in a related page. $1: The page where templatedata already exists.",
|
||||
"templatedata-helplink": "The label of the link to the TemplateData documentation, appearing above the editor field.",
|
||||
"templatedata-helplink-target": "{{ignore}} The target of the link to the TemplateData documentation",
|
||||
"templatedata-invalid-duplicate-value": "Displayed when an array that must only contain unique values contains a duplicate.\n* $1 - name of property containing the duplicate\n* $2 - name of property with first occurrence of value\n* $3 - the value being duplicated",
|
||||
|
|
|
@ -61,17 +61,28 @@ OO.mixinClass( mw.TemplateData.Model, OO.EventEmitter );
|
|||
/**
|
||||
* Get information from the mediaWiki API
|
||||
* @param {string} page Page name
|
||||
* @param {boolean} [getTemplateData] Fetch the templatedata in the page.
|
||||
* @return {jQuery.Promise} API promise
|
||||
*/
|
||||
mw.TemplateData.Model.static.getApi = function ( page ) {
|
||||
var api = new mw.Api();
|
||||
return api.get( {
|
||||
action: 'query',
|
||||
prop: 'revisions',
|
||||
rvprop: 'content',
|
||||
indexpageids: '1',
|
||||
titles: page
|
||||
} );
|
||||
mw.TemplateData.Model.static.getApi = function ( page, getTemplateData ) {
|
||||
var config,
|
||||
api = new mw.Api(),
|
||||
baseConfig = {
|
||||
action: getTemplateData ? 'templatedata' : 'query',
|
||||
titles: page
|
||||
};
|
||||
if ( getTemplateData ) {
|
||||
config = $.extend( baseConfig, {
|
||||
redirects: '1'
|
||||
} );
|
||||
} else {
|
||||
config = $.extend( baseConfig, {
|
||||
prop: 'revisions',
|
||||
rvprop: 'content',
|
||||
indexpageids: '1'
|
||||
} );
|
||||
}
|
||||
return api.get( config );
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -8,19 +8,32 @@
|
|||
'use strict';
|
||||
|
||||
$( function () {
|
||||
var config = {
|
||||
var pieces, isDocPage,
|
||||
pageName = mw.config.get( 'wgPageName' ),
|
||||
config = {
|
||||
pageName: pageName,
|
||||
isPageSubLevel: false
|
||||
},
|
||||
$textbox = $( '#wpTextbox1' ),
|
||||
pageName = mw.config.get( 'wgPageName' );
|
||||
$textbox = $( '#wpTextbox1' );
|
||||
|
||||
// Check if there's an editor textarea and if we're in the proper namespace
|
||||
if ( $textbox.length && mw.config.get( 'wgCanonicalNamespace' ) === 'Template' ) {
|
||||
if ( pageName.indexOf( '/' ) > -1 ) {
|
||||
config.parentPage = pageName.substr( 0, pageName.indexOf( '/' ) );
|
||||
config.isPageSubLevel = pageName.indexOf( '/' ) > -1;
|
||||
}
|
||||
pieces = pageName.split( '/' );
|
||||
isDocPage = pieces.length > 1 && pieces[ pieces.length - 1 ] === 'doc';
|
||||
|
||||
config = {
|
||||
pageName: pageName,
|
||||
isPageSubLevel: pieces.length > 1,
|
||||
parentPage: pageName,
|
||||
isDocPage: isDocPage
|
||||
};
|
||||
|
||||
// Only if we are in a doc page do we set the parent page to
|
||||
// the one above. Otherwise, all parent pages are current pages
|
||||
if ( isDocPage ) {
|
||||
pieces.pop();
|
||||
config.parentPage = pieces.join( '/' );
|
||||
}
|
||||
// Prepare the editor
|
||||
mw.libs.tdgUi.init( $( '#mw-content-text' ), $textbox, config );
|
||||
}
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
'use strict';
|
||||
mw.libs.tdgUi = ( function () {
|
||||
var isPageSubLevel,
|
||||
isDocPage,
|
||||
pageName,
|
||||
parentPage,
|
||||
$textbox,
|
||||
/**
|
||||
|
@ -28,13 +30,20 @@
|
|||
* Display error message in the edit window
|
||||
* @param {string} msg Message to display
|
||||
* @param {string} type Message type 'notice' or 'error'
|
||||
* @param {boolean} [parseHTML] The message should be parsed
|
||||
*/
|
||||
setNoticeMessage: function ( msg, type ) {
|
||||
setNoticeMessage: function ( msg, type, parseHTML ) {
|
||||
type = type || 'error';
|
||||
editNoticeLabel.$element.toggleClass( 'errorbox', type === 'error' );
|
||||
|
||||
if ( parseHTML ) {
|
||||
// OOUI's label elements do not parse strings and display them
|
||||
// as-is. If the message contains html that should be parsed,
|
||||
// we have to transform it into a jQuery object
|
||||
msg = $( '<span>' ).append( $.parseHTML( msg ) );
|
||||
}
|
||||
editNoticeLabel.setLabel( msg );
|
||||
editNoticeLabel.$element.show();
|
||||
editNoticeLabel.toggle( true );
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -42,7 +51,7 @@
|
|||
*/
|
||||
resetNoticeMessage: function () {
|
||||
editNoticeLabel.setLabel( '' );
|
||||
editNoticeLabel.$element.hide();
|
||||
editNoticeLabel.toggle( false );
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -114,13 +123,15 @@
|
|||
* current wikitext from.
|
||||
*/
|
||||
init: function ( $container, $editorTextbox, userConfig ) {
|
||||
var editHelpButtonWidget,
|
||||
var editHelpButtonWidget, relatedPage,
|
||||
config = userConfig;
|
||||
|
||||
$textbox = $editorTextbox;
|
||||
|
||||
pageName = config.pageName;
|
||||
parentPage = config.parentPage;
|
||||
isPageSubLevel = !!config.isPageSubLevel;
|
||||
isDocPage = !!config.isDocPage;
|
||||
|
||||
editOpenDialogButton = new OO.ui.ButtonWidget( {
|
||||
label: mw.msg( 'templatedata-editbutton' )
|
||||
|
@ -144,6 +155,26 @@
|
|||
tdgDialog = new mw.TemplateData.Dialog( config );
|
||||
windowManager.addWindows( [ tdgDialog ] );
|
||||
|
||||
// Check if there's already a templatedata in a related page
|
||||
relatedPage = isDocPage ? parentPage : pageName + '/doc';
|
||||
editOpenDialogButton.setDisabled( true );
|
||||
mw.TemplateData.Model.static.getApi( relatedPage, true )
|
||||
.then( function ( result ) {
|
||||
var msg;
|
||||
if ( !$.isEmptyObject( result.pages ) ) {
|
||||
// HACK: Setting a link in the messages doesn't work. The bug report offers
|
||||
// a somewhat hacky work around that includes setting a separate message
|
||||
// to be parsed.
|
||||
// https://phabricator.wikimedia.org/T49395#490610
|
||||
msg = mw.message( 'templatedata-exists-on-related-page', relatedPage ).plain();
|
||||
mw.messages.set( { 'templatedata-string-exists-hack-message': msg } );
|
||||
msg = mw.message( 'templatedata-string-exists-hack-message' ).parse();
|
||||
|
||||
editArea.setNoticeMessage( msg, 'error', true );
|
||||
}
|
||||
editOpenDialogButton.setDisabled( false );
|
||||
} );
|
||||
|
||||
// Prepend to container
|
||||
$container
|
||||
.prepend(
|
||||
|
|
Loading…
Reference in a new issue