MediaWiki Ask Query - mediawiki

I have created two pages in a MediaWiki: John, and Category:Smith (note that the page Smith is a category page). Both pages were part of the Category:Person. When I run an Ask query to return all the pages that are under the category Person, only the page John is returned.
{{#ask: [[:Category:Person]] | ?label}}. It seems to me that the Ask query does not return pages that are category pages.
Any comment or solution to this problem?

The “Semantic MediaWiki” way to do it would be to query for properties, rather than categories. You could make both John and Category:Smith have the property [[Is a::Person]], and make a query like {{#ask:[[Is a::Person]] |?label}}.
There are valid uses for categories even with SMW, of course, but it is hard to give you advice on your semantic structure without seeing the whole picture. In your example, though, it seems to be like Smith is a surname, not a person, and thus should no be a subcategory to Category:Persons. Rather, you would normally have all persons directly in Category:Persons, and add properties like Has surname::Smith, etc, so that you could ask questions like {{#ask: [[Category:Persons]] [[Has surname::Smith]] [[Age::>36]]}}

Related

Onenote page hierarchy

Let's say I have a notebooks with name 'MyNotebook'. Now this notebook have a section group 'Group1' and now 'Group1' have another section group 'Group2'. Now inside 'Group2' I have section 'Section1' which has a page 'Page1'.
If we look this at like a directory structure the path to page will be -MyNotebook/Group1/Group2/Section1/Page1
When I try to get page using get page api I am able to get only immediate parent i.e Section1. So let's say I want get this complete hierarchy how I can get that ?
What API specifically are you using to get pages?
If you are using GET https://www.onenote.com/api/v1.0/me/notes/pages, this will give you all the pages, though that API has limitations (For example, it is paginated, so it will only give you the most recent 20 pages. In addition, it won't work if the user has a big number of sections).
https://blogs.msdn.microsoft.com/onenotedev/2017/07/21/a-few-performance-tips-for-using-the-onenote-api/
See the section "When getting all pages for a user, do so for each section separately"
I recommend you make a call like:
GET https://www.onenote.com/api/v1.0/me/notes/Notebooks?$expand=sections,sectionGroups($expand=sections,sectionGroups($levels=max;$expand=sections))
To obtain all the sections, and then make a call like:
GET https://www.onenote.com/api/v1.0/me/notes/sections/{id}/pages
To obtain each section's pages.
In addition to what Jorge said, if you specifically want the upwards hierarchy (and not downwards), you could do:
GET https://www.onenote.com/api/v1.0/me/notes/pages?$expand=parentSection($expand=parentSectionGroup($expand=parentSectionGroup($expand=parentNotebook)))
But as Jorge said, be careful when using the GET pages API since it has some limitations

Referencing data from one article on another

(For the downvote: the reason I am asking on Stack Overflow is because this is a problem involving "programming" with MediaWiki's template system)
I am looking for a way of including data on a MediaWiki article page, such that the data values can be referenced from other pages as well, without needing to duplicate the data on the other pages. Preferably without installing extra extensions.
What I am after is the ability to create an article page that looks like this:
<!-- This page is 'Example' in the main namespace -->
{{Infobox
| CreationDate = 2015-01-01
| CreatedBy = John Smith
}}
This article is about the item created by {{d|CreatedBy}}.
When this page is viewed in the browser, it should appear like this:
+------------------------+
| Example |
| Created on: 2015-01-01 |
| Created by: John Smith |
+------------------------+
This article is about the item created by John Smith.
And then on another page, I can reference the data in the above 'Example' page, like this:
* Example created by {{d|Example|CreatedBy}} on {{d|Example|CreationDate}}
Which will appear like this:
* Example created by John Smith on 2015-01-01
The typical use for this is to place the data on the article page, then be able to provide lists which are richer than you can achieve by using categories. Currently all the data on the lists is duplicated, so if it is ever changed it needs to be updated in two places - both within the article and in the "rich list".
I think I have worked out how to do this. Firstly, the correct solution seems to be to use Semantic MediaWiki, an extension designed for using MediaWiki for data storage. However in normal MediaWiki, this can be achieved as follows.
Page Template:D:
{{#if:{{{2|}}}|{{:{{{1}}}|{{{2}}}}}
| {{:{{FULLPAGENAME}}|{{{1}}}}}
}}
This allows {{d|Page|Field}} and {{d|Field}} to work as in the original question.
The infobox code also needs to be changed so that it is surrounded by this:
{{#if:{{{1|}}}|{{#ifeq:{{{1}}}|_valid|1|{{{{{{1}}}|}}}}}|
<!-- Existing infobox goes here -->
}}
This makes the infobox data-enabled. It means you can treat pages with one of these infoboxes on it as a template, and include it in another page. This is what Template:D does - it includes the whole article as a template, and this bit of code in the infobox ensures that instead of the entire page content being included at the Template:D point, only the field of interest gets included.
It also adds a special field called _valid with a value of 1 which can be used to detect pages that contain a valid infobox or not. If you make sure {{d|Pagename|_valid}} is equal to 1 (e.g. with {{#ifeq:...}}) before using any fields on that page, then you will get correct data. This is important because if the page you are using does not have a data-enabled infobox, then each Template:D occurrence will embed the entire contents of the page!
Last of all, each infobox has to be changed to be entered like this:
<onlyinclude>{{My Infobox|{{{1|}}}
| Field1 = Value1
| Field2 = Value2
| etc.
}}</onlyinclude>
This is required because MediaWiki can't embed <onlyinclude> tags within templates. The |{{{1|}}} at the end of the infobox name is used to pass the field parameter from Template:D through the article page and onto the infobox template itself.
Here is a working example of this:
Template:D
Data-enabled Infobox
List of pages, with content extracted from each page's infobox - note this page uses a custom {{#foreach:}} command to repeat wikitext for each page in a category, where {{#i:}} is replaced with the name of the page in each loop iteration. So {{d|{{#i:}}|Example}} is used to extract the Example field from the page in the current loop iteration.

mediawiki api. how to chose page from response

When I make api query sometimes I have list with few pages. For example
http://en.wikipedia.org/wiki/Ask gives a lot of pages, I need website "Ask.com, a web search engine, formerly Ask Jeeves"
can I make query only for some category ("websites")?
How I can check category for each page in response?
Thanks
There is no trivial way to do what you're asking. You could do something like this:
Get the list of pages the disambiguation page list. You could do this by listing the links on that page (action=query&prop=links).
Get the categories of all the pages from the previous step and use that to decide which one is the one you're looking for. This is not that simple, because Ask.com is not directly in Category:Websites, it's in one of its subcategories.
I have list with few pages, for example http://en.wikipedia.org/wiki/Ask
The problem is that you're not getting a list of pages, you just are getting an ordinary page which is in the disambiguation pages category. To get the list, you need to get the links in that page.
can I make query only for some category ("websites")?
No, mediawiki does not support that.
How I can check category for each page in response?
Use the links property as a title list generator and get the categories of each page in the response. In your case, that would be http://en.wikipedia.org/w/api.php?action=query&titles=Ask&generator=links&prop=categories (don't forget to continue the query).
If you are OK with "full-text search" for "ask",
you can do that like this:
http://en.wikipedia.org/w/api.php?format=json&action=query&generator=search&gsrsearch=ask%20incategory:%22Online%20companies%22&prop=info
As you can see, "search" text is [ask incategory:"Online companies"]
The same solution also can be seen at:
Wikipedia API: how to search for a term in a specific category

Export Excel file to create html webpages

I'd like to know how you would try to solve the following problem:
I have an excel-spreadsheet containing "linked information" (like a matrix-type) of business processes which need to be transformed to HTML websites.
Only certain parts of the spreadsheet should be exported.
The needed data consists of a hierarchical representations of certain categories that hold different components.
So for example category 1 consists of component A which has sub-components A1, A2 and so on.
The goal is to represent that single excel spreadsheet with html websites where the main-categories lead to pages with subcategories (always listing which subcategories they hold) and so on. Kind of like a process or business flow-chart.
Whenever something gets changed, added, removed within the spreadsheet I'd like to reflect this new information with the webpages accordingly.
The important part would be not having to edit several webpages but have everything rebuild at once - with the right structure.
My first thoughts were to define one XSD file to extract and transform the data with XSL and there create the final web structure. I'm not quite sure how time-intensive this would be and if I could actually have a satisfying outcome.
Maybe you have a better solution for me or you can point me to some link where something similar is accomplished.
I hope I could get my problem across.
Thanks for your time.
UPDATE
I made a simple version of my spreadsheet.
|*Sub*|*Description*|*Key*|
|SubName|some text| 11|
|SubName|some text| 11|
|SubName|some text| 21|
|SubName|some text| 22|
Here the "key"-column is needed to structure the final html layout where 11 and 12 belong to an even higher category 10 which later needs to be added to the result set. What also needs to be added is a "title-category" with the highest level of 1, 2 etc.
I want to reach a point where I can create an html webpage with the title categories being listed (just like headlines) and (on the same page) in some sort of rectangle frame one can see the next level of categories (here 10 and 20) which work as a link and take one to another webpage displaying category 10 and 20 now as headlines and have the sub-categories listed and clickable to reach the final, detailed table listing. So basically it's a top-to-bottom drill down of information.
I have three excel files with these title categories (for example: customers, orders, services)
Returning these three spreadsheets in one html webpage would be the goal. And from there one could click through to the detail pages. For now I'd be happy just to get one spreadsheet in order.
Has anyone got a good idea how I can:
a) write a schema-file to receive a proper xml file,
b) and of course turn the xml file to an html file.
if you can point me to some examples with a similar problem, I'd be happy as well.
thanks for your support.

Transclude a category in MediaWiki

I'm not quite sure if this is possible in MediaWiki.
I've got several categories, each containing a few pages. If you open a category page you'll see the contents of the category that usualy consists of these three parts:
A user defined text (which can be edited by using the edit link).
All subcategories that are attached to this category.
All pages that are attached to this category.
My goal is to create a page that includes at least part #3 of several categories. A page that shows me all page names that are attached to multiple categories of my choosing, grouped by their category.
My first approach was to use the standard transclude syntax of MediaWiki:
Category A contains these pages:
{{:Category:A}}
Category B contains these pages:
{{:Category:B}}
Category C contains these pages:
{{:Category:C}}
...
Unfortunatly, this only transcluded part #1 of a category: the user defined text. The page name listing was missing.
My second idea was to have a look at the parser functions. Perhaps there are some functions that offer enumerating through the pages of a category. But I didn't find any.
Perhaps there is a MediaWiki extension out there...
Is there a clever way to realize this?
Try http://www.mediawiki.org/wiki/Extension:CategoryTree, with the following syntax:
Category A contains these pages:
<categorytree hideroot="true" namespaces="-">Category A</categorytree>
If you want more control over how the results are displayed, you may want to give Semantic Mediawiki a try.
The syntax would look something like:
Pages in Category A:
{{#ask:[[Category:A]]
|format=ul
}}
Even if you are not using semantic properties, you can use the query mechanism to display pages based on categories.
The MediaWiki extension Dynamic Page List (http://www.mediawiki.org/wiki/Extension:DynamicPageList_(third-party)) does this with ease, producing bulleted lists of articles in a category:
Pages in Category A:
<dpl>
category=A
</dpl>
without a heavyweight solution like Semantic MediaWiki. Just install and go.
DPL has a rich syntax for more powerful dynamic lists. For example, to produce a numbered list in 3 columns:
<dpl>
category=A
mode=ordered
columns=3
</dpl>