ব্যবহারকারী:Ahm masum/common.js

উইকিপিডিয়া, মুক্ত বিশ্বকোষ থেকে

লক্ষ্য করুন: প্রকাশ করার পর, পরিবর্তনগুলো দেখতে আপনাকে আপনার ব্রাউজারের ক্যাশে পরিষ্কার করার প্রয়োজন হতে পারে।

  • ফায়ারফক্স / সাফারি: পুনরায় লোড-এ ক্লিক করার সময় শিফট টিপে ধরে রাখুন, অথবা হয় Ctrl-F5 বা Ctrl-R টিপুন (ম্যাকে ⌘-R টিপুন)
  • গুগল ক্রোম: Ctrl-Shift-R (ম্যাকে ⌘-Shift-R) টিপুন
  • ইন্টারনেট এক্সপ্লোরার / এজ: Ctrl ধরে রাখা অবস্থায় Refresh-এ ক্লিক করুন, অথবা Ctrl-F5 টিপুন
  • অপেরা: Ctrl-F5 টিপুন।
mw.loader.load("//bn.wikipedia.org/w/index.php?title=User:Yahya/mobilemenu.js&action=raw&ctype=text/javascript");
//[[User:Yahya/mobilemenu.js]]
mw.loader.load('//bn.wikipedia.org/w/index.php?title=ব্যবহারকারী:Jayantanth/closeAFD.js&action=raw&ctype=text/javascript')
/* পাতার লিঙ্কগুলোকে রঙ্গিন করবে , যাতে পুনঃনির্দেশ , বহিঃসংযোগ ও অন্যান্য পাতাগুলোকে সহজে চেনা যায় । যায় । (মূল  স্ক্রিপ্ট পাতাঃ https://en.wikipedia.org/wiki/User:Anomie/linkclassifier  )েনা  
importScript('User:Anomie/linkclassifier.js'); // Linkback: [[User:Anomie/linkclassifier.js]] */
var LinkClassifier = {
	/* This object maps classes to the categories for which to apply them. Values may be an array of strings or a regex. */
	cats: {
		deletion: [
			'Category:All articles proposed for deletion',
			'Category:All books proposed for deletion',
			'Category:All categories for discussion',
			'Category:All disputed non-free Wikipedia files',
			'Category:All orphaned non-free use Wikipedia files',
			'Category:All redirects for discussion',
			'Category:All replaceable non-free use Wikipedia files',
			'Category:All Wikipedia files with no non-free use rationale',
			'Category:All Wikipedia files with unknown copyright status',
			'Category:All Wikipedia files with unknown source',
			'Category:Articles for deletion',
			'Category:Articles for deletion using wrong syntax',
			'Category:Articles on deletion review',
			'Category:Articles to be merged after an Articles for deletion discussion',
			'Category:Candidates for speedy deletion',
			'Category:Candidates for undeletion',
			'Category:Categories for conversion',
			'Category:Categories for deletion',
			'Category:Categories for listifying',
			'Category:Categories for merging',
			'Category:Categories for renaming',
			'Category:Categories for speedy renaming',
			'Category:Categories to be listified then deleted',
			'Category:Duplicate or hardcoded templates awaiting deletion',
			'Category:Items pending OTRS confirmation of permission for over 30 days',
			'Category:Miscellaneous pages for deletion',
			'Category:Templates for deletion',
			'Category:Wikipedia files for discussion'
		].sort(),
		disambiguation: [
			'Category:All disambiguation pages'
		].sort(),
		'set-index': [
			'Category:All set index articles'
		].sort(),
		'featured-content': [
			'Category:Featured articles',
			'Category:Featured lists',
			'Category:Featured pictures',
			'Category:Featured sounds',
			'Category:Featured videos',
			'Category:Featured portals'
		].sort(),
		'good-content': [
			'Category:Good articles'
		].sort(),
		'soft-redirect-cats': [
			'Category:Wikipedia soft redirected categories'
		].sort(),
		'spoken-articles': [
			'Category:Spoken articles'
		].sort(),
		stubcls: /^Category:.* stubs$/,
		'nonfree-media': [
			'Category:All non-free media'
		].sort(),
		unprintworthy: [
			'Category:Unprintworthy redirects',
			'Category:Middle-earth redirects from redundant titles'
		].sort(),
		'unprintworthy-shortcut': [
			'Category:Redirects from shortcuts'
		].sort()
	},

	/* This object maps page props to CSS classes for which to apply them. Values may be an array of strings or a function returning such. */
	props: {
		disambiguation: [
			'disambiguation'
		]
	},

	/* This regex matches page titles to be marked as intentional links to disambiguation pages */
	intentionaldab: / \(disambiguation\)$/,

	/* Was it run already? */
	wasRun: false,

	onAjaxError: function ( xhr, textStatus, errorThrown ) {
		throw new Error( 'AJAX error: ' + textStatus + ' ' + errorThrown );
	},

	callback: function ( r ) {
		var i, j, k, k2, v, node, alist, q, prefix, seen, cls,
			redir = {},
			redirlist = [],
			cats = {},
			missing = {},
			classes = {};

		if ( !r.query ) {
			if ( !window.console || !$.isFunction( window.console.error ) ) {
				throw new Error( 'Bad response' );
			}
			window.console.error( 'Bad response', r );
			return;
		}
		if ( r['query-continue'] ) {
			q = this.rawdata;
			for ( k in r['query-continue'] ) {
				for ( k2 in r['query-continue'][k] ) {
					q[k2] = r['query-continue'][k][k2];
				}
			}
			$.ajax( {
				url: mw.util.wikiScript( 'api' ),
				dataType: 'json',
				type: 'POST',
				data: q,
				rawdata: this.rawdata,
				success: LinkClassifier.callback,
				error: LinkClassifier.onAjaxError
			} );
		}
		r = r.query;

		node = document.getElementById( 'wikiPreview' );
		if ( !node ) {
			node = document.getElementById( 'bodyContent' );
		}
		if ( !node ) {
			throw new Error( 'Huh? No body content?' );
		}
		alist = node.getElementsByTagName( 'A' );
		if ( alist.length === 0 ) {
			return;
		}

		if ( r.redirects ) {
			for ( i = r.redirects.length - 1; i >= 0; i-- ) {
				redir[r.redirects[i].from] = r.redirects[i].to;
				redirlist.push( r.redirects[i].from );
			}
		}
		if ( redirlist.length > 0 ) {
			q = {
				format: 'json',
				action: 'query',
				titles: redirlist.join( '|' ),
				prop: 'categories|info',
				inprop: 'protection',
				cllimit: 'max',
				rawcontinue: 1
			};
			$.ajax( {
				url: mw.util.wikiScript( 'api' ),
				dataType: 'json',
				type: 'POST',
				data: q,
				rawdata: q,
				success: LinkClassifier.callback,
				error: LinkClassifier.onAjaxError
			} );
		}

		prefix = this.rawdata.redirects ? '' : 'redir-';
		if ( r.pages ) {
			for ( i in r.pages ) {
				classes[r.pages[i].title] = [];
				missing[r.pages[i].title] = r.pages[i].missing !== undefined;
				if ( r.pages[i].categories ) {
					cats[r.pages[i].title] = r.pages[i].categories.map( function ( a ) {
						return a.title;
					} ).sort();
				}
				if ( r.pages[i].pageprops ) {
					for ( k in r.pages[i].pageprops ) {
						if ( !LinkClassifier.props[k] ) {
							continue;
						}
						v = LinkClassifier.props[k];
						if ( $.isFunction( v ) ) {
							v = v( r.pages[i].pageprops[k], k, r.pages[i].title );
						}
						classes[r.pages[i].title].push.apply( classes[r.pages[i].title], v );
					}
				}
				if ( r.pages[i].protection ) {
					seen = {};
					for ( j = r.pages[i].protection.length - 1; j >= 0; j-- ) {
						cls = prefix + 'protection-' + r.pages[i].protection[j].type + '-' + r.pages[i].protection[j].level;
						if ( !seen[cls] ) {
							seen[cls] = 1;
							classes[r.pages[i].title].push( cls );
						}
						if ( r.pages[i].protection[j].expiry === 'infinity' ) {
							cls += '-indef';
							if ( !seen[cls] ) {
								seen[cls] = 1;
								classes[r.pages[i].title].push( cls );
							}
						}
					}
				}
				if ( r.pages[i].flagged ) {
					if ( r.pages[i].lastrevid !== r.pages[i].flagged.stable_revid ) {
						classes[r.pages[i].title].push( 'needs-review' );
					}
				}
			}
		}
		Array.prototype.forEach.call( alist, function ( a ) {
			var cns, cls, m, i, j, pageCats, matchCats,
				$a = $( a );

			if ( a.wikipage === undefined ) {
				return;
			}
			if ( redir[a.wikipage] ) {
				$a.addClass( 'redirect' );
				a.wikipage = redir[a.wikipage];
				a.title = a.wikipage;
				cns = mw.config.get( 'wgCanonicalNamespace' );
				if ( a.wikipage === ( cns ? cns + ':' : '' ) + mw.config.get( 'wgTitle' ) ) {
					$a.addClass( 'self-redirect' );
				}
				if ( missing[a.wikipage] ) {
					$a.addClass( 'broken-redirect' );
				}
			}
			m = a.href.match( /#.*/ );
			if ( m && m[0].substr( 0, 10 ) !== '#cite_note' ) {
				a.title = a.title.replace( /#.*/, '' ) +
					m[0].replace( /_/g, ' ' ).replace( /\.([0-9A-F][0-9A-F])/gi, function ( x, n ) {
						return String.fromCharCode( parseInt( n, 16 ) );
					} );
			}
			if ( LinkClassifier.intentionaldab.test( a.origwikipage ) ) {
				$a.addClass( 'intentional-disambiguation' );
			}
			if ( classes[a.wikipage] ) {
				for ( j = classes[a.wikipage].length - 1; j >= 0; j-- ) {
					$a.addClass( classes[a.wikipage][j] );
				}
			}
			if ( a.wikipage !== a.origwikipage && classes[a.origwikipage] ) {
				for ( j = classes[a.origwikipage].length - 1; j >= 0; j-- ) {
					$a.addClass( classes[a.origwikipage][j] );
				}
			}

			pageCats = [];
			if ( cats[a.wikipage] ) {
				pageCats = pageCats.concat( cats[a.wikipage] );
			}
			if ( a.wikipage !== a.origwikipage && cats[a.origwikipage] ) {
				pageCats = pageCats.concat( cats[a.origwikipage] );
			}
			if ( pageCats.length > 0 ) {
				pageCats = pageCats.sort();
				for ( cls in LinkClassifier.cats ) {
					i = pageCats.length - 1;
					matchCats = LinkClassifier.cats[cls];
					if ( matchCats instanceof RegExp ) {
						while ( i >= 0 ) {
							if ( matchCats.test( pageCats[i] ) ) {
								$a.addClass( cls );
								break;
							}
							i--;
						}
					} else {
						j = matchCats.length - 1;
						while ( i >= 0 && j >= 0 ) {
							if ( pageCats[i] === matchCats[j] ) {
								$a.addClass( cls );
								break;
							}
							if ( pageCats[i] > matchCats[j] ) {
								--i;
							} else {
								--j;
							}
						}
					}
				}
			}
		} );
	},

	draftsCallback: function ( r ) {
		var i, node, alist,
			found = {};

		if ( !r.query ) {
			if ( !window.console || !$.isFunction( window.console.error ) ) {
				throw new Error( 'Bad response' );
			}
			window.console.error( 'Bad response', r );
			return;
		}
		r = r.query;

		node = document.getElementById( 'wikiPreview' );
		if ( !node ) {
			node = document.getElementById( 'bodyContent' );
		}
		if ( !node ) {
			throw new Error( 'Huh? No body content?' );
		}
		alist = node.getElementsByTagName( 'A' );
		if ( alist.length === 0 ) {
			return;
		}

		if ( r.pages ) {
			for ( i in r.pages ) {
				found[r.pages[i].title] = r.pages[i].missing === undefined;
			}
		}
		Array.prototype.forEach.call( alist, function ( a ) {
			if ( a.wikipage !== undefined && found['Draft:' + a.origwikipage] ) {
				$( a ).addClass( 'has-draft' );
			}
		} );
	},

	getPageName: function ( url ) {
		var t, m = url.match( /\/wiki\/([^?#]+)/ );
		if ( !m ) {
			m = url.match( /\/w\/index.php\?(?:.*&)?title=([^&#]+)/ );
		}
		if ( !m ) {
			return '';
		}
		t = decodeURIComponent( m[1] ).replace( /_/g, ' ' );
		if ( t.substr( 0, 6 ) === 'Image:' ) {
			t = 'File:' + t.substr( 6 );
		}
		if ( t.substr( 0, 11 ) === 'Image talk:' ) {
			t = 'File talk:' + t.substr( 6 );
		}
		if ( t.substr( 0, 8 ) === 'Special:' ) {
			t = '';
		}
		return t;
	},

	classifyChildren: function ( node ) {
		mw.loader.using( [ 'mediawiki.util', 'mediawiki.user' ], function () {
			var alist, titles, draftTitles, re, self, props, i, k;

			LinkClassifier.wasRun = true;
			alist = node.getElementsByTagName( 'A' );
			if ( !alist.length ) {
				return;
			}
			self = LinkClassifier.getPageName( location.href );
			titles = Array.prototype.map.call( alist, function ( a ) {
				a.wikipage = '';
				if ( /(^|\s)(external|extiw)(\s|$)/.test( a.className ) ) {
					return '';
				}
				if ( !/(^|\s)(image)(\s|$)/.test( a.className ) ) {
					a.className += ' nonimage';
				}
				a.wikipage = LinkClassifier.getPageName( a.href );
				if ( a.wikipage === self ) {
					a.wikipage = '';
				}
				a.origwikipage = a.wikipage;
				return a.wikipage;
			} ).sort().filter( function ( e, i, a ) {
				return e !== '' && ( i === 0 || a[i - 1] !== e );
			} );

			re = [];
			for ( k in mw.config.get( 'wgNamespaceIds' ) ) {
				if ( k !== '' ) {
					re.push( k.replace( /_/g, ' ' ) );
				}
			}
			re = new RegExp( '^(' + re.join( '|' ) + '):', 'i' );
			draftTitles = [];
			for ( i = titles.length - 1; i >= 0; i-- ) {
				if ( !re.test( titles[i] ) ) {
					draftTitles.push( 'Draft:' + titles[i] )
				}
			}

			props = [];
			for ( k in LinkClassifier.props ) {
				props.push( k );
			}

			function processLinks( limit ) {
				var q;
				while ( titles.length > 0 ) {
					q = {
						format: 'json',
						action: 'query',
						titles: titles.splice( 0, limit ).join( '|' ),
						prop: 'categories|pageprops|info|flagged',
						redirects: 1,
						cllimit: 'max',
						inprop: 'protection',
						rawcontinue: 1
					};
					if ( props.length <= limit ) {
						q.ppprop = props.join( '|' );
					}
					$.ajax( {
						url: mw.util.wikiScript( 'api' ),
						dataType: 'json',
						type: 'POST',
						data: q,
						rawdata: q,
						success: LinkClassifier.callback,
						error: LinkClassifier.onAjaxError
					} );
				}

				while ( draftTitles.length > 0 ) {
					q = {
						format: 'json',
						action: 'query',
						titles: draftTitles.splice( 0, limit ).join( '|' ),
						rawcontinue: 1
					};
					$.ajax( {
						url: mw.util.wikiScript( 'api' ),
						dataType: 'json',
						type: 'POST',
						data: q,
						rawdata: q,
						success: LinkClassifier.draftsCallback,
						error: LinkClassifier.onAjaxError
					} );
				}
			}

			if ( titles.length <= 100 ) {
				// Not worth querying the API to see if the user has apihighlimits
				processLinks( 50 );
			} else {
				// Note mw.user.getRights queries the API
				mw.user.getRights( function ( rights ) {
					processLinks( ( rights.indexOf( 'apihighlimits' ) >= 0 ) ? 500 : 50 );
				} );
			}
		} );
	},

	onLoad: function () {
		if ( window.LinkClassifierOnDemand ) {
			return;
		}
		if ( window.AJAXPreview ) {
			window.AJAXPreview.AddOnLoadHook( LinkClassifier.classifyChildren );
		}
		LinkClassifier.onDemand();
	},

	onDemand: function () {
		mw.hook( 'LinkClassifier' ).fire( this );
		var node = document.getElementById( 'wikiPreview' );
		if ( !node ) {
			node = document.getElementById( 'bodyContent' );
		}
		if ( node ) {
			LinkClassifier.classifyChildren( node );
		}
	},

	rerun: function () {
		if ( LinkClassifier.wasRun ) {
			LinkClassifier.onDemand();
		}
	}
};

if ( !window.LinkClassifierOnDemand ) {
	$( document ).ready( LinkClassifier.onLoad );
}
/* ------------------- শেষ   শেষ  শেষ ----- User:Anomie/linkclassifier শেষ  --শেষ    ------ শেষ   ------------------------------------*/

/* সম্পাদনা করার সময় প্লেইন টেক্সট  plaintext [[wikilinks]], {{transclusions}}  ও  ইউ আর এল কে ক্লিকযোগ্য করবে । পাতার ইতিহাস ও .js পাতাতেও ।(মূল  স্ ক্রিপ্টUser:Lenore/autolinkssifier    */

$(function () {

    var autolinkCronoSpecial = mw.config.get('wgCanonicalSpecialPageName') == "Recentchanges" || /*
    */ mw.config.get('wgCanonicalSpecialPageName') == "Watchlist" || /*
    */ mw.config.get('wgCanonicalSpecialPageName') == "Recentchangeslinked" || /*
    */ mw.config.get('wgCanonicalSpecialPageName') == "Newpages" || /*
    */ mw.config.get('wgCanonicalSpecialPageName') == "Log" || /*
    */ mw.config.get('wgCanonicalSpecialPageName') == "Contributions";
    // Special crono pages where this script is enabled

    if ((typeof(autolinkMySpecialPage) != "undefined"))
       autolinkCronoSpecial = autolinkCronoSpecial || mw.config.get('wgPageName') == autolinkMySpecialPage;

    if (mw.config.get('wgCanonicalNamespace') == "Special" && !autolinkCronoSpecial) {

       return; // Disabled in the other special pages

    }

    if (typeof(autolinkParseLink) == 'undefined') { 

       autolinkParseLink = true; // Parse links in all cases, even in diffs. To be disabled when wikEd is active

    }

/* ---------------------------------------- Variables ------------------------------------------- */

    var autolinkDiff = location.href.indexOf('&diff=') != -1;
    // It says if I'm in a diff page

    var autolinkCrono = (mw.config.get('wgAction') == 'history' || autolinkCronoSpecial);
    // It says if I'm in a history page

    var autolinkEdit = ($.inArray(mw.config.get('wgAction'), ['edit' , 'submit']) !== -1);
    // It says if I'm in an edit or submit page
	
	var autolinkColor; // links color

    var autolinkTargetDiv = [];

    if (autolinkDiff) { // in diff pages
		if (autolinkParseLink) { // without wikEd
			autolinkTargetDiv[0] = $('.diff');

			autolinkTargetDiv[1] = $('.firstrevisionheader');
			autolinkColor = 'inherit'; // not coloured links
		} else { // with wikEd
			autolinkTargetDiv[0] = $('.comment');
			autolinkColor = ''; // coloured links 
		}
    } else if (autolinkCrono || autolinkEdit) { // in comments
		autolinkTargetDiv[0] = $('.comment');
		autolinkColor = ''; // coloured links
	} else { // in code sections
           autolinkTargetDiv[0] = $('source');
           autolinkTargetDiv[1] = $('.javascript');
           autolinkTargetDiv[2] = $('.source-javascript');
           autolinkTargetDiv[3] = $('.css');
           autolinkTargetDiv[4] = $('.source-css');
	   autolinkColor = ''; // coloured links
    }

/* ------------------------------------------ Regex --------------------------------------------- */

	var autolinkRegexTl;
	var autolinkRegexURL;
	
	var autolinkRegexURLinWcodeWoLabel;
	var autolinkRegexSubstinWcodeWoLabel;
	var autolinkRegexURLinWcodeWithLabel;
	var autolinkRegexSubstinWcodeWithLabel;
	var autolinkRegexOtherPages;
	var autolinkRegexSubstOtherPages;	
	var autolinkRegexTemplate;
	var autolinkRegexSubstTemplate;
	var autolinkRegexWlink1;
	var autolinkRegexSubstWlink1;
	var autolinkRegexWlink2;
	var autolinkRegexSubstWlink2;
	
	var autolinkRegexInternalURL;
	var autolinkRegexImportScript;

        var autolinkActivateHTML = false;

	/*   ------------------------------------------------------------------------------------------ */

	autolinkRegexTl = /([^{]{{2}\s*[Tt]l\|)([^[\]{}|:<>\n]+)/g;
    // For {{tl}}
	
	autolinkRegexURL = /((?:[^"\[]|[^=]")(?:<span class="diffchange">)?)((?:https?|ftps?):\/\/[\w._\/\\~%\-+&#?!=()@:]+?)(?=(?:<\/span>)?[\s|)\]}'"])/g;
    // External links (no wikicode)

// Regex for diffs

        autolinkRegexURLinWcodeWoLabel = /((?:[^\[]|^)\[\s*(?:<\/span>)?\s*(?:<span class="diffchange">)?\s*)((?:https?|ftps?):\/\/[\w._\/\\~%\-+&#?!=()@:]+)((?:<\/span>)?(?:<span class="diffchange">)?)([\w._\/\\~%\-+&#?!=()@:]*)((?:<\/span>)?(?:<span class="diffchange">)?)([\w._\/\\~%\-+&#?!=()@:]*)([^\]\n]*\])/gm;
		autolinkRegexSubstinWcodeWoLabel = '$1<a class="external autolink" style="color:' + autolinkColor + '" href="$2$4$6">$2</a>$3<a class="external autolink" style="color:' + autolinkColor + '" href="$2$4$6">$4</a>$5<a class="external autolink" style="color:' + autolinkColor + '" href="$2$4$6">$6</a>$7';
		// External links in diff pages, wikicode without label

		autolinkRegexURLinWcodeWithLabel = autolinkRegexURLinWcodeWoLabel;
		autolinkRegexSubstinWcodeWithLabel = autolinkRegexSubstinWcodeWoLabel;
		// External links in diff pages, wikicode with label
		
		autolinkRegexOtherPages = /((?:[^{]|^)\{{2}\s*(?:<\/span>)?\s*(?:<span class="diffchange">)?\s*(?:(?:[Ss][Uu][Bb][Ss][Tt]|[Mm][Ss][Gg]|[Mm][Ss][Gg][Nn][Ww])\s*:)?\s*(?:<\/span>)?\s*(?:<span class="diffchange">)?\s*)((?:[Dd]iscussion[ei] ?)?\s*(?:[Ss]peciale?|[Ww](?:ikipedia|P)|[Tt]emplate|[Uu](?:ser|tente)|[Pp]ortale?|[Pp]rogetto)?\s*(?: ?[Tt]alk)?\s*:[^[\]{}|:<>\n]+)((?:<\/span>)?(?:<span class="diffchange">)?)([^[\]{}|:<>\n]*)((?:<\/span>)?(?:<span class="diffchange">)?)([^[\]{}|:<>\n]*)(\||}{2})/gm;
		autolinkRegexSubstOtherPages = '$1<a class="autolink" style="color:' + autolinkColor + '" href="/wiki/$2$4$6">$2</a>$3<a class="autolink" style="color:' + autolinkColor + '" href="/wiki/$2$4$6">$4</a>$5<a class="autolink" style="color:' + autolinkColor + '" href="/wiki/$2$4$6">$6</a>$7';
		// Other pages included in diff pages
	   
		autolinkRegexTemplate = /((?:[^{]|^)\{{2}\s*(?:<\/span>)?\s*(?:<span class="diffchange">)?\s*(?:(?:[Ss][Uu][Bb][Ss][Tt]|[Mm][Ss][Gg]|[Mm][Ss][Gg][Nn][Ww])\s*:)?\s*(?:<\/span>)?\s*(?:<span class="diffchange">)?)([^[\]{}|:<>\n]+)((?:<\/span>)?(?:<span class="diffchange">)?)([^[\]{}|:<>\n]*)((?:<\/span>)?(?:<span class="diffchange">)?)([^[\]{}|:<>\n]*)(\||}{2}|:)/gm;
		autolinkRegexSubstTemplate = '$1<a class="autolink" style="color:' + autolinkColor + '" href="/wiki/Template:$2$4$6">$2</a>$3<a class="autolink" style="color:' + autolinkColor + '" href="/wiki/Template:$2$4$6">$4</a>$5<a class="autolink" style="color:' + autolinkColor + '" href="/wiki/Template:$2$4$6">$6</a>$7';
		// Templates in diff pages   
		
		autolinkRegexWlink1 = /(\[{2}\s*(?:<\/span>)?\s*(?:<span class="diffchange">)?\s*)([^[\]{}|<>\n]+)((?:<\/span>)?(?:<span class="diffchange">)?)([^[\]{}|<>\n]*)((?:<\/span>)?(?:<span class="diffchange">)?)([^[\]{}|<>\n]*)((?:[^\]\n]|\][^\]])*\]{2})/g;
		autolinkRegexSubstWlink1 = '$1<a class="autolink" style="color:' + autolinkColor + '" href="/wiki/$2$4$6">$2</a>$3<a class="autolink" style="color:' + autolinkColor + '" href="/wiki/$2$4$6">$4</a>$5<a class="autolink" style="color:' + autolinkColor + '" href="/wiki/$2$4$6">$6</a>$7';
		// Wikilinks in diff pages
		
		autolinkRegexWlink2 = autolinkRegexWlink1;
		autolinkRegexSubstWlink2 = autolinkRegexSubstWlink1;

// Regex for comments or code sections

    if (!autolinkDiff || (autolinkDiff && !autolinkParseLink)) {

      autolinkRegexURLinWcodeWoLabel = /([^\[]|^)\[\s*((?:https?|ftps?):\/\/[\w._\/\\~%\-+&#?!=()@:]+)\s*\]/gm;
      autolinkRegexSubstinWcodeWoLabel = '$1<a class="external autolink" style="color:' + autolinkColor + '" href="$2">$2</a>';
      // External links in comments or code sections, wikicode without label

      autolinkRegexURLinWcodeWithLabel = /([^\[]|^)\[\s*((?:https?|ftps?):\/\/[\w._\/\\~%\-+&#?!=()@:]+)\s+([^\n]+?)\s*\]/gm;
      autolinkRegexSubstinWcodeWithLabel = '$1<a class="external autolink" style="color:' + autolinkColor + '" href="$2">$3</a>';
      // External links in comments or code sections, wikicode with label (the URL will not be visible)
	  
	  autolinkRegexOtherPages = /((?:[^{]|^)\{{2}\s*(?:(?:[Ss][Uu][Bb][Ss][Tt]|[Mm][Ss][Gg]|[Mm][Ss][Gg][Nn][Ww])\s*:)?\s*)((?:[Dd]iscussion[ei] ?)?\s*(?:[Ss]peciale?|[Ww](?:ikipedia|P)|[Tt]emplate|[Uu](?:ser|tente)|[Pp]ortale?|[Pp]rogetto)?\s*(?: ?[Tt]alk)?\s*:[^[\]{}|:<>\n]+)(\||}{2})/gm;
	  autolinkRegexSubstOtherPages = '$1<a class="autolink" style="color:' + autolinkColor + '" href="/wiki/$2">$2</a>$3';
	  // Other pages included in comments or code sections
	  
	  autolinkRegexTemplate = /((?:[^{]|^)\{{2}\s*(?:(?:[Ss][Uu][Bb][Ss][Tt]|[Mm][Ss][Gg]|[Mm][Ss][Gg][Nn][Ww])\s*:)?\s*)([^[\]{}|:<>\n]+)(\||}{2}|:)/gm;
	  autolinkRegexSubstTemplate = '$1<a class="autolink" style="color:' + autolinkColor + '" href="/wiki/Template:$2">$2</a>$3';
	  // Templates in comments or code sections	  

	  autolinkRegexWlink1 = /\[{2}\s*([^[\]{}|<>\n]+?)\s*\|\s*(.+?)\s*\]{2}/g;
      autolinkRegexSubstWlink1 = '<a class="autolink" style="color:' + autolinkColor + '" href="/wiki/$1">$2</a>';
	  // Wikilinks in code sections, with label
	  
	  autolinkRegexWlink2 = /\[{2}\s*([^[\]{}|<>\n]+?)\s*\|?\s*\]{2}/g;
      autolinkRegexSubstWlink2 = '<a class="autolink" style="color:' + autolinkColor + '" href="/wiki/$1">$1</a>';
	  // Wikilinks in code sections, without label
	  
	  autolinkActivateHTML = true;
	  // Activate some HTML (inline) and wikicode for bold and italic

    }

    autolinkRegexInternalURL = /([^=])('|"|\s)((?:\/?w\/index\.php\?|\/?wiki\/)[\w._\/\\~%\-+&#?!=()@:]+)\2/g;
    // External links (no wikicode, under wgServer)

    autolinkRegexImportScript = /([Ii]mport[Ss]cript(?:<span class="br0">)?\((?:<\/span><span class="st0">)?)('|")([^[\]{}|<>\n]+?)(\2(?:<\/span><span class="br0">)?\)(?:<\/span>)?)/g;
    // ImportScript

/*   ---------------------------------------------------------------------------------------------- */

    for (i=0; i<autolinkTargetDiv.length; i++) {

       for (j=0; j<autolinkTargetDiv[i].length; j++) {

			var autolinkContent = autolinkTargetDiv[i][j].innerHTML;

			autolinkContent = autolinkContent.replace(/&lt;/g, '&shy;<&shy;');
			autolinkContent = autolinkContent.replace(/&gt;/g, '&shy;>&shy;');
			// &amp;lt; to &amp;shy;<&amp;shy; and &amp;gt; to &amp;shy;>&amp;shy; (&amp;shy; is a marker)

			autolinkContent = autolinkContent.replace(/&amp;/g, '&');
			// &amp;amp; to &
			
			/* ----------------------------------------------------------------------------------- */

			autolinkContent = autolinkContent.replace(autolinkRegexTl, '$1<a class="autolink" style="color:' + autolinkColor + '" href="/wiki/Template:$2">$2</a>');
			// For {{tl}}: make his argument into link

			autolinkContent = autolinkContent.replace(autolinkRegexURL, '$1<a class="external autolink" style="color:' + autolinkColor + '" href="$2">$2</a>'); 
			// Parse inactive external links (no wikicode)

			autolinkContent = autolinkContent.replace(autolinkRegexURLinWcodeWoLabel, autolinkRegexSubstinWcodeWoLabel);
			// Make external links in wikicode without label into links


			autolinkContent = autolinkContent.replace(autolinkRegexURLinWcodeWithLabel, autolinkRegexSubstinWcodeWithLabel);
			// Make external links in wikicode with label into links
			
			autolinkContent = autolinkContent.replace(autolinkRegexOtherPages, autolinkRegexSubstOtherPages);
			// Make other pages included code into links

			autolinkContent = autolinkContent.replace(autolinkRegexTemplate, autolinkRegexSubstTemplate);
			autolinkContent = autolinkContent.replace(/href\="\/wiki\/Template\:#/g, 'href="/wiki/Help:');
			// Make template code into links

			autolinkContent = autolinkContent.replace(autolinkRegexWlink1, autolinkRegexSubstWlink1);
			autolinkContent = autolinkContent.replace(autolinkRegexWlink2, autolinkRegexSubstWlink2);
			// Make wikilink code into links

			autolinkContent = autolinkContent.replace(autolinkRegexInternalURL, '$1$2<a class="external autolink" style="color:' + autolinkColor + '" href="' + mw.config.get('wgServer') + '$3">$3</a>$2');
			// Parse inactive external links (no wikicode, under wgServer)

			autolinkContent = autolinkContent.replace(autolinkRegexImportScript, '$1$2<a class="autolink" style="color:' + autolinkColor + '" href="/wiki/$3">$3</a>$4');
			// Parse ImportScript

			/* ----------------------------------------------------------------------------------- */
			
			autolinkContent = autolinkContent.replace(/&shy;<&shy;/g, '&lt;');
			autolinkContent = autolinkContent.replace(/&shy;>&shy;/g, '&gt;');
			// &amp;shy;<&amp;shy; to &amp;lt; and &amp;shy;>&amp;shy; to &amp;gt; (revert)
			
			if (autolinkActivateHTML) {
		 
				autolinkContent = autolinkContent.replace(/&lt;(span|b|i|strong|small|tt|del|s|u|sub|sup)&gt;(.*?)&lt;\/(\1)&gt;/g, '<$1>$2</$3>');
				autolinkContent = autolinkContent.replace(/([^']|^)'{3}(.+?)'{3}([^']|$)/gm, '$1<b>$2</b>$3');
				autolinkContent = autolinkContent.replace(/([^']|^)'{2}(.+?)'{2}([^']|$)/gm, '$1<i>$2</i>$3');
			
                                if (autolinkCrono || autolinkEdit)
                                	autolinkContent = autolinkContent.replace(/<i>(.*?)<\/i>/g, '<span title="italic" style="border: 1px solid silver; padding: 2px;">$1</span>');
                                // I'm in a comment field (italic)

				}

                        if (autolinkDiff && autolinkParseLink) {
                        	autolinkContent = autolinkContent.replace(/<a [^>]+><\/a>/g, ''); // Clean
                                autolinkContent = autolinkContent.replace(/([^\[]|^)\[\s*(<a [^>]+>)(?:https?|ftps?):\/\/[\w._\/\\~%\-+&#?!=()@:]+(<\/a>)\s+([^\]\n]+)\]/gm, '$1$2$4$3');
                                autolinkContent = autolinkContent.replace(/([^\[]|^)\[\s*(<a [^>]+>)((?:https?|ftps?):\/\/[\w._\/\\~%\-+&#?!=()@:]+)(<\/a>)\s*\]/gm, '$1$2$3$4');
                        }

			autolinkTargetDiv[i][j].innerHTML = autolinkContent; // Write it back

       }

    }

});

// [[বিষয়শ্রেণী:উইকিপিডিয়া স্ক্রিপ্ট|Autolink]]