MediaWiki:Gadget-Adiutor.js

Not: Sayfayı kaydettikten sonra değişiklikleri görebilmek için tarayıcınızın önbelleğinizi temizlemeniz gerekir. Google Chrome, Firefox, Microsoft Edge ve Safari: ⇧ Shift tuşuna basılı tutun ve Yeniden Yükle araç çubuğu düğmesine tıklayın. Ayrıntılar ve diğer tarayıcılara yönelik yönergeler için Vikipedi:Önbelleğinizi atlayın sayfasını inceleyin.

/* Adiutor: Enhancing Wikipedia Editing Through a Comprehensive Set of Versatile Tools and Modules.
 * Author: Vikipolimer
 * Learn more at: https://meta.wikimedia.org/wiki/Adiutor
 * License: Licensed under Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)
<nowiki> */
const api = new mw.Api();
const wikiOptions = 'userjs-adiutor-' + mw.config.get( 'wgWikiID' );
// Function to update user options
// This function sends updated options to the server via the API.
function updateOptions( options ) {
    api.postWithEditToken( {
        action: 'globalpreferences',
        format: 'json',
        optionname: wikiOptions,
        optionvalue: JSON.stringify( options ),
        formatversion: 2
    } ).fail( function ( err ) {
        mw.notify( 'Failed to update user options: ' + err );
    } );
}
// Function to update translations
function updateTranslations() {
	api.get( {
		action: 'query',
		prop: 'revisions',
		titles: 'MediaWiki:Gadget-Adiutor-i18.json',
		rvprop: 'content',
		formatversion: 2
	} ).done( function ( data ) {
		const page = data.query.pages[ 0 ];
		if ( page && page.revisions && page.revisions[ 0 ] ) {
			const jsonData = JSON.parse( page.revisions[ 0 ].content );
			// Check if jsonData is an object
			if ( typeof jsonData === 'object' ) {
				for ( const langCode in jsonData ) {
					if ( jsonData.hasOwnProperty( langCode ) && langCode !== '@metadata' ) {
						processTranslation( langCode, jsonData[ langCode ] );
					}
				}
			} else {
				mw.notify( 'Invalid translation data found in the response.' );
			}
		} else {
			mw.notify( 'Failed to fetch translation data.' );
		}
	} ).fail( function ( err ) {
		mw.notify( 'Failed to fetch translation data: ' + err );
	} );
}

// Processes individual translations and updates them via the API.
function processTranslation( langCode, translationData ) {
    const optionValue = JSON.stringify( translationData );
    api.postWithEditToken( {
        action: 'globalpreferences',
        format: 'json',
        optionname: 'userjs-adiutor-i18-' + langCode,
        optionvalue: optionValue,
        formatversion: 2
    } ).done( function ( response ) {
		if ( response && response.globalpreferences && response.globalpreferences.status === 'success' ) {
			mw.notify( 'Successfully updated translation for ' + langCode );
		} else {
			mw.notify( 'Failed to update translation for ' + langCode );
		}
    } ).fail( function ( err ) {
        mw.notify( 'Failed to update translation for ' + langCode + ': ' + err );
    } );
}
// Define default user options for the Adiutor gadget
const adiutorUserOptionsDefault = {
	myWorks: [],
	myCustomSummaries: [],
	speedyDeletion: {
		csdSendMessageToCreator: true,
		csdLogNominatedPages: true,
		csdLogPageName: 'HS günlüğü'
	},
	articlesForDeletion: {
		afdSendMessageToCreator: true,
		afdLogNominatedPages: true,
		afdLogPageName: 'SAS günlüğü',
		afdNominateOpinionsLog: true,
		afdOpinionLogPageName: 'SAS görüş günlüğü'
	},
	proposedDeletion: {
		prdSendMessageToCreator: true,
		prdLogNominatedPages: true,
		prdLogPageName: 'BS günlüğü'
	},
	status: {
		showMyStatus: true,
		myStatus: 'active'
	},
	stats: {
		csdRequests: 0,
		afdRequests: 0,
		prodRequests: 0,
		blockRequests: 0,
		userWarnings: 0,
		pageTags: 0
	},
	inlinePageInfo: true,
	showEditSummaries: true,
	adiutorVersion: 'v1.3.0'
};
// Get user options related to the Adiutor gadget
const adiutorUserOptions = JSON.parse( mw.user.options.get( wikiOptions ) || null );

// Check if user options are not present or empty
// If the settings are not found or are empty, the defaults are set.
if ( !adiutorUserOptions || Object.keys( adiutorUserOptions ).length === 0 ) {
    updateOptions( adiutorUserOptionsDefault );
    updateTranslations();
} else {
    let hasNewOptions = false;
    // Loop through default settings and add any missing settings to the user's current options.
    for ( const key in adiutorUserOptionsDefault ) {
        if ( adiutorUserOptionsDefault.hasOwnProperty( key ) && !adiutorUserOptions.hasOwnProperty( key ) ) {
            hasNewOptions = true;
            adiutorUserOptions[ key ] = adiutorUserOptionsDefault[ key ];
        }
    }
    // Update the user's settings if new options were added.
    if ( hasNewOptions ) {
        updateOptions( adiutorUserOptions );
        updateTranslations();
    }
}
try {
    const userLanguage = mw.config.get( 'wgUserLanguage' );
    let adiutorUserInterfaceTranslations = mw.user.options.get( 'userjs-adiutor-i18-' + userLanguage );

    // Use English as a fallback if no translation is available for the user's language.
    if ( !adiutorUserInterfaceTranslations ) {
        adiutorUserInterfaceTranslations = mw.user.options.get( 'userjs-adiutor-i18-en' );
    }

    // Parse and set the translations for the interface.
    const messages = JSON.parse( adiutorUserInterfaceTranslations || '{}' );
    if ( typeof messages !== 'object' || !messages || Object.keys( messages ).length === 0 ) {
        throw new Error( 'Invalid or empty translations' );
    }

    mw.messages.set( messages );
	// Load the Adiutor interface launcher
	mw.loader.load( mw.util.getUrl( 'MediaWiki:Gadget-Adiutor-AIL.js', {
		action: 'raw'
	} ) + '&ctype=text/javascript', 'text/javascript' );
} catch ( error ) {
	mw.notify( 'Adiutor: Failed to load translations: ' + error );
	updateTranslations();
}
/* </nowiki> */