How to query/limit a transclusion when including the talk page? - mediawiki

As the tag implies, I am using MediaWiki as wiki-software. I would like to include the talk page/discussion into the page the talk/discussion is about.
I figured out how to include the talk page as a whole already doing something like this fo example (don't bother with the German notation): {{Diskussion:Test}} which add the talk page of the article Test.
The next step would be to limit the output to e.g. the 5 most recent talk "posts" (they are rather gouped under 2nd-grade headlines, I presume). Insertin of special pages can be limited by using additional parameters like so: {{Special:RecentChanges/days=5,limit=40}} as mentioned in MediaWiki help articles. However, these parameters obviously don't work when including the talk page because it is a single page/element. {{Diskussion:Test/days=5,limit=40}} is not even parsed.
Any hints and examples ae appreciated, although I prefer not to use extensions IF POSSIBLE.

The usual way to do this is to edit [[Diskussion:Test]] by adding appropriate noinclude (or onlyinclude) tags:
<noinclude>
blabla
</noinclude>
== The ==
...
== sections ==
...
== I ==
...
== want==
...
== transcluded ==
...
Now {{Diskussion:Test}} won't transclude the older stuff. This is the cleanest solution but might be tedious to do on many pages: you could automate this with a bot.
There are countless on-wiki solutions possible, for instance you could transclude everything and then use JavaScript to hide "excess" sections; or you could wrap all talk page discussions in a template, which then shows only the latest X when transcluded in subject namespace.
As for "proper" solutions, perhaps you're looking for a discussion extension. If you're brave you could test LiquidThreads, add threads directly on the page (rather than talk) and set up autoarchiving as you wish.

Related

mediawiki - make link evaluation case insensitive

i'm running a small wiki and our users would like an interface they find less confusing. the complaint is that a page titled something like 'Big_news' displays as a redlink if the link is 'Big News' or 'big news' or some other upper/lower case permutation, and they'd like these to appear as normal-coloured links if the page exists. when a user clicks on the link, the appropriate page is displayed correctly, but it would be better to see that the page already exists beforehand.
i've tried to implement solutions such as those presented here, here, and here, but they don't work -- links still display as redlinks on the page. [indeed, i think some of the articles are out of date ; mediawiki 1.27 doesn't seem to have the tables mentioned in them.]
any ideas how i might go about doing this ?
You could look at how $wgCapitalLinks is being used. Chances are, all-lowercase titles will need special casing in the same places where code needs to be branched based on that setting.
You could hook on HtmlPageLinkRendererBegin and use the link target to run a database query to find any case-insensitive matches for the page name (on page title, and it'd have to do this only for internal links), and then replace the target if there's a match.
thanks for the tip, #Sam Wilson. that looks like an interesting function, but unless i miss my guess, i'd have to query the database for every single link in a page -- correct ? if so, i think performance would suffer. anyway, that hook didn't seem to work for me [mostly because my unfamiliarity with mediawiki left me scratching my head...]. the solution i came up with is as follows :
1- add the variable $wgLinksIgnoreCase to your LocalSettings.php file. set this to true if you want link displays to be mapped case-insensitively.
2- modify the file includes/parser/LinkHolderArray.php as follows [diff accurate for wikimedia version 1.29] -
283a284
> global $wgLinksIgnoreCase;
370a373,376
> if (!empty($wgLinksIgnoreCase)) {
> $mapper = array_combine(array_keys($colours), array_keys($colours));
> $mapper = array_change_key_case($mapper);
> }
373a380,381
> if (!empty($wgLinksIgnoreCase) && isset($mapper[strtolower($pdbk)]))
> $pdbk = $mapper[strtolower($pdbk)];
as i say, i'm not very familiar with the software, so if anyone who is familiar with it finds a more elegant solution, feel free to chime in.

Direct link to MediaWiki page section

In my Wikipedia page, I have a section called subtitleA. Before arriving at this point when reading, I have one sentence that has a link that jumps to the content of that section.
To be more clear, this is a simple illustration:
To do this, you will need `this` (link to subtitleA).
To do that, you will do another thing..
== SubtitleA ==
this is how you do it....
I found the following solution:
To do this, you will need [http://wikisite.com/pageName#SubtitleA this].
This has already been proven correct; however, one of my subtitles contains spaces, brackets and directory like the following:
== SubtitleA (balabalaA\balabalaB\balabala....) ==
I can no longer use the solution I found because of those spaces... Can anyone provide me an alternative solutions? Thanks.
To do this, you will need [[pageName#SubtitleA|this]].
Use the exact same format as in the section title.
Anchor encoding is similar to percent encoding (with a . instead of a %) but not exactly the same (e.g. spaces are collapsed and encoded to _). If you really, really need to do it directly, you can use {{anchorencode|original title}}.
I found the solution:
URL encoder is the key, but not using standard %xx as the replacements for special characters. Use .xx (e.g. .5C .28) would work in the mediawiki framework.

Multiple open graph tags, which one is prioritized?

I've seen various SO threads about FB open graph image tags such as this: Facebook multiple og:image tags - Which is Default?
These threads are 2.5 years old so I'm wondering if the rules have been updated. Also, the accepted answer of the highest resolution image being the one displayed seems imperfect. What if the images aren't the same? For example, how to have one image for the homepage and then a different one on AJAX loaded pages?
As these rules are used by FB, Reddit and many high-traffic sites obviously this information is very valuable. Thanks!
Since reddit is open-source, you can look at see what its behavior is.
The place you want to look is _find_thumbnail_image(). Right now, this is the code that pertains to Open Graph:
# Allow the content author to specify the thumbnail using the Open
# Graph protocol: http://ogp.me/
og_image = (soup.find('meta', property='og:image') or
soup.find('meta', attrs={'name': 'og:image'}))
if og_image and og_image['content']:
return og_image['content'], None
og_image = (soup.find('meta', property='og:image:url') or
soup.find('meta', attrs={'name': 'og:image:url'}))
if og_image and og_image['content']:
return og_image['content'], None
So, it'll use whatever Beautiful Soup's find() method returns, which should be the first matching tag.

Mediawiki 1.16: Template documentation example usage

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

How to setup content in other languages?

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 :)