User:Gryllida/js/plagiarismcheck.js

/* Author : Svetlana Tkachenko svetlana@members.fsf.org Licence: GPLv3+ Description: [beta] provides links to dupdet results against the external links present in the article TODO: [ ] add 'check plagiarism' links next to the sources, IF the article is not yet published See also . mw.loader.using(['mediawiki.api', 'jquery.ui'], function {	// 'jquery.ui',	"use strict";	/* 	== Quit if this is not main namespace ==	 */	if (wgNamespaceNumber < 0)		return;	/*	== Code ==	*/	var api = new mw.Api;	/*	== Show a dialog with links to dupdet ==	This parses article contents, looks for URLs in the 	templates, and provides a list of links to check the current article	plagiarism score against these source URLs.	*/	function _showDupDetLinks{		/*		== Show dialog ==		This is stolen from 		https://www.mediawiki.org/wiki/MediaWiki:Tutorial-QuickRC.js		from		https://www.mediawiki.org/wiki/Gadget_kitchen		*/		var $dialog = $( '  ' )			.html( ' Loading... '			)			.dialog({ autoOpen: true, title: 'Open DupDet - plagiarism check against external links.', width: '70%', position: ['top',30] , modal: true });		/*		== Parse the page and find external URLs provided as params ==		This is Wikinews-specific. 		Avoid using regex for this task.		*/		// Construct an empty list		var list = $('');		// Get current page name and URL		var title = mw.config.get( 'wgPageName' );		var url1 = 'http:' + mw.config.get ('wgServer') + wgArticlePath.replace('$1', title);		// Create an API object		var api = new mw.Api;		// Query the wiki API to parse the page		api.get( { // Corresponds to "api.php?action=parse&page=test" action: 'parse', page: mw.config.get( 'wgPageName' ) } ).done( function ( data ) { // Get all external links in the article var elinks = data.parse.externallinks; for(var i=0; i').append(		   		$("", {    href : ddlink, text: elink, target: '_blank'})		    	); list.append(li); }		} );		// Feedback links		var a1 = $('', { href: 'http://en.wikinews.org/wiki/User talk:Gryllida/js/plagiarismcheck.js', text: 'This script feedback' });		var a2 = $('', { href: 'https://en.wikinews.org/wiki/User:Gryllida/Tasks#Task_1:_Check_plagiarism', text: 'This script design' });		var a3 = $('', { href: 'https://en.wikinews.org/w/index.php?title=Wikinews:Water_cooler/technical&action=edit&section=new', text: 'Ask a technical question' });		var li = $('');		li.append('[');		li.append(a1);li.append(', ');		li.append(a2);li.append(', ');		li.append(a3);		li.append(']');		list.append(li);		$dialog.html(list);	}	var link = mw.util.addPortletLink(mw.config.get('skin') === 'vector' ? 'p-views' : 'p-cactions', 'javascript:void(0);', 'Open DupDet', 'p-gryllida-plagiarismcheck', 'Check plagiarism in dupdet', '6' );	link.addEventListener('click', _showDupDetLinks); });