משתמש:חיים 7/test.js

מתוך ויקיפדיה, האנציקלופדיה החופשית

הערה: לאחר הפרסום, ייתכן שיהיה צורך לנקות את זיכרון המטמון (cache) של הדפדפן כדי להבחין בשינויים.

  • פיירפוקס / ספארי: להחזיק את המקש Shift בעת לחיצה על טעינה מחדש (Reload) או ללחוץ על צירוף המקשים Ctrl-F5 או Ctrl-R (במחשב מק: ⌘-R).
  • גוגל כרום: ללחוץ על צירוף המקשים Ctrl-Shift-R (במחשב מק: ⌘-Shift-R).
  • אינטרנט אקספלורר / אדג': להחזיק את המקש Ctrl בעת לחיצה על רענן (Refresh) או ללחוץ על צירוף המקשים Ctrl-F5.
  • אופרה: ללחוץ על Ctrl-F5.
/*
 * Original version: https://pl.wikipedia.org/wiki/MediaWiki:Wikibugs.js (2008-12-17)
 * Russian version by [[User:Александр Сигачёв]], [[User:Putnik]], [[User:LEMeZza]]
 * Converted to OOjs (2017-05-20) by [[User:Putnik]]


Adaptation for hewiki (27/10/2021):
 * @author: [[User:חיים 7]]
 */

( function ( mw, $ ) {
	//'use strict';

	var wb$bugsPage = 'ויקיפדיה:דיווח על טעויות';
	var wb$badPages = 'ויקיפדיה:דיווח על טעויות';

	var wb$link = function ( page ) {
		return mw.config.get( 'wgArticlePath' ).replace( /\$1/, page.replace( / /g, '_' ) );
	};

	var wb$i18n = {
		nsFile: 'קובץ:',
		nsSpecial: 'שירות:',
		nsCat: 'קטגוריה:',
		title: 'פרטי הדיווח',
		btnFix: 'אנסה לתקן לבד',
		btnReport: 'דיווח על באג',
		btnCancel: 'ביטול',
		btnSend: 'שליחה',
		fldPage: 'כותרת הדף',
		fldText: 'תוכן ההודעה',
		fldTextInfo: 'נא לתאר את השגיאה בצורה מפורטת ככל האפשר, בעת דיווח' +
			' על טעות עובדתית, יש להקפיד לכלול את המקור התומך' +
			' בדיווח שלך.',
		fldCaptcha: 'קוד אימות',
		fldSign: 'חתימה',
		fldSignIP: 'כתובת ה-IP שלך תוצג',
		alertShort: 'תיאור השגיאה קצר מדי. בבקשה להרחיב אותה.',
		alertNoPage: 'נא להזין את שם הדף.',
		alertCaptcha: 'הטקסט שלך מכיל קישורים חיצוניים,' +
			' נא להזין את הקוד מהתמונה ולשלוח בשנית.',
		alertError: 'אירעה שגיאה במהלך השליחה, נא לנסות שנית.',
		msgSign: '\n\nפרטי המדווח:',
		newTopic: 'נושא חדש',
		htmlIpWarn: '<strong>אזהרה.</strong> כתובת ה-IP שלך תופיע' +
			' בהיסטוריית העריכות.',
		htmlInfo: '<div style="float:right;width:200px;padding:4px 10px;\
			margin:2px 0px 0px 10px;font-size:90%;border:2px solid #a6170f;\
			border-radius:3px">\
				<p>טופס זה <strong>אינו מיועד</strong> לדיווח על תקלות באתרים אחרים\
					דיווחים כאלו יש לדווח לאתר הרלוונטי.</p>\
				<p>כמו כן היעד ערך אינו טעות, ניתן לשלוח\
					<a href="' + wb$link( 'ויקיפדיה:בקשת ערך' ) + '">בקשה ליצירת ערך</a>.</p>\
			</div>\
			<p>באם אבחנת בשגיאה, ניתן לתקן זאת בעצמך,\
				כל אחד יכול לערוך כמעט כל דף בויקיפדיה,\
				אל תתביישו, אחד הכללים בויקיפדיה אומר <a href="' + wb$link( 'ויקיפדיה:היו נועזים בעריכת ערכים' ) + '">היו נועזים בעריכת ערכים</a>\
				באם אין ביכולתך לתקן את השגיאה בעצמך, ניתן לדווח עליו.\
				באמצעות טופס זה</p>\
				<p><strong>אם הטעות תוקנה\
				נא לא לדווח עליו.</strong></p>\
			<p>אל תשאירו מספר טלפון או כתובת דואר אלקטרוני!\
				התשובה תינתן בעמוד הדיווח על הטעויות ורק בעמוד זה.</p>\
			<p>לתשומת ליבך!\
				כתובת ה-IP שלך תופיע בהיסטוריית העריכה של הדף.</p>\
			<p><a href="' + wb$link( wb$bugsPage ) + '">רשימת\
				דיווחי הטעויות</a></p>'
	};

	var wb$isValidPageName = function (name) {
		if ( !name || name.substr( 0, name.indexOf( ':' ) + 1 ) === wb$i18n.nsSpecial ) {
			return false;
		}
		name = name.replace( /_/g, ' ' );
		for ( var i = 0; i < wb$badPages.length; i++ ) {
			if ( name === wb$badPages[i] ) {
				return false;
			}
		}

		return true;
	};

	var wb$popWikibug = function () {
		// Info popup
		var canEdit = false,
			$editLink = $( '#ca-edit a' );
		if ( $editLink.length ) {
			canEdit = true;
		}

		// Prepare messages
		var $infoHtml = $( '<div>' ).html( $.parseHTML( wb$i18n.htmlInfo ) );
		if ( !mw.config.get( 'wgUserName' ) ) {
			$infoHtml.append( $( '<p>' ).html( $.parseHTML( wb$i18n.htmlIpWarn ) ) );
		}

		// OOjs window
		var windowManager = new OO.ui.WindowManager();
		var infoDialog = new OO.ui.MessageDialog();
		$( 'body' ).append( windowManager.$element );
		windowManager.addWindows( [ infoDialog ] );
		windowManager.openWindow( infoDialog, {
			title: wb$i18n.title,
			message: $infoHtml,
			actions: [
				{ label: wb$i18n.btnFix, action: 'edit', flags: 'progressive' },
				{ label: wb$i18n.btnReport, action: 'report', flags: 'progressive' },
				{ label: wb$i18n.btnCancel },
			],
			size: 'large',
		} ).then( function ( opened ) {
			opened.then( function ( closing, data ) {
				if ( data && data.action === 'edit' ) {
					// Go to edit page
					var $editLink = $( '#ca-edit a' ),
						editUrl = mw.config.get( 'wgArticlePath' ).replace( /\$1/, wb$bugsPage );
					if ( $editLink.length ) {
						editUrl = $editLink.attr( 'href' );
					}
					window.location.assign( editUrl );

				} else if ( data && data.action === 'report' ) {
					// Prepare form
					var inputPage = new OO.ui.TextInputWidget( {
						placeholder: wb$i18n.fldPage,
						value: mw.config.get( 'wgPageName' ).replace( /_/g, ' ' ),
						disabled: wb$isValidPageName( mw.config.get( 'wgPageName' ) ) && !mw.config.get( 'wgNamespaceNumber' ),
					} );

					var inputText = new OO.ui.MultilineTextInputWidget( {
						placeholder: wb$i18n.fldTextInfo,
						rows: 5
					} );

					var inputCaptcha = new OO.ui.TextInputWidget( {
						placeholder: wb$i18n.fldCaptcha,
					} );

					var panelCaptcha = new OO.ui.FieldLayout( inputCaptcha, {
						label: wb$i18n.fldCaptcha,
					} );
					panelCaptcha.toggle( false );

					var imageCaptcha = new OO.ui.ToggleWidget();
					imageCaptcha.$element.css( 'text-align', 'right' );
					imageCaptcha.$element.append( $( '<img>' )
						.attr( 'id', 'wikibugs-captcha-img' )
						.attr( 'width', 249 )
						.attr( 'height', 63 ) );
					imageCaptcha.toggle( false );

					var inputSign = new OO.ui.TextInputWidget( {
						placeholder: wb$i18n.fldSign,
						value: mw.config.get( 'wgUserName' ) || wb$i18n.fldSignIP,
						disabled: true
					} );

					var fieldset = new OO.ui.FieldsetLayout( {
						classes: [ 'container' ],
					} );

					fieldset.addItems( [
						new OO.ui.FieldLayout( inputPage, {
							label: wb$i18n.fldPage,
							align: 'top'
						} ),
						new OO.ui.FieldLayout( inputText, {
							label: wb$i18n.fldText,
							align: 'top'
						} ),
						panelCaptcha,
						imageCaptcha,
						new OO.ui.FieldLayout( inputSign, {
							label: wb$i18n.fldSign,
						} ),
					] );

					// Add the FieldsetLayout to a FormLayout.
					var form = new OO.ui.FormLayout( {
						items: [ fieldset ],
					} );

					// Open window with report form
					function ReportDialog( config ) {
						ReportDialog.parent.call( this, config );
					}
					OO.inheritClass( ReportDialog, OO.ui.MessageDialog );
					ReportDialog.static.name = 'reportDialog';
					ReportDialog.prototype.getActionProcess = function ( action ) {
						var dialog = this;
						if ( action ) {
							return new OO.ui.Process( function () {
								if ( action === 'send' ) {
									dialog.getActions().setAbilities({ send: false });
									
									// Send message
									var content = inputText.getValue();
									if ( content === '' || content.length < 20 || !content.match( ' ' ) ) {
										mw.notify( wb$i18n.alertShort );
										inputText.focus();
										dialog.getActions().setAbilities({ send: true });
										return;
									}

									var page = inputPage.getValue()
											.replace( /^https?:\/\/he\.wikipedia\.org\/wiki\/(.+)$/, '$1' )
											.replace( /_/g, ' ' );
									page = decodeURIComponent( page );

									var section;

									if ( page === mw.config.get( 'wgPageName' ).replace( /_/g, ' ' ) &&
										wb$isValidPageName( mw.config.get( 'wgPageName' ) )
									) {
										if ( mw.config.get( 'wgNamespaceNumber' ) === 6 ) {
											section = '[[:' + wb$i18n.nsFile + mw.config.get( 'wgTitle' ) + '|' + window.wgTitle + ']]';
											content = '[[' + wb$i18n.nsFile + mw.config.get( 'wgTitle' ) +
													'|thumb|left|100px]]\n* ' + content + '\n{{clear}}';
										} else {
											var re = new RegExp( '^('+ wb$i18n.nsCat + '|'+ wb$i18n.nsFile + '|\\/)' );
											section = page.replace( re, ':$1' );
											section = '[[' + section + ']]';
										}
									} else {
										page = page
											.replace( /\[\[([^\[\]\|]+)\|[^\[\]\|]+\]\]/g, '$1' )
											.replace( /[\[\]\|]/g, '' )
											.replace( /^\s+/g, '' )
											.replace( /\s+$/g, '' );

										if ( !wb$isValidPageName( page ) ) {
											mw.notify( wb$i18n.alertNoPage );
											if ( wb$isValidPageName( mw.config.get( 'wgPageName' ) ) ) {
												inputPage.setValue( mw.config.get( 'wgPageName' ) );
											} else {
												inputPage.setValue( '' );
												inputPage.focus();
											}
											dialog.getActions().setAbilities({ send: true });
											return;
										}
										if ( page.indexOf( ':' ) > 0 ) {
											section = '[[:' + page + ']]';
										} else {
											section = '[[' + page + ']]';
										}
									}

									content += wb$i18n.msgSign;
									content += ' ~~' + '~~';

									dialog.getActions().get()[0].pushPending();

									var data = {
										format: 'json',
										action: 'edit',
										title: wb$bugsPage,
										section: 'new',
										sectiontitle: section,
										summary: '/* ' + page + ' */ ' + wb$i18n.newTopic,
										text: content.trim(),
										token: mw.user.tokens.get( 'csrfToken' )
									};
									var captchaId = $( '#wikibugs-captcha-img' ).data( 'id' );
									if ( captchaId ) {
										data.captchaid = captchaId;
										data.captchaword = inputCaptcha.getValue().trim();
									}

									$.ajax( {
										url: '/w/api.php',
										type: 'POST',
										data: data,
										success: function ( xhr ) {
											if ( xhr && xhr.edit && xhr.edit.result === 'Success' ) {
												// Success
												var url = mw.config.get( 'wgArticlePath' )
														.replace( /\$1/, wb$bugsPage )
														.replace( / /g, '_' );
												page = page.replace( / /g, '_' );
												window.location.href = url + '#' + page;
											} else if ( xhr &&
												xhr.edit &&
												xhr.edit.captcha &&
												xhr.edit.captcha.type === 'image'
											) {
												// Captcha
												$( '#wikibugs-captcha-img' )
													.attr( 'src', xhr.edit.captcha.url )
													.data( 'id', xhr.edit.captcha.id );
												imageCaptcha.toggle( true );
												inputCaptcha.setValue( '' );
												panelCaptcha.toggle( true );
												dialog.getActions().get()[0].popPending();
												mw.notify( wb$i18n.alertCaptcha );
												dialog.getActions().setAbilities({ send: true });
											} else {
												// Error
												dialog.getActions().get()[0].popPending();
												mw.notify( wb$i18n.alertError );
												dialog.getActions().setAbilities({ send: true });
											}
										},
										error: function() {
											dialog.getActions().get()[0].popPending();
											mw.notify( wb$i18n.alertError );
											dialog.getActions().setAbilities({ send: true });
										}
									} );
								} else {
									dialog.close();
								}
							} );
						}
						return ReportDialog.parent.prototype.getActionProcess.call( this, action );
					};

					var reportDialog = new ReportDialog();
					windowManager.addWindows( [ reportDialog ] );

					windowManager.openWindow( reportDialog, {
						title: wb$i18n.title,
						message: form.$element,
						actions: [
							{ label: wb$i18n.btnSend, action: 'send', flags: 'progressive' },
							{ label: wb$i18n.btnCancel },
						],
						size: 'medium',
					} );
				}
			} );
		} );
	};

	// Click event
	$( function() {
		$( '#n-bug_in_article a' ).click( function ( e ) {
			e.preventDefault();
			mw.loader.using( [
				'mediawiki.api',
				'oojs-ui-core',
				'oojs-ui-widgets',
				'oojs-ui-windows'
			] ).then( wb$popWikibug );
		} );
	} );

}( mediaWiki, jQuery ) );