mediawiki-extensions-Templa.../modules/ext.templateDataGenerator.editPage.js
Moriel Schottlender d59d517339 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
2015-02-18 17:56:13 -08:00

44 lines
1.1 KiB
JavaScript

( function () {
/**
* TemplateData Generator button fixture
* The button will appear on Template namespaces only, above the edit textbox
*
* @author Moriel Schottlender
*/
'use strict';
$( function () {
var pieces, isDocPage,
pageName = mw.config.get( 'wgPageName' ),
config = {
pageName: pageName,
isPageSubLevel: false
},
$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' ) {
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 );
}
} );
}() );