Open main menu

Changes

MediaWiki:Gadget-2020Cohort.js

1,042 bytes added, 3 months ago
Updating the profile page creation for 2025
// 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').append("You have to login first.");
// 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:", ""),
} ),
schoolAndcohort = new OO.ui.DropdownWidget( {
label: 'Select schooland Cohort',
menu: {
items: schoolOptions schoolAndCohortOptions
}
} ),
// 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();
});
// Check whether the all fields are enough to run the function
if( nameResp !== "" && schoolAndcohortResp !== "" && schoolResp !== ""
&& majorResp !== "" && countryResp !== "" ) {
}
catch(err) {
wikiContent += "[[File:OalogoOOjs UI icon userAvatar.jpgsvg|300px]]\n";
}
wikiContent += "|-\n|\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;
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 );
}