WikiRoot

Summary: Add Markup to insert the root path to your Wiki allowing, for example, something like a relative address for images or files in your Wiki.
Version: 2020-10-14
Prerequisites: none
Status:
Maintainer: Kirk Siqveland
License: (Apache 2.0|BSD-3-clause|BSD-2-clause|GPL|LGPL|MIT|MPL-2.0|CDDL-1.0|EPL-1.0) - OpenSourceLicenses Cookbook:Cookbook Licenses
Users: (view? / edit)
Discussion: WikiRoot-Talk

Questions answered by this recipe

  • How can I use a URL with a variable for the root of my Wiki installation path?
  • Can I use Markup to make it easy to copy whole Wiki installations to a new address?
  • Can I build template Wiki's that don't have the URL hard-coded in the pages with content references?
(Okay, that's really the same question re-written three ways. ;-)

All sections are optional, you can remove those that do not apply to your recipe, and add new ones.

Description

Add Markup to allow you to insert the root path to your Wiki by referencing a variable in your .../local/config.php file.

Installation

This can all be handled in your .../local/config.php file.
To begin, we make a $WikiRoot variable with the proper url/path to the root of your Wiki installation.
Namely the directory where the pmwiki.php file resides, e.g.:
https://www.myowndomain.org/pmwiki
Then, we add markup which uses that Variable to allow you to use it from the Edit Window.

First:

Declare the $WikiRoot variable:

Option 1 - the typical PMWiki Method.
Add code to declare the $WikiRoot variable and set it to your actual Path.
I recommend just before where you declare the $ScriptURL variable, you add something like this:
$WikiRoot = https://www.myowndomain.org/pmwiki
Obviously you need to replace the example URL with yours. (That should be everything in the Pathname before the /pmwiki.php file)

Option 2 - use the WikiHost recipe so you don't worry about http vs https and you only declare your path once for the entire installation.
Then you can can declare your WikiRoot with this code:
$WikiRoot = WikiHost.WikiRoot;

Second:

Add the Markup

Now, add the following to your .../local/config.php file:


## -- WikiRoot Markup  Allows the use of (:WikiRoot:) as part of any URL that includes the root path of your Wiki.
##    For Example, you have an image  "https://www.myowndomain.org/mypersonaldirectory/pmwiki/media/MyPhoto.jpg"
##    You can now use the markup 
##       (:WikiRoot:)/media/MyPhoto.jpg
##    Now even if you move or copy your Wiki install, that URL remains valid! 

Markup( 'WikiRoot', 'directives', '/\\(:WikiRoot:\\)/',$WikiRoot);

Usage

From Edit-Mode in your Wiki you can now type (:WikiRoot:) to get the full URL of the Root of your Wiki

You can combine that with other address parts to create a full URL that acts like a relative URL within your installation.
e.g. instead of writing out the full URL: https://www.myowndomain.org/mypersonaldirectory/pmwiki/media/MyPhoto.jpg
You can write:
(:WikiRoot:)/media/MyPhoto.jpg
and it works the same here, but if you copied that page to another wiki (with this recipe) it would work as well!

Notes

To do / some day / maybe

If you have future plans or wishes for this recipe.

Change log / Release notes

If the recipe has multiple releases, then release notes can be placed here. Note that it's often easier for people to work with "release dates" instead of "version numbers".

See also

Contributors

Comments

See discussion at WikiRoot-Talk

User notes? : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.