Open main menu

Changes

MediaWiki:Gadget-UpdateWikiBio.js

2,255 bytes added, 5 years ago
no edit summary
requestAPI = new mw.Api();
// Create widgets var bio = new OO.ui.MultilineTextInputWidgetgetCategoryItem( { placeholder: 'Bio', autosize: true, rows: 10 } ), achievements = new OO.ui.MultilineTextInputWidgetdone( { placeholder: 'Achievements', autosize: true, rows: 10 } ), social = new OO.ui.MultilineTextInputWidgetfunction ( { placeholder: 'Social media profiles', autosize: true, rows: 10 } resData ), currentPage = new OO.ui.TextInputWidget( { placeholder: 'https://universityinnovation.org/wiki/Fellow:ABCD' } ), name = new OO.uiconsole.TextInputWidgetlog( { placeholder: 'Name' } resData ),; school schoolOptions = new OO.ui.TextInputWidget( { placeholder: 'School'[]; } ), cohort members = new OOresData.uiquery.TextInputWidget( { categorymembers; placeholder: '2019 Fall' } ), image = new OO.ui.TextInputWidget( { placeholder: 'https://universityinnovation.org/wiki/File:ABCD'Creating MenuItems array from Category Members } ), major = new OO members.ui.TextInputWidgetforEach( function( { placeholder: 'Majoring in' } mem), country = new OO.ui.TextInputWidget( { placeholder: 'Country' } ), createBtn = new OO.ui schoolOptions.ButtonWidgetpush( { label: 'Create Page', flags: [ 'progressive', 'primary' ] } ), cancelBtn = new OO.ui.ButtonWidgetMenuOptionWidget( { label data: 'Cancel', flags: [ 'primary', 'destructive' ], href: mwmem.configtitle.getreplace( 'wgServer' ) } ), label1 = $('<p>').text('Current Fellow link"Category:').css('font-weight'",'bold' ""), label2 = $('<p>').text('Name label:').css('font-weight','bold' ), label3 = $('<p>').text('School:').css('font-weight','bold' ), label4 = $('<p>').text('Cohort:')mem.css('font-weight','bold' ), uploadLink = $("<a>")title.attrreplace("href", "httpsCategory://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 // 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.appendMultilineTextInputWidget({ label1 placeholder: 'Social media profiles', autosize: true, rows: 10 } ), currentPage= new OO.$elementui.TextInputWidget( { placeholder: 'https://universityinnovation.org/wiki/Fellow:ABCD' } ), label2, name= new OO.$elementui.TextInputWidget( { placeholder: 'Name' } ), label3, school= new OO.$elementui.DropdownWidget( { label: 'Select school', label4 menu: { items: schoolOptions } } ), cohort= new OO.$elementui.TextInputWidget( { placeholder: '2019 Fall' } ), label5, image= new OO.ui.TextInputWidget( { placeholder: 'https://universityinnovation.$elementorg/wiki/File:ABCD' } ), label6, major= new OO.ui.$elementTextInputWidget( { placeholder: 'Majoring in' } ), label7 country = new OO.ui.TextInputWidget( { placeholder: 'Country' } ), country overwriteCheckbox = new OO.ui.$elementCheckboxInputWidget( { value: 1, label8 selected: true } ), bio overwritePage = new OO.ui.$elementFieldLayout( overwriteCheckbox,{ label9, achievements label: 'Do you want to redirect your username page ( ' + mw.config.get("wgUserName") + ' ) to Fellow page.$element',align: 'inline' label10 } ), social createBtn = new OO.ui.$elementButtonWidget( { label: 'Create Page', flags: [ '<br/>progressive','primary' ] createBtn.$element } ), cancelBtn= new OO.$elementui.ButtonWidget( { label: 'Cancel', flags: [ 'primary', 'destructive' ], href: mw.config.get( 'wgServer' ); } ), waitMsg label1 = $('<p>').removetext('Current Fellow link:');.css('font-weight','bold' ), label2 = $( '#mw-content-<p>').text('Name:' ).appendcss( divMainBox 'font-weight','bold' );, // Create button click event handler createBtn label3 = $('<p>').text('School:').oncss( 'clickfont-weight', function('bold' ) {, currentPageResp label4 = currentPage$('<p>').getValuetext('Cohort:').trimcss('font-weight','bold' ), nameResp uploadLink = name$("<a>").attr("href", "https://universityinnovation.org/wiki/Special:Upload").getValueattr("target", "_blank" ).trimtext("Upload"), schoolResp label5 = school$('<p>').html('Image page link: (' + uploadLink.getValueprop('outerHTML') + ' if did not upload yet!)' ).trimcss('font-weight','bold' ), cohortResp label6 = cohort$('<p>').getValuetext('Majoring in:').trimcss('font-weight','bold' ), imageResp label7 = image$('<p>').getValuetext('Country:').trimcss('font-weight','bold' ), majorResp label8 = major$('<p>').getValuetext('Bio:').trimcss('font-weight','bold' );, countryResp label9 = country$('<p>').getValuetext('Achievements:').trimcss('font-weight','bold' ), bioResp label10 = bio$('<p>').getValuetext('Social media profiles:').trimcss('font-weight','bold' );, achievementsResp divMainBox = achievements$('<div />').getValuecss(){ 'box-shadow': '0 .trim5rem 1rem rgba(0, 0, 0, .15)', 'border': '1px solid', 'padding': '1rem', 'margin-bottom': '3rem', 'border-radius': '.5rem' }); socialResp = 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.getValue$element, overwritePage.$element, '<br/>', createBtn.$element, cancelBtn.$element ); waitMsg.remove(); $( '#mw-content-text' ).trimappend(divMainBox );
// Check whether user gave current Fellow linkEvent handler for Select cohort if( currentPageRespschoolResp = ''; school.toLowerCasegetMenu().indexOfon("fellow:") === -1'select', function(data){ mwschoolResp = data.notifygetData( "Please give current Fellow page link.", { autoHide: false } ); return; });
// Check whether the all fields are enough to run the Create button click event handler createBtn.on( 'click', function() { if currentPageResp = currentPage.getValue().trim( ), nameResp !== "" && schoolResp !== "" &&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(), wikiContent socialResp = '{| classsocial.getValue().trim(); overwitePageResp ="wikitable" style="border: 5px ridge grey; float:right;" \n|-\n|'overwriteCheckbox.isSelected(); try { wikiContent += "[[File:"+ //File:Check whether user gave current Fellow link if(currentPageResp.+\.\w{3}toLowerCase()/i.execindexOf(imageResp"fellow:")[=== -1] +){ mw.notify( "|300px]]\nPlease 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;
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;
}
});
});
// Editing the Fellow page function getCategoryItem(){ catMemberParam = { doEdit(pageTitle "action": "query", wikiContent); }).fail(function(){"format": "json", mw.notify( "list": "Can't fetc current Fellow page categories.categorymembers", { autoHide "cmtitle": "Category: false } );Schools Categories", });"cmprop": "title", } else { "cmtype": "subcat", mw.notify( "Some fields have no text cmlimit":( Please fill them." )500" }; returnrequestAPI.get( catMemberParam, { async: false } ); }
});  function doEdit(title, wikiContent, redirect){
// Edit the page
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] === 'CreateFellowUpdateWikiBio' ) { mw.loader.using( ['oojs-ui-core', 'oojs-ui-widgets', 'mediawiki.api', 'mediawiki.notify'], init );
}
});
 
// </nowiki>