Open main menu

Difference between revisions of "MediaWiki:Gadget-2020Cohort.js"

(Updating the profile page creation for 2025)
 
(9 intermediate revisions by 2 users not shown)
Line 5: Line 5:
 
// Remove the default content
 
// Remove the default content
 
$('#mw-content-text > p').remove();
 
$('#mw-content-text > p').remove();
     $('#firstHeading').text('Create Public Profile - 2020');
+
     if( mw.config.get("skin") === "minerva" ){
 +
    $('#section_0').text('Create Public Profile - 2025');
 +
    } else {
 +
                $('#firstHeading').text('Create Public Profile - 2025');
 +
        }
  
// Check user login 
+
// Check user login  2
 
     if( mw.config.get("wgUserId") === null){
 
     if( mw.config.get("wgUserId") === null){
 
     $('#mw-content-text').append("You have to login first.");
 
     $('#mw-content-text').append("You have to login first.");
Line 20: Line 24:
 
     requestAPI = new mw.Api();
 
     requestAPI = new mw.Api();
  
getSchoolItem().done( function( schoolDataResp ){
+
// API param to get Category:2025 cohort members
schoolOptions = [];
+
    catMemberParam = {
schoolCatMembers = schoolDataResp.query.categorymembers;
+
"action": "query",
 +
"format": "json",
 +
"list": "categorymembers",
 +
"cmtitle": "Category:2025 cohort",
 +
"cmprop": "title",
 +
"cmtype": "subcat",
 +
"cmlimit": "500"
 +
};
  
// Creating MenuItems array from Category:School Categories's Member
+
requestAPI.get( catMemberParam, { async: false }  ).done( function(resData){
schoolCatMembers.forEach( function(mem){
+
schoolAndCohortOptions = [];
schoolOptions.push(
+
members = resData.query.categorymembers;
 +
 
 +
// Creating MenuItems array from Category Members
 +
members.forEach( function(mem){
 +
schoolAndCohortOptions.push(
 
new OO.ui.MenuOptionWidget( {
 
new OO.ui.MenuOptionWidget( {
 
data: mem.title.replace("Category:", ""),
 
data: mem.title.replace("Category:", ""),
Line 34: Line 49:
 
});
 
});
  
// API param to get Category:2020 cohort members
+
// Create widgets
    catMemberParam = {
+
var bio = new OO.ui.MultilineTextInputWidget( {
"action": "query",
+
            placeholder: 'Bio',
"format": "json",
+
            autosize: true,
"list": "categorymembers",
+
            rows: 10
"cmtitle": "Category:2020 cohort",
+
        } ),
"cmprop": "title",
+
        achievements = new OO.ui.MultilineTextInputWidget( {
"cmtype": "subcat",
+
            placeholder: 'Achievements',
"cmlimit": "500"
+
            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( 'wgServer' )
 +
} ),
 +
label1 = $('<p>').text('Name:').css('font-weight','bold' ),
 +
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' ),
 +
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
 +
schoolResp = '';
 +
schoolAndcohortResp = '';
 +
schoolAndcohort.getMenu().on('select', function(data){
 +
schoolAndcohortResp = data.getData();
 +
patternReg = /(.*)\(\d{4}/gim;
 +
schoolResp = patternReg.exec( schoolAndcohortResp )[1].trim();
 +
});
 +
 +
// 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( catMemberParam, { async: false } ).done( function(resData){
+
// Check whether the all fields are enough to run the function
schoolAndCohortOptions = [];
+
if( nameResp !== "" && schoolAndcohortResp !== "" && schoolResp !== ""
members = resData.query.categorymembers;
+
&& majorResp !== "" && countryResp !== "" ) {
+
 
// Creating MenuItems array from Category Members
+
wikiContent = '{| class="wikitable" style="border: 5px ridge grey; float:right;" \n|-\n|';
members.forEach( function(mem){
+
try {
schoolAndCohortOptions.push(
+
wikiContent += "[[File:"+ /File:(.+\.\w{3})/i.exec(imageResp)[1] +"|300px]]\n";
new OO.ui.MenuOptionWidget( {
+
}
data: mem.title.replace("Category:", ""),
+
catch(err) {
label: mem.title.replace("Category:", "")
+
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";
 
 
// Create widgets
+
pageTitle = "Fellow:" + nameResp;
var bio = new OO.ui.MultilineTextInputWidget( {
+
            placeholder: 'Bio',
+
requestAPI.get( {
            autosize: true,  
+
formatversion: 2,
            rows: 10
+
action: 'query',
        } ),
+
titles: pageTitle,
        achievements = new OO.ui.MultilineTextInputWidget( {
+
redirects: true
            placeholder: 'Achievements',
+
}, { async: false } ).then( function ( response ) {
            autosize: true,  
+
var page = response.query.pages[ 0 ];
            rows: 10
+
if ( page.missing || page.invalid ) {
        } ),
+
doEdit( pageTitle, wikiContent );
        social = new OO.ui.MultilineTextInputWidget( {
+
} else {
            placeholder: 'Social media profiles',
+
requestAPI.get( {
            autosize: true,  
+
formatversion: 2,
            rows: 10
+
action: 'query',
        } ),
+
titles: pageTitle + " (" + /\d{4}/.exec( schoolAndcohortResp.replace("Category:", "") ) + ")",
        name = new OO.ui.TextInputWidget( {  
+
redirects: true
            placeholder: 'Name'
+
}, { async: false } ).then( function ( response ) {
        } ),
+
var page = response.query.pages[ 0 ];
        school = new OO.ui.DropdownWidget( {
+
if ( page.missing || page.invalid ) {
            label: 'Select school',
+
doEdit( pageTitle + " (" + /\d{4}/.exec( schoolAndcohortResp.replace("Category:", "") ) + ")", wikiContent );
            menu: {
+
} else {
items: schoolOptions
+
pageTitle = pageTitle + " (" + /(^.+)\(/.exec(schoolAndcohortResp.replace("Category:", ""))[1].trim() + ", " + /\d{4}/.exec( schoolAndcohortResp.replace("Category:", "") ) + ")";
}
+
doEdit( pageTitle, wikiContent );
        } ),
+
}
        schoolAndcohort = new OO.ui.DropdownWidget( {
+
});
            label: 'Select school and Cohort',
 
            menu: {
 
items: schoolAndCohortOptions
 
 
}
 
}
        } ),
+
} );
        image = new OO.ui.TextInputWidget( {
+
} else {
            placeholder: 'https://universityinnovation.org/wiki/File:ABCD'
+
mw.notify( "Some fields have no text :( Please fill them." );
        } ),
+
return;
        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( 'wgServer' )
 
} ),
 
label1 = $('<p>').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" ).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();
 
});
 
 
// 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(){
 
}).fail( function(){
 
$( '#mw-content-text' ).append( "Something went wront. Please report it to Jay Prakash (User:Jayprakash)." );
 
$( '#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){
 
     function doEdit(title, wikiContent){
Line 251: Line 215:
 
title: title,
 
title: title,
 
text: wikiContent,
 
text: wikiContent,
summary: "Created Fellow Page - 2020",
+
summary: "Created Fellow Page - 2025",
 
format: 'json'
 
format: 'json'
 
};
 
};

Latest revision as of 04:46, 19 August 2025

// <nowiki>
$( document ).ready( function (){

	function init() {
		// 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 Public Profile - 2025');
        }

		// Check user login  	2
    	if( mw.config.get("wgUserId") === null){
    		$('#mw-content-text').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:2025 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 Members
			members.forEach( function(mem){
				schoolAndCohortOptions.push(
						new OO.ui.MenuOptionWidget( {
						data: mem.title.replace("Category:", ""),
						label: mem.title.replace("Category:", "")
					} )
				);
			});

			// 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( 'wgServer' )
				} ),
				label1 = $('<p>').text('Name:').css('font-weight','bold' ),
				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' ),
				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
			schoolResp = '';
			schoolAndcohortResp = '';
			schoolAndcohort.getMenu().on('select', function(data){
				schoolAndcohortResp = data.getData();
				patternReg = /(.*)\(\d{4}/gim;
				schoolResp = patternReg.exec( schoolAndcohortResp )[1].trim();
			});
			
			// 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)." );
		});

    	function doEdit(title, wikiContent){

    		// Edit the page
			var editParams = {
				action: 'edit',
				title: title,
				text: wikiContent,
				summary: "Created Fellow Page - 2025",
				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] === 'CreatePublicProfile' ) {
		mw.loader.using( ['oojs-ui-core', 'oojs-ui-widgets', 'mediawiki.api', 'mediawiki.notify'], init );
	}
});

// </nowiki>