MediaWiki:ArchiveTool/code-hu.js

/* * Copyright © 2009, Daniel Friesen * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: *    * Redistributions of source code must retain the above copyright *      notice, this list of conditions and the following disclaimer. *    * Redistributions in binary form must reproduce the above copyright *      notice, this list of conditions and the following disclaimer in the *      documentation and/or other materials provided with the distribution. *    * Neither the name of the script nor the *      names of its contributors may be used to endorse or promote products *      derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY DANIEL FRIESEN AS IS AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL DANIEL FRIESEN BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ if ( skin == "monaco" ) { importStylesheetPage('ArchiveTool/code.css', 'dev'); (function($) {		var archiveListTemplate = window.archiveListTemplate || 'ArchiveList';		var archivePageTemplate = window.archivePageTemplate || 'ArchivePage';

if ( wgNamespaceNumber % 2 === 1 && ( wgAction === "view" || wgAction === "purge" ) ) { $(function {				function api(q, fn) {					q.format = 'json';					return $.post(wgScriptPath + '/api.php', q, fn, "json");				}				function token(page, fn) {					api({ action: 'query', query: 'prop', prop: 'info', titles: page, intoken: 'edit' }, function(q) { for ( var k in q.query.pages ) return fn(q.query.pages[k]); });				}				function startArchiving {					var c = archiveListTemplate.substr(0,1);					var archiveListRegex = '['+c.toUpperCase+c.toLowerCase+']'+archiveListTemplate.substr(1);					var bc = $('#bodyContent').addClass('archiving').empty;					$('')						.attr({src: stylepath+'/common/progress-wheel.gif'}).appendTo(bc);					api({ action: 'query', prop: 'revisions', titles: wgPageName, rvprop: 'timestamp|content' }, function(q) { bc.empty; var rev = q.query.pages[wgArticleId].revisions[0]; var time = rev.timestamp; var talkToken, tokenTime; var content = rev['*']; token(wgPageName, function(p) {							talkToken = p.edittoken;							tokenTime = p.starttimestamp;						}); var lines = content.split('\n'); var table = $(' ').appendTo(bc); var ul = $(' ').appendTo(table); for ( var l = 0; l < lines.length; l++ ) { var line = lines[l]; $(' ').toggleClass('noarchive', (new RegExp('^\\{\\{'+archiveListRegex+'\}\}')).test(line)) .attr({line:line}) .append( $(' ').text(line).append(' ') ).appendTo(ul); }						var sections = []; var sectionEnd = lines.length-1; for ( var l = lines.length-1; l >= 0; l-- ) { var line = lines[l]; if ( /^=.+?=/.test(line) || l === 0 ) { var section = { start: l, end: sectionEnd }; section.length = section.end - section.start + 1; sections.unshift(section); sectionEnd = l-1; }						}						var section; while( section = sections.shift ) { var tr = ul.children.eq(section.start); $(' ').attr({rowspan: section.length}).appendTo(tr); }						$(' ').append(							$('Archive all').click(function(e) { e.preventDefault; ul.children('tr').addClass('archive'); }), ' ',							$('Deselect all').click(function(e) { e.preventDefault; ul.children('tr').removeClass('archive'); }), ' ',							$('Archiválás vége (mentés)').click(function(e) { archive; })						).prependTo(bc).clone(true).appendTo(bc); var click = false; var add; table.mousedown(function(e) {							e.preventDefault;							var $li = $(e.target).closest('tr');							if(!$li.length) return;							var $section = $(e.target).closest('.section');							if ( $section.length ) {								var slist = $li.nextAll(':lt('+(parseInt($section.attr('rowspan'),10)-1)+')').andSelf;								var sadd = slist.filter(function { return !$(this).hasClass('archive') }).length;								slist.toggleClass('archive', !!sadd);								return;							}							click = true;							add = !$li.hasClass('archive');							$li.toggleClass('archive', !!add);						}); table.mouseover(function(e) {							if (!click) return;							var $li = $(e.target).closest('tr');							if(!$li.length) return;							$li.toggleClass('archive', !!add);						}); $('body').mouseup(function(e) {							click = false;						}); function archive { var talkLines = []; var archiveLines = []; ul.children.each(function {								var arr = $(this).hasClass('noarchive') || !$(this).hasClass('archive')									? talkLines : archiveLines;								arr.push( $(this).attr('line') );							}); if ( !/^\{\{[Aa]rchiveList\}\}/.test(talkLines[0]) ) talkLines = [, ].concat(talkLines); archiveLines = [, ].concat(archiveLines); bc.empty; $('') .attr({src: stylepath+'/common/progress-wheel.gif'}).appendTo(bc); //$(' ').text(talkLines.join('\n')).appendTo(bc); //$(' ').text(archiveLines.join('\n')).appendTo(bc); runArchive(talkLines.join('\n'), archiveLines.join('\n')); }						var archiveTitle; function runArchive(talkContent, archiveContent) { var archiveNo; function findArchives { var m = $(' Archív keresése: ').appendTo(bc); api({									action: 'query',									list: 'allpages',									apnamespace: wgNamespaceNumber,									apprefix: wgTitle+'/Archív',									aplimit: 1,									apdir: 'descending'								}, function(q) {									archiveNo = q.query.allpages.length ?										parseInt(q.query.allpages[0].title.substr(wgPageName.length+"/Archív".length),10)+1 :										1;									archiveTitle = wgPageName+'/Archív '+archiveNo;									m.append('kész... ('+archiveNo+')');									saveArchive;								}); }							function saveArchive { var m = $(' Keresés: '+archiveTitle+': ').appendTo(bc); token(archiveTitle, function(p) {									m.append('done...');									m = $(' Archív oldal mentése: ').appendTo(bc);									api({ action: 'edit', title: archiveTitle, text: archiveContent, token: p.edittoken, summary: "Automatikus archiválás "+wgPageName+".", minor: true, createonly: true }, function(q) { if ( q.error && q.error.code === "articleexists" ) { m.append('sikertelen...'); bc.append(" Az archív oldal már létezik. "); return abort; }										m.append('kész...'); saveTalk; });								});							}							function saveTalk { var m = $(' Keresés: '+wgPageName+': ').appendTo(bc); m.append('kész...'); m = $(' Vitalap frissítése: ').appendTo(bc); api({									action: 'edit',									title: wgPageName,									text: talkContent,									token: talkToken,									summary: "Automatikus archiválás -> "+archiveTitle+".",									minor: true,									basetimestamp: time,									starttimestamp: tokenTime								}, function(q) {									if ( q.edit.result === "Success" ) {										m.append('kész...');										bc.find('.ajax').remove;										location = wgServer+wgScript+'?title='+encodeURI(wgPageName)+'&action=purge';									} else {										m.append('failed...');										bc.append(" Nem sikerült a vitalap frissítése. ");										return abort;									}								}); }							function abort { bc.find('.ajax').remove; bc.append(" Visszavonás... ");

$(" You may want to ") .append( $('frissíts').attr({href: wgServer+wgArticlePath.replace('$1', encodeURI(wgPageName))}) ) .append(' és próbáld újra.') .appendTo(bc); }							// start findArchives; }					});				}				$('Archive')					.click(startArchiving)					.appendTo('#page_controls');			}); }	})(jQuery); } /*