Медиавики:Gadget-newTopicOnTop.js

Мавод аз Википедиа — донишномаи озод

Эзоҳ: Баъди захира намудан, Шумо метавонед тағйиротҳои худро аз хотираи браузер гузариш карда, бубинед. Дар браузерҳои Mozilla / Firefox / Safari: тугмаи Shift-ро пахш намуда бо мушак Reload-ро пахш кунед, ё Ctrl-Shift-R-ро пахш намоед (Cmd-Shift-R барои компютерҳои Apple Mac); дар браузери IE: тугмаи Ctrl-ро пахш намуда бо мушак Refresh-ро пахш намоед, ё Ctrl-F5-ро пахш намоед; дар браузери Konqueror:: бо мушак Reload-ро пахш кунед, ё тугмаи F5-ро пахш намоед; дар браузери Opera ба Шумо пурра тоза кардани хотираи браузер ба воситаи Tools→Preferences лозим аст.

mw.hook( 'wikipage.editform' ).add( function () {

var decodedQuery, textboxContent,
	$textbox = $( '#wpTextbox1' ),
	$summary = $( '#wpSummary' ),
	summary = $summary.val();

function transferHeadingToSummary() {
	var matches, heading, summary,
		textboxContent = $textbox.val();

	// Remove HTML comments
	textboxContent = textboxContent && textboxContent.replace( /<!--[^]*?-->/g, '' );
	matches = textboxContent && textboxContent.match( /^==(.+)==/m );
	if ( !matches ) {
		return;
	}

	heading = matches[ 1 ]
		// Constructs like [[Namespace:Page|<empty string>]]
		.replace( /\[\[:?(?:[^:\]]+?:)?([^|\]]+)\|\]\]/g, '$1' )
		// Extract displayed text from wikilinks
		.replace( /\[\[:?(?:[^|\]]+\|)?(.+?)\]\]/g, '$1' )
		// Remove bold
		.replace( /'''(.+?)'''/g, '$1' )
		// Remove italics
		.replace( /''(.+?)''/g, '$1' )
		// Remove opening tags (won't work with <smth param=">">, but wikiparser fails too)
		.replace( /<\w+( [\w ]+?=[^<>]+?| ?\/?)>/g, '' )
		// Remove closing tags
		.replace( /<\/\w+ ?>/g, '' )
		// Remove multiple spaces
		.replace( / {2,}/g, ' ' )
		.trim();
	if ( !heading ) {
		return;
	}

	summary = $summary.val();
	if ( summary === undefined ) {
		return;
	}

	$summary
		.val( /\/\*.*\*\//.test( summary ) ?
			'/* ' + heading + ' */' + summary.substr( summary.indexOf( '*/' ) + 2 ) :
			'/* ' + heading + ' */ ' + summary
		)
		.trigger( 'change' );
}

try {
	decodedQuery = decodeURIComponent( location.search );
} catch ( e ) {}

if ( decodedQuery &&
	$textbox.length &&
	( /[?&]summary=\/\*[+ ]*\*\//.test( decodedQuery ) ||
		( mw.config.get( 'wgAction' ) === 'submit' &&
			summary !== undefined &&
			/\/\*\s*\*\//.test( summary )
		)
	)
) {
	if ( mw.config.get( 'wgAction' ) !== 'submit' ) {
		textboxContent = $textbox.val();
		// Remove HTML comments
		textboxContent = textboxContent && textboxContent.replace( /<!--[^]*?-->/g, '' );
		if ( textboxContent.search( /^==.+==/m ) === -1 ) {
			$textbox
				.focus()
				.val( $textbox.val() + '\n==  ==\n' )
				.textSelection( 'setSelection', { start: $textbox.val().length - 4 } );
		}
	}

	// Workaround until T197632 is fixed. The handler will run twice in most cases.
	// ".CodeMirror-code" for Chrome, focusin on ".editOptions" for Firefox.
	$textbox.add( '.CodeMirror-code' ).blur( transferHeadingToSummary );
	$( '.editOptions' ).focusin( transferHeadingToSummary );
}

} );