Участник:Hercules63/reporter.js

Материал из Википедии — свободной энциклопедии
<
Участник:Hercules63
/* 
Скрипт для запросов на ЗКА или УЗ, делаемых с любой страницы как в Твинкле. 
Автор — ru.wikipedia.org/wiki/user:Absconditus
v.1.0
*/

var newPageName = mw.config.get('wgPageName').replace( /_/g, ' ' ).replace(/(Special|Служебная)\:(Contributions|Вклад)\//i, 'User:').replace(/(User talk\:|Обсуждение участни(ка|цы)\:)/i, 'User:');
var newPGregexp = '[['+newPageName+ (mw.config.get('wgPageName').match(/(user|contrib|участни|вклад)/i) ? '|'+mw.config.get('wgPageName').replace( /_/g, ' ' ).replace(/(Special|Служебная)\:(Вклад|Contributions)\//i, '').replace(/(User talk\:|Обсуждение участни(ка|цы)\:)/i, '').replace(/(user|участник)\:/i, '')+']]' : ']]');
var newPGregexp2 = mw.config.get('wgPageName').replace( /_/g, ' ' ).replace(/(Special|Служебная)\:(Вклад|Contributions)\//i, '').replace(/(User talk\:|Обсуждение участни(ка|цы)\:)/i, '').replace(/(user|участник)\:/i, '');
var reportPage = (mw.config.get('wgPageName').match(/(user|contrib|участни|вклад)/i) ? 'Википедия:Запросы к администраторам' : 'Википедия:Установка защиты');
$(function () {
if( mw.config.get('wgNamespaceNumber') != -1 || (mw.config.get('wgNamespaceNumber') == -1 && mw.config.get('wgCanonicalSpecialPageName') == "Contributions") ) {
mw.util.addPortletLink('p-cactions', 'javascript: show_window2()', 'Запрос', 'ca-reporter', 'Добавить запрос на ЗКА или УЗ'); };
});

function show_window2() {
		var windown = '<div xmlns="http://www.w3.org/1999/xhtml" id="reporter-window" style="background: white; border:1px double black; padding: 15px; position: fixed; top: 200px; left: 200px; z-index: 2; height: 250px; width: 700px; text-align:left;"><table>' +
			'<tr><td>Отправить на страницу: ' +reportPage+ '</td></tr>' +
                        '<tr><td>Тема/заголовок: <input style="width:80%;" value="'+newPGregexp+'" /></td></tr>'+
			'<tr><td><textarea id="reporterTextarea" rows="8" cols="200" width="90%" align="left" placeholder="Введите сюда текст запроса. Подпись будет добавлена автоматически после введённого текста."></textarea></td></tr>'+
			'<tr><td width="80%"><input type="button" id="reporter-confirm" value="Отправить" /><input type="button" id="reporter-cancel" value="Не отправлять" /><p align="right" width="20%" style="float:right;font-size:95%"><a href="//ru.wikipedia.org/wiki/user_talk:Absconditus/reporter.js" target="_blank">О скрипте</a></p></td></tr>' + 

			'</table></div>';
		$( '#bodyContent' ).append( $.parseXML( windown ).firstChild );
		$( '#reporter-confirm' )[0].onclick = function() { makeReport(); };
		$( '#reporter-cancel' )[0].onclick = function() {
			$( 'div#reporter-window' ).remove();
		};
};
function makeReport() {
        $.getJSON( mw.config.get('wgScriptPath') + '/api.php?action=tokens&format=json', function( resp ) {
if(reportPage == 'Википедия:Запросы к администраторам') {
        $.post( mw.config.get('wgScriptPath') + '/api.php', { action: 'edit', title: reportPage, token: resp.tokens.edittoken, summary: '\/* '+newPGregexp+' *\/ новая тема ([[user talk:Absconditus/reporter.js|запросчик.js]])', section: '0',  appendtext: '\n== '+newPGregexp+' ==\n\{\{userlinks|' + newPGregexp2 + ((/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/).test(newPGregexp2) ? '|ip=1' : '') + '}}<br/>' + $('#reporterTextarea').val() + ' ~~' + '~~', minor: '1' }, function() { window.location = mw.config.get('wgServer') + '/wiki/' + reportPage });
}
if(reportPage == 'Википедия:Установка защиты') {
$.post( mw.config.get('wgScriptPath') + '/api.php', { action: 'edit', title: reportPage, token: resp.tokens.edittoken, summary: '\/* '+newPGregexp+' *\/ новая тема ([[user talk:Absconditus/reporter.js|запросчик.js]])',  appendtext: '\n== '+newPGregexp+' ==\n\{\{pagelinks|' +newPageName+ '}}<br/>' + $('#reporterTextarea').val() + ' ~~' + '~~', minor: '1' }, function() { window.location = mw.config.get('wgServer') + '/wiki/' + reportPage });
}
		});
};