module MediaWiki::Gateway::Site
Public Instance Methods
export(page_titles, options = {})
click to toggle source
Exports a page or set of pages
- page_titles
-
String or array of page titles to fetch
- options
-
Hash of additional options
Returns MediaWiki
XML dump
# File lib/media_wiki/gateway/site.rb 30 def export(page_titles, options = {}) 31 send_request(options.merge( 32 'action' => 'query', 33 'titles' => Array(page_titles).join('|'), 34 'export' => nil, 35 'exportnowrap' => nil 36 )) 37 end
extensions(options = {})
click to toggle source
Get a list of all installed (and registered) extensions
- options
-
Hash of additional options
Returns array of extensions (name => version)
# File lib/media_wiki/gateway/site.rb 82 def extensions(options = {}) 83 res = send_request(options.merge( 84 'action' => 'query', 85 'meta' => 'siteinfo', 86 'siprop' => 'extensions' 87 )) 88 89 REXML::XPath.match(res, '//ext').each_with_object({}) { |extension, extensions| 90 name = extension.attributes['name'] || '' 91 extensions[name] = extension.attributes['version'] 92 } 93 end
import(xmlfile, options = {})
click to toggle source
Imports a MediaWiki
XML dump
- xml
-
String or array of page names to fetch
- options
-
Hash of additional options
Returns XML array <api><import><page/><page/>… <page revisions=“1”> (or more) means successfully imported <page revisions=“0”> means duplicate, not imported
# File lib/media_wiki/gateway/site.rb 15 def import(xmlfile, options = {}) 16 send_request(options.merge( 17 'action' => 'import', 18 'xml' => File.new(xmlfile), 19 'token' => get_token('import', 'Main Page'), # NB: dummy page name 20 'format' => 'xml' 21 )) 22 end
namespaces_by_prefix(options = {})
click to toggle source
Get a list of all known namespaces
- options
-
Hash of additional options
Returns array of namespaces (name => id)
# File lib/media_wiki/gateway/site.rb 64 def namespaces_by_prefix(options = {}) 65 res = send_request(options.merge( 66 'action' => 'query', 67 'meta' => 'siteinfo', 68 'siprop' => 'namespaces' 69 )) 70 71 REXML::XPath.match(res, '//ns').each_with_object({}) { |namespace, namespaces| 72 prefix = namespace.attributes['canonical'] || '' 73 namespaces[prefix] = namespace.attributes['id'].to_i 74 } 75 end
siteinfo(options = {})
click to toggle source
Get the wiki's siteinfo as a hash. See www.mediawiki.org/wiki/API:Siteinfo.
- options
-
Hash of additional options
# File lib/media_wiki/gateway/site.rb 42 def siteinfo(options = {}) 43 res = send_request(options.merge( 44 'action' => 'query', 45 'meta' => 'siteinfo' 46 )) 47 48 REXML::XPath.first(res, '//query/general') 49 .attributes.each_with_object({}) { |(k, v), h| h[k] = v } 50 end