User:Phe/Auto create page.js

// Auto create page when requesting a non existent Page:*, inefficient since there is // two request per page, see setupNextLink which avoid it in most case. function autoCreatePage { if (wgArticleId == 0 && wgAction == 'view') { url = document.URL.slice((wgServer + '/wiki/').length); url = mw.config.get('wgServer') + mw.config.get('wgScript') + '?title=' + url + '&action=edit'; window.location = url; } }

if (wgCanonicalNamespace == 'Page') addOnloadHook(autoCreatePage);

// when acting on a Page:* setup the next link to edit mode if the next page doesn't exist. function setupNextLink {   ca_next = document.getElementById('ca-next'); if (!ca_next) return; href = ca_next.firstChild; if (!href) return; var r = new RegExp("(\\d+)$"); page = Number(r.exec(wgTitle)[1]) + 1; next_page = wgPageName.replace(/\d+$/g, page);

var url = wgServer + wgScriptPath + "/api.php?format=xml&action=query&prop=info&titles=" + encodeURIComponent(next_page); var request = sajax_init_object; request.open('GET', url, true); request.onreadystatechange = function { if (request.readyState == 4) { var xml = request.responseXML ; if (xml == null) return ; var page = xml.getElementsByTagName( "page" )[0]; if (page.getAttribute("missing") == "") href.href = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/index.php?title=' + encodeURIComponent(next_page) + '&action=edit'; }   };    request.send(null); }

if (wgCanonicalNamespace == 'Page') addOnloadHook(setupNextLink);