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

Content deleted Content added
fix bug involving extra spaces in heading (publish.php)
add deleteNoWikiTags(), couple of bug fixes (publish.php)
Line 1:
// <nowiki>
 
//* THIS SCRIPT IS STILL IN BETA AND IS BUGGY ABOUT 25% OF THE TIME. Be sure to check the diff that pops up before submitting.
 
/*
- Adds "Run DraftCleaner" link to the left sidebar
 
- Clicking it does the following:
- Top uses:
- removes extra line breaks
- bolds the title
 
- More detailed list of uses:
- converts [inline external links] to <ref>s
- reduces more than 2 enters in a row, to 2 enters
- removes spaces in front of <ref>s
- get rid of any level 2 heading that contains the article's title
- boldbolds the first occurrence of the article title
- removeremoves bold from headings
- convertconverts =TitleHeading= to ==H2Heading==
- replacereplaces Covid-19 with COVID-19
- removeremoves enter characters between <ref>s
- trimtrims whitespace at beginning and end
- remove self wikilinks to the article title
- convert ==Reference== to ==References==
Line 207 ⟶ 211:
wikicode = this.deleteEmptySections(wikicode);
wikicode = this.fixHeadingsInAllCaps(wikicode);
wikicode = this.deleteDuplicateReferencesSection(wikicode);
wikicode = this.deleteNoWikiTags(wikicode);
// delete empty sections. for example, empty ==See Also== section
// all ==sections== should start with a capital letter
Line 220 ⟶ 226:
// duplicate citation fixer
// move refs that are below {{Reflist}}, to above {{Reflist}}
// 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. -->
wikicode = this.trimEmptyLines(wikicode);
wikicode = this.deleteMoreThanTwoEntersInARow(wikicode);
Line 272 ⟶ 280:
headingNameToLookFor = headingNameToLookFor.replace(/^Draft:/, '');
headingNameToLookFor = this._escapeRegEx(headingNameToLookFor);
let regEx = new RegExp("^== ?"+headingNameToLookFor+"[^=]* ?==\n", "gmi");
wikicode = wikicode.replace(regEx, "");
// now look for titles that contain Draft: at the beginning, too
headingNameToLookFor = titleWithNamespaceAndSpaces;
headingNameToLookFor = this._escapeRegEx(headingNameToLookFor);
regEx = new RegExp("^== ?"+headingNameToLookFor+"[^=]* ?==\n", "gmi");
wikicode = wikicode.replace(regEx, "");
return wikicode;
Line 303 ⟶ 311:
titleToLookFor = this._escapeRegEx(titleToLookFor);
// Be pretty strict, to avoid adding ''' to image paths and infoboxes, which messes up the image.
let regEx = new RegExp("^(The )?("+titleToLookFor+")([ |<,])", "mi");
wikicode = wikicode.replace(regEx, "$1'''$2'''$3");
}
Line 425 ⟶ 433:
let draft = (namespace == 118);
if ( draft ) {
wikicode = wikicode.replace(/:?(\[\[)(Category:[^\]]*\]\])/gm, '$1:$2');
}
return wikicode;
Line 549 ⟶ 557:
// TODO:
return wikicode;
}
 
deleteDuplicateReferencesSection(wikicode) {
// TODO:
return wikicode;
}
 
deleteNoWikiTags(wikicode) {
return wikicode.replace(/<\/?nowiki>/g, '');
}