Documentation ¶
Overview ¶
Package mediawiki provides a wrapper for interacting with the Mediawiki API
Please see https://www.mediawiki.org/wiki/API:Main_page for any API specific information or refer to any of the functions defined for the MWApi struct for information regarding this specific implementation.
The examples/ subdirectory contains an example application that uses this API.
Index ¶
- type MWApi
- func (m *MWApi) API(values ...map[string]string) ([]byte, error)
- func (m *MWApi) Download(filename string) (io.ReadCloser, error)
- func (m *MWApi) Edit(values map[string]string) error
- func (m *MWApi) GetEditToken() error
- func (m *MWApi) Login(username, password string) error
- func (m *MWApi) Logout()
- func (m *MWApi) Read(pageName string) (*Page, error)
- func (m *MWApi) Upload(dstFilename string, file io.Reader) error
- type Page
- type Response
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MWApi ¶
type MWApi struct { Domain string UseBasicAuth bool BasicAuthUser string BasicAuthPass string // contains filtered or unexported fields }
MWApi is used to interact with the MediaWiki server.
func New ¶
New generates a new MediaWiki API (MWApi) struct.
Example: mediawiki.New("https://en.wikipedia.org/w/api.php", "My Mediawiki Bot") Returns errors if the URL is invalid
func (*MWApi) API ¶
API is a generic interface to the Mediawiki API. Refer to the MediaWiki API reference for details.
This is used by all internal functions to interact with the API.
func (*MWApi) Download ¶
func (m *MWApi) Download(filename string) (io.ReadCloser, error)
Download a file.
Returns a readcloser that must be closed manually. Refer to the example app for additional usage.
func (*MWApi) Edit ¶
Edit a page.
This function will request an edit token if the MWApi struct doesn't already contain one.
Example:
editConfig := map[string]string{ "title": "SOME PAGE", "summary": "THIS IS WHAT SHOWS UP IN THE LOG", "text": "THE ENTIRE TEXT OF THE PAGE", } err = client.Edit(editConfig)
func (*MWApi) GetEditToken ¶
GetEditToken retrieves an edit token from the MediaWiki site and saves it.
This is necessary for editing any page.
The Edit() function will call this automatically but it is available if you want to make direct calls to API().
type Page ¶
type Page struct { Pageid int Ns int Title string Touched string Lastrevid int // Mediawiki will return ” for zero, this makes me sad. // If for some reason you need this value you'll have to // do some type assertion sillyness. Counter interface{} Length int Edittoken string Revisions []struct { Revid int `json:"revid"` Parentid int `json:"parentid"` Minor string `json:"minor"` User string `json:"user"` Userid int `json:"userid"` Timestamp time.Time `json:"timestamp"` Size int `json:"size"` Sha1 string `json:"sha1"` ContentModel string `json:"contentmodel"` Comment string `json:"comment"` ParsedComment string `json:"parsedcomment"` ContentFormat string `json:"contentformat"` Body string `json:"*"` // Take note, MediaWiki literally returns { '*': } Imageinfo []struct { Url string Descriptionurl string } }
A Page represents a MediaWiki page and its metadata.
type Response ¶
type Response struct { Query struct { // The JSON response for this part of the struct is dumb. // It will return something like { '23': { 'pageid': 23 ... // // As a workaround you can use PageSlice which will create // a list of pages from the map. Pages map[string]Page } }
Response is a struct used for unmarshaling the MediaWiki JSON response.