User:Sean William/monobook.js

From Wikipedia, the free encyclopedia
Jump to navigation Jump to search
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/* <pre> */

importScript('User:AzaToth/morebits.js');
importScript('User:AzaToth/twinklespeedy.js');
importScript('User:AzaToth/twinkleimage.js');
importScript('User:AzaToth/twinkledelimages.js');

TwinkleConfig = {
        revertMaxRevisions              :       50,
        userTalkPageMode                :       'window',
        showSharedIPNotice              :       true,
        openTalkPage                    :       [ 'agf', 'norm', 'vand' ],
        openTalkPageOnAutoRevert        :       false,
        summaryAd                       :       " ",
        deletionSummaryAd               :       " ",
        protectionSummaryAd             :       " ",
        watchSpeedyPages                :       [ 'g3', 'g5', 'g10', 'g11', 'g12' ],
        watchProdPages                  :       true,
        openUserTalkPageOnSpeedyDelete  :       [ 'g1', 'g2', 'g10', 'g11', 'g12', 'a1', 'a7', 'i3', 'i4', 'i5', 'i6', 'i7', 'u3', 't1' ],
        watchRevertedPages              :       [ 'agf', 'norm', 'vand', 'torev' ],
        markRevertedPagesAsMinor        :       [ 'agf', 'norm', 'vand', 'torev' ],
        deleteTalkPageOnDelete          :       false,
        watchWarnings                   :       true,
        markAIVReportAsMinor            :       true,
        markSpeedyPagesAsMinor          :       true,
        offerReasonOnNormalRevert       :       true,
        orphanBacklinksOnSpeedyDelete   :       {orphan:false, exclude:['g6']}
};

// If TwinkleConfig aint exist.
if( typeof( TwinkleConfig ) == 'undefined' ) {
	TwinkleConfig = {};
}

/**
 TwinkleConfig.summaryAd (string)
 If ad should be added or not to summary, default [[WP:TWINKLE|TWINKLE]]
 */
if( typeof( TwinkleConfig.summaryAd ) == 'undefined' ) {
	TwinkleConfig.summaryAd = " using [[WP:TW|TW]]";
}

/**
 TwinkleConfig.saltTarget (string)
 What page should be used as salt target, default Wikipedia:Protected titles/Twinkle
 */
if( typeof( TwinkleConfig.saltTarget ) == 'undefined' ) {
	TwinkleConfig.saltTarget = "User:Sean William/Salt";
}

function twinklesalt() {
	if( wgCurRevisionId != false || wgNamespaceNumber < 0 || ! userIsInGroup( 'sysop' ) ) {
		return;
	}
	mw.util.addPortletLink('p-cactions', "javascript:twinklesalt.callback()", "salt", "ca-salt", "Salt this page using cascading protection", "");
}


addOnloadHook(twinklesalt);

twinklesalt.callback = function twinklesaltCallback() {
	var Window = new SimpleWindow( 800, 400 );
	var form = new QuickForm( twinklesalt.callback.evaluate );
	form.append( {
			type: 'textarea',
			name: 'reason',
			label: 'Reason:'
		} );
	form.append( { type:'submit' } );
	var result = form.render();
	Window.setContent( result );
	Window.display();	
}

twinklesalt.callback.evaluate = function twinklesaltCallbackEvaluate(e) {
	var reason = e.target.reason.value;
	Status.init( e.target );

	var query = {
		'title': TwinkleConfig.saltTarget,
		'action': 'submit'
	}
	var wikipedia_wiki = new Wikipedia.wiki( 'Salting', query, twinklesalt.callbacks.salt );
	wikipedia_wiki.params = { reason: reason };
	wikipedia_wiki.get();

}


twinklesalt.callbacks = {
	salt: function ( self ) {
		var form = this.responseXML.getElementById( 'editform' );
		var text = form.wpTextbox1.value;
		var reason = self.params.reason ? "|reason=" + self.params.reason : '';
		var ns = wgNamespaceNumber != Namespace.MAIN ? "|ns=" + namespaces[wgNamespaceNumber] : '';

		text += "*\{\{protected title|" + wgTitle + reason + ns + "\}\}  \~\~\~\~";

		var postData = {
			'wpMinoredit': form.wpMinoredit.checked ? '' : undefined,
			'wpWatchthis': form.wpWatchthis.checked ? '' : undefined,
			'wpStarttime': form.wpStarttime.value,
			'wpEdittime': form.wpEdittime.value,
			'wpAutoSummary': form.wpAutoSummary.value,
			'wpEditToken': form.wpEditToken.value,
			'wpSummary': 'Adding \[\[:' + wgPageName + '\]\].' + TwinkleConfig.summaryAd,
			'wpTextbox1': text
		};

		self.post ( postData );
	}
}