[dokuwiki] Re: How does Dokuwiki detect templates? (Differently from plugins apparently)

  • From: Chris G <cl@xxxxxxxx>
  • To: dokuwiki@xxxxxxxxxxxxx
  • Date: Fri, 2 Sep 2011 16:36:41 +0100

On Fri, Sep 02, 2011 at 05:03:17PM +0200, Håkan Sandell wrote:
> a) template.php @row 20
> 
> b) http://se2.php.net/is_readable
> 
I've done a little work and I have found where the problem (not
detecting templates which are symbolic links) is.  It's in the
config.class.php file in <dw>/lib/plugins/config/settings which has:- 

class setting_dirchoice extends setting_multichoice {

    var $_dir = '';

    function initialize($default,$local,$protected) {

      // populate $this->_choices with a list of directories
      $list = array();

      if ($dh = @opendir($this->_dir)) {
        while (false !== ($entry = readdir($dh))) {
          if ($entry == '.' || $entry == '..') continue;
          if ($this->_pattern && !preg_match($this->_pattern,$entry)) continue;

          $file = (is_link($this->_dir.$entry)) ? readlink($this->_dir.$entry) 
: $entry;
          if (is_dir($this->_dir.$file)) $list[] = $entry;
        }
        closedir($dh);
      }
      sort($list);
      $this->_choices = $list;

      parent::initialize($default,$local,$protected);
    }
  }



It's the line 
    $file = (is_link($this->_dir.$entry)) ? readlink($this->_dir.$entry) : 
$entry;

that doesn't work.  The readlink() function returns the full path of the
symbolic link and this is then *appended* to $this->_dir and tested to
see if it's a directory.  Not surprisingly this doesn't work.

I *think* the code should probably be:-

    $file = (is_link($this->_dir.$entry)) ? readlink($this->_dir.$entry) : 
$this->_dir.$file
    if (is_dir($file)) $list[] = $entry;

Changing the code as above certainly seems to make templates which are
symbolic links appear on the config screen.

-- 
Chris Green
--
DokuWiki mailing list - more info at
http://www.dokuwiki.org/mailinglist

Other related posts: