User:Novem Linguae/Scripts/DraftCleaner.js: Difference between revisions

Content deleted Content added
pass more unit tests (publish.php)
change execution order, trying to fix a bug where you have to run DraftCleaner twice (publish.php)
Line 184:
class DraftCleaner {
cleanDraft(wikicode, namespaceNumber, titleWithNamespaceAndSpaces) {
// run before other stuff
wikicode = this.deleteSomeHTMLTags(wikicode);
wikicode = this.deleteBigTag(wikicode);
 
wikicode = this.fixWikilinksContainingURL(wikicode);
wikicode = this.fixExternalLinksToWikipediaArticles(wikicode);
Line 190 ⟶ 194:
wikicode = this.convertH1ToH2(wikicode);
wikicode = this.convertVeryLongHeadingToParagraph(wikicode);
wikicode = this.bareURLToRef(wikicode);
wikicode = this.refShortLinkToLongLink(wikicode);
wikicode = this.inlineExternalLinksToRefs(wikicode); // buggy
wikicode = this.deleteSpacesInFrontOfRefs(wikicode);
wikicode = this.deleteHeadingsWithTitle(wikicode, titleWithNamespaceAndSpaces);
wikicode = this.unlinkWikilinksToThisTitle(wikicode, titleWithNamespaceAndSpaces);
wikicode = this.capitalizeCOVID19(wikicode);
wikicode = this.removeBoldFromHeadings(wikicode);
wikicode = this.deleteNewLinesBetweenRefs(wikicode);
wikicode = this.convertReferenceToReferences(wikicode);
wikicode = this.swapRefPeriodWithPeriodRefaddReferencesSectionIfMissing(wikicode); // buggy
wikicode = this.addReferencesSectionIfMissing(wikicode); // buggy
wikicode = this.fixEmptyReferencesSection(wikicode);
wikicode = this.deleteWhitespaceAtEndOfLines(wikicode);
Line 210 ⟶ 208:
wikicode = this.changeYearRangeDashToNDash(wikicode);
wikicode = this.disableCategoriesInDraftspace(wikicode, namespaceNumber);
wikicode = this.deleteBRTagsOutsideInfoboxes(wikicode, namespaceNumber); // buggy
// wikicode = this.rightAlignImages(wikicode); // commenting out, too many false positives in featured articles
wikicode = this.correctCapitalizationOfEndMatterHeaders(wikicode);
Line 216 ⟶ 214:
wikicode = this.deleteCopyPastedEditAndEditSource(wikicode);
wikicode = this.replaceUnicodeBulletsWithAsterisks(wikicode);
wikicode = this.fixDoublePeriod(wikicode);
wikicode = this.deleteEmptySections(wikicode);
wikicode = this.fixHeadingsInAllCaps(wikicode);
wikicode = this.deleteDuplicateReferencesSection(wikicode);
wikicode = this.deleteSomeHTMLTags(wikicode);
wikicode = this.deleteBlankLinesBetweenBullets(wikicode);
wikicode = this.deleteBigTag(wikicode);
wikicode = this.removeUnderscoresFromWikilinks(wikicode);
 
// delete empty sections. for example, empty ==See Also== section
// all ==sections== should start with a capital letter
// after swap, if citation has no spaces on either side, and is not touching two other citations, add a space on the right
// strip [[File: from infobox's image field
// example 1: | image = [[File:SAMIR 1626.png|thumb|Samir Mohanty]]
// example 2: | image = [[File:SAMIR 1626.pngypng]]
// trim whitespace inside refs, e.g. <ref> abc </ref>
// single quotes to double quotes, i.e. This 'thing' to This "thing"
// replace unreliable sources with {{cn}}.
// if adjacent to other sources, just delete
Line 239 ⟶ 233:
// move refs out of headings
// delete AFC submission templates located mid-article, they end up self-hiding then appear as inexplicable whitespace. example: {{AfC submission|t||ts=20211212134609|u=Doezdemir|ns=118|demo=}}<!-- Important, do not remove this line before article has been created. -->
// delete <!-- Inline citations added to your article will automatically display here. See en.wikipedia.org/wiki/WP:REFB for instructions on how to add citations. -->
// remove <big></big> tags. test: == '''''<big>Saroj Kumar Basu</big>''''' ==, '''''<big>Saroj Kumar Basu</big>'''''
// in wikilinks, underscores to spaces
// fix redundant wikilinks, e.g. [[Spotify|Spotify]]
// change youtu.be to youtube.com, to avoid the blacklist. test: https://youtu.be/bnWHeRNIPiA
wikicode = this.boldArticleTitle(wikicode, titleWithNamespaceAndSpaces); // buggy
 
// convert refs toward the end. we want deleteSomeHTMLTags() to run first, to get rid of <nowiki> tags around URLs
wikicode = this.bareURLToRef(wikicode);
wikicode = this.refShortLinkToLongLink(wikicode);
wikicode = this.inlineExternalLinksToRefs(wikicode); // buggy
wikicode = this.deleteSpacesInFrontOfRefs(wikicode);
wikicode = this.deleteNewLinesBetweenRefs(wikicode);
wikicode = this.fixDoublePeriodswapRefPeriodWithPeriodRef(wikicode);
// stuff we want to run at the end
wikicode = this.fixDoublePeriod(wikicode); // need test cases. I've seen this one not work.
wikicode = this.boldArticleTitle(wikicode, titleWithNamespaceAndSpaces); // buggy
wikicode = this.trimEmptyLines(wikicode);
wikicode = this.deleteMoreThanTwoEntersInARow(wikicode);