Open main menu

Difference between revisions of "MediaWiki:Gadget-UpdateWikiBio.js"

(Created page with "// <nowiki> $( document ).ready( function (){ function init() { // Remove the default content $('#mw-content-text > p').remove(); $('#firstHeading').text('Create Fe...")
 
 
(2 intermediate revisions by the same user 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 Fellow Page');
+
     $('#firstHeading').text('Update wiki bio');
  
 
// Check user login
 
// Check user login
Line 20: Line 20:
 
     requestAPI = new mw.Api();
 
     requestAPI = new mw.Api();
  
// Create widgets
+
getCategoryItem().done(function ( resData ){
var bio = new OO.ui.MultilineTextInputWidget( {
+
console.log( resData );
            placeholder: 'Bio',
+
schoolOptions = [];
            autosize: true,
+
members = resData.query.categorymembers;
            rows: 10
+
 
        } ),
+
// Creating MenuItems array from Category Members
        achievements = new OO.ui.MultilineTextInputWidget( {
+
members.forEach( function(mem){
            placeholder: 'Achievements',
+
schoolOptions.push(
            autosize: true,
+
new OO.ui.MenuOptionWidget( {
            rows: 10
+
data: mem.title.replace("Category:", ""),
        } ),
+
label: mem.title.replace("Category:", "")
        social = new OO.ui.MultilineTextInputWidget( {
+
} )
            placeholder: 'Social media profiles',
+
);
            autosize: true,
 
            rows: 10
 
        } ),
 
currentPage = new OO.ui.TextInputWidget( {  
 
placeholder: 'https://universityinnovation.org/wiki/Fellow:ABCD'
 
} ),
 
        name = new OO.ui.TextInputWidget( {
 
            placeholder: 'Name'
 
        } ),
 
school = new OO.ui.TextInputWidget( {
 
    placeholder: 'School'
 
} ),
 
        cohort = new OO.ui.TextInputWidget( {
 
    placeholder: '2019 Fall'
 
} ),
 
        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('Current Fellow link:').css('font-weight','bold' ),
 
label2 = $('<p>').text('Name:').css('font-weight','bold' ),
 
label3 = $('<p>').text('School:').css('font-weight','bold' ),
 
label4 = $('<p>').text('Cohort:').css('font-weight','bold' ),
 
uploadLink = $("<a>").attr("href", "https://universityinnovation.org/wiki/Special:Upload").attr( "target", "_blank" ).text("Upload"),
 
label5 = $('<p>').html('Image page link: (' + uploadLink.prop('outerHTML') + ' if did not upload yet!)' ).css('font-weight','bold' ),
 
label6 = $('<p>').text('Majoring in:').css('font-weight','bold' ),
 
label7 = $('<p>').text('Country:').css('font-weight','bold' ),
 
label8 = $('<p>').text('Bio:').css('font-weight','bold' ),
 
label9 = $('<p>').text('Achievements:').css('font-weight','bold' ),
 
label10 = $('<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(
+
// Create widgets
label1, currentPage.$element,
+
var bio = new OO.ui.MultilineTextInputWidget( {
label2, name.$element,
+
            placeholder: 'Bio',
label3, school.$element,
+
            autosize: true,
label4, cohort.$element,
+
            rows: 10
label5, image.$element,
+
        } ),
label6, major.$element,
+
        achievements = new OO.ui.MultilineTextInputWidget( {
label7, country.$element,  
+
            placeholder: 'Achievements',
label8, bio.$element,
+
            autosize: true,
label9, achievements.$element,
+
            rows: 10
label10, social.$element,
+
        } ),
'<br/>',
+
        social = new OO.ui.MultilineTextInputWidget( {
createBtn.$element,
+
            placeholder: 'Social media profiles',
cancelBtn.$element
+
            autosize: true,
);
+
            rows: 10
 
+
        } ),
waitMsg.remove();
+
currentPage = new OO.ui.TextInputWidget( {
$( '#mw-content-text' ).append( divMainBox );
+
placeholder: 'https://universityinnovation.org/wiki/Fellow:ABCD'
+
} ),
// Create button click event handler
+
        name = new OO.ui.TextInputWidget( {
createBtn.on( 'click', function() {
+
            placeholder: 'Name'
currentPageResp = currentPage.getValue().trim(),
+
        } ),
nameResp = name.getValue().trim(),
+
school = new OO.ui.DropdownWidget( {
schoolResp = school.getValue().trim(),
+
label: 'Select school',
cohortResp = cohort.getValue().trim(),
+
menu: {
imageResp = image.getValue().trim(),
+
items: schoolOptions
majorResp = major.getValue().trim();
+
}
countryResp = country.getValue().trim(),
+
        } ),
bioResp = bio.getValue().trim();
+
        cohort = new OO.ui.TextInputWidget( {
achievementsResp = achievements.getValue().trim(),
+
    placeholder: '2019 Fall'
socialResp = social.getValue().trim();
+
} ),
 +
        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'
 +
        } ),
 +
        overwriteCheckbox = new OO.ui.CheckboxInputWidget( {
 +
value: 1,
 +
selected: true
 +
} ),
 +
overwritePage = new OO.ui.FieldLayout( overwriteCheckbox, {
 +
label: 'Do you want to redirect your username page ( ' + mw.config.get("wgUserName") + ' ) to Fellow page.', align: 'inline'
 +
} ),
 +
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('Current Fellow link:').css('font-weight','bold' ),
 +
label2 = $('<p>').text('Name:').css('font-weight','bold' ),
 +
label3 = $('<p>').text('School:').css('font-weight','bold' ),
 +
label4 = $('<p>').text('Cohort:').css('font-weight','bold' ),
 +
uploadLink = $("<a>").attr("href", "https://universityinnovation.org/wiki/Special:Upload").attr( "target", "_blank" ).text("Upload"),
 +
label5 = $('<p>').html('Image page link: (' + uploadLink.prop('outerHTML') + ' if did not upload yet!)' ).css('font-weight','bold' ),
 +
label6 = $('<p>').text('Majoring in:').css('font-weight','bold' ),
 +
label7 = $('<p>').text('Country:').css('font-weight','bold' ),
 +
label8 = $('<p>').text('Bio:').css('font-weight','bold' ),
 +
label9 = $('<p>').text('Achievements:').css('font-weight','bold' ),
 +
label10 = $('<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, currentPage.$element,
 +
label2, name.$element,
 +
label3, school.$element,
 +
label4, cohort.$element,
 +
label5, image.$element,
 +
label6, major.$element,
 +
label7, country.$element,
 +
label8, bio.$element,
 +
label9, achievements.$element,
 +
label10, social.$element,
 +
overwritePage.$element,
 +
'<br/>',
 +
createBtn.$element,
 +
cancelBtn.$element
 +
);
 +
 +
waitMsg.remove();
 +
$( '#mw-content-text' ).append( divMainBox );
 
 
// Check whether user gave current Fellow link
+
// Event handler for Select cohort
if( currentPageResp.toLowerCase().indexOf("fellow:") === -1){
+
schoolResp = '';
mw.notify( "Please give current Fellow page link.", { autoHide: false } );
+
school.getMenu().on('select', function(data){
return;
+
schoolResp = data.getData();
}
+
});
  
// Check whether the all fields are enough to run the function
+
// Create button click event handler
if( nameResp !== "" && schoolResp !== "" &&
+
createBtn.on( 'click', function() {
cohortResp !== "" && majorResp !== "" && countryResp !== "" ) {
+
currentPageResp = currentPage.getValue().trim(),
 
+
nameResp = name.getValue().trim(),
wikiContent = '{| class="wikitable" style="border: 5px ridge grey; float:right;" \n|-\n|';
+
cohortResp = cohort.getValue().trim(),
try {
+
imageResp = image.getValue().trim(),
wikiContent += "[[File:"+ /File:(.+\.\w{3})/i.exec(imageResp)[1] +"|300px]]\n";
+
majorResp = major.getValue().trim();
 +
countryResp = country.getValue().trim(),
 +
bioResp = bio.getValue().trim();
 +
achievementsResp = achievements.getValue().trim(),
 +
socialResp = social.getValue().trim();
 +
overwitePageResp = overwriteCheckbox.isSelected();
 +
 +
// Check whether user gave current Fellow link
 +
if( currentPageResp.toLowerCase().indexOf("fellow:") === -1){
 +
mw.notify( "Please give current Fellow page link.", { autoHide: false } );
 +
return;
 
}
 
}
catch(err) {
+
wikiContent += "[[File:OOjs UI icon userAvatar.svg|300px]]\n";
+
// Check whether the all fields are enough to run the function
}
+
if( nameResp !== "" && schoolResp !== "" &&
wikiContent += "|-\n|\n";
+
cohortResp !== "" && majorResp !== "" && countryResp !== "" ) {
wikiContent += ";Name: " + nameResp + "\n";
+
wikiContent += ";School (Cohort): " + schoolResp + " (" + cohortResp + ")\n";
+
wikiContent = '{| class="wikitable" style="border: 5px ridge grey; float:right;" \n|-\n|';
wikiContent += ";Majoring in: " + majorResp + "\n";
+
try {
wikiContent += ";Country: " + countryResp + "\n";
+
wikiContent += "[[File:"+ /File:(.+\.\w{3})/i.exec(imageResp)[1] +"|300px]]\n";
wikiContent += ";Email: [[Special:EmailUser/" + mw.config.get("wgUserName") + "]]\n";
+
}
wikiContent += "|}\n";
+
catch(err) {
wikiContent += "==Bio==\n" + bioResp + "\n";
+
wikiContent += "[[File:OOjs UI icon userAvatar.svg|300px]]\n";
wikiContent += "==Achievements==\n" + achievementsResp + "\n";
+
}
wikiContent += "==Social media profiles==\n" + socialResp + "\n";
+
wikiContent += "|-\n|\n";
 
+
wikiContent += ";Name: " + nameResp + "\n";
pageTitle = /Fellow:([^&\?]*)/i.exec( currentPageResp )[0];
+
wikiContent += ";School (Cohort): " + schoolResp + " (" + cohortResp + ")\n";
+
wikiContent += ";Majoring in: " + majorResp + "\n";
categoriesParam = {
+
wikiContent += ";Country: " + countryResp + "\n";
"action": "query",
+
wikiContent += ";Email: [[Special:EmailUser/" + mw.config.get("wgUserName") + "]]\n";
"format": "json",
+
wikiContent += "|}\n";
"prop": "categories",
+
wikiContent += "==Bio==\n" + bioResp + "\n";
"titles": pageTitle,
+
wikiContent += "==Achievements==\n" + achievementsResp + "\n";
"utf8": 1
+
wikiContent += "==Social media profiles==\n" + socialResp + "\n";
};
+
 
+
pageTitle = /Fellow:([^&\?]*)/i.exec( currentPageResp )[0];
requestAPI.get( categoriesParam ).done( function(dataResp){
 
categories = dataResp.query.pages[Object.keys(dataResp.query.pages)[0]].categories;
 
 
 
categories.forEach( function(cat){
+
categoriesParam = {
wikiContent += "\n[[" + cat.title + "]]";
+
"action": "query",
 +
"format": "json",
 +
"prop": "categories",
 +
"titles": pageTitle,
 +
"utf8": 1
 +
};
 +
 +
requestAPI.get( categoriesParam ).done( function(dataResp){
 +
categories = dataResp.query.pages[Object.keys(dataResp.query.pages)[0]].categories;
 +
 +
categories.forEach( function(cat){
 +
wikiContent += "\n[[" + cat.title + "]]";
 +
});
 +
 +
wikiContent += "\n{{CatTree|" + schoolResp + "}}";
 +
 +
// Editing the Fellow page
 +
doEdit(pageTitle, wikiContent, overwitePageResp);
 +
}).fail(function(){
 +
mw.notify( "Can't fetc current Fellow page categories.", { autoHide: false } );
 
});
 
});
 +
} else {
 +
mw.notify( "Some fields have no text :( Please fill them." );
 +
return;
 +
}
 +
 +
    });
 +
});
  
// Editing the Fellow page
+
function getCategoryItem(){
doEdit(pageTitle, wikiContent);
+
catMemberParam = {
}).fail(function(){
+
"action": "query",
mw.notify( "Can't fetc current Fellow page categories.", { autoHide: false } );
+
"format": "json",
});
+
"list": "categorymembers",
} else {
+
"cmtitle": "Category:Schools Categories",
mw.notify( "Some fields have no text :( Please fill them." );
+
"cmprop": "title",
return;
+
"cmtype": "subcat",
}
+
"cmlimit": "500"
 +
};
 +
 +
return requestAPI.get( catMemberParam, { async: false }  );
 +
}
  
    });
+
     function doEdit(title, wikiContent, redirect){
 
 
     function doEdit(title, wikiContent){
 
  
 
     // Edit the page
 
     // Edit the page
Line 187: Line 236:
 
requestAPI.postWithToken( 'csrf', editParams, { async: false } ).done( function ( res ) {
 
requestAPI.postWithToken( 'csrf', editParams, { async: false } ).done( function ( res ) {
 
if( res.edit.result === "Success"){
 
if( res.edit.result === "Success"){
mw.notify( title + " page has created :)");
+
if( redirect === true){
window.location.replace( mw.config.get( 'wgServer' ) + "/wiki/" + title );
+
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 failed.");
 +
window.location.replace( mw.config.get( 'wgServer' ) + "/wiki/" + title );
 +
});
 +
} else {
 +
mw.notify( title + " page has created :)" );
 +
window.location.replace( mw.config.get( 'wgServer' ) + "/wiki/" + title );
 +
}
 
} else{
 
} else{
 
mw.notify( "Something went worng :(" );
 
mw.notify( "Something went worng :(" );
Line 197: Line 263:
 
}
 
}
 
 
if ( mw.config.get('wgCanonicalSpecialPageName') === 'Blankpage' && mw.config.get('wgTitle').split('/', 2)[1] === 'CreateFellow' ) {
+
if ( mw.config.get('wgCanonicalSpecialPageName') === 'Blankpage' && mw.config.get('wgTitle').split('/', 2)[1] === 'UpdateWikiBio' ) {
mw.loader.using( ['oojs-ui-core', 'mediawiki.api', 'mediawiki.notify'], init );
+
mw.loader.using( ['oojs-ui-core', 'oojs-ui-widgets', 'mediawiki.api', 'mediawiki.notify'], init );
 
}
 
}
 
});
 
});
 
// </nowiki>
 

Latest revision as of 09:34, 2 July 2020

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

	function init() {
		// Remove the default content
		$('#mw-content-text > p').remove();
    	$('#firstHeading').text('Update wiki bio');

		// Check user login
    	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();

		getCategoryItem().done(function ( resData ){
			console.log( resData );
			schoolOptions = [];
			members = resData.query.categorymembers;

			// Creating MenuItems array from Category Members
			members.forEach( function(mem){
				schoolOptions.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
	        	} ),
				currentPage = new OO.ui.TextInputWidget( { 
					placeholder: 'https://universityinnovation.org/wiki/Fellow:ABCD'
				} ),
		        name = new OO.ui.TextInputWidget( { 
		            placeholder: 'Name'
		        } ),
				school = new OO.ui.DropdownWidget( {
					label: 'Select school',
					menu: {
						items: schoolOptions 
					}
		        } ),
		        cohort = new OO.ui.TextInputWidget( { 
				    placeholder: '2019 Fall'
				} ),
		        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'
		        } ),
		        overwriteCheckbox = new OO.ui.CheckboxInputWidget( {
					value: 1,
					selected: true
				} ),
				overwritePage = new OO.ui.FieldLayout( overwriteCheckbox, {
					label: 'Do you want to redirect your username page ( ' + mw.config.get("wgUserName") + ' ) to Fellow page.', align: 'inline'
				} ),
				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('Current Fellow link:').css('font-weight','bold' ),
				label2 = $('<p>').text('Name:').css('font-weight','bold' ),
				label3 = $('<p>').text('School:').css('font-weight','bold' ),
				label4 = $('<p>').text('Cohort:').css('font-weight','bold' ),
				uploadLink = $("<a>").attr("href", "https://universityinnovation.org/wiki/Special:Upload").attr( "target", "_blank" ).text("Upload"),
				label5 = $('<p>').html('Image page link: (' + uploadLink.prop('outerHTML') + ' if did not upload yet!)' ).css('font-weight','bold' ),
				label6 = $('<p>').text('Majoring in:').css('font-weight','bold' ),
				label7 = $('<p>').text('Country:').css('font-weight','bold' ),
				label8 = $('<p>').text('Bio:').css('font-weight','bold' ),
				label9 = $('<p>').text('Achievements:').css('font-weight','bold' ),
				label10 = $('<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, currentPage.$element,
				label2, name.$element,
				label3, school.$element,
				label4, cohort.$element,
				label5, image.$element,
				label6, major.$element,
				label7, country.$element, 
				label8, bio.$element,
				label9, achievements.$element,
				label10, social.$element,
				overwritePage.$element,
				'<br/>',
				createBtn.$element,
				cancelBtn.$element
			);
	
			waitMsg.remove();
			$( '#mw-content-text' ).append( divMainBox );
			
			// Event handler for Select cohort
			schoolResp = '';
			school.getMenu().on('select', function(data){
				schoolResp = data.getData();
			});

			// Create button click event handler
			createBtn.on( 'click', function() {
				currentPageResp = currentPage.getValue().trim(),
				nameResp = name.getValue().trim(),
				cohortResp = cohort.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();
				overwitePageResp = overwriteCheckbox.isSelected();
				
				// Check whether user gave current Fellow link
				if( currentPageResp.toLowerCase().indexOf("fellow:") === -1){
					mw.notify( "Please give current Fellow page link.", { autoHide: false } );
					return;
				}
	
				// Check whether the all fields are enough to run the function
				if( nameResp !== "" && schoolResp !== "" &&
					cohortResp !== "" && 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): " + schoolResp + " (" + cohortResp + ")\n";
					wikiContent += ";Majoring in: " + majorResp + "\n";
					wikiContent += ";Country: " + countryResp + "\n";
					wikiContent += ";Email: [[Special:EmailUser/" + mw.config.get("wgUserName") + "]]\n";
					wikiContent += "|}\n";
					wikiContent += "==Bio==\n" + bioResp + "\n";
					wikiContent += "==Achievements==\n" + achievementsResp + "\n";
					wikiContent += "==Social media profiles==\n" + socialResp + "\n";
	
					pageTitle = /Fellow:([^&\?]*)/i.exec( currentPageResp )[0];
					
					categoriesParam = {
						"action": "query",
						"format": "json",
						"prop": "categories",
						"titles": pageTitle,
						"utf8": 1
					};
	
					requestAPI.get( categoriesParam ).done( function(dataResp){
						categories = dataResp.query.pages[Object.keys(dataResp.query.pages)[0]].categories;
						
						categories.forEach( function(cat){
							wikiContent += "\n[[" + cat.title + "]]";	
						});
						
						wikiContent += "\n{{CatTree|" + schoolResp + "}}";
	
						// Editing the Fellow page
						doEdit(pageTitle, wikiContent, overwitePageResp);
					}).fail(function(){
						mw.notify( "Can't fetc current Fellow page categories.", { autoHide: false } );
					});
				} else {
					mw.notify( "Some fields have no text :( Please fill them." );
					return;
				}
	
	    	});
		});

		function getCategoryItem(){
			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, redirect){

    		// Edit the page
			var editParams = {
				action: 'edit',
				title: title,
				text: wikiContent,
				summary: "Recreated Fellow Page",
				format: 'json'
			};
	
			requestAPI.postWithToken( 'csrf', editParams, { async: false } ).done( function ( res ) {
				if( res.edit.result === "Success"){
					if( redirect === true){
						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 failed.");
							window.location.replace( mw.config.get( 'wgServer' ) + "/wiki/" + title );
						});
					} else {
						mw.notify( title + " page has created :)" );
						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] === 'UpdateWikiBio' ) {
		mw.loader.using( ['oojs-ui-core', 'oojs-ui-widgets', 'mediawiki.api', 'mediawiki.notify'], init );
	}
});