Skip to content

Commit

Permalink
DOKU_TPL* considered harmful
Browse files Browse the repository at this point in the history
Some plugins want to dynamically switch the template based on users,
namspaces or the phase of the moon. Having fixed paths in a unchangable
constant prevents this.

This changes deprecates the DOKU_TPL* constants in favor of two new
tpl_* functions that return the correct paths based on the $conf
variables which can be changed from the DOKUWIKI_STARTED event.
  • Loading branch information
splitbrain committed Jan 30, 2012
1 parent 378325f commit c476695
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
4 changes: 2 additions & 2 deletions inc/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@ function delta_time($start=0) {
// define main script
if(!defined('DOKU_SCRIPT')) define('DOKU_SCRIPT','doku.php');

// define Template baseURL
// DEPRECATED, use tpl_basedir() instead
if(!defined('DOKU_TPL')) define('DOKU_TPL',
DOKU_BASE.'lib/tpl/'.$conf['template'].'/');

// define real Template directory
// DEPRECATED, use tpl_incdir() instead
if(!defined('DOKU_TPLINC')) define('DOKU_TPLINC',
DOKU_INC.'lib/tpl/'.$conf['template'].'/');

Expand Down
31 changes: 27 additions & 4 deletions inc/template.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,29 @@ function template($tpl){
return DOKU_INC.'lib/tpl/default/'.$tpl;
}


/**
* Convenience function to access template dir from local FS
*
* This replaces the deprecated DOKU_TPLINC constant
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function tpl_incdir(){
return DOKU_INC.'lib/tpl/'.$conf['template'].'/';
}

/**
* Convenience function to access template dir from web
*
* This replaces the deprecated DOKU_TPL constant
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function tpl_basedir(){
return DOKU_BASE.'lib/tpl/'.$conf['template'].'/';
}

/**
* Print the content
*
Expand Down Expand Up @@ -1034,7 +1057,7 @@ function tpl_getConf($id){
*/
function tpl_loadConfig(){

$file = DOKU_TPLINC.'/conf/default.php';
$file = tpl_incdir().'/conf/default.php';
$conf = array();

if (!@file_exists($file)) return false;
Expand All @@ -1055,7 +1078,7 @@ function tpl_getLang($id){
static $lang = array();

if (count($lang) === 0){
$path = DOKU_TPLINC.'lang/';
$path = tpl_incdir().'lang/';

$lang = array();

Expand Down Expand Up @@ -1476,7 +1499,7 @@ function tpl_getMediaFile($search, $abs=false, &$imginfo=null){
$file = mediaFN($img);
$ismedia = true;
}else{
$file = DOKU_TPLINC.$img;
$file = tpl_incdir().$img;
$ismedia = false;
}

Expand All @@ -1492,7 +1515,7 @@ function tpl_getMediaFile($search, $abs=false, &$imginfo=null){
if($ismedia){
$url = ml($img, '', true, '', $abs);
}else{
$url = DOKU_TPL.$img;
$url = tpl_basedir().$img;
if($abs) $url = DOKU_URL.substr($url, strlen(DOKU_REL));
}

Expand Down

2 comments on commit c476695

@selfthinker
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please document that those two constants are deprecated on http://www.dokuwiki.org/devel:releases#deprecation?

@bug
Copy link
Collaborator

@bug bug commented on c476695 Feb 1, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DOKU_TPL also appears in several files under lib/ dir. Shouldn't those be changed too?

Please sign in to comment.