Refactor things concerning wpEditToken
This commit is contained in:
parent
e80f95d0d7
commit
429c18b54d
1 changed files with 23 additions and 19 deletions
|
@ -1,7 +1,7 @@
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
# TODO:
|
# TODO:
|
||||||
# - Fix HTML parsing, no regexen! See wpEditToken+wpEdittime
|
# - Fix HTML parsing, no regexen! See wpEditToken+wpEdittime. Unfortunately,
|
||||||
# - EditToken-stuff in its own method?
|
# REXML is slow.
|
||||||
|
|
||||||
module MediaWikiBot
|
module MediaWikiBot
|
||||||
|
|
||||||
|
@ -59,8 +59,7 @@ class WikiBot
|
||||||
end
|
end
|
||||||
|
|
||||||
def url_what_links_here (title)
|
def url_what_links_here (title)
|
||||||
return @wiki \
|
return @wiki + "index.php?title=Special:Whatlinkshere&target=" + url_encode(title)
|
||||||
+ "index.php?title=Special:Whatlinkshere&target=" + url_encode(title)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def url_delete (title)
|
def url_delete (title)
|
||||||
|
@ -76,7 +75,6 @@ class WikiBot
|
||||||
end
|
end
|
||||||
|
|
||||||
def login(wiki_name, wiki_password)
|
def login(wiki_name, wiki_password)
|
||||||
|
|
||||||
post_form(url_submitlogin(),
|
post_form(url_submitlogin(),
|
||||||
{ "wpName" => wiki_name,
|
{ "wpName" => wiki_name,
|
||||||
"wpPassword" => wiki_password,
|
"wpPassword" => wiki_password,
|
||||||
|
@ -129,12 +127,26 @@ class WikiBot
|
||||||
return what_links_here
|
return what_links_here
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_token (xhtml)
|
||||||
|
token = nil
|
||||||
|
|
||||||
|
# No token for MediaWiki 1.3.x
|
||||||
|
if xhtml =~ /wpEditToken/
|
||||||
|
begin
|
||||||
|
token = xhtml.scan(/name='wpEditToken' value="(.*?)"/)[0][0]
|
||||||
|
rescue
|
||||||
|
token = xhtml.scan(/value="(.*?)" name="wpEditToken" /)[0][0]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return token
|
||||||
|
end
|
||||||
|
|
||||||
def delete (title, reason)
|
def delete (title, reason)
|
||||||
$stderr.print("Deleting '", title, "'\n")
|
$stderr.print("Deleting '", title, "'\n")
|
||||||
token_page = post_form(url_delete(title),
|
token = get_token(post_form(url_delete(title),
|
||||||
{ "wpReason" => reason,
|
{ "wpReason" => reason,
|
||||||
"wpConfirm" => "1",})
|
"wpConfirm" => "1",}))
|
||||||
token = token_page.scan(/name='wpEditToken' value="(.*?)"/)[0][0]
|
|
||||||
post_form(url_delete(title),
|
post_form(url_delete(title),
|
||||||
{ "wpReason" => reason,
|
{ "wpReason" => reason,
|
||||||
"wpConfirm" => "1",
|
"wpConfirm" => "1",
|
||||||
|
@ -172,12 +184,9 @@ class WikiBot
|
||||||
# FIXME: This workaround loop really fucking sucks.
|
# FIXME: This workaround loop really fucking sucks.
|
||||||
token_page = @client.get_content(url_edit(title))
|
token_page = @client.get_content(url_edit(title))
|
||||||
end
|
end
|
||||||
time = token_page.scan(/value="(.*?)" name="wpEdittime" /)[0][0]
|
|
||||||
|
|
||||||
# No token for MediaWiki 1.3.x
|
time = token_page.scan(/value="(.*?)" name="wpEdittime" /)[0][0]
|
||||||
if token_page =~ /wpEditToken/
|
token = get_token(token_page)
|
||||||
token = token_page.scan(/value="(.*?)" name="wpEditToken" /)[0][0]
|
|
||||||
end
|
|
||||||
|
|
||||||
post_form(url_edit_submit(title),
|
post_form(url_edit_submit(title),
|
||||||
{ "wpTextbox1" => body,
|
{ "wpTextbox1" => body,
|
||||||
|
@ -250,12 +259,7 @@ class WikiBot
|
||||||
end
|
end
|
||||||
|
|
||||||
def protect(title, reason)
|
def protect(title, reason)
|
||||||
|
token = get_token(@client.get_content(url_protect(title)))
|
||||||
token_page = @client.get_content(url_protect(title))
|
|
||||||
# No token for MediaWiki 1.3.x
|
|
||||||
if token_page =~ /wpEditToken/
|
|
||||||
token = token_page.scan(/name='wpEditToken' value="(.*?)"/)[0][0]
|
|
||||||
end
|
|
||||||
|
|
||||||
post_form(url_protect(title),
|
post_form(url_protect(title),
|
||||||
{ "wpReasonProtect" => reason,
|
{ "wpReasonProtect" => reason,
|
||||||
|
|
Reference in a new issue