Wikidata API: Check whether a Wikivoyage article is linked from Wikidata - mediawiki

I want to programmatically check whether an English Wikivoyage article (for instance Bronzeville) is linked from the Wikidata database or not.
For instance, the Bronzeville article at English Wikivoyage is NOT linked from Wikidata (even though the item exists).
Note: Some Wikidata items have labels, but that does not imply existence or non-existence, as some items have no label, and some items with the same label refer to two different things (for instance a place and a person).
Is there a way to do this, via the Wikidata API or other?

Whether a Wikivoyage article is linked from Wikidata or not can be found via a query like the ones below:
https://en.wikivoyage.org/w/api.php?action=query&titles=Bronzeville&prop=pageprops&format=jsonfm
https://en.wikivoyage.org/w/api.php?action=query&titles=Paris&prop=pageprops&format=jsonfm
If the response contains "wikibase_item", then it means it is linked.

You can use the wbgetentities method for this. To do this, ask it for the entity that's related to the desired article on enwikivoyage. For example, for an entity where the link exists (Prague):
http://www.wikidata.org/w/api.php?action=wbgetentities&sites=enwikivoyage&titles=Prague&format=xml&props=
You get result like this:
<entity id="q1085" type="item" />
If the link doesn't exist (Bronzeville):
http://www.wikidata.org/w/api.php?action=wbgetentities&sites=enwikivoyage&titles=Bronzeville&format=xml&props=
The result is:
<entity site="enwikivoyage" title="Bronzeville" missing="" />
(The props= part of the query is there so that you don't get all the information about the entry, just whether it exists or not.)

Related

How to get all contributions of a wikipedia user?

Given a Wikipedia user/editor id and a timeframe, is there a way in Python to get details about all the contributions/edits made the user/editor? I want to fetch details like page edited, action taken, bytes added/deleted in case of revision, and comments (if any). Is this possible at all?
Many thanks!
Yes, pywikibot’s User class has a .contributions() method you can use to iterate over all contributions for a user.
It returns a generator that, for each edit, yields a tuple of (pywikibot.Page, oldid, pywikibot.Timestamp, comment). You don’t get the diff, but you can retrieve the page at this point (page.getOldVersion(oldid=…)) and do the diff from the point just before.
Simple code example:
from pywikibot import Site, User
user = User(Site(), "SanMelkote")
for page, oldid, ts, comment in user.contributions():
print(Page.title(), comment)

Retrieve Assortments (Dutch: "Assortimenten") on Exact Online

For a CSV dump of articles with stock and price information from Exact Online, I need to restrict the list of articles the CSV to articles in an Assortment (Dutch: "Assortiment").
The REST-APIs do not seem to offer this information. It is possible to retrieve Item information, but the assortment is nowhere to be found:
select * from exactonlinerest..items
It seems weird that it is missing from the APIs. Assortments are used often on Exact Online.
An alternative might be to maintain a separate table in addition to Exact Online for assortimenten (assortments).
Or is there a better approach?
You can use the XML API better:
select * from itemcategories
But note that the fields have a totally different naming style, since the XML APIs have typically very long column names. For item code, it would be ITEM_CODE_ATTR.
The GUIDs are only present in some weird text format {GUID}, so remember to remove the { and } first.

How to get list of Wikipedia pages need edit based on categories selection?

How to take a list of pages which need edit based on categories and sub-categories by using MediaWiki API?
If assuming that all Wikipedia pages that need edit include Template:Cleanup, which means that all they will be placed in Category:All articles needing cleanup, to get a list of all them by using MediaWiki API you have two variants:
Variant 1: Get all articles which include Template:Cleanup with embeddedin:
https://en.wikipedia.org/w/api.php?action=query&list=embeddedin&einamespace=0&eititle=Template:Cleanup
Variant 2: Get all articles from Category:All articles needing cleanup with categorymembers:
https://en.wikipedia.org/w/api.php?action=query&list=categorymembers&cmnamespace=0&cmtitle=Category:All articles needing cleanup

Categories and Keywords access via Razor Template in Tridion

I am attempting to access values in the Categories and Keywords information for a Tridion Publication via a Razor TBB in Tridion 2011. The Razor documentation lists the following example code:
<ul>
#foreach (var keyword in Publication.MetaData.SomeKeywordFields) {
<li>#keyword.Title (#keyword.Id)</li>
}
</ul>
I have a Keyword inside of a Category though... in fact, that's the only way I am myself aware that you can even have a Keyword in Tridion, but correct me if I am wrong. Extrapolating from the example's syntax, I tried the following where "myCategory" is a Category in the publication, and "myKeyword" is a Keyword inside of the myCategory Category:
#foreach (var keyword in Publication.MetaData.myCategory) {
if(#keyword.Title == "myKeyword") {
#keyword.Title
}
When I run this template, I get an error stating that DynamicItemsFields: Key 'testcategory' Not Found In ItemFields (Object reference not set to an instance of an object)
Can anyone help with identifying if it is even possible to do what I am attempting here (as it seems like it is based on the documentation but still not sure) and if so, provide an example of the correct syntax?
You're almost there with your code except that you're using the actual CategoryName. As Puf commented, you have to use the "fieldname" of you Publication Metadata not the actual CategoryName. You should just change the "myCategory" to the actual fieldname
#foreach (var keyword in Publication.MetaData.*<<FIELDNAME>>*) {
if(#keyword.Title == "myKeyword") {
#keyword.Title
}
}
[FIELDNAME] --> is the XMLName of publication metadata schema.
Keywords are indeed always within a Category or another Keyword. But they are used within items like Components and (as in the example) metadata on Publications, Folders, etc.
The example from the documentation is outputting each value of a multi-valued metadata Keyword field on the Publication (i.e. "Allow Multiple Values", "Values selected from a list" and "Category" all checked in the Metadata Schema).
If you are trying to do something similar, you can indeed modify the name of the field and it will work. From your question, however, it seems like you are trying to loop over all Keywords within a certain Category - which requires a different approach.
For that, you would need the equivalent of a GetList call within your TBB. I'm not familiar enough with the Razor mediator to provide sample code for that, sorry.
Thanks to Ram G in chat:
The Publication itself, typically your 010, 020... 050 etc. levels, can have a metadata schema attached to them as well. The XMLName of the field being targeted by the Razor logic block above is actually the field name of this metadata schema item, not the name of the Category itself. In the metadata schema for the publication, if you select the Design tab, Make your XML field for the item a "Text" type, select "Options will be selected from a list", by default, another Checkbox will appear called "Category" which, if checked, automatically pulls in the full list of Category items present in that publication. So, when that Field is targeted by the Razor logic now, it is in multiple steps targeting the Category value as well.
Thanks again Ram G

bot to edit mediawiki categories

I have a mediawiki with different type of categories.
If a page has 2 categories
[[Category:Pear]][[Category:Strawberry]])
I want to add a third category
[[Category:Fruit_Salad]]
Is it possible to do that automatically? (using a bot for instance)
Edit: In fact, what I need is an API for categories
a way to read the category
a way to add a new category
The rest can be done by any program
You are probably looking for the pywikipediabot framework. (Check catlib.py for the category manipulation code, and category.py for an end-user-friendly mass category modification bot.)