// Remove the default content
$('#mw-content-text > p').remove();
$('#firstHeading').text('Create Fellow Page Public Profile - 2020');
// Check user login
// Creating API Object
requestAPI = new mw.Api();
catMemberParam = {
"action": "query",
"format": "json",
"list": "categorymembers",
"cmtitle": "Category:2020 cohort",
"cmprop": "title",
"cmtype": "subcat",
"cmlimit": "500"
};
requestAPI.getgetSchoolItem( catMemberParam, { async: false } ).done( function(resDataschoolDataResp ){
schoolOptions = [];
members schoolCatMembers = resDataschoolDataResp.query.categorymembers;
// Creating MenuItems array from Category Members:School Categories's Member membersschoolCatMembers.forEach( function(mem){
schoolOptions.push(
new OO.ui.MenuOptionWidget( {
});
// Create widgetsAPI param to get Category:2020 cohort members var bio catMemberParam = new OO.ui.MultilineTextInputWidget( { placeholder "action": 'Bio'"query", autosize "format": true"json", rows "list": 10 } )"categorymembers", achievements = new OO.ui.MultilineTextInputWidget( { placeholder "cmtitle": 'Achievements', autosize"Category: true2020 cohort", rows "cmprop": 10 } )"title", social = new OO.ui.MultilineTextInputWidget( { placeholder "cmtype": 'Social media profiles'"subcat", autosize "cmlimit": true, "500" rows: 10 } ),; name = new OO.ui.TextInputWidget( { placeholder: 'Name' } ), schoolAndcohort = new OO requestAPI.ui.DropdownWidgetget( { label: 'Select school'catMemberParam, menu: { itemsasync: schoolOptions } false } ), image = new OO.ui.TextInputWidgetdone( { placeholder: 'https://universityinnovation.org/wiki/File:ABCD' } ), major = new OO.ui.TextInputWidgetfunction( { placeholder: 'Majoring in' } resData), country = new OO.ui.TextInputWidget( { placeholder: 'Country' } ), createBtn schoolAndCohortOptions = new OO.ui.ButtonWidget( { label: 'Create Page', flags: [ 'progressive', 'primary' ]; } ), cancelBtn members = new OOresData.uiquery.ButtonWidget( {categorymembers; label: 'Cancel', flags: [ 'primary', 'destructive' ], href: mw.config.get( 'wgServer' ) } ),// Creating MenuItems array from Category Members label1 = $members.forEach('<p>').textfunction('Name:'mem){ schoolAndCohortOptions.csspush('font-weight','bold' ), label2 = $('<p>') new OO.text('School (Cohort):')ui.cssMenuOptionWidget('font-weight','bold' ),{ uploadLink = $("<a>").attr("href", "https data://universityinnovationmem.org/wiki/Special:Upload")title.attrreplace( "targetCategory:", "_blank" ).text("Upload"), label3 = $('<p>').html('Image page link label: (' + uploadLinkmem.prop('outerHTML') + ' if did not upload yet!)' )title.cssreplace('font-weight','bold' ), label4 = $('<p>').text('Majoring in"Category:').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, 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
schoolAndcohortResp = '';
schoolAndcohort.getMenu().on('select', function(data){
schoolAndcohortResp = data.getData();
});
// 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 functionCreate widgets ifvar bio = new OO.ui.MultilineTextInputWidget( nameResp !{ placeholder: 'Bio', autosize: true, rows: 10 } ), achievements =new OO.ui.MultilineTextInputWidget( { placeholder: 'Achievements', autosize: true, rows: 10 } ), social = "" && schoolAndcohortResp !== "" new OO.ui.MultilineTextInputWidget( { placeholder: 'Social media profiles', autosize: true, rows: 10 } ), && majorResp ! name == "" && countryResp !== "" ) new OO.ui.TextInputWidget( { placeholder: 'Name' wikiContent } ), school = new OO.ui.DropdownWidget( { label: 'Select school', menu: {| class items: schoolOptions } } ), schoolAndcohort ="wikitable" style="bordernew OO.ui.DropdownWidget( { label: 5px ridge grey; float:right;" \n|-\n|';Select school and Cohort', try menu: { items: schoolAndCohortOptions wikiContent +} } ), image = "[[Filenew OO.ui.TextInputWidget( { placeholder: 'https:"+ //universityinnovation.org/wiki/File:ABCD' } ), major = new OO.ui.TextInputWidget({ placeholder: 'Majoring in' } ), country = new OO.+\ui.\wTextInputWidget( {3 placeholder: 'Country' })/i, createBtn = new OO.ui.execButtonWidget(imageResp){ label: 'Create Page', flags: [1'progressive', 'primary' ] +"|300px]]\n"; }), catchcancelBtn = new OO.ui.ButtonWidget(err) { wikiContent += " label: 'Cancel', flags: [[File'primary', 'destructive' ], href:OOjs UI icon userAvatar mw.config.svg|300px]]\n";get( 'wgServer' ) }), label1 = $('<p>').text('Name:').css('font-weight','bold' ), wikiContent +label2 = $('<p>').text('School:').css('font-weight','bold' ), label22 = "|$('<p>').text('School (Cohort):').css('font-\n|\n";weight','bold' ), wikiContent +uploadLink = $(";Name<a>").attr("href", "https://universityinnovation.org/wiki/Special: Upload").attr( "target", "_blank" + nameResp + ).text("\nUpload";), wikiContent +label3 = ";School $(Cohort'<p>').html('Image page link: " (' + schoolAndcohortResp uploadLink.prop('outerHTML') + "\n";' if did not upload yet!)' ).css('font-weight','bold' ), wikiContent +label4 = ";$('<p>').text('Majoring in: " + majorResp + "\n";').css('font-weight','bold' ), wikiContent +label5 = ";$('<p>').text('Country: " + countryResp + "\n";').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' ), wikiContent +divMainBox = ";Email$('<div />').css( { 'box-shadow': '0 .5rem 1rem rgba(0, 0, 0, .15)', 'border': '1px solid', 'padding': '1rem', 'margin-bottom': [[Special'3rem', 'border-radius':EmailUser'.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' ).configappend( divMainBox ); // Event handler for Select cohort schoolResp = ''; schoolAndcohortResp = ''; school.getMenu().on('select', function(data){ schoolResp = data.getgetData("wgUserName") + "]]\n"; }); schoolAndcohort.getMenu().on('select', function(data){ wikiContent +schoolAndcohortResp = "|data.getData(); }\n"); // Create button click event handler createBtn.on( 'click', function() { wikiContent +nameResp = "name.getValue().trim(), imageResp =image.getValue().trim(), majorResp =Biomajor.getValue().trim(); countryResp =country.getValue().trim(), bioResp =\n" + bioResp + "\n"bio.getValue().trim(); wikiContent +achievementsResp = "achievements.getValue().trim(), socialResp ==Achievements==\n" + achievementsResp + "\n"social.getValue().trim(); wikiContent +// Check whether the all fields are enough to run the function if( nameResp !== "" && schoolAndcohortResp !==Social media profiles"" && schoolResp !==\n" + socialResp + "\n"; wikiContent + && majorResp !== "[[Category:" + schoolAndcohortResp + "]]\n"; wikiContent +&& countryResp !== "[[Category:Student Contributors]]\n";) {
pageTitle wikiContent = '{| class="wikitable" style= "Fellowborder:" + nameResp5px ridge grey; requestAPI.get( { formatversion: 2, actionfloat: 'query', titles: pageTitle, redirects: true }, { async: false } ).then( function ( response ) { var page = response.query.pages[ 0 ]right; if ( page.missing " \n|-\n| page.invalid ) { doEdit( pageTitle, wikiContent )'; } else try { requestAPI.get( { formatversion: 2, action: 'query', titles: pageTitle wikiContent + = " ([[File:" + /\d{4}/.execFile:( schoolAndcohortResp.replace("Category:", "") ) + ")", redirects: true }, { async: false } )\.then( function ( response ) { var page = response.query.pages[ 0 ]; if ( page.missing || page.invalid ) { doEdit( pageTitle + " (" + /\dw{43}/.exec( schoolAndcohortResp.replace("Category:", "") ) + ")", wikiContent ); } else { pageTitle = pageTitle + " (" + /(^.+)\(/i.exec(schoolAndcohortResp.replace("Category:", "")imageResp)[1].trim() + ", " + /|300px]]\d{4}/.exec( schoolAndcohortResp.replace("Category:", "n") ) + ")"; doEdit( pageTitle, wikiContent ); } });
}
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; 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){
requestAPI.postWithToken( 'csrf', editParams, { async: false } ).done( function ( res ) {
if( res.edit.result === "Success"){
var editUserpage = { action: 'edit', title: 'User:' + mw.config.get("wgUserName"), text: '#REDIRECT [[' + title + ']]', summary: "Redirect to Fellow Page", format: 'json' }; requestAPI.postWithToken( 'csrf', editUserpage, { async: false } ).done( function ( res ) { mw.notify( title + " page has created :)and userpage redirected."); window.location.replace( mw.config.get( 'wgServer' ) + "/wiki/" + title ); }).fail( function(){ mw.notify( title + " page has created :) but userpage redirecction failed."); window.location.replace( mw.config.get( 'wgServer' ) + "/wiki/" + title ); });
} else{
mw.notify( "Something went worng :(" );
}
if ( mw.config.get('wgCanonicalSpecialPageName') === 'Blankpage' && mw.config.get('wgTitle').split('/', 2)[1] === 'CreateFellow2020CreatePublicProfile' ) {
mw.loader.using( ['oojs-ui-core', 'oojs-ui-widgets', 'mediawiki.api', 'mediawiki.notify'], init );
}