Documentation
¶
Overview ¶
Package provides some mediawiki convenience functions along with a pseudo-ORM for creating wikibase items and their associated properties.
Index ¶
- func StringClaimToAPIData(value string) (*string, error)
- type APIError
- type AccessToken
- type Client
- func (c *Client) CreateClaimOnItem(item ItemPropertyType, property_id string, encoded_data []byte) (string, error)
- func (c *Client) CreateItemInstance(label string, i interface{}) error
- func (c *Client) CreateOrUpdateArticle(title string, body string) (int, error)
- func (c *Client) FetchItemIDsForLabel(label string) ([]string, error)
- func (c *Client) FetchPropertyIDsForLabel(label string) ([]string, error)
- func (c *Client) GetEditingToken() (string, error)
- func (c *Client) MapItemConfigurationByLabel(label string, create_if_not_there bool) error
- func (c *Client) MapPropertyAndItemConfiguration(i interface{}, create_if_not_there bool) error
- func (c *Client) ProtectPageByID(page_id int) error
- func (c *Client) ProtectPageByTitle(title string) error
- func (c *Client) UploadClaimsForItem(i interface{}, allow_refresh bool) error
- type ConsumerInformation
- type ItemClaim
- type ItemHeader
- type ItemPropertyType
- type NetworkClientInterface
- type OAuthInformation
- type OAuthNetworkClient
- type QuantityClaim
- type SparqlHead
- type SparqlResponse
- type SparqlResult
- type SparqlResults
- type SparqlValue
- type TimeDataClaim
- type WikiBaseType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func StringClaimToAPIData ¶
Types ¶
type AccessToken ¶
type Client ¶
type Client struct { // Mapping of labels to IDs for Items and Properties. PropertyMap map[string]string ItemMap map[string]ItemPropertyType // contains filtered or unexported fields }
The Wikibase/media wiki client struct. Create this with a call to NewClient, passing it a valid network client.
func NewClient ¶
func NewClient(oauthClient NetworkClientInterface) *Client
NewClient is a factory method for creating a new Client object.
func (*Client) CreateClaimOnItem ¶
func (*Client) CreateItemInstance ¶
CreateItemInstance will take a pointer to a Go structure that has the embedded wikibase header and item and property tags on its fields and create a new item with the provided label. Any fields in the structure with a Property tag that does not contain the "omitoncreate" clause will also be created as item claims at the same time.
func (*Client) CreateOrUpdateArticle ¶
CreateOrUpdateArticle will create a new mediawiki page if necessary, and set its content to the provided body text. The body should be in wikitext format, or if your Mediawiki instance supports it, parsoidHTML.
func (*Client) FetchItemIDsForLabel ¶
FetchPropertyIDsForLabel will find Wikibase items with the exact matching label and return them as a list of Q numbers.
func (*Client) FetchPropertyIDsForLabel ¶
FetchPropertyIDsForLabel will find Wikibase properties with the exact matching label and return them as a list of P numbers.
func (*Client) GetEditingToken ¶
GetEditingToken returns an already acquired editing token for this session, or fetches a new one if necessary. This method is thread safe.
func (*Client) MapItemConfigurationByLabel ¶
MapItemConfigurationByLabel will attempt to find the item with the exact matching label on Wikibase and populate the Wikibase client structs internal map of labels to Item IDs. The client will use this when performing ORM like operations on structures to upload to Wikibase.
func (*Client) MapPropertyAndItemConfiguration ¶
MapPropertyAndItemConfiguration will take a pointer to a Go structure that has the embedded wikibase header and item and property tags on its fields and create a map that goes from the labels in the tags to the Item and Property IDs used by Wikibase.
func (*Client) ProtectPageByID ¶
ProtectPageByID will attempt to set the edit protection on a page with the given title to admin. Will fail if page does not exist.
func (*Client) ProtectPageByTitle ¶
ProtectPageByTitle will attempt to set the edit protection on a page with the given title to admin. Will fail if page does not exist.
func (*Client) UploadClaimsForItem ¶
UploadClaimsForItem will take a pointer to a Go structure that has the embedded wikibase header and item and property tags on its fields and set the claims on the item to match. The item must have been created already. If allow_refresh is set to true, all properties will be written, regardless of whether they've been uploaded before; if set to false only items with no existing Wikibase Property ID in the map will be updated.
type ConsumerInformation ¶
type ItemClaim ¶
func ItemClaimToAPIData ¶
func ItemClaimToAPIData(value ItemPropertyType) (ItemClaim, error)
type ItemHeader ¶
type ItemHeader struct { ID ItemPropertyType `json:"wikibase_id,omitempty"` PropertyIDs map[string]string `json:"wikibase_property_ids,omitempty"` }
ItemHeader must be embedded in all structs that are to be uploaded to Wikibase. If you give this embedded struct a JSON Tag then you can save and restore the Wikibase ID state for the entire struct, which can be used to avoid creating the item multiple times when you run.
Each field that you want to sync as a property on the item in Wikibase must have a "property" tag, with the name of the label of a property on Wikibase. We use labels rather than P numbers as it's impossible to guarantee that production, staging, and test servers will use the same P numbers as they are allocated automatically by the Wikibase server; labels on the other hand can be managed by humans/bots. You should always call the client function MapPropertyAndItemConfiguration to populate it's internal map before attempting to create/update Items and their properties. If you add an "omitoncreate" clause then the Property will not be added to the item at create time, only later on during property sync.
type ItemPropertyType ¶
type ItemPropertyType string
If you're trying to encode structs to properties then you should use these types to help guide the code in encoding things properly for the API
type NetworkClientInterface ¶
type NetworkClientInterface interface { Get(args map[string]string) (io.ReadCloser, error) Post(args map[string]string) (io.ReadCloser, error) }
type OAuthInformation ¶
type OAuthInformation struct { Consumer ConsumerInformation `json:"consumer"` Access *AccessToken `json:"access,omitempty"` }
func LoadOauthInformation ¶
func LoadOauthInformation(path string) (OAuthInformation, error)
type OAuthNetworkClient ¶
type OAuthNetworkClient struct { APIURL string AccessToken *oauth.AccessToken // contains filtered or unexported fields }
func NewOAuthNetworkClient ¶
func NewOAuthNetworkClient(oauthInfo OAuthInformation, urlbase string) *OAuthNetworkClient
func (*OAuthNetworkClient) Get ¶
func (client *OAuthNetworkClient) Get(args map[string]string) (io.ReadCloser, error)
func (*OAuthNetworkClient) Post ¶
func (client *OAuthNetworkClient) Post(args map[string]string) (io.ReadCloser, error)
type QuantityClaim ¶
func QuantityClaimToAPIData ¶
func QuantityClaimToAPIData(value int) (QuantityClaim, error)
type SparqlHead ¶
type SparqlHead struct {
Vars []string `json:"vars"`
}
type SparqlResponse ¶
type SparqlResponse struct { Head SparqlHead `json:"head"` Results SparqlResults `json:"results"` }
func MakeSPARQLQuery ¶
func MakeSPARQLQuery(service_url string, sparql string) (*SparqlResponse, error)
type SparqlResult ¶
type SparqlResult map[string]SparqlValue
type SparqlResults ¶
type SparqlResults struct {
Bindings []SparqlResult `json:"bindings"`
}
type SparqlValue ¶
type TimeDataClaim ¶
type TimeDataClaim struct { Time string `json:"time"` TimeZone int `json:"timezone"` Before int `json:"before"` After int `json:"after"` Precision int `json:"precision"` CalendarModel string `json:"calendarmodel"` }
func TimeDataClaimToAPIData ¶
func TimeDataClaimToAPIData(value string) (TimeDataClaim, error)
type WikiBaseType ¶
type WikiBaseType string
const ( WikiBaseProperty WikiBaseType = "property" WikiBaseItem WikiBaseType = "item" )