Use wikitext instead of page prop when checking for existing TemplateData

On the edit page, we show the user a message if a related page
(parent of /doc page, or vice versa) already has templatedata.

This check was wrongly detecting that the parent page has templatedata
when editing '/doc'. The check shouldn't use the 'templatedata' API
since that also includes transcluded templatedata.

Look in the wikitext content instead.

Change-Id: I9788e2beb0809ac3e676a90cd0dfe519c005afc9
This commit is contained in:
Moriel Schottlender 2015-02-19 13:20:55 -08:00 committed by Krinkle
parent 08cd710c96
commit 3cc6afaa75

View file

@ -158,19 +158,30 @@
// 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 )
mw.TemplateData.Model.static.getApi( relatedPage )
.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();
var msg, matches, content,
response = result.query.pages[ result.query.pageids[0] ];
// HACK: When checking whether a related page (parent for /doc page or
// vice versa) already has a templatedata string, we shouldn't
// ask for the 'templatedata' action but rather the actual content
// of the related page, otherwise we get embedded templatedata and
// wrong information is presented.
if ( response.missing === undefined ) {
content = response.revisions[0]['*'];
matches = content.match( /<templatedata>/i );
// There's a templatedata string
if ( matches ) {
// 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 );
editArea.setNoticeMessage( msg, 'error', true );
}
}
editOpenDialogButton.setDisabled( false );
} );