// Create a new GA review page
function createNewPage() {
var pageName = mw.config.get('wgPageName');
var reviewPage;
var pages = mw.loader.moduleRegistry['ext.gadget.GATools']._module.pages;
if (pages.length > 0) {
var lastPageName = pages[pages.length - 1].name;
var lastIndex = lastPageName.lastIndexOf('/GA');
var lastNumber = parseInt(lastPageName.substring(lastIndex + 3), 10);
reviewPage = pageName + '/GA' + (lastNumber + 1);
} else {
reviewPage = pageName + '/GA1';
}
// Create the review page
var editUrl = mw.util.getUrl(reviewPage, { action: 'edit' });
var reviewLink = '<a href="' + editUrl + '">Create new GA review page</a>';
var gaReviewLink = $('<li id="p-ga-review"></li>').html(reviewLink);
$('#p-tb').append(gaReviewLink);
}
// Add a link to the talk page to create a new GA review page
addOnloadHook(function() {
var pageNamespace = mw.config.get('wgNamespaceNumber');
var isTalkPage = pageNamespace === 1 || pageNamespace === 3;
if (isTalkPage) {
createNewPage();
}
});