User:Theleekycauldron/Scripts/PSHAW/dependencies/Prep.js: Difference between revisions

Content deleted Content added
ce
Restored revision 1303816471 by Theleekycauldron (talk): Test over
 
(41 intermediate revisions by the same user not shown)
Line 12:
copies or substantial portions of the Software.
*/
 
importScript('User:Theleekycauldron/Scripts/PSHAW/dependencies/Hook.js');
importScript('User:Theleekycauldron/Scripts/PSHAW/dependencies/Credit.js');
importScript('User:Theleekycauldron/Scripts/PSHAW/dependencies/File.js');
 
class Prep {
constructor(title,page){
this.title = title; //MediaWiki stuff
this.page = respage
this.content = this.page[0].revisions[0].slots.main.content;
}
static async initializecreate(title){
title = title.replaceAll("_"," "); //MediaWiki stuff
let page = await get_pages(this.title,"user|content",null,"older").then((res) => {;
this.page = res
let prep = new Prep(title,page)
this.content = this.page[0].revisions[0].slots.main.content;
if (!(title.includes("/Queue/") && prep.content.length<200)){
this.loadHooks();
thisprep.loadFilesloadHooks();
prep.loadFiles();
})
prep.loadDYKbotdo();
}
return prep
}
Line 39 ⟶ 37:
let creditstext = splittext.slice(ip[2],ip[3]);
this.hooks = []
for (let c in creditstext){
creditstext[c] = new Credit(creditstext[c]);
creditstext[c].used = creditstext[c].user == "Editor";
})
for (var h=0; h<hooktext.length; h++){
let hook = new Hook(h,hooktext[h].slice(2),[])
this.hooks.push(hook)
if (hook.articles.length > 0){
console.log( data hook);
for (c in creditstext){
for (let credit =of new Credit(creditstext[c]);{
if (credit.article in hook.articlesused){
continue;
}
console.log(credit)
console.log(hook.articles.includes(credit.article))
if (hook.articles.includes(credit.article)){
console.log("match!")
hook.credits.push(credit)
if (!credit.make){
credit.subpage = hook.credits[0].subpage
}
credit.used = true;
}
}
} else {
hook.credits.push(new Credit("* {{DYKmake|Example|Editor|subpage=}}nullmake"))
if (h==hooktext.length-1){
hook.credits.push(new Credit("* {{DYKnom|Example|Nominator}}nullnom"))
}
} );
}
this.lost_credits = []
for (let credit of creditstext){
if (!credit.used){
this.lost_credits.push(credit)
}
}
Line 61 ⟶ 79:
let filetext = this.content.match(/\{\{main page image\/DYK.*?}}/g);
this.file = new File(filetext[0])
}
loadDYKbotdo(){
let botdotext = this.content.match(/\{\{DYKbotdo\|(.*)\}\}/)
if (botdotext != null) {
this.botdo = botdotext[1]
} else {
if (this.title.includes("/Queue/")){
this.botdo = "~~~"
} else {
this.botdo = null
}
}
}
morebits(){
let res = []
for (let hook ofi=0; i<this.hooks.length; i++){
res.push({ type: 'option', label: hookthis.hooks[i].morebits(), value: JSON.stringify(this.hooks[i])})
}
if (this.isEmpty()){
Line 72 ⟶ 103:
}
return res
}
lostcredits(){
let res = ''
for (let credit of this.lost_credits){
res += ' <b>Warning</b>: Credit for \"[[' + credit.article + ']]\" in prep set unrecognized. That usually means the article or hook has been moved. The credit <b>will be removed</b> if it is not cured.\n\n';
}
return res.substring(0, res.length - 2)
}
Line 87 ⟶ 126:
assemble(){
let res = []
res.push(`${this.title.includes("Queue")?"{{DYKbotdo|"+this.botdo+"}}":""}
res.push(`<noinclude>{{Did you know/Clear/header}}
==Hooks==
</noinclude>{{DYK bottom prep notice}}
<!--Hooks-->`)
res.push(this.file.mplmpi()+"<!--See [[Template:Main page image/DYK]] for other parameters-->")
for (let hook of this.hooks){
res.push("* "+hook.content)
}
Line 116 ⟶ 156:
*********************************************************
-->`)
for (let hook of this.hooks){
for (let credit of hook.credits){
res.push(credit.content)
}
}
for (let credit of this.lost_credits){
res.push(credit.content)
}
res.push(`</div>
Line 131 ⟶ 174:
action: 'edit',
title: this.title,
summary: summary+tag,
text: this.content,
format: 'json'
}
return api.postWithToken( 'csrf', params ).done( function ( data ) {;
console.log( data );
} );
}