Changes

Jump to navigation Jump to search

MediaWiki:Gadget-2020Cohort.js

1,336 bytes removed, 5 years ago
no edit summary
requestAPI = new mw.Api();
getSchoolItem().done( function( schoolDataResp )// API param to get Category:2020 cohort members catMemberParam = { schoolOptions = [];"action": "query", "format": "json", schoolCatMembers = schoolDataResp.query."list": "categorymembers", "cmtitle": "Category:2020 cohort", "cmprop": "title", "cmtype": "subcat", "cmlimit": "500" };
requestAPI.get( catMemberParam, { async: false } ).done( function(resData){ schoolAndCohortOptions = []; members = resData.query.categorymembers;  // Creating MenuItems array from Category:School Categories's MemberMembers schoolCatMembersmembers.forEach( function(mem){ schoolOptionsschoolAndCohortOptions.push(
new OO.ui.MenuOptionWidget( {
data: mem.title.replace("Category:", ""),
});
// API param to Create widgets var bio = new OO.ui.MultilineTextInputWidget( { placeholder: 'Bio', autosize: true, rows: 10 } ), achievements = new OO.ui.MultilineTextInputWidget( { placeholder: 'Achievements', autosize: true, rows: 10 } ), social = new OO.ui.MultilineTextInputWidget( { placeholder: 'Social media profiles', autosize: true, rows: 10 } ), name = new OO.ui.TextInputWidget( { placeholder: 'Name' } ), schoolAndcohort = new OO.ui.DropdownWidget( { label: 'Select school and Cohort', menu: { items: schoolAndCohortOptions } } ), image = new OO.ui.TextInputWidget( { placeholder: 'https://universityinnovation.org/wiki/File:ABCD' } ), major = new OO.ui.TextInputWidget( { placeholder: 'Majoring in' } ), country = new OO.ui.TextInputWidget( { placeholder: 'Country' } ), createBtn = new OO.ui.ButtonWidget( { label: 'Create Page', flags: [ 'progressive', 'primary' ] } ), cancelBtn = new OO.ui.ButtonWidget( { label: 'Cancel', flags: [ 'primary', 'destructive' ], href: mw.config.get Category( 'wgServer' ) } ), label1 = $('<p>').text('Name:2020 cohort members ').css('font-weight','bold' ), catMemberParam label2 = {$('<p>').text('School (Cohort):').css('font-weight','bold' ), uploadLink = $("action<a>").attr("href", "https: //universityinnovation.org/wiki/Special:Upload"query).attr( "target", "format_blank": ).text("jsonUpload"), "list"label3 = $('<p>').html('Image page link: (' + uploadLink.prop('outerHTML') + ' if did not upload yet!)' ).css('font-weight','bold' ), label4 = $('<p>').text('Majoring in: "categorymembers"').css('font-weight','bold' ), "cmtitle"label5 = $('<p>').text('Country: "Category').css('font-weight','bold' ), label6 = $('<p>').text('Bio:2020 cohort"').css('font-weight','bold' ), "cmprop"label7 = $('<p>').text('Achievements: "title"').css('font-weight','bold' ), "cmtype"label8 = $('<p>').text('Social media profiles: "subcat"').css('font-weight','bold' ), "cmlimit"divMainBox = $('<div />').css( { 'box-shadow': '0 .5rem 1rem rgba(0, 0, 0, .15)', 'border': '1px solid', 'padding': '1rem', 'margin-bottom': '3rem', 'border-radius': "500"'.5rem' });  divMainBox.append( label1, name.$element, label2, schoolAndcohort.$element, label3, image.$element, label4, major.$element, label5, country.$element, label6, bio.$element, label7, achievements.$element, label8, social.$element, '<br/>', createBtn.$element, cancelBtn.$element );  waitMsg.remove(); $( '#mw-content-text' ).append( divMainBox );  // Event handler for Select cohort schoolResp = ''; schoolAndcohortResp = ''; schoolAndcohort.getMenu().on('select', function(data){ schoolAndcohortResp = data.getData(); patternReg = /(.*)\(\d{4}/gim console.log( patternReg.exec( schoolAndcohortResp ) ); }); // Create button click event handler createBtn.on( 'click', function() { nameResp = name.getValue().trim(), imageResp = image.getValue().trim(), majorResp = major.getValue().trim(); countryResp = country.getValue().trim(), bioResp = bio.getValue().trim(); achievementsResp = achievements.getValue().trim(), socialResp = social.getValue().trim();
requestAPI.get // Check whether the all fields are enough to run the function if( catMemberParam, nameResp !== "" && schoolAndcohortResp !== "" && schoolResp !== "" && majorResp !== "" && countryResp !== "" ) { async  wikiContent = '{| class="wikitable" style="border: 5px ridge grey; float:right;" \n|-\n|'; try { wikiContent += "[[File: false "+ /File:(.+\.\w{3} )/i.doneexec( functionimageResp)[1] +"|300px]]\n"; } catch(resDataerr){ schoolAndCohortOptions wikiContent += "[[File:OOjs UI icon userAvatar.svg|300px]]\n"; members } wikiContent += resData.query.categorymembers"|-\n|\n"; wikiContent += ";Name: " + nameResp + "\n"; // Creating MenuItems array from Category Members members.forEach wikiContent += ";School ( function(memCohort){: " + schoolAndcohortResp + "\n"; schoolAndCohortOptions.push(wikiContent += ";Majoring in: " + majorResp + "\n"; new OO.ui.MenuOptionWidget( { wikiContent += ";Country: " + countryResp + "\n"; data wikiContent += ";Email: mem[[Special:EmailUser/" + mw.titleconfig.replaceget("Category:wgUserName") + "]]\n"; wikiContent += "|}\n"; wikiContent += "\n==Bio==\n" + bioResp + "\n"; wikiContent += "\n==Achievements==\n" + achievementsResp + "\n"; wikiContent += "\n==Social media profiles==\n", + socialResp + "\n"),; label: mem.title.replace( wikiContent += "\n[[Category:", + schoolAndcohortResp + "]]\n") } ); )wikiContent += "[[Category:Student Contributors]]\n"; wikiContent += "\n{{CatTree|" + schoolResp + "}})\n";
// Create widgets pageTitle = "Fellow:" + nameResp; var bio = new OO requestAPI.ui.MultilineTextInputWidgetget( { placeholder formatversion: 2, action: 'Bioquery', autosize titles: truepageTitle, rows redirects: 10true }, { async: false } ),.then( function ( response ) { achievements var page = new OOresponse.query.pages[ 0 ]; if ( page.missing || page.uiinvalid ) { doEdit( pageTitle, wikiContent ); } else { requestAPI.MultilineTextInputWidgetget( { placeholder formatversion: 'Achievements'2, autosize action: true'query', rows titles: 10 pageTitle + " (" + /\d{4} ), social = new OO/.uiexec( schoolAndcohortResp.MultilineTextInputWidgetreplace( { placeholder"Category: 'Social media profiles'", "") ) + ")", autosize redirects: true }, rows{ async: 10 false } ),.then( function ( response ) { name var page = new OOresponse.uiquery.TextInputWidgetpages[ 0 ]; if ( page.missing || page.invalid ) { placeholder doEdit( pageTitle + " (" + /\d{4}/.exec( schoolAndcohortResp.replace("Category: 'Name'", "") ) + ")", wikiContent ); } ),else { school pageTitle = new OOpageTitle + " (" + /(^.+)\(/.uiexec(schoolAndcohortResp.DropdownWidgetreplace( { label"Category: 'Select school'", ""))[1].trim() + ", menu: " + /\d{ items: schoolOptions 4} } ), schoolAndcohort = new OO/.uiexec( schoolAndcohortResp.DropdownWidgetreplace( { "Category:", "") ) + ")"; label: 'Select school and Cohort' doEdit( pageTitle,wikiContent ); menu: { } items: schoolAndCohortOptions });
}
} ),; image = new OO.ui.TextInputWidget( { placeholder: 'https://universityinnovation.org/wiki/File:ABCD' } ), major = new OO.ui.TextInputWidget( else { placeholder: 'Majoring in' } ), country = new OO.ui.TextInputWidget( { placeholder: 'Country' } ), createBtn = new OO.ui.ButtonWidget( { label: 'Create Page', flags: [ 'progressive', 'primary' ] } ), cancelBtn = new OO.ui.ButtonWidget( { label: 'Cancel', flags: [ 'primary', 'destructive' ], href: mw.config.getnotify( 'wgServer' ) } ), label1 = $('<p>')."Some fields have no text('Name:').css('font-weight','bold' ), label2 = $('<p>').text('School:').css('font-weight','bold' ), label22 = $('<p>').text('School (Cohort):').css('font-weight','bold' ), uploadLink = $("<a>").attr("href", "https://universityinnovation.org/wiki/Special:Upload").attr( "target", "_blank" )Please fill them.text("Upload"), label3 = $('<p>').html('Image page link: (' + uploadLink.prop('outerHTML') + ' if did not upload yet!)' ).css('font-weight','bold' ), label4 = $('<p>').text('Majoring in:').css('font-weight','bold' ), label5 = $('<p>').text('Country:').css('font-weight','bold' ), label6 = $('<p>').text('Bio:').css('font-weight','bold' ), label7 = $('<p>').text('Achievements:').css('font-weight','bold' ), label8 = $('<p>').text('Social media profiles:').css('font-weight','bold' ), divMainBox = $('<div />').css( { 'box-shadow': '0 .5rem 1rem rgba(0, 0, 0, .15)', 'border': '1px solid', 'padding': '1rem', 'margin-bottom': '3rem', 'border-radius': '.5rem' }); divMainBox.append( label1, name.$element, label2, school.$element, label22, schoolAndcohort.$element, label3, image.$element, label4, major.$element, label5, country.$element, label6, bio.$element, label7, achievements.$element, label8, social.$element, '<br/>', createBtn.$element, cancelBtn.$element ); waitMsg.remove(); $( '#mw-content-text' ).append( divMainBox ); // Event handler for Select cohort schoolResp = ''; schoolAndcohortResp = ''; school.getMenu().on('select', function(data){ schoolResp = data.getData(); }); schoolAndcohort.getMenu().on('select', function(data){ schoolAndcohortResp = data.getData()return; }); // Create button click event handler createBtn.on( 'click', function() { nameResp = name.getValue().trim(), imageResp = image.getValue().trim(), majorResp = major.getValue().trim(); countryResp = country.getValue().trim(), bioResp = bio.getValue().trim(); achievementsResp = achievements.getValue().trim(), socialResp = social.getValue().trim(); // Check whether the all fields are enough to run the function if( nameResp !== "" && schoolAndcohortResp !== "" && schoolResp !== "" && majorResp !== "" && countryResp !== "" ) {
wikiContent = '{| class="wikitable" style="border: 5px ridge grey; float:right;" \n|-\n|'; try { wikiContent += "[[File:"+ /File:(.+\.\w{3})/i.exec(imageResp)[1] +"|300px]]\n"; } catch(err) { wikiContent += "[[File:OOjs UI icon userAvatar.svg|300px]]\n"; } wikiContent += "|-\n|\n"; wikiContent += ";Name: " + nameResp + "\n"; wikiContent += ";School (Cohort): " + schoolAndcohortResp + "\n"; wikiContent += ";Majoring in: " + majorResp + "\n"; wikiContent += ";Country: " + countryResp + "\n"; wikiContent += ";Email: [[Special:EmailUser/" + mw.config.get("wgUserName") + "]]\n"; wikiContent += "|}\n"; wikiContent += "\n==Bio==\n" + bioResp + "\n"; wikiContent += "\n==Achievements==\n" + achievementsResp + "\n"; wikiContent += "\n==Social media profiles==\n" + socialResp + "\n"; wikiContent += "\n[[Category:" + schoolAndcohortResp + "]]\n"; wikiContent += "[[Category:Student Contributors]]\n"; wikiContent += "\n{{CatTree|" + schoolResp + "}}\n"; pageTitle = "Fellow:" + nameResp; requestAPI.get( { formatversion: 2, action: 'query', titles: pageTitle, redirects: true }, { async: false } ).then( function ( response ) { var page = response.query.pages[ 0 ]; if ( page.missing || page.invalid ) { doEdit( pageTitle, wikiContent ); } else { requestAPI.get( { formatversion: 2, action: 'query', titles: pageTitle + " (" + /\d{4}/.exec( schoolAndcohortResp.replace("Category:", "") ) + ")", redirects: true }, { async: false } ).then( function ( response ) { var page = response.query.pages[ 0 ]; if ( page.missing || page.invalid ) { doEdit( pageTitle + " (" + /\d{4}/.exec( schoolAndcohortResp.replace("Category:", "") ) + ")", wikiContent ); } else { pageTitle = pageTitle + " (" + /(^.+)\(/.exec(schoolAndcohortResp.replace("Category:", ""))[1].trim() + ", " + /\d{4}/.exec( schoolAndcohortResp.replace("Category:", "") ) + ")"; doEdit( pageTitle, wikiContent ); } }); } } ); } else { mw.notify( "Some fields have no text :( Please fill them." ); return; } }); }).fail( function(){ $( '#mw-content-text' ).append( "Something went wront. Please report it to Jay Prakash (User:Jayprakash)." ); });
}).fail( function(){
$( '#mw-content-text' ).append( "Something went wront. Please report it to Jay Prakash (User:Jayprakash)." );
});
function getSchoolItem(){
catMemberParam = {
"action": "query",
"format": "json",
"list": "categorymembers",
"cmtitle": "Category:Schools Categories",
"cmprop": "title",
"cmtype": "subcat",
"cmlimit": "500"
};
return requestAPI.get( catMemberParam, { async: false } );
}
function doEdit(title, wikiContent){

Navigation menu