There's some overlap with T245811: PagePreparation doesn't detect languages tag already in page; but I don't think it's actually a dupe, as that is requesting a specific format...
In this case, I'm questioning whether Special:PagePreparation should be touching an apparently already formatted page, rather than duplicating syntax etc.
As it's just running various regexes over the text, it will make those changes...
It also makes whitespace changes...
Which gives errors like the below if you try and publish it (meaning the syntax is now wrong):
{ "error": { "code": "pt-shake-empty", "info": "Empty translation unit for marker \"3\".", "*": "See https://www.mediawiki.org/w/api.php for API usage. Subscribe to the mediawiki-api-announce mailing list at <https://lists.wikimedia.org/postorius/lists/mediawiki-api-announce.lists.wikimedia.org/> for notice of API deprecations and breaking changes." }, "servedby": "mw-api-ext.eqiad.main-5cf9879585-tlrxx" }
And then poorly handles them; hiding the error as per T342628: No error handling (effectively error suppression) on Special:PagePreparation.
It also removes <translate> tags from paragraphs/blocks; which I don't know whether is desired (the code does it explicitly), but is a pattern that we use extensively throughout Wikimedia usages of Page Translation:
/** * Remove all the <translate> tags and {{translation}} templates before * preparing the page. The tool will add them back wherever needed. * * @param {string} pageContent * @return {string} */ function cleanupTags( pageContent ) { pageContent = pageContent.replace( /<\/?translate>\n?/gi, '' ); return pageContent; } /** * Cleanup done after the page is prepared for translation by the tool. * * @param {string} pageContent * @return {string} */ function postPreparationCleanup( pageContent ) { // Removes any extra newlines introduced by the tool pageContent = pageContent.replace( /\n\n+/gi, '\n\n' ); // Removes redundant <translate> tags pageContent = pageContent.replace( /\n<translate>(\n*?)<\/translate>/gi, '' ); // Removes the Special:MyLanguage/ prefix for section links pageContent = pageContent.replace( /Special:MyLanguage\/#/gi, '#' ); return pageContent; }
There's some overlap with T342622: Clicking Prepare multiple times on Special:PagePreparation results in multiple diffs being appended too, but that is more specifically about the diff resulting in multiple diffs for "Line 1" further down...
Maybe it should detect there's some syntax already, and either clearly warn the user (at the same time as making the changes), and/or ask the user for confirmation before trying to make any..

