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>
Related
I want to extract the pages mentioned in the infobox and templates of pages.
E.g. From this page:
https://en.wikipedia.org/wiki/DNA
I want to extract all of the links in the infobox, like: "Genetics", "Introduction to Genetics" etc.
I want to do it, by using the sql dumps, possibly avoiding to parse the xml of whole pages, and I don't want to do it with APIs.
I could not find a way.
While Pagelinks does include also the links of infoboxes, I cannot find a way to exclude them.
I thought Templatelinks may have that info, but it is not: I could not find the pageids of the corresponding links in infoboxes.
Where is this information stored?
Or which kind of tables should I look at?
I consulted previous questions:
where can I find the infobox templates used in wiki?
and Mediawiki reference:
https://www.mediawiki.org/wiki/Manual:Templatelinks_table#Schema_summary
but could not find a solution.
That is a sidebar rather than an infobox: https://en.wikipedia.org/wiki/Template:Genetics_sidebar
I don't think there's a way of doing it other than parsing the content of the template to extract the links or using the API: e.g. https://en.wikipedia.org/w/api.php?action=query&prop=links&titles=Template:Genetics%20sidebar&pllimit=100&plnamespace=0
Something like this should also work but it's not returning any results for me:
SELECT * from pagelinks
where pl_title = 'Genetics_sidebar'
and pl_namespace = 0
and pl_from_namespace = 10
https://quarry.wmcloud.org/query/71442
Little by little I am trying to learn Semantic Mediawiki almost like in a tutorial. I got so save info (including uri, titles and tags) for each element of a list using subobjects and then to get the list of the tag.
This is the wiki page with the list of the tags: link
Now I'd like to further explore the articles related to each tag. For example, is it possible to list the articles having the tag x? I wonder if it would be a nice idea to create a Module to parse the output of the semantic query.
SemanticMediawiki: embed some property into a piece of text
Can I use Semantic Mediawiki to add properties to each element of a list?
MediaWiki Semantic Template: Property "" (as page type) with input value contains invalid characters or is incomplete can cause unexpected results
Semantic Mediawiki error: processing error text "#category " cannot be used as a property name in this wiki
Semantic Mediawiki: writing a query that returns all the suboject defined in a page
Semantic Mediawiki: aggregation similar to SQL GROUP BY like #ask query
Best solution here is to make use of array extension.
Create an array containing all tags, and make it unique to have a "distinct list".
Then print your array, and run an ask query for each tag in the print loop, with the count format .
{{#arraydefine:tags| {{#ask:[[-Has subobject::{{FULLPAGENAME}}]] |?Tags#-=| mainlabel=-|limit = 1000}} |,|unique}}
{{#arrayprint:tags|, |####|<nowiki/>
[[####]] ({{#ask:[[Tags::####]]|format=count}})
}}
This code will print a link to each page named as tag value, and print the number of subobjects that hold this tag. Even if the solution is not optimal, as you are running a lot of independent queries, you should not have performance issues unless you have very high traffic on your wiki.
Nota bene : The best practice is to create a specific template for tag pages, one that list all articles having the tag. With the Page Forms extension, you can create each page automatically with this template, simply by running the job queue.
I'm building a mediawiki infobox. I'm using the standard table based infobox as opposed to importing the various templates and CSS functionality, and extensions that Wikipedia is now using.
One of the fields in the infobox is a link to various wiki categories. I'd like to keep the linking code in the template, so the source article can just list the category names as perameter values for the infobox.
For example, my template currently contains
<tr>
<th>Some Categories</th>
<td>[[:Category:{{{category_name}}}|{{{category_name}}}]]</td>
</tr>
This works fine if I enter the category name on the source article in my infobox declarations as:
| category_name = Cat-1
In this case, the article displays an infobox, with a link to the Cat-1 category.
However I can't find how to include multiple category entries in the source article, and allow them to link to each one separately. The articles which use this infobox can have from one to eight of these categories to declare.
Do I need to import all of the wikipedia style CSS infobox templates in order to achieve this, or can it be done with a simple table-based infobox?
You will need to add as many template parameters as the maximum number of category names you want to pass to the template and to test for their being defined
So your template code might be something like
<td>[[:Category:{{{cat1}}}|{{{cat1}}}]]<!--
-->{{#if: {{{cat2|}}} |, [[:Category:{{{cat2}}}|{{{cat2}}}]] |}}<!--
-->{{#if: {{{cat3|}}} |, [[:Category:{{{cat3}}}|{{{cat3}}}]] |}}</td>
Etc. This was a common strategy before the Scribunto/Lua templates, which can just loop through data.
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
I'm writing template documentation for a wiki and wanted to include a working example of the template. However, I wrote the template to auto-categorize various fields and the entire template itself is also auto-categorized.
This means if I simply call on the template, it will categorize the doc page...and because the actual template page transcludes the doc page, the template page will also be categorized.
Is there a way to prevent these categories from automatically kicking in?
Something like the following should do the trick. Wrap the categorization in your template inside a parserfunction:
{{#ifeq: {{NAMESPACE}} | Help || [[Category:Some_Category]] }}
This sets the category when the template is transcluded onto a page that is not in the "Help" namespace.
Another option is to allow a parameter such as demo to avoid including the category.
If you don't mind being slightly cryptic, you could do the category in the template as {{{cat|[[Category:Some_Category]]}}}; then specifying the parameter as {{my template|cat=}} will prevent the category inclusion.
I'm not sure if I understand the question completely (what is "auto-categorize various fields"?). I am assuming here that you want to show a template "in action" on a documentation page - without attaching some categories (those categories the documentation page usually attaches to articles using this template) to the documentation page.
So
<onlyinclude>[[Category:Some_Category]]</onlyinclude>
will not do the job - as the template is in fact included. Right?
Try passing a parameter categorize=false to the template to indicate that categories are not to be attached in this case:
{{#ifeq:{{{categorize|}}}|false||[[Category:Some_Category]]}}
The double pipe after "false" means: if(categorize==false) then (empty), else [[Category:Some_Category]] - i.e. it is an equivalent construction for if(NOT(categorize==false))...
Good luck and thanks for all the fish,
Achim