WikiHost

Summary: Code for your Config.php file to simplify updates/templating/migration regardless of http or https
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: WikiHost-Talk?

Questions answered by this recipe

  • How can I Declare my installation path as a variable, so I only type it once?
  • Can I simplify use of the local paths in my config.php so I can easily copy it as a template?
  • Can I ensure that the path to my install works for both http and https instances with no editing needed?

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

Description

Code to simplify updates/templating/migration regardless of http or https
I prefer to use variables instead of hard-coding paths, and I was having issues with https vs. http
this is the solution I came up with, which works across my dozen or so pmwiki installations.
Now I can update config.php files across installations and only edit one directory name, once, and that only
if the root Wiki directory is not "pmwiki"
I also eliminated some issues I was having with my .htaccess files and path references inside of my Wiki's due to https

Installation:

These are all edits / additions to the .../local/config.php file to simplify updates/templating/migration

First:
The following should go at the beginning of your config.php file just after if (!defined('PmWiki')) exit();

## -- If you have a default "/pmwiki" installation in a first level directory --
## 
##     == Y O U   C A N   U S E   T H I S   W I T H   N O   E D I T I N G ==
##                    
##  Define the Path after the domain name, to YOUR directory containing pmwiki.php 
##   e.g. pmwiki is normally in the www.myexample.com/pmwiki directory	
##   In this case, "/pmwiki" is the WikiRoot path.
##   Notice we never use the domain name! The Php finds it for us below.
  	if (!defined('WikiRoot')){ define('WikiRoot', '/pmwiki'); }

  ## If you just use a different name for the wiki folder it might look like:
  ##  ww.myexample.com/SomeFolder then you would use
  #  if (!defined('WikiRoot')){ define('WikiRoot', '/SomeFolder'); }

  ## If your installation is at the Domain level (really a bad idea!) 
  ## For example all the PMWiki files are located at http://www.mysite.com/  then
  #  if (!defined('WikiRoot')){ define('WikiRoot', ''); } 

  ## If your installation is several directories deep:
  ## For example  https://www.mysite.com/somedirectory/anotherone/pmwiki  then
  #  if (!defined('WikiRoot')){ define('WikiRoot', '/somedirectory/anotherone/pmwiki'); } 	


## Define the domain of the pmwiki site, testing for https:
##    You might change to default HTTP if you find you are having problems with your certificate.
## 
## This code depends on the "check_https" function at the bottom of this page

	if (check_https()) {
		if (!defined('WikiHost')){ define('WikiHost', 'https://'.$_SERVER['HTTP_HOST']); }
	} else {
		if (!defined('WikiHost')){ define('WikiHost', 'http://'.$_SERVER['HTTP_HOST']); }
	}			

##-- Default PATHS --
##   Now we can use the WikiHost and WikiRoot variables anywhere else we need in this file:
   $WikiRoot      = WikiHost.WikiRoot;
   $ScriptUrl     = WikiHost.WikiRoot.'/pmwiki.php';
   $PubDirUrl     = WikiHost.WikiRoot.'/pub';
   $FarmPubDirUrl = WikiHost.WikiRoot.'/pub';


## Function to check if the current installation URL uses an https or http prefix
function check_https() {

	if ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || $_SERVER['SERVER_PORT'] == 443) {

		return true; 
	}
	return false;
}   



Be sure you don't declare those variables again later in the file or you override what you just did.

Configuration

The comments in the above code pretty much tell you everything.
Be VERY sure you get the PMWiki root directory path correct, but you never need to write out your domain name.

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".

Comments

See discussion at WikiHost-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.