Wiktionary:User scripts/Snippets

Hello, you have come here looking for the meaning of the word Wiktionary:User scripts/Snippets. In DICTIOUS you will not only get to know all the dictionary meanings for the word Wiktionary:User scripts/Snippets, but we will also tell you about its etymology, its characteristics and you will know how to say Wiktionary:User scripts/Snippets in singular and plural. Everything you need to know about the word Wiktionary:User scripts/Snippets you have here. The definition of the word Wiktionary:User scripts/Snippets will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofWiktionary:User scripts/Snippets, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.

Here are the list of snippets that are proof of concepts. They are supposed to be useful for creators.

Get wikitext

pageTitle is a fully qualified name.

function get_wikitext(pageTitle) {
	var wikitext = "";
	$.ajax({
		url: mw.util.wikiScript( 'index' ),
		data: {
			action:	 'raw',
			title: pageTitle
		},
		type: 'GET',
		success: function( result ) {
			wikitext = result;
		},
		error: function( xhr ) {
			alert( 'Error.\nRequest failed.' );
		},
		async: false
	});
	return wikitext;
}

Editing page

function addNewSection( pageTitle, summary, content, editToken ) {
	$.ajax({
		url: mw.util.wikiScript( 'api' ),
		data: {
			format: 'json',
			action: 'edit',
			title: pageTitle,
			section: 'new',
			summary: summary,
			text: content,
			token: editToken
		},
		dataType: 'json',
		type: 'POST',
		success: function( data ) {
			if ( data && data.edit && data.edit.result == 'Success' ) {
				window.location.reload(); // reload page if edit was successful
			} else if ( data && data.error ) {
				alert( 'Error: API returned error code "' + data.error.code + '": ' + data.error.info );
			} else {
				alert( 'Error: Unknown result from API.' );
			}
		},
		error: function( xhr ) {
			alert( 'Error: Request failed.' );
		}
	});
}

Current pageTitle can be obtained by mw.config.get( 'wgPageName' )

editToken can be obtained by mw.user.tokens.get('editToken') For more see mediawiki's API reference

LangName → LangCode

new LanguageUtilsAsync().GetWiktionaryCodeByCanonicalName("Georgian").then(function(langcode){
    //do something with langcode
});

LangCode → Canonical name

new LanguageUtilsAsync().GetCanonicalNameByWiktionaryCode("ka").then(function(langname){
    //do something with langname. Here it is "Georgian"
});