<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>MediaWiki &amp;mdash; KJ7RRV</title>
    <link>https://kj7rrv.com/tag:MediaWiki</link>
    <description></description>
    <pubDate>Wed, 29 Apr 2026 10:25:33 -0700</pubDate>
    <item>
      <title>User configuration template for MediaWiki</title>
      <link>https://kj7rrv.com/user-configuration-template-for-mediawiki-wl4x</link>
      <description>&lt;![CDATA[I wrote a #MediaWiki template that allows for the creation of templates that change based on user configuration.&#xA;&#xA;Edit: This will invalidate MediaWiki cache on pages that use it, increasing server CPU usage and page load times. Use this template sparingly.&#xA;&#xA;Dependencies/Prerequisites&#xA;&#xA;The GetUserName and ParserFunctions extensions are required. Also, you must create namespaces called DefaultConfig and UserConfig.&#xA;&#xA;define(&#34;NSDEFAULTCONFIG&#34;, 3000);&#xA;define(&#34;NSDEFAULTCONFIGTALK&#34;, 3001);&#xA;define(&#34;NSUSERCONFIG&#34;, 3002);&#xA;define(&#34;NSUSERCONFIGTALK&#34;, 3003);&#xA;$wgExtraNamespaces[NSUSERCONFIG] = &#34;UserConfig&#34;;&#xA;$wgExtraNamespaces[NSUSERCONFIGTALK] = &#34;UserConfigtalk&#34;;&#xA;$wgExtraNamespaces[NSDEFAULTCONFIG] = &#34;DefaultConfig&#34;;&#xA;$wgExtraNamespaces[NSDEFAULTCONFIGTALK] = &#34;DefaultConfigtalk&#34;;&#xA;$wgNamespaceProtection[NSDEFAULTCONFIG] = array(&#34;editdefaultconfig&#34;);&#xA;$wgGroupPermissions&#39;sysop&#39; = true;&#xA;$wgCapitalLinkOverrides[NSDEFAULTCONFIG] = false;&#xA;$wgCapitalLinkOverrides[NSDEFAULTCONFIGTALK] = false;&#xA;$wgNamespacesWithSubpages[NSUSERCONFIG] = true;&#xA;wfLoadExtension(&#39;GetUserName&#39;);&#xA;wfLoadExtension(&#39;ParserFunctions&#39;);&#xA;&#xA;It is recommended to only allow administrators or other trusted users to edit the DefaultConfig namespace. Unfortunately, I am not aware of any way to prevent users from editing other users&#39; UserConfig pages; this means that users can change the configuration settings of others.&#xA;   &#xA;Template&#xA;&#xA;Put this in Template:Config:&#xA;&#xA;{{#ifexist:DefaultConfig:{{{1}}}|{{#ifexist:UserConfig:{{#USERNAME:}}/{{{1}}}|{{UserConfig:{{#USERNAME:}}/{{{1}}}}}|{{ DefaultConfig:{{{1}}}}}}}|&#39;&#39;&#39;ERROR&#39;&#39;&#39;: No such configuration option exists. Please {{#ifexist:UserConfig:{{#USERNAME:}}/isadmin|create|ask an administrator to create}} [[DefaultConfig:{{{1}}}]].}}&#xA;&#xA;If you wish, you can create a UserConfig:[username]/isadmin page for all admin users. This has no effect other than changing the error message, so it is not important. Unlike other configuration settings, the content of this page does not matter; it only has to exist.&#xA;&#xA;Usage&#xA;&#xA;Simply use {{config|[option name]}} to get a configuration option. You must have a DefaultConfig:[option name] page. By default, {{config}} will return its content. However, if a user has a UserConfig:[user name]/[option name] page, its content will be returned instead.&#xA;&#xA;Example&#xA;&#xA;On the PBARC Web site, we use this for several things, including a {{time}} template. This takes time values in the format {{time|18|45}} and allows users to choose whether to see times as &#34;6:45 PM&#34; (12-hour time) or &#34;18:45&#34; (24-hour/military time). &#xA;&#xA;Here is the code for Template:Time:&#xA;&#xA;{{#ifeq: {{config|miltime}}|true|{{{1}}}:{{{2}}}|{{#ifexpr: ({{{1}}} = 12) and ({{{2}}} = 00)|12:00 noon|{{#ifexpr: ({{{1}}} = 00) and ({{{2}}} = 00)|12:00 midnight| {{#ifeq: {{#expr: {{{1}}} mod 12}} | 0 | 12 | {{#expr: {{{1}}} mod 12}}}}:{{{2}}} {{#ifexpr: {{{1}}} &lt; 12|AM|PM}}}}}}}}&#xA;&#xA;It will check the miltime configuration value and, if it is true, use 24-hour time; otherwise, it will use 12-hour time. On the PBARC site, it is set to false by default, but it could also be set to true. &#xA;&#xA;License&#xA;&#xA;This post, including all code, is released into the public domain under Creative Commons Zero. Feel free to use it for any purpose without asking permission or giving attribution.&#xA;&#xA;#PBARC #FOSS #Programming]]&gt;</description>
      <content:encoded><![CDATA[<p>I wrote a <a href="https://kj7rrv.com/tag:MediaWiki" class="hashtag"><span>#</span><span class="p-category">MediaWiki</span></a> template that allows for the creation of templates that change based on user configuration.</p>

<p><strong>Edit:</strong> This will invalidate MediaWiki cache on pages that use it, increasing server CPU usage and page load times. Use this template sparingly.</p>

<h2 id="dependencies-prerequisites" id="dependencies-prerequisites">Dependencies/Prerequisites</h2>

<p>The <a href="https://www.mediawiki.org/wiki/Extension:GetUserName"><code>GetUserName</code></a> and <a href="https://www.mediawiki.org/wiki/Extension:ParserFunctions"><code>ParserFunctions</code></a> extensions are required. Also, you must create namespaces called <code>DefaultConfig</code> and <code>UserConfig</code>.</p>

<pre><code class="language-php">define(&#34;NS_DEFAULTCONFIG&#34;, 3000);
define(&#34;NS_DEFAULTCONFIG_TALK&#34;, 3001);
define(&#34;NS_USERCONFIG&#34;, 3002);
define(&#34;NS_USERCONFIG_TALK&#34;, 3003);
$wgExtraNamespaces[NS_USERCONFIG] = &#34;UserConfig&#34;;
$wgExtraNamespaces[NS_USERCONFIG_TALK] = &#34;UserConfig_talk&#34;;
$wgExtraNamespaces[NS_DEFAULTCONFIG] = &#34;DefaultConfig&#34;;
$wgExtraNamespaces[NS_DEFAULTCONFIG_TALK] = &#34;DefaultConfig_talk&#34;;
$wgNamespaceProtection[NS_DEFAULTCONFIG] = array(&#34;editdefaultconfig&#34;);
$wgGroupPermissions[&#39;sysop&#39;][&#39;editdefaultconfig&#39;] = true;
$wgCapitalLinkOverrides[NS_DEFAULTCONFIG] = false;
$wgCapitalLinkOverrides[NS_DEFAULTCONFIG_TALK] = false;
$wgNamespacesWithSubpages[NS_USERCONFIG] = true;
wfLoadExtension(&#39;GetUserName&#39;);
wfLoadExtension(&#39;ParserFunctions&#39;);
</code></pre>

<p>It is recommended to only allow administrators or other trusted users to edit the <code>DefaultConfig</code> namespace. Unfortunately, I am not aware of any way to prevent users from editing other users&#39; <code>UserConfig</code> pages; this means that users can change the configuration settings of others.</p>

<h2 id="template" id="template">Template</h2>

<p>Put this in <code>Template:Config</code>:</p>

<pre><code class="language-mediawiki">{{#ifexist:DefaultConfig:{{{1}}}|{{#ifexist:UserConfig:{{#USERNAME:}}/{{{1}}}|{{UserConfig:{{#USERNAME:}}/{{{1}}}}}|{{ DefaultConfig:{{{1}}}}}}}|&#39;&#39;&#39;ERROR&#39;&#39;&#39;: No such configuration option exists. Please {{#ifexist:UserConfig:{{#USERNAME:}}/isadmin|create|ask an administrator to create}} [[DefaultConfig:{{{1}}}]].}}
</code></pre>

<p>If you wish, you can create a <code>UserConfig:[username]/isadmin</code> page for all admin users. This has no effect other than changing the error message, so it is not important. Unlike other configuration settings, the content of this page does not matter; it only has to exist.</p>

<h2 id="usage" id="usage">Usage</h2>

<p>Simply use <code>{{config|[option name]}}</code> to get a configuration option. You must have a <code>DefaultConfig:[option name]</code> page. By default, <code>{{config}}</code> will return its content. However, if a user has a <code>UserConfig:[user name]/[option name]</code> page, its content will be returned instead.</p>

<h2 id="example" id="example">Example</h2>

<p>On the <a href="https://w7bkg.org/wiki/Home_Page">PBARC Web site</a>, we use this for several things, including a <code>{{time}}</code> template. This takes time values in the format <code>{{time|18|45}}</code> and allows users to choose whether to see times as “6:45 PM” (12-hour time) or “18:45” (24-hour/military time).</p>

<p>Here is the code for <code>Template:Time</code>:</p>

<pre><code class="language-mediawiki">{{#ifeq: {{config|miltime}}|true|{{{1}}}:{{{2}}}|{{#ifexpr: ({{{1}}} = 12) and ({{{2}}} = 00)|12:00 noon|{{#ifexpr: ({{{1}}} = 00) and ({{{2}}} = 00)|12:00 midnight| {{#ifeq: {{#expr: {{{1}}} mod 12}} | 0 | 12 | {{#expr: {{{1}}} mod 12}}}}:{{{2}}} {{#ifexpr: {{{1}}} &lt; 12|AM|PM}}}}}}}}
</code></pre>

<p>It will check the <code>miltime</code> configuration value and, if it is <code>true</code>, use 24-hour time; otherwise, it will use 12-hour time. On the PBARC site, it is set to <code>false</code> by default, but it could also be set to <code>true</code>.</p>

<h2 id="license" id="license">License</h2>

<p>This post, including all code, is released into the public domain under <a href="https://creativecommons.org/publicdomain/zero/1.0/">Creative Commons Zero</a>. Feel free to use it for any purpose without asking permission or giving attribution.</p>

<p><a href="https://kj7rrv.com/tag:PBARC" class="hashtag"><span>#</span><span class="p-category">PBARC</span></a> <a href="https://kj7rrv.com/tag:FOSS" class="hashtag"><span>#</span><span class="p-category">FOSS</span></a> <a href="https://kj7rrv.com/tag:Programming" class="hashtag"><span>#</span><span class="p-category">Programming</span></a></p>
]]></content:encoded>
      <guid>https://kj7rrv.com/user-configuration-template-for-mediawiki-wl4x</guid>
      <pubDate>Wed, 15 Mar 2023 00:46:19 +0000</pubDate>
    </item>
  </channel>
</rss>