MediaWiki:ArchiveTool/code.js

/* ').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(                     $(buttonSecondary[0] + msg('buttonSelectAll') + buttonSecondary[1]).click(function(e) { e.preventDefault; ul.children('tr').addClass('archive'); }), ' ',                    $(buttonSecondary[0] + msg('buttonDeselectAll') + buttonSecondary[1]).click(function(e) { e.preventDefault; ul.children('tr').removeClass('archive'); }), ' ',                    $(buttonPrimary[0] + msg('buttonSaveArchive') + buttonPrimary[1]).click(function(e) { archive; }), ' ',                    $(buttonPrimary[0] + msg('buttonAbort') + buttonPrimary[1]).click(function(e) { bc.find('.ajax').remove; location = wgServer+wgScript+'?title='+encodeURI(wgPageName)+'&action=purge'; })                 ).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 ( !(new RegExp('^\\{\\{'+archiveListRegex+'\}\}')).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 = $(' Finding archive id: ').appendTo(bc); api({                          action: 'query',                           list: 'allpages',                           apnamespace: wgNamespaceNumber,                           apprefix: wgTitle+'/'+config.archiveSubpage,                           aplimit: 1,                           apdir: 'descending'                        }, function(q) {                           archiveNo = q.query.allpages.length ?                              parseInt(q.query.allpages[0].title.substr(wgPageName.length+("/"+config.archiveSubpage).length),10)+1 :                              1;                           archiveTitle = wgPageName+'/'+config.archiveSubpage+' '+archiveNo;                           m.append('done... (using '+archiveNo+')');                          saveArchive;                        }); }                    function saveArchive { var m = $(' Finding token for '+archiveTitle+': ').appendTo(bc); token(archiveTitle, function(p) {                          m.append('done...');                           m = $(' Saving archive page: ').appendTo(bc);                           api({ action: 'edit', title: archiveTitle, text: archiveContent, token: p.edittoken, summary: ""+ msg('summaryArchiveFrom') + " "+wgPageName+".", minor: true, createonly: true }, function(q) { if ( q.error && q.error.code === "articleexists" ) { m.append('failed...'); bc.append(" The archive page we tried to create already exists. "); return abort; }                             m.append('done...'); saveTalk; });                       });                     }                     function saveTalk { var m = $(' Finding token for '+wgPageName+': ').appendTo(bc); m.append('done...'); m = $(' Updating talk page: ').appendTo(bc); api({                          action: 'edit',                           title: wgPageName,                           text: talkContent,                           token: talkToken,                           summary: "" + msg('summaryArchiveTo') + " "+archiveTitle+".",                           minor: true,                           basetimestamp: time,                           starttimestamp: tokenTime                        }, function(q) {                           if ( q.edit.result === "Success" ) {                              m.append('done...');                              bc.find('.ajax').remove;                              location = wgServer+wgScript+'?title='+encodeURI(wgPageName)+'&action=purge';                           } else {                              m.append('failed...');                              bc.append(" Failed to update talkpage, you may wish to have the archive subpage we just created deleted. ");                             return abort;                           }                        });                     }                     function abort {                        bc.find('.ajax').remove;                        bc.append(" Aborting... ");                        $(" You may want to ")                           .append( $('refresh').attr({href: wgServer+wgArticlePath.replace('$1', encodeURI(wgPageName))}) )                           .append(' and try again.')                           .appendTo(bc);                     }                     // start                     findArchives;                  }               });            }            $(pageControlHTML)               .click(startArchiving)               .appendTo(pageControls);         });      }   })(jQuery); } /* */