Ruby-MediaWiki/Documentation: Unterschied zwischen den Versionen

Aus C3D2
Wechseln zu: Navigation, Suche
(I can even document myself :-))
(I can even document myself :-))
 
(7 dazwischenliegende Versionen von 2 Benutzern werden nicht angezeigt)
Zeile 3: Zeile 3:
 
==MediaWiki==
 
==MediaWiki==
  
===MediaWiki::dotfile===
+
Logger is required by article.rb
 +
 
 +
===MediaWiki::dotfile(myrealm=nil,mywiki=nil)===
 +
 
 
dotfile function reads the user's MediaWiki config and creates a Wiki instance.
 
dotfile function reads the user's MediaWiki config and creates a Wiki instance.
  
 
The filename is determined by the environment variable MEDIAWIKI_RC or defaults to ~/.mediawikirc .
 
The filename is determined by the environment variable MEDIAWIKI_RC or defaults to ~/.mediawikirc .
  
A configured wiki can be chosen with the MEDIAWIKI_WIKI environment variable, or defaults to the wiki pointed by default.
+
A configured wiki can be chosen with the MEDIAWIKI_WIKI environment variable, by the option mywiki or defaults to the wiki pointed by default.
  
 
A robot may set [myrealm] to retrieve a second result output: a section with this name in the current wiki's configuration file for configuration of specific robot tasks.
 
A robot may set [myrealm] to retrieve a second result output: a section with this name in the current wiki's configuration file for configuration of specific robot tasks.
 +
 +
 +
===MediaWiki::logger()===
  
  
 
==MediaWiki::Article==
 
==MediaWiki::Article==
 +
 +
Inherited from '''Object'''
  
 
The Article class represents MediaWiki articles.
 
The Article class represents MediaWiki articles.
  
===MediaWiki::Article#delete===
+
===MediaWiki::Article#name (RW)===
 +
 
 +
Article name, will be refreshed upon Article#reload
 +
 
 +
 
 +
===MediaWiki::Article#read_only (RW)===
 +
 
 +
this Article is read_only
 +
 
 +
 
 +
===MediaWiki::Article#text (RW)===
 +
 
 +
Article text, will be set by Article#reload
 +
 
 +
 
 +
===MediaWiki::Article::new(wiki, name, section = nil, load_text=true)===
 +
 
 +
Create a new Article instance
 +
 
 +
; wiki:
 +
: [Wiki] instance to be used to theive the MiniBrowser
 +
; name:
 +
: [String] Article name
 +
; section:
 +
: [Fixnum] Optional article section number
 +
; load_text:
 +
: [Boolean] Invoke Article#reload to retrieve Article#text
 +
 
 +
 
 +
===MediaWiki::Article#delete(reason)===
 +
 
 
Delete this article
 
Delete this article
  
* '''reason:''' [String] Delete reason
+
; reason:
 +
: [String] Delete reason
 +
 
 +
 
 +
===MediaWiki::Article#full_name()===
 +
 
 +
Return the full article name
 +
 
 +
This will only return @name, but may be overriden by descendants to include namespaces.
 +
 
 +
; result:
 +
: [String] Full name
 +
 
 +
 
 +
===MediaWiki::Article#parse(html)===
 +
 
 +
 
 +
===MediaWiki::Article#protect(reason, moves_only=false)===
  
===MediaWiki::Article#protect===
 
 
Protect this article
 
Protect this article
  
* '''reason:''' [String] Protect reason
+
; reason:
 +
: [String] Protect reason
 +
 
 +
 
 +
===MediaWiki::Article#reload()===
  
===MediaWiki::Article#reload===
 
 
Reload Article#text, should be done by Article#initialize.
 
Reload Article#text, should be done by Article#initialize.
  
  
===MediaWiki::Article#submit===
+
===MediaWiki::Article#submit(summary, minor_edit=false, watch_this=false, retries=10)===
 +
 
 
Push the '''Submit''' button
 
Push the '''Submit''' button
  
 
Send the modified Article#text to the MediaWiki.
 
Send the modified Article#text to the MediaWiki.
  
* '''summary:''' [String] Change summary
+
; summary:
* '''minor_edit:''' [Boolean] This is a Minor Edit
+
: [String] Change summary
* '''watch_this:''' [Boolean] Watch this article
+
; minor_edit:
 +
: [Boolean] This is a Minor Edit
 +
; watch_this:
 +
: [Boolean] Watch this article
 +
 
 +
 
 +
===MediaWiki::Article#to_rexml( html )===
 +
 
 +
 
 +
===MediaWiki::Article#unprotect(reason)===
  
===MediaWiki::Article#unprotect===
 
 
Unprotect this article
 
Unprotect this article
  
* '''reason:''' [String] Unprotect reason
+
; reason:
 +
: [String] Unprotect reason
 +
 
 +
 
 +
===MediaWiki::Article#what_links_here()===
  
===MediaWiki::Article#what_links_here===
 
 
What articles link to this article?
 
What articles link to this article?
  
* '''result:''' [Array] of [String] Article names
+
; result:
 +
: [Array] of [String] Article names
 +
 
 +
 
 +
===MediaWiki::Article#xhtml()===
  
===MediaWiki::Article#xhtml===
 
 
Get the XHTML, will invoke Article#xhtml_reload if not already cached
 
Get the XHTML, will invoke Article#xhtml_reload if not already cached
  
* '''result:''' [REXML::Element] html root element
+
; result:
 +
: [REXML::Element] html root element
  
===MediaWiki::Article#xhtml_reload===
 
Reload the xhtml, will be automatically done by Article#xhtml if not already cached.
 
  
 +
===MediaWiki::Article#xhtml_reload()===
  
===MediaWiki::Article::new===
+
Reload the xhtml, will be automatically done by Article#xhtml if not already cached.
Create a new Article instance
 
  
* '''wiki:''' [Wiki] instance to be used to theive the MiniBrowser
 
* '''name:''' [String] Article name
 
* '''section:''' [Fixnum] Optional article section number
 
* '''load_text:''' [Boolean] Invoke Article#reload to retrieve Article#text
 
  
 
==MediaWiki::Category==
 
==MediaWiki::Category==
 +
 +
Inherited from '''Article'''
  
 
The Category class represents MediaWiki categories.
 
The Category class represents MediaWiki categories.
  
===MediaWiki::Category#articles===
+
===MediaWiki::Category#articles()===
 +
 
 
Which articles belong to this category?
 
Which articles belong to this category?
  
* '''result:''' [Array] of [String] Article names
+
; result:
 +
: [Array] of [String] Article names
  
===MediaWiki::Category#reload===
 
Reload the XML, will be invoked by Category#articles, if not already cached.
 
  
 +
===MediaWiki::Category#full_name()===
  
===MediaWiki::Category::new===
+
This returns the full article name prefixed with "Category:" instead of the name, which should not carry a prefix.
Create a new Category instance
+
 
 +
 
 +
===MediaWiki::Category#reload()===
 +
 
 +
Calls the reload function of the super-class (Article#reload) but removes the prefix (namespace) then.
 +
 
 +
Use to full_name to obtain the name with namespace.
  
* '''wiki:''' [Wiki] instance to be used to theive the MiniBrowser
 
* '''name:''' [String] Category name, to be prefixed with "Category:" when being fetched
 
  
 
==MediaWiki::MiniBrowser==
 
==MediaWiki::MiniBrowser==
  
===MediaWiki::MiniBrowser#add_cookie===
+
Inherited from '''Object'''
 +
 
 +
The MiniBrowser is used to perform GET and POST requests over HTTP and HTTPS, supporting:
 +
 
 +
* HTTP-Auth encoding in URLs (proto://user:password@host/...)
 +
* Cookie support
 +
* HTTP Redirection (max. 10 in a row)
 +
 
 +
All interaction with MiniBrowser is normally done by MediaWiki::Wiki.
 +
 
 +
===MediaWiki::MiniBrowser::new(url)===
 +
 
 +
Initialize a MiniBrowser instance
 +
 
 +
; url:
 +
: [URI::HTTP] or [URI::HTTPS]
 +
 
 +
 
 +
===MediaWiki::MiniBrowser#add_cookie(cookies)===
 +
 
 +
Add cookies to the volatile cookie cache
 +
 
 +
; cookies:
 +
: [Array]
 +
 
 +
 
 +
===MediaWiki::MiniBrowser#cookies()===
 +
 
 +
Get the cookie cache in a serialized form ready for HTTP.
 +
 
 +
; result:
 +
: [String]
 +
 
 +
 
 +
===MediaWiki::MiniBrowser#get_content(url)===
 +
 
 +
Perform a GET request
 +
 
 +
This method accepts 10 HTTP redirects at max.
 +
 
 +
; url:
 +
: [String]
 +
; result:
 +
: [String] Document
 +
 
 +
 
 +
===MediaWiki::MiniBrowser#post_content(url, data)===
 +
 
 +
Perform a POST request
 +
 
 +
Will switch to MiniBrowser#get_content upon HTTP redirect.
 +
 
 +
; url:
 +
: [String]
 +
; data:
 +
: [Hash] POST data
 +
; result:
 +
: [String] Document
 +
 
 +
 
 +
==MediaWiki::SpecialPage==
 +
 
 +
Inherited from '''Article'''
  
===MediaWiki::MiniBrowser#cookies===
+
The SpecialPage class represents MediaWiki special pages.
  
===MediaWiki::MiniBrowser#get_content===
+
===MediaWiki::SpecialPage#xhtml_reload()===
  
===MediaWiki::MiniBrowser#post_content===
+
Reload the xhtml, will be automatically done by SpecialPage#xhtml if not already cached.
  
===MediaWiki::MiniBrowser::new===
 
  
 
==MediaWiki::Table==
 
==MediaWiki::Table==
  
===MediaWiki::Table#text===
+
Inherited from '''Object'''
 +
 
 +
The MediaWiki::Table class is used to parse existing tables from mediawiki articles and to create tables from arrays. Currently only the mediawiki pipe syntax is supported.
 +
 
 +
===MediaWiki::Table#data (RW)===
 +
 
 +
 
 +
===MediaWiki::Table#header (RW)===
 +
 
  
===MediaWiki::Table::new===
+
===MediaWiki::Table#header_style (RW)===
  
===MediaWiki::Table::parse===
 
takes the wiki markup of a table and returns a 2-dimensional array representing the rows and columns of the table
 
  
TODO: fill member variables according to parsed tables
+
===MediaWiki::Table#row_style (RW)===
 +
 
 +
 
 +
===MediaWiki::Table#style (RW)===
 +
 
 +
 
 +
===MediaWiki::Table::new( data = [], header = [] )===
 +
 
 +
Initialize a Table instance
 +
 
 +
; data:
 +
: [Array] 2-dimensional Array with the tables and cells
 +
; header:
 +
: [Array] 1-dimensional Array used as header
 +
 
 +
 
 +
===MediaWiki::Table::parse( text )===
 +
 
 +
Parses the wiki markup of a table and returns a 2-dimensional array representing rows and columns of the table. Currently only the mediawiki pipe syntax is supported.
 +
 
 +
; text:
 +
: [String] String to parse
 +
 
 +
 
 +
===MediaWiki::Table#text()===
 +
 
 +
Creates the mediawiki markup to be put in an article
  
  
 
==MediaWiki::Wiki==
 
==MediaWiki::Wiki==
  
===MediaWiki::Wiki#allpages===
+
Inherited from '''Object'''
 +
 
 +
===MediaWiki::Wiki#browser (R)===
 +
 
 +
The MiniBrowser instance used by this Wiki. This must be readable as it's used by Article and Category to fetch themselves.
 +
 
 +
 
 +
===MediaWiki::Wiki::new(url, user = nil, password = nil, loglevel = Logger::WARN)===
 +
 
 +
Initialize a new Wiki instance.
 +
 
 +
; url:
 +
: [String] URL-Path to index.php (without index.php), may containt <em>user:password</em> combination.
 +
; user:
 +
: [String] If not nil, log in with that MediaWiki username (see Wiki#login)
 +
; password:
 +
: [String] If not nil, log in with that MediaWiki password (see Wiki#login)
 +
; loglevel:
 +
: [Integer] Loglevel, default is to log all messages &gt;= Logger::WARN = 2
 +
 
 +
 
 +
===MediaWiki::Wiki#allpages(namespace_id=nil)===
 +
 
 
Returns the pages listed on "Special:Allpages"
 
Returns the pages listed on "Special:Allpages"
  
* '''result:''' [Array] of [String] Articlenames
+
TODO: Handle big wikis with chunked Special:Allpages
 +
 
 +
; namespace_id:
 +
: Optional namespace for article index (see Wiki#namespace_ids to retrieve id)
 +
; result:
 +
: [Array] of [String] Articlenames
 +
 
 +
 
 +
===MediaWiki::Wiki#article(name, section = nil)===
  
===MediaWiki::Wiki#article===
 
 
Return a new Article instance with given name, will be constructed with [self] (for MiniBrowser usage)
 
Return a new Article instance with given name, will be constructed with [self] (for MiniBrowser usage)
  
* '''name:''' [String] Article name
+
; name:
* '''section:''' [Fixnum] Optional section number
+
: [String] Article name
 +
; section:
 +
: [Fixnum] Optional section number
 +
 
 +
 
 +
===MediaWiki::Wiki#article_url(name, section = nil)===
  
===MediaWiki::Wiki#article_url===
 
 
Construct the URL to a specific article
 
Construct the URL to a specific article
  
Zeile 130: Zeile 330:
 
Often called by Article, Category, ...
 
Often called by Article, Category, ...
  
* '''name:''' [String] Article name
+
; name:
* '''section:''' [Fixnum] Optional section number
+
: [String] Article name
 +
; section:
 +
: [Fixnum] Optional section number
 +
 
 +
 
 +
===MediaWiki::Wiki#category(name)===
  
===MediaWiki::Wiki#category===
 
 
Return a new Category instance with given name, will be constructed with [self] (for MiniBrowser usage)
 
Return a new Category instance with given name, will be constructed with [self] (for MiniBrowser usage)
  
* '''name:''' [String] Category name (to be prepended with "Category:")
+
; name:
 +
: [String] Category name (to be prepended with "Category:")
 +
 
 +
 
 +
===MediaWiki::Wiki#full_article_url(name, section=nil)===
 +
 
 +
 
 +
===MediaWiki::Wiki#login( username, password )===
  
===MediaWiki::Wiki#login===
 
 
Log in into MediaWiki
 
Log in into MediaWiki
  
 
This is '''not''' HTTP authentication (put HTTP-Auth into [url] of Wiki#initialize!)
 
This is '''not''' HTTP authentication (put HTTP-Auth into [url] of Wiki#initialize!)
  
* '''user:''' [String] MediaWiki username
+
; user:
* '''password:''' [String] MediaWiki password
+
: [String] MediaWiki username
 +
; password:
 +
: [String] MediaWiki password
 +
 
 
May raise an exception if cannot authenticate
 
May raise an exception if cannot authenticate
  
  
===MediaWiki::Wiki::new===
+
===MediaWiki::Wiki#namespace_ids()===
Initialize a new Wiki instance.
+
 
 +
Retrieve all namespaces and their IDs, which could be used for Wiki#allpages
  
* '''url:''' [String] URL-Path to index.php (without index.php), may containt <tt>user:password</tt> combination.
+
; result:
* '''user:''' [String] If not nil, log in with that MediaWiki username (see Wiki#login)
+
: [Hash] String =&gt; Fixnum
* '''password:''' [String] If not nil, log in with that MediaWiki password (see Wiki#login)
 

Aktuelle Version vom 11. Juni 2006, 00:47 Uhr

Inhaltsverzeichnis

Ruby-MediaWiki Documentation

MediaWiki

Logger is required by article.rb

MediaWiki::dotfile(myrealm=nil,mywiki=nil)

dotfile function reads the user's MediaWiki config and creates a Wiki instance.

The filename is determined by the environment variable MEDIAWIKI_RC or defaults to ~/.mediawikirc .

A configured wiki can be chosen with the MEDIAWIKI_WIKI environment variable, by the option mywiki or defaults to the wiki pointed by default.

A robot may set [myrealm] to retrieve a second result output: a section with this name in the current wiki's configuration file for configuration of specific robot tasks.


MediaWiki::logger()

MediaWiki::Article

Inherited from Object

The Article class represents MediaWiki articles.

MediaWiki::Article#name (RW)

Article name, will be refreshed upon Article#reload


MediaWiki::Article#read_only (RW)

this Article is read_only


MediaWiki::Article#text (RW)

Article text, will be set by Article#reload


MediaWiki::Article::new(wiki, name, section = nil, load_text=true)

Create a new Article instance

wiki
[Wiki] instance to be used to theive the MiniBrowser
name
[String] Article name
section
[Fixnum] Optional article section number
load_text
[Boolean] Invoke Article#reload to retrieve Article#text


MediaWiki::Article#delete(reason)

Delete this article

reason
[String] Delete reason


MediaWiki::Article#full_name()

Return the full article name

This will only return @name, but may be overriden by descendants to include namespaces.

result
[String] Full name


MediaWiki::Article#parse(html)

MediaWiki::Article#protect(reason, moves_only=false)

Protect this article

reason
[String] Protect reason


MediaWiki::Article#reload()

Reload Article#text, should be done by Article#initialize.


MediaWiki::Article#submit(summary, minor_edit=false, watch_this=false, retries=10)

Push the Submit button

Send the modified Article#text to the MediaWiki.

summary
[String] Change summary
minor_edit
[Boolean] This is a Minor Edit
watch_this
[Boolean] Watch this article


MediaWiki::Article#to_rexml( html )

MediaWiki::Article#unprotect(reason)

Unprotect this article

reason
[String] Unprotect reason


MediaWiki::Article#what_links_here()

What articles link to this article?

result
[Array] of [String] Article names


MediaWiki::Article#xhtml()

Get the XHTML, will invoke Article#xhtml_reload if not already cached

result
[REXML::Element] html root element


MediaWiki::Article#xhtml_reload()

Reload the xhtml, will be automatically done by Article#xhtml if not already cached.


MediaWiki::Category

Inherited from Article

The Category class represents MediaWiki categories.

MediaWiki::Category#articles()

Which articles belong to this category?

result
[Array] of [String] Article names


MediaWiki::Category#full_name()

This returns the full article name prefixed with "Category:" instead of the name, which should not carry a prefix.


MediaWiki::Category#reload()

Calls the reload function of the super-class (Article#reload) but removes the prefix (namespace) then.

Use to full_name to obtain the name with namespace.


MediaWiki::MiniBrowser

Inherited from Object

The MiniBrowser is used to perform GET and POST requests over HTTP and HTTPS, supporting:

  • HTTP-Auth encoding in URLs (proto://user:password@host/...)
  • Cookie support
  • HTTP Redirection (max. 10 in a row)

All interaction with MiniBrowser is normally done by MediaWiki::Wiki.

MediaWiki::MiniBrowser::new(url)

Initialize a MiniBrowser instance

url
[URI::HTTP] or [URI::HTTPS]


MediaWiki::MiniBrowser#add_cookie(cookies)

Add cookies to the volatile cookie cache

cookies
[Array]


MediaWiki::MiniBrowser#cookies()

Get the cookie cache in a serialized form ready for HTTP.

result
[String]


MediaWiki::MiniBrowser#get_content(url)

Perform a GET request

This method accepts 10 HTTP redirects at max.

url
[String]
result
[String] Document


MediaWiki::MiniBrowser#post_content(url, data)

Perform a POST request

Will switch to MiniBrowser#get_content upon HTTP redirect.

url
[String]
data
[Hash] POST data
result
[String] Document


MediaWiki::SpecialPage

Inherited from Article

The SpecialPage class represents MediaWiki special pages.

MediaWiki::SpecialPage#xhtml_reload()

Reload the xhtml, will be automatically done by SpecialPage#xhtml if not already cached.


MediaWiki::Table

Inherited from Object

The MediaWiki::Table class is used to parse existing tables from mediawiki articles and to create tables from arrays. Currently only the mediawiki pipe syntax is supported.

MediaWiki::Table#data (RW)

MediaWiki::Table#header (RW)

MediaWiki::Table#header_style (RW)

MediaWiki::Table#row_style (RW)

MediaWiki::Table#style (RW)

MediaWiki::Table::new( data = [], header = [] )

Initialize a Table instance

data
[Array] 2-dimensional Array with the tables and cells
header
[Array] 1-dimensional Array used as header


MediaWiki::Table::parse( text )

Parses the wiki markup of a table and returns a 2-dimensional array representing rows and columns of the table. Currently only the mediawiki pipe syntax is supported.

text
[String] String to parse


MediaWiki::Table#text()

Creates the mediawiki markup to be put in an article


MediaWiki::Wiki

Inherited from Object

MediaWiki::Wiki#browser (R)

The MiniBrowser instance used by this Wiki. This must be readable as it's used by Article and Category to fetch themselves.


MediaWiki::Wiki::new(url, user = nil, password = nil, loglevel = Logger::WARN)

Initialize a new Wiki instance.

url
[String] URL-Path to index.php (without index.php), may containt user:password combination.
user
[String] If not nil, log in with that MediaWiki username (see Wiki#login)
password
[String] If not nil, log in with that MediaWiki password (see Wiki#login)
loglevel
[Integer] Loglevel, default is to log all messages >= Logger::WARN = 2


MediaWiki::Wiki#allpages(namespace_id=nil)

Returns the pages listed on "Special:Allpages"

TODO: Handle big wikis with chunked Special:Allpages

namespace_id
Optional namespace for article index (see Wiki#namespace_ids to retrieve id)
result
[Array] of [String] Articlenames


MediaWiki::Wiki#article(name, section = nil)

Return a new Article instance with given name, will be constructed with [self] (for MiniBrowser usage)

name
[String] Article name
section
[Fixnum] Optional section number


MediaWiki::Wiki#article_url(name, section = nil)

Construct the URL to a specific article

Uses the [url] the Wiki instance was constructed with, appends "index.php", the name parameter and, optionally, the section.

Often called by Article, Category, ...

name
[String] Article name
section
[Fixnum] Optional section number


MediaWiki::Wiki#category(name)

Return a new Category instance with given name, will be constructed with [self] (for MiniBrowser usage)

name
[String] Category name (to be prepended with "Category:")


MediaWiki::Wiki#full_article_url(name, section=nil)

MediaWiki::Wiki#login( username, password )

Log in into MediaWiki

This is not HTTP authentication (put HTTP-Auth into [url] of Wiki#initialize!)

user
[String] MediaWiki username
password
[String] MediaWiki password

May raise an exception if cannot authenticate


MediaWiki::Wiki#namespace_ids()

Retrieve all namespaces and their IDs, which could be used for Wiki#allpages

result
[Hash] String => Fixnum