User:Theleekycauldron/Scripts/PSHAW/dependencies/Nomination.js: Difference between revisions
Content deleted Content added
trim |
underscores |
||
(44 intermediate revisions by the same user not shown) | |||
Line 12:
copies or substantial portions of the Software.
*/
class Nomination {
constructor(title,page){
this.title = title; //MediaWiki stuff
get_pages(this.title,"user|content",null,"older").then((res) => {▼
▲ this.page = res
▲ this.content = this.page[0].revisions[0].slots.main.content;
▲ this.isHatted = this.content.includes("'''No further edits should be made to this page'''.")
▲ this.isApproved = this.content.includes("[[File:Symbol voting keep.svg|16px]]") || this.content.includes("[[File:Symbol confirmed.svg|16px]]") || this.content.match(/\|.*?status.*?=.*?y/g) != undefined
▲ this.alphanumericals="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
this.loadHooks();▼
this.loadFiles();▼
});▼
}
static async create(title){
title = title.replaceAll("_"," "); //MediaWiki stuff
let nom = new Nomination(title,page)
return nom
}
hasBeenEditedByUser(){
Line 38 ⟶ 43:
}
hat(type,prep="",topmessage=""){
var splittext = this.content.split("\n");
splittext[0] = "{{subst:DYKsubpage";
splittext[2] = "|passed="+type;
//console.log(topmessage)
if (
splittext.splice(4,0,topmessage);
}
this.content = splittext.join("\n");
return this.content
}
clean() {
}
comment() {
}
unhat(prep){
console.log(this.page[0])
for (let revision of this.page[0].revisions){
let revtext = revision.slots.main.content;
if (revtext.includes("{{DYKsubpage")){
this.content = revtext;
break;
}
}
async retransclude(){
let res = await get_pages("Template talk:Did you know","user|content",null,"older");
let dykn = res[0].revisions[0].slots.main.content.split("\n");
for (var i=0; i<dykn.length; i++){
if (dykn[i].includes("===Articles created/expanded on")){
dykn.splice(i+2,0,`{{${this.title}}}`)
dykn = dykn.join("\n")
let params = {
action: 'edit',
title: "Template talk:Did you know",
summary: `retranscluding [[${this.title}]]`+tag,
text: dykn,
format: 'json'
}
return api.postWithToken( 'csrf', params );
}
}
}
loadHooks(){
this.hooks = []
//console.log(this.content)
let credits = this.content.match(/\* \{\{DYK(make|nom).*?\}\}/g);
if (credits
credits =
}
let hooktext = this.content.match(/('''ALT.+?)?(\.\.\..*?)(?:{{-\?}}|\?)/g);
//console.log(hooktext)
let u=0;
for (let hook of hooktext){
Line 71 ⟶ 113:
u++;
}
for (let c=0; c<credits.length; c++){
hook.credits.push(new Credit(credits[c]));
}
this.hooks.push(hook);
}
}
Line 88 ⟶ 134:
let res = []
for (let hook of this.hooks){
res.push({type: 'option', label: hook.morebits(), value:
}
return res
Line 97 ⟶ 143:
action: 'edit',
title: this.title,
summary: summary+tag,
text: this.content,
format: 'json'
|