User:Altt311/Gadget/friendlycopyvio.js

注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google ChromeFirefoxMicrosoft EdgeSafari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
// If FriendlyConfig aint exist.
if( typeof( FriendlyConfig ) == 'undefined' ) {
	FriendlyConfig = {};
}
 
/**
 FriendlyConfig.summaryAd ( string )
 If ad should be added or not to summary, default [[WP:FRIENDLY|Friendly]]
 */
if( typeof( FriendlyConfig.summaryAd ) == 'undefined' ) {
	FriendlyConfig.summaryAd = " using [[WP:FRIENDLY|Friendly]]";
}
 
/**
 FriendlyConfig.markCopyvioAsMinor ( boolean )
 */
if( typeof( FriendlyConfig.markCopyvioAsMinor ) == 'undefined' ) {
	FriendlyConfig.markCopyvioAsMinor = false;
}
 
/**
 FriendlyConfig.markCopyvioAsPatrolled ( boolean )
 */
if( typeof( FriendlyConfig.markCopyvioAsPatrolled ) == 'undefined' ) {
	FriendlyConfig.markCopyvioAsPatrolled = true;
}
 
/**
 FriendlyConfig.autoNotifyCopyvio( boolean )
 */
if( typeof( FriendlyConfig.autoNotifyCopyvio ) == 'undefined' ) {
	FriendlyConfig.autoNotifyCopyvio = true;
}
 
/**
 FriendlyConfig.autoReportCopyvio( boolean )
 */
if( typeof( FriendlyConfig.autoReportCopyvio ) == 'undefined' ) {
	FriendlyConfig.autoReportCopyvio = true;
}
 
$(friendlycopyvio);
 
function friendlycopyvio() {
	if( wgNamespaceNumber < 0 || wgCurRevisionId == false ) {
		return;
	} else {
		mw.util.addPortletLink( 'p-cactions', "javascript:friendlycopyvio.callback()", "侵權", "friendly-cv", "標記侵權條目", "");
	}
}
 
friendlycopyvio.callback = function friendlycopyvioCallback( uid ) {
	var Window = new SimpleWindow( 600, 200 );
	Window.setTitle( "標記侵權條目" );
	var form = new QuickForm( friendlycopyvio.callback.evaluate , 'change' );
	form.append( {
			type: 'input',
			name: 'source',
			label: '條目侵權的原內容網址:',
		}
	);
 
	form.append( { type:'submit', label:'標記侵權' } );
 
	var result = form.render();
	Window.setContent( result );
	Window.display();
}
 
friendlycopyvio.callbacks = {
		main: function( self ) {
			++Wikipedia.numberOfActionsLeft;
			var xmlDoc = self.responseXML;
			var exists = xmlDoc.evaluate( 'boolean(//pages/page[not(@missing)])', xmlDoc, null, XPathResult.BOOLEAN_TYPE, null ).booleanValue;
			if( ! exists ) {
				self.statelem.error( "頁面不存在,或已被刪除。" );
				return;
			}
			var query = { 
				'title': wgPageName, 
				'action': 'submit'
			};
 
			var wikipedia_wiki = new Wikipedia.wiki( 'Tagging page', query, friendlycopyvio.callbacks.tagPage );
			wikipedia_wiki.params = self.params;
			wikipedia_wiki.followRedirect = false;
			wikipedia_wiki.get();
		},
		tagPage: function( self ) {
			form = this.responseXML.getElementById( 'editform' );
 
			var code;
			code = "\{\{subst:Copyvio/auto|url=\*" + self.params.source + "\}\}";
 
			if( FriendlyConfig.markCopyvioAsPatrolled && self.params.rcid != '' ) {
				var query = {
					'title': wgPageName,
					'action': 'markpatrolled',
					'rcid': self.params.rcid
				};
 
				var wikipedia_wiki = new Wikipedia.wiki( 'Marking page as patrolled', query );
				wikipedia_wiki.post();
			}
 
			var query = {
				'action': 'query',
				'prop': 'revisions',
				'titles': wgPageName,
				'rvlimit': 1,
				'rvprop': 'user',
				'rvdir': 'newer'
			}
			var callback = function( self ) {
				var xmlDoc = self.responseXML;
				var user = xmlDoc.evaluate( '//rev/@user', xmlDoc, null, XPathResult.STRING_TYPE, null ).stringValue;
				if( wgPageName != ( 'User talk:' + user ) ) {
					var query = {
						'title': 'User talk:' + user,
						'action': 'submit'
					};
					var wikipedia_wiki = new Wikipedia.wiki( 'Notifying of initial contributor (' + user + ')', query, friendlycopyvio.callbacks.userNotification );
					wikipedia_wiki.params = self.params;
					wikipedia_wiki.get();
				} else {
					Status.info( 'Info', 'Current page is initial contributor\'s talk page, aborting notification' );
				}
			}
 
			if( self.params.usertalk ) {
				var wikipedia_api = new Wikipedia.api( 'Grabbing data of initial contributor', query, callback );
				wikipedia_api.params = self.params;
				wikipedia_api.post();
			}
 
			var postData = {
				'wpMinoredit': FriendlyConfig.markCopyvioAsMinor ? '' : undefined,
				'wpWatchthis': form.wpWatchthis.checked ? '' : undefined,
				'wpStarttime': form.wpStarttime.value,
				'wpEdittime': form.wpEdittime.value,
				'wpAutoSummary': form.wpAutoSummary.value,
				'wpEditToken': form.wpEditToken.value,
				'wpSection': '',
				'wpSummary': "Tagging page as copyvio" + FriendlyConfig.summaryAd,
				'wpTextbox1': code
			};
			self.post( postData );
 
			var querywp = {
				'action': 'query',
				'prop': 'revisions',
				'titles': wgPageName,
				'rvlimit': 1,
				'rvprop': 'user',
				'rvdir': 'newer'
			}
			var callback = function( self ) {
				var xmlDoc = self.responseXML;
				var user = xmlDoc.evaluate( '//rev/@user', xmlDoc, null, XPathResult.STRING_TYPE, null ).stringValue;
				if( wgPageName != ( 'Wikipedia:頁面存廢討論/疑似侵權' ) ) {
					var query = {
						'title': 'Wikipedia:頁面存廢討論/疑似侵權',
						'action': 'submit'
					};
					var wikipedia_wiki = new Wikipedia.wiki( 'Reporting to WP:CV', query, friendlycopyvio.callbacks.reportCopyvio );
					wikipedia_wiki.params = self.params;
					wikipedia_wiki.get();
				} else {
					Status.info( 'Info', 'Current page is the page we\'ll report on, aborting report' );
				}
			}
 
			if( self.params.toreport ) {
				var wikipedia_api = new Wikipedia.api( 'Grabbing data of reporting page', query, callback );
				wikipedia_api.params = self.params;
				wikipedia_api.post();

			}
 
			var postData = {
				'wpMinoredit': FriendlyConfig.markCopyvioAsMinor ? '' : undefined,
				'wpWatchthis': form.wpWatchthis.checked ? '' : undefined,
				'wpStarttime': form.wpStarttime.value,
				'wpEdittime': form.wpEdittime.value,
				'wpAutoSummary': form.wpAutoSummary.value,
				'wpEditToken': form.wpEditToken.value,
				'wpSection': '',
				'wpSummary': "Tagging page as copyvio" + FriendlyConfig.summaryAd,
				'wpTextbox1': code
			};
			self.post( postData );
		},
		userNotification: function( self ) {
			var form = self.responseXML.getElementById( 'editform' );
			var text = form.wpTextbox1.value;
			if( text == '\n' ) {
				text += "\{\{subst:welcome\}\}"
			}
			text += "\n\{\{subst:CopyvioNotice|" + wgPageName + "\}\}";
			var postData = {
				'wpMinoredit': form.wpMinoredit.checked ? '' : undefined,
				'wpWatchthis': form.wpWatchthis.checked ? '' : undefined,
				'wpStarttime': form.wpStarttime.value,
				'wpEdittime': form.wpEdittime.value,
				'wpAutoSummary': form.wpAutoSummary.value,
				'wpEditToken': form.wpEditToken.value,
				'wpSection': '',
				'wpSummary': 'Notification: Copyvio tagging of \[\[' + wgPageName + '\]\]' + FriendlyConfig.summaryAd,
				'wpTextbox1': text
			};
			self.post( postData );
		},
 
		reportCopyvio: function( self ) {
			var form = self.responseXML.getElementById( 'editform' );
			var text = form.wpTextbox1.value;
			text += "\{\{subst:CopyvioVFDRecord|" + wgPageName + "\}\}";
			var postData = {
				'wpMinoredit': form.wpMinoredit.checked ? '' : undefined,
				'wpWatchthis': form.wpWatchthis.checked ? '' : undefined,
				'wpStarttime': form.wpStarttime.value,
				'wpEdittime': form.wpEdittime.value,
				'wpAutoSummary': form.wpAutoSummary.value,
				'wpEditToken': form.wpEditToken.value,
				'wpSection': '',
				'wpSummary': 'Report: Reporting \[\[' + wgPageName + '\]\] to WP:CV' + FriendlyConfig.summaryAd,
				'wpTextbox1': text
			};
			self.post( postData );
		}
}
 
friendlycopyvio.callback.evaluate = function friendlycopyvioCallbackEvaluate(e) {
	wgPageName = wgPageName.replace( /_/g, ' ' );
	//var value = e.target.value;
 
	var params = {
		usertalk: FriendlyConfig.autoNotifyCopyvio != -1, //&& e.target.form.notify.checked,
		toreport: FriendlyConfig.autoReportCopyvio != -1, //&& e.target.form.report.checked,
		source: e.target.form.source.value,
		rcid: QueryString.exists( 'rcid' ) ? QueryString.get( 'rcid' ) : ''
	};
 
	Status.init( e.target.form );
 
	Wikipedia.actionCompleted.redirect = wgPageName;
	Wikipedia.actionCompleted.notice = "提報侵權頁面完成";
 
	var query = {
		'action': 'query',
		'titles': wgPageName
	}
 
	var wikipedia_api = new Wikipedia.api( 'Checking if page exists', query, friendlycopyvio.callbacks.main );
	wikipedia_api.params = params;
	wikipedia_api.post();
}