Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3674
webaccess_mediawiki.rb
Public
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Authored By
•
bzimport
Nov 21 2014, 9:35 PM
2014-11-21 21:35:26 (UTC+0)
Size
2 KB
Referenced Files
None
Subscribers
None
webaccess_mediawiki.rb
View Options
#!/usr/local/bin/ruby
require
'net/http'
require
'net/https'
require
'rubygems'
require
'mechanize'
agent
=
WWW
::
Mechanize
.
new
#--------------------------------------------------------------------
# Get Wiki's login page
#--------------------------------------------------------------------
puts
"Get login page"
page
=
agent
.
get
(
'https://wiki.ourcompany.de/index.php?title=Special:Userlogin'
)
puts
"Page:
\"
"
+
page
.
title
+
"
\"
"
#puts page.body
# fill the login form
puts
"login"
login_form
=
page
.
form
(
'userlogin'
)
login_form
.
wpName
=
'myusername'
login_form
.
wpPassword
=
'mypassword'
# submit the form
page
=
agent
.
submit
(
login_form
,
login_form
.
buttons
.
first
)
#--------------------------------------------------------------------
# Check next page's title to determine if login was successful
#--------------------------------------------------------------------
# the title of this page should read "Login successful - UB-Wiki"
puts
"Page:
\"
"
+
page
.
title
+
"
\"
"
#--------------------------------------------------------------------
# Get page to edit
#--------------------------------------------------------------------
puts
"Get page to edit"
page
=
agent
.
get
(
'https://wiki.ourcompany.de/index.php/Rubytest'
)
puts
"Page:
\"
"
+
page
.
title
+
"
\"
"
# click the edit button
page
=
agent
.
click
page
.
links
.
text
(
'Edit'
)
# get text out of edit form (field wpTextbox1)
puts
"Get text"
edit_form
=
page
.
form
(
'editform'
)
text
=
edit_form
.
wpTextbox1
# edit text
puts
"Edit text"
edit_form
.
wpTextbox1
=
text
+
text
.
length
.
to_s
# enter comment at "Summary" (field name wpSummary)
edit_form
.
wpSummary
=
"Test
\n
"
# submit the form
puts
"Save page"
page
=
agent
.
submit
(
edit_form
,
edit_form
.
buttons
.
first
)
puts
"Page:
\"
"
+
page
.
title
+
"
\"
"
# debug output of all form's buttons
edit_form
.
buttons
.
each_with_index
do
|
b
,
index
|
puts
"Button "
+
index
.
to_s
+
": "
+
b
.
name
+
","
+
b
.
value
end
# pretty print the page
pp
page
puts
"---"
# debug output all page links
page
.
links
.
each
do
|
link
|
puts
link
.
text
end
puts
"---"
File Metadata
Details
Attached
Mime Type
text/x-ruby
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3241
Default Alt Text
webaccess_mediawiki.rb (2 KB)
Attached To
Mode
T10912: The "Prompt me when entering a blank edit summary" wrongly triggers for undo edits
Attached
Detach File
Event Timeline
Log In to Comment