(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.
Related
How can I display spaces in Media Wiki Page Title but not in the URL?
Desired Result: if someone types in example.com/w/John1:1-5 then I'd like the page title on that page to show John 1:1-5.
I realize I could create a page at example.com/w/John_1:1-5, but I don't want users to have to type the underscore.
Is there a way to do this without creating a redirect?
Thanks!
You can use the DISPLAYTITLE magic word for this, e.g. {{DISPLAYTITLE:John 1:1-5}}.
$wgAllowDisplayTitle must be set to true order to use it, and $wgRestrictDisplayTitle set to false. The former enables the feature, and the latter permits more than just letter-case changes (i.e. the display title can be anything at all, even quite different from the page title).
If you want to display inbound links on other pages (i.e. you type [[John1:1-5]] but want it to display as John 1:1-5) then the Display Title extension can do that.
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.
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.
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
I would like to allow users to create content for their own languages. I am running a single MediaWiki instance, so I cannot set it up for one language per install.
I would like to try and format the pages like the following, where a different language version of the page has the language code appended to it.
myWiki/SomePageContent
myWiki/SomePageContent/de
myWiki/SomePageContent/fr
How can I ensure users follow this structure? Is there some setting in MediaWiki that can help with this? I have no idea what are best practices for this.
Thanks!
Best practices are to use a separate instance of MediaWiki for each language and use interwiki links to connect them. This way, users are in one language and everything works as you'd expect: if you're in the English instance, a link to [[Foo]] stays in English, and only a link to [[fr:Foo]] goes to the French Foo. It's not particularly hard to set this up even with a single server and single database, see http://www.mediawiki.org/wiki/Manual:Wiki_family. The way this appears to the user is configurable: eg. Wikipedia uses http://en.wikipedia.org/wiki/Paris, Wikitravel uses http://wikitravel.org/en/Paris.
If this is not possible for whatever reason, the next best thing to do is to set up a separate namespace for each language (eg. "de" or "fr"), and this way you can at least do eg. searches across one (or more) languages. However, users of languages other than the 'main' language still have to manually punch in the language code in front of every article name and link, so it's not nearly as user-friendly. See http://www.mediawiki.org/wiki/Manual:Namespace.
An easier way for smaller wikis is through the use of a simple template. It may not be as efficient as an extension or creating a family of wikis, which is a lot of work, but quite fast to set up.
Create a page under Template:Otherlang with the following code:
{{otherlang
|ru=Template:Otherlang:ru
}}
This template adds available translations for the page to the top through the use of flags.
To prevent issues, this template must be placed '''at the very beginning of a page'''.
Tip! When contributing a new translation to a document that already has other translations, please carry over the existing translations to the otherlang template of your contributed page. This way all multilingual pages are linked.
== Syntax ==
{{otherlang
| noborder=true (OPTIONAL)
| title=localized page display title
| lang=page:lang
| lang2=page:lang2
| etc...
}}
Warning! Do not include the language of the current page. This will only confuse readers.
=== Example ===
On a page called [[Template:Otherlang]]:
{{otherlang
| title=Template:Otherlang
| ru=Category:Programming:ru
}}
Note that:
* The language "en" is not included, as it is the language of the page that template is being used on.
* title is assigned the translated name of the page, and will appear as the display title (heading) for the page. This can replace the existing {{wrongtitle}} and {{DISPLAYTITLE}} templates currently in common use.
* The English page has no suffix.
== Available Languages ==
{| class="table table-bordered" border="2" cellpadding="7"
! Language
! Syntax
! Result
|- id="en"
|English
|en=Page_name
|[[File:En.png]]
|- id="ru"
|Russian
|ru=Page_name:ru
|[[File:Ru.png]]
|}
{{#if: {{{title|}}} | {{DISPLAYTITLE:{{{title}}}}} }}{{#if: {{{en|}}} | '''[[File:En.png|alt=English|link={{{en}}}]]''' }} {{#if: {{{ru|}}} | [[File:Ru.png|alt=Русский|link={{{ru}}}]] }}
Then within each English article, paste use the following code to get a flag to show up, representing the respective language.
{{otherlang
| title=Tutorials/Galacticraft Getting Started Guide
| ru=Tutorials/Galacticraft_Getting_Started_Guide/ru
}}
An example of this can be found here. If you click on the Russian flag to the right you will find a Russian translation of the article.
anyone interested, you might wanna try this
http://www.mediawiki.org/wiki/Help:Extension:Translate
when this page
myWiki/SomePageContent
is translated to German, it will create the link like this:
myWiki/SomePageContent/de
and so on :)