Skip to content
Browse files

r3614@pinealgland: sven | 2006-04-04 20:24:37 +0200

 added read_only flag for article


git-svn-id: svn://78.47.249.61/ruby-mediawiki/trunk@57 ba9c31aa-a806-0410-9a81-9f13d15ee83b
  • Loading branch information...
1 parent dd54d79 commit bad4c8c8fc129145b6faff29166b9f6c9e7f10d0 sven committed Apr 4, 2006
Showing with 20 additions and 9 deletions.
  1. +20 −9 lib/mediawiki/article.rb
View
29 lib/mediawiki/article.rb
@@ -15,6 +15,9 @@ class Article
##
# Article text, will be set by Article#reload
attr_accessor :text
+ ##
+ # this Article is read_only
+ attr_accessor :read_only
##
# Create a new Article instance
@@ -79,15 +82,22 @@ def parse(html)
doc = to_rexml( html )
# does not work for MediaWiki 1.4.x and is always the same name you ask for under 1.5.x
# @name = doc.elements['//span[@class="editHelp"]/a'].attributes['title']
- form = doc.elements['//form[@name="editform"]']
- @text = form.elements['textarea[@name="wpTextbox1"]'].text
- begin
- form.each_element('input') { |e|
- @wp_edittoken = e.attributes['value'] if e.attributes['name'] == 'wpEditToken'
- @wp_edittime = e.attributes['value'] if e.attributes['name'] == 'wpEdittime'
- }
- rescue NoMethodError
- # wpEditToken might be missing, that's ok
+ if form = doc.elements['//form[@name="editform"]']
+ # we got an editable article
+ @text = form.elements['textarea[@name="wpTextbox1"]'].text
+ begin
+ form.each_element('input') { |e|
+ @wp_edittoken = e.attributes['value'] if e.attributes['name'] == 'wpEditToken'
+ @wp_edittime = e.attributes['value'] if e.attributes['name'] == 'wpEdittime'
+ }
+ @read_only = false
+ rescue NoMethodError
+ # wpEditToken might be missing, that's ok
+ end
+ else
+ # the article is probably locked and you do not have sufficient privileges
+ @text = doc.elements['//textarea'].text
+ @read_only = true
end
end
@@ -99,6 +109,7 @@ def parse(html)
# minor_edit:: [Boolean] This is a Minor Edit
# watch_this:: [Boolean] Watch this article
def submit(summary, minor_edit=false, watch_this=false, retries=10)
+ raise "This Article is read-only." if read_only
puts "Posting to #{@wiki.article_url(full_name, @section)}&action=submit with wpEditToken=#{@wp_edittoken} wpEdittime=#{@wp_edittime}"
data = {'wpTextbox1' => @text, 'wpSummary' => summary, 'wpSave' => 1, 'wpEditToken' => @wp_edittoken, 'wpEdittime' => @wp_edittime}
data['wpMinoredit'] = 1 if minor_edit

0 comments on commit bad4c8c

Please sign in to comment.
Something went wrong with that request. Please try again.