summaryrefslogtreecommitdiff
path: root/post_fsd_wiki.phantomjs
diff options
context:
space:
mode:
authorbill-auger <mr.j.spam.me@gmail.com>2018-01-15 05:39:29 -0500
committerbill-auger <mr.j.spam.me@gmail.com>2018-02-13 13:29:34 -0500
commitfb9dd411b72c72ea89ff2c88a16ca7e5183ea4db (patch)
treefba88dca0ec4532f376d470c79498b6ee4ea49e0 /post_fsd_wiki.phantomjs
parenteca20f9c8263c51dfc1f1a3527daf9db10c09fc1 (diff)
add wiki post script
Diffstat (limited to 'post_fsd_wiki.phantomjs')
-rw-r--r--post_fsd_wiki.phantomjs169
1 files changed, 169 insertions, 0 deletions
diff --git a/post_fsd_wiki.phantomjs b/post_fsd_wiki.phantomjs
new file mode 100644
index 0000000..af8e5c8
--- /dev/null
+++ b/post_fsd_wiki.phantomjs
@@ -0,0 +1,169 @@
+console.log("in") ;
+
+var WIKI_BASE_URL = 'http://localhost/mediawiki/index.php' ;
+// var WIKI_BASE_URL = 'https://directory.fsf.org/wiki?title=' ;
+// var LOGIN_URL = WIKI_URL + '/index.php?title=Special:Userlogin&action=submitlogin' ;
+var LOGIN_URL = WIKI_BASE_URL + '?title=Special:UserLogin' ;
+var EDIT_URL = WIKI_BASE_URL + '?title=_TITLE_&action=edit&redlink=1' ;
+var TITLE_URL_REGEX = '/_TITLE_/' ;
+var USAGE_MSG = "USAGE: phantomjs ./post_fsd_wiki.phantomjs <WIKI_LOGIN> <WIKI_PASS>" ;
+var LOGIN_IMPUT_ID = 'wpName1' ;
+var PASS_IMPUT_ID = 'wpPassword1' ;
+var SUBMIT_IMPUT_ID = 'wpLoginAttempt' ;
+var USERNAME_LI_ID = 'pt-userpage' ;
+var CONTENT_INPUT_ID = 'wpTextbox1' ;
+var EDIT_FORM_ID = 'editform' ;
+
+
+var System = require('system') ;
+var Args = System.args ;
+var Page = require('webpage').create() ;
+var WIKI_LOGIN = Args[1] || '' ;
+var WIKI_PASS = Args[2] || '' ;
+var IsLoading = false ;
+var ShouldQuit = false ;
+var StepN = 0 ;
+
+if (WIKI_LOGIN == '' || WIKI_PASS == '') { console.log(USAGE_MSG) ; phantom.exit() ; }
+
+
+var Steps =
+[
+ function prepare()
+ {
+ var title = 'a title' ;
+ var page_title = JSON.encode(title.eplace(' ' , '_')) ;
+ } ,
+
+ function login()
+ {
+console.log("login() in") ;
+ // Page.settings.userAgent = 'SpecialAgent';
+
+ OpenUrl(LOGIN_URL , function()
+ {
+console.log("login() open ok") ;
+// console.log("Page.content=" + Page.content) ;
+
+ Page.evaluate(function(login_input_id , pass_input_id , submit_input_id ,
+ wiki_login , wiki_pass )
+ {
+ var login_input = document.getElementById(login_input_id ) ;
+ var pass_input = document.getElementById(pass_input_id ) ;
+ var submit_input = document.getElementById(submit_input_id) ;
+
+ if (login_input === 'undefined' || login_input === 'undefined' ||
+ submit_input === 'undefined' || submit_input.form === 'undefined' )
+ { console.log("ERROR: invalid login page") ; ShouldQuit = true ; return ; }
+
+ login_input.value = wiki_login ;
+ pass_input.value = wiki_pass ;
+
+console.log("login_input.value=" + login_input.value) ;
+console.log("pass_input.value=" + pass_input.value) ;
+console.log("submit_input.value=" + submit_input.value) ;
+
+ submit_input.form.submit() ; IsLoading = true ;
+
+console.log("login() open out") ;
+
+ } , LOGIN_IMPUT_ID , PASS_IMPUT_ID , SUBMIT_IMPUT_ID , WIKI_LOGIN , WIKI_PASS) ;
+ }) ;
+
+console.log("login() out") ;
+ } ,
+
+ function verifyLogin()
+ {
+console.log("verifyLogin() in") ;
+
+ Page.evaluate(function(username_li_id , wiki_login)
+ {
+ var username_li = document.getElementById(username_li_id) ;
+
+console.log("verifyLogin() username_li.textContent=" + username_li.textContent ) ;
+
+ if (username_li === 'undefined' || username_li.textContent != wiki_login)
+ { console.log("ERROR: login failed") ; ShouldQuit = true ; }
+ } , USERNAME_LI_ID , WIKI_LOGIN) ;
+ } ,
+
+ function fetchEditPage()
+ {
+console.log("fetchEditPage() in") ;
+
+ var page_title = 'New Page' ;
+
+ OpenUrl(EDIT_URL.replace(TITLE_URL_REGEX , page_title) , function()
+ {
+ Page.evaluate(function(content_input_id , edit_form_id , content_text)
+ {
+ var content_input = document.getElementById(content_input_id) ;
+ var edit_form = document.getElementById(edit_form_id ) ;
+
+console.log("(edit_form == content_input.form)=" + (edit_form == content_input.form)) ;
+console.log("fetchEditPage() content_input.textContent=" + content_input.textContent ) ;
+
+ if (content_input === 'undefined') { console.log("ERROR: invalid edit page") ; ShouldQuit = true ; }
+ } , CONTENT_INPUT_ID , EDIT_FORM_ID , content_text) ;
+ }) ;
+ }
+] ;
+
+
+/* main loop */
+
+var MainIvl = setInterval(function()
+{
+ if (IsLoading) return ;
+
+console.log("test");
+
+ if (typeof Steps[StepN] !== 'function') ShouldQuit = true ;
+
+ if (ShouldQuit) { clearInterval(MainIvl) ; phantom.exit() ; }
+ else { console.log("Step " + StepN + ": " + Steps[StepN].name) ; Steps[StepN++]() ; }
+}) ;
+
+
+/* helpers */
+
+function OpenUrl(url , callback)
+{
+ Page.open(LOGIN_URL , function(status)
+ {
+ if (status != 'success') { console.log("ERROR: status: " + status) ; ShouldQuit = true ; }
+ else { callback() ; }
+ }) ;
+}
+
+
+/* event hendlers */
+
+Page.onLoadStarted = function() { IsLoading = true ;
+ console.log("page.onLoadStarted");
+ printArgs.apply(this, arguments);
+} ;
+
+Page.onLoadFinished = function() { IsLoading = false ;
+ console.log("page.onLoadFinished");
+ console.log("Page.url=" + Page.url) ;
+ printArgs.apply(this, arguments);
+} ;
+
+Page.onUrlChanged = function() {
+ console.log("page.onUrlChanged");
+ printArgs.apply(this, arguments);
+} ;
+
+Page.onConsoleMessage = function(msg) { console.log(msg) ; } ;
+
+
+
+function printArgs() {
+ var i, ilen;
+ for (i = 0, ilen = arguments.length; i < ilen; ++i) {
+ console.log(" arguments[" + i + "] = " + JSON.stringify(arguments[i]));
+ }
+ console.log("");
+}