PmWiki / LocalCustomizations

A Wiki Administrator can make a lot of customizations simply by setting variables in the /local/config.php and defining cascading style sheets in /pub/css/local.css files. Any group or page can also have its own configuration file and configuration css file.

This page describes how customizations work in general, see PmWiki.Documentation Index for specific customizations that are commonly performed at many PmWiki installations, including:

local/config.php

From its inception, PmWiki has been designed so that Wiki Administrators can greatly customize the way PmWiki displays pages and the markup sequences used to generate pages. (This is even mentioned explicitly in PmWiki Philosophy #4 Collaborative Maintenance.) As a result, the core pmwiki.php script makes extensive use of PmWiki.Variables to determine how markup sequences will be processed and what each individual page will output.

The simplest type of customization is merely setting a variable to 1 (or TRUE). Here's an example that enables ?action=diag and ?action=phpinfo actions:

You can begin a line with a "#" (an octothorpe, a.k.a. a hash symbol or pound sign) to add a comment. Additionally, some built-in PmWiki variables take values other than 1 or 0 (true or false). Here's another example that customizes the wiki's behavior with respect to search engine web robots (see Cookbook:ControllingWebRobots):

# Remove the default "rel='nofollow'" attribute for external links.
$UrlLinkFmt = "<a class='urllink' href='\$LinkUrl' title='\$LinkAlt'>\$LinkText</a>";

The scripts/ subdirectory (below the directory holding the pmwiki.php script) has many customizations. The PmWiki Cookbook contains many example customizations (recipes) that you can download into the cookbook/ subdirectory, The first few lines of each of these scripts generally contain instructions about how to enable (and use) the feature provided by the script.

These customizations are included in your config.php site configuration. For most scripts this is done by simply adding lines like:

include_once("cookbook/recipefile.php");

and

include_once("scripts/scriptfile.php");

at the end of the config.php file to enable them.

Some of the scripts are automatically enabled for you via the scripts/stdconfig.php script unless you disable it by setting $EnableStdConfig=0; in local/config.php.

Order of the commands in config.php

The following order is recommended:

If you need to set per-page, per-group, or per-user variables or addons, it is recommended to add them into files named local/Group.php and local/Group.Page.php. If you must do it from config.php, or if you need to set these variables after the local files are included, use the following at the bottom of config.php:

  $pagename = ResolvePageName($pagename);
  include_once("$FarmD/scripts/pgcust.php");
  list($group, $name) = explode('.', $pagename);
  if ($group != 'Private') {...} # do whatever you need
  if (CondAuth($pagename, 'edit')) {...} # only for editors

Any direct function call in config.php, like CondAuth(), PageTextVar(), PageVar(), RetrieveAuthPage(), or others, should be done near the end of config.php after the above snippet. Alternatively, you can add those in a custom function or script in the $PostConfig array:

  # PmWiki will call this function and include this file after
  #    farmconfig.php, config.php, Group.Page.php and Group.php
  #    but before scripts/stdconfig.php:
  function MyFunction1($pagename) {...}
  $PostConfig['MyFunction1'] = 25;               # < 50
  $PostConfig["cookbook/some-addon.php"] = 26;   # < 50

  # PmWiki will call this function and include this file after
  #    farmconfig.php, config.php, Group.Page.php, Group.php
  #    and scripts/stdconfig.php:
  function MyFunction2($pagename) {...}
  $PostConfig['MyFunction2'] = 125;              # >= 50
  $PostConfig["cookbook/other-addon.php"] = 100; # >= 50

The $PostConfig functions and scripts will be called ordered by their values, ie above "MyFunction2" (125) will be called after "other-addon.php" (100). This allows recipe authors more control over the precise order of their recipe compared to other recipes (when that is important).

Note, each part is not required, but if your wiki needs it, this is the recommended order in config.php.

Character encoding of config.php

The encoding used when you save config.php has an effect. Your text editor should allow you to save config.php in the encoding of your wiki. (The default encoding of PmWiki is ISO-8859-1, for new wikis it is recommended to enable UTF-8.)

Newer operating systems like GNU/Linux, FreeBSD and Apple generally default to saving text files in Unicode/UTF-8; in Windows the default encoding is ANSI/Windows-1252 which is almost the same as PmWiki's ISO-8859-1.

The following free/libre software text editors can edit and save a file in different encodings:

Note that if you use the UTF-8 encoding, you should save your files "without Byte Order Mark (BOM)".

Over time PmWiki will be updated to default to Unicode/UTF-8 encoding, which allows all possible alphabets and languages. See UTF-8 for more information.

pub/css/local.css

You can create this file and set there some custom CSS styles which will override any styles set by skins. For example:

  h1, h2, h3, h4, h5 { color: #880000; } /*dark red titles*/
  a { text-decoration: none; } /* don't underline links */

CSS files are included in the order

  1. $PubDirUrl/css/local.css - for the wiki
  2. $PubDirUrl/css/{$Group}.css - for groups
  3. $PubDirUrl/css/{$FullName}.css - for single pages
  4. $PageCSSListFmt

Don't modify pmwiki.php or other core files

You should strongly resist the temptation to directly modify the pmwiki.php script or the files in the scripts/ subdirectory. Any modifications you make to these files will probably be overwritten whenever you upgrade. Instead, look at some of the sample scripts for examples of customizations that can be performed from config.php. You can even create your own script to do a customization and use include_once(...) to include it from config.php. If you do make your own customization script, you can safely put it in the cookbook/ subdirectory--it won't get overwritten by an upgrade there. You might also want to submit your customization to the pmwiki-users mailing list or the Cookbook so that others can benefit from your effort and so that it can perhaps be included in future releases of PmWiki.

FAQ

There's no "config.php"; it's not even clear what a "local customisation file" is!

The "sample-config.php" file in the "docs" folder, is given as an example. Copy it to the "local" folder and rename it to "config.php". You can then remove the "#" symbols or add other commands shown in the documentation. See also Group Customizations.

Can I change the default page something other than Main.HomePage ($DefaultPage)?

Yes, just set the $DefaultPage variable to the name of the page you want to be the default. You might also look at the $DefaultGroup and $DefaultName configuration variables.

$DefaultPage = 'ABC.StartPage';

Note the recommendations in $DefaultName and the need to set $PagePathFmt as well if you are changing the default startup page for groups.

How do I get the group / page name in a local configuration file (e.g. local/config.php)?

Use the following markup in pmwiki-2.1.beta21 or newer:

## Get the group and page name
$pagename = ResolvePageName($pagename);
$page = PageVar($pagename, '$FullName');
$group = PageVar($pagename, '$Group');
$name = PageVar($pagename, '$Name');

Note the importance of the order of customizations in config.php above to avoid caching problems.

If you need the verbatim group and page name (from the request) early in config.php, $pagename is guaranteed to be set to

  1. Any value of ?n= if it's set, or
  2. Any value of ?pagename= if it's set, or
  3. The "path info" information from REQUEST_URI (whatever follows SCRIPT_NAME), or
  4. Blank otherwise

according to this posting

Can I remove items from the wikilib.d folder on my site?

The files named Site.* and SiteAdmin.* contain parts of the interface and the configuration and they should not be removed. The other files named PmWiki* contain the documentation and could be removed.

How do I customize my own 404 error page for non-existent pages?

To change the text of the message, try editing the Site.PageNotFound page.

Is the order of customizations in config.php important? Are there certain things that should come before or after others in that file?

Yes, see Order of the commands in config.php.

I have an online hosted wiki, and a local copy on my home computer. How can I differentiate in config.php whether I'm online or on the local computer? So that I don't have to maintain the config.php twice.

You can try something like the following:

if($_SERVER['SERVER_ADDR'] == '127.0.0.1') {
  # Home wiki

}
else {
  # Online wiki

}

You can add $EnableDiag = 1; to config.php for both servers, and look at ?action=diag.

The $_SERVER variable will have different values on the different servers, notably 'SERVER_ADDR' or 'SERVER_NAME'. You can configure the different wikis based on the different values.


This page may have a more recent version on pmwiki.org: PmWiki:LocalCustomizations, and a talk page: PmWiki:LocalCustomizations-Talk.