From 3cc6afaa750c01beb3675b1e9e4c6e04605b2923 Mon Sep 17 00:00:00 2001 From: Moriel Schottlender Date: Thu, 19 Feb 2015 13:20:55 -0800 Subject: [PATCH] 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 --- modules/ext.templateDataGenerator.ui.js | 33 ++++++++++++++++--------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/modules/ext.templateDataGenerator.ui.js b/modules/ext.templateDataGenerator.ui.js index 0c886cb7..285f5c55 100644 --- a/modules/ext.templateDataGenerator.ui.js +++ b/modules/ext.templateDataGenerator.ui.js @@ -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( //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 ); } );