User:MPGuy2824/MoveToDraft/draftifyLog.js

/****************************************************************************** Companion file for MoveToDraft /* jshint laxbreak: true, undef: true, maxerr:999 */ /* globals console, window, document, $, mw */ //

/* ========== Show draftifications for a user ======================= */ function showDraftifications(username, fromDate) { var targetUser = username; if ( !targetUser && targetUser !== "" ) { var pageNameParts = window.config.mw.wgPageName.split( '/' ); targetUser = ( pageNameParts.length > 1 ) ? pageNameParts[ 1 ] : ''; }	$('#mw-content-text').empty; // TODO: Form for setting user var today = new Date.toISOString.slice(0,10); $('#mw-content-text').append(		$(` User:  From date (and earlier)   `)	);	$('#draftifyUsername').val(targetUser); $('#draftifyLogForm').on('submit', function(e) {		e.preventDefault;		$('#draftifyLog, #draftifyLogWikitext').show;		showDraftifications($('#draftifyUsername').val, $('#draftifyFromDate').val);	});

$('#mw-content-text').append(		$(`  `)	);

$('#draftifyLogWikitext').val(`{|class="wikitable" !scope='col'|From !scope='col'|To !scope='col'|Time !scope='col'|User !scope='col'|Reason
 * }`);

var query = { action: "query", format: "json", list: "logevents", leprop: "title|timestamp|comment|details|user", letype: "move", lenamespace: "0", lelimit: "500", lestart: (fromDate || today) + "T23:59:59Z" };	if (targetUser) { query.leuser = targetUser; }

var continueInfo = {};

function onLoadMoreClick(e) { e.preventDefault; $('#draftifyStatus').empty.text("Loading..."); searchAndShowResults; }

function parseLogTable(wikitext) { window.API.post({			"action": "parse",			"format": "json",			"text": wikitext,			"prop": "text",			"contentmodel": "wikitext"		}).then(function(response) {			const parsedLogTable = $(response.parse.text["*"]);			$('#draftifyLog tbody').empty.append( parsedLogTable.find('tr').slice(1) );		});	}

function searchAndShowResults { window.API.get( $.extend({}, query, continueInfo) ) .then(function(response) {				// Store continuing info, if any				continueInfo = response.continue || {};				// Reset status, add a "Load more" if there are more results				$('#draftifyStatus').empty.append( response.continue ? $('').css("cursor", "pointer").text('Load more').click(onLoadMoreClick) : null );				// Filter to only MoveToDraft script moves				var draftifyEvents = response.query && response.query.logevents && response.query.logevents.filter(function(logevent) { return logevent.params.target_ns === 118; // Moved to Draft namespace });				var noDraftifyEvents = !draftifyEvents || !draftifyEvents.length;

switch(true) { case noDraftifyEvents && !response.continue: $('#draftifyStatus').empty.text(							$('#draftifyLog tbody tr').length === 0 ? "No results" : "No further results"						); break; case noDraftifyEvents: // Continue with next batch of results, otherwise table will initially have no results but a load more link, // or clicking "Load more" will appear to show "Loading..." but not actually add any results searchAndShowResults; break; case !response.continue: $('#draftifyStatus').empty.text("No further results"); /* falls through */ default: draftifyEvents.forEach(function(logevent) {							var fromTitle = logevent.title;							var toTitle = logevent.params.target_title;							var timeOfMove = new Date(logevent.timestamp).toUTCString.replace("GMT", "(UTC)");							var user = logevent.user;							var comment = logevent.comment;							var wikitext = $('#draftifyLogWikitext').val.replace("|}", `|- $('#draftifyLogWikitext').val(wikitext); parseLogTable(wikitext); });				}			});	}
 * ${fromTitle}
 * ${toTitle}
 * ${timeOfMove}
 * ${user}
 * ${comment}
 * }`);

// Run by default, unless page loaded without a /username suffix if (username || username==="") { searchAndShowResults; } else { $('#draftifyLog, #draftifyLogWikitext').hide; }

// End of function showDraftifications }

document.title = "Draftify log - Wikipedia"; $('h1').text("Draftify log"); $('#mw-content-text').empty .text("Loading...") .before(	$(' ').append( 'Note: This page only works with the ', $('').attr('href','/wiki/User:MPGuy2824/MoveToDraft').text('MoveToDraft'), ' userscript installed.' ),	$(' ') ); showDraftifications; //