Open main menu

Changes

MediaWiki:Gadget-2020Cohort.js

2,158 bytes added, 3 months ago
Updating the profile page creation for 2025
// <nowiki>
$( document ).ready( function (){
// Remove the default content
$('#mw-content-text > p').remove();
if( mw.config.get("skin") === "minerva" ){ $('#section_0').text('Create Public Profile - 2025'); } else { $('#firstHeading').text('Create Fellow Page Public Profile - 20202025'); }  // Check user login 2
if( mw.config.get("wgUserId") === null){
$('#mw-content-text > p').append("You have to login first.");
return;
}
// Wait Message
var waitMsg = $('<p>').text('Wait, Page is loading.....').css('font-weight','bold' );
$('#mw-content-text').append( waitMsg );
// Creating API Object
requestAPI = new mw.Api();
// API param to get Category:2025 cohort members
catMemberParam = {
"action": "query",
"format": "json",
"list": "categorymembers",
"cmtitle": "Category:2020 2025 cohort",
"cmprop": "title",
"cmtype": "subcat",
requestAPI.get( catMemberParam, { async: false } ).done( function(resData){
schoolOptions schoolAndCohortOptions = [];
members = resData.query.categorymembers;
// Creating MenuItems array from Category Members
members.forEach( function(mem){
schoolOptionsschoolAndCohortOptions.push(
new OO.ui.MenuOptionWidget( {
data: mem.title.replace("Category:", ""), label: mem.title.replace("Category:", "")
} )
);
} ),
schoolAndcohort = new OO.ui.DropdownWidget( {
label: 'Select schooland Cohort',
menu: {
items: schoolOptions schoolAndCohortOptions
}
} ),
image = new OO.ui.TextInputWidget( {
placeholder: 'https://universityinnovation.org/wiki/File:ABCD'
} ),
major = new OO.ui.TextInputWidget( {
href: mw.config.get( 'wgServer' )
} ),
label2 label1 = $('<p>').text('Name:').css('font-weight','bold' ), label3 label2 = $('<p>').text('School (Cohort):').css('font-weight','bold' ), uploadLink = $("<a>").attr("href", "https://universityinnovation.org/wiki/Special:Upload").attr( "target", "_blank" ).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' ),
divMainBox.append(
label1, name.$element, label2, nameschoolAndcohort.$element, label3, schoolAndcohortimage.$element,
label4, major.$element,
label5, country.$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;
schoolResp = patternReg.exec( schoolAndcohortResp )[1].trim();
});
createBtn.on( 'click', function() {
nameResp = name.getValue().trim(),
imageResp = image.getValue().trim(),
majorResp = major.getValue().trim();
countryResp = country.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:Oalogo"+ /File:(.+\.\w{3})/i.exec(imageResp)[1] +"|300px]]\n"; } catch(err) { wikiContent += "[[File:OOjs UI icon userAvatar.jpgsvg|300px]]\n"; } wikiContent += "|-\n|\n";
wikiContent += ";Name: " + nameResp + "\n";
wikiContent += ";School (Cohort): " + schoolAndcohortResp + "\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;
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(aschoolAndcohortResp.replace("Category:", ""))[1].trim() + ", " + /\d{4}/.exec( schoolAndcohortResp .replace("Category:", "") ) + ")";
doEdit( pageTitle, wikiContent );
}
title: title,
text: wikiContent,
summary: "Created Fellow Page - 20202025",
format: 'json'
};
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 );
}
});
 
// </nowiki>