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

Content deleted Content added
update
 
Restored revision 1303816471 by Theleekycauldron (talk): Test over
 
(62 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');
 
let api=new mw.Api();
class Prep {
constructor(title,page){
this.title = title; //MediaWiki stuff
this.page = respage
get_pages(mw.config.get(this.title),"user|content",null,"older").then((res) => {
this.content = this.page[0].revisions[0].slots.main.content;
this.page = res
}
this.content = this.page[0].revisions[0].slots.main.content;
});
static async create(title){
this.loadHooks()
title = title.replaceAll("_"," "); //MediaWiki stuff
this.loadFile()
let page = await get_pages(mw.config.get(this.title),"user|content",null,"older").then((res) => {;
let prep = new Prep(title,page)
if (!(title.includes("/Queue/") && prep.content.length<200)){
this prep.loadHooks();
prep.loadFiles();
prep.loadDYKbotdo();
});
return prep
}
loadHooks(){
hooktextlet splittext = this.content.split("\n");
let ip = [this.contentsplittext.indexOf("<!--Hooks-->")+2,this.contentsplittext.indexOf("<!--HooksEnd-->"),this.contentsplittext.indexOf("-->")+21,this.contentsplittext.indexOf("</div>")]; //important split points
let hooktext = this.contentsplittext.slice(ip[0],ip[1]);
let creditstext = this.contentsplittext.slice(ip[2],ip[3]);
this.hooks = []
for (hlet c in hooktextcreditstext){
hookcreditstext[c] = new HookCredit(h,hooktext[h].slice(2),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){
creditfor =(let newcredit of 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 (clet incredit of creditstext){
if (!credit.used){
this.lost_credits.push(credit)
}
}
Line 55 ⟶ 77:
loadFiles(){
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 (hooklet ofi=0; i<this.hooks.length; i++){
res.push({ type: 'option', label: hookthis.id+": "+hookhooks[i].morebits(), value: JSON.stringify(this.hooks[i])})
}
if (this.isEmpty()){
Line 68 ⟶ 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 82 ⟶ 125:
assemble(){
let res = []
res.push(`${this.title.includes("Queue")?"{{DYKbotdo|"+this.botdo+"}}":""}
res.push(`<noinclude>{{Did you know/Clear/header}}
</noinclude>{{DYKDid bottomyou prep noticeknow/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 111 ⟶ 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 126 ⟶ 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 );
} );
}