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