MediaWiki:Gadget-codeBacklinks.js

From Lotro-Wiki.com
Jump to navigation Jump to search

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
// <nowiki>
( function ( mw, $ ) {
	var PCM = mw.config.get( 'wgPageContentModel' );
	$( 'pre.source-' + PCM ).find( 'span.co1, span.coMULTI' ).each( function() {
		var codeComment = $( this ).html().substr( $( this ).html().indexOf( '[[' ) );
		var wikiLinkPipe = '';
		var extraLinks =  '';
		while ( codeComment.indexOf( '[[' ) !== -1 && codeComment.indexOf( ']]' ) !== -1 ) {
			if ( codeComment.indexOf( '|' ) !== -1 && codeComment.indexOf( '|' ) > codeComment.indexOf( '[[' ) && codeComment.indexOf( '|' ) < codeComment.indexOf( ']]' ) ) {
				var wikiLink = codeComment.slice( codeComment.indexOf( '[[' ) + 2, codeComment.indexOf( '|' ) );
				wikiLinkPipe = codeComment.slice( codeComment.indexOf( '|' ), codeComment.indexOf( ']]' ) );
			} else {
				var wikiLink = codeComment.slice( codeComment.indexOf( '[[' ) + 2, codeComment.indexOf( ']]' ) );
			}
			var replaceWikiLink = codeComment.slice( codeComment.indexOf( '[[' ), codeComment.indexOf( ']]' ) + 2 );
			codeComment = codeComment.substr( codeComment.indexOf( ']]' ) + 2 );
			if ( wikiLink.search( 'Special:' ) === -1 ) {
				extraLinks =  ' <small style=\"font-style: normal;\">( <a href=\"' + mw.config.get( 'wgServer' ) + '/edit/' +
					wikiLink + '\" title=\"Please use [show preview] before saving.\">edit</a>';
				extraLinks += ' | <a href=\"' + mw.config.get( 'wgServer' ) +
					mw.config.get( 'wgArticlePath' ).replace( '$1', 'Special:WhatLinksHere/' + wikiLink) +
					'\" title=\"A list of all wiki pages that link here.\">wlh</a> )</small>';
			}
			$( this ).html( $( this ).html().replace( replaceWikiLink,
				'<b>[[</b><a href=\"' + mw.config.get( 'wgServer' ) + mw.config.get( 'wgArticlePath' ).replace('$1', wikiLink) +
				'\" title=\"' + wikiLink + '\">' + wikiLink + '</a><b>' + wikiLinkPipe + ']]</b>' + extraLinks )
			);
			wikiLinkPipe = '';
			extraLinks =  '';
		}
		// var urlLinks = $( this ).html().match( /irc|telnet|gopher|[fh]t?tps?:\/\/[\S]*/i );
		// for ( URL in urlLinks ) {
			// $( this ).html($( this ).html().replace(urlLinks[URL], '<a href=\"' + urlLinks[URL] + '\" title=\"This is an external URL link.  Follow at your own risk.\">' + urlLinks[URL] + '</a>' ) );
		// }
	} );
} )( mediaWiki, jQuery );
// </nowiki> [[Category:Gadgets]]