dokuwiki中文文件名及sitemap乱码的解决

dokuwiki默认是使用urlencode函数对文件名进行编码后存储的,而索引文章的indexer.php文件在生成sitemap.xml时也会对文件名编码,这样对搜索引擎是不友好的,实际上将这两个编码的功能去掉就可以了。

中文文件名的乱码可以参考http://www.dokuwiki.org/zh:pagename进行更改,即:

function utf8_encodeFN($file, $safe = true) {
  if ($safe && preg_match('#^[a-zA-Z0-9/_\-.%]+$#', $file)) {
    return $file;
  }
  /* 把这个部分注释掉
     $file = urlencode($file);
     $file = str_replace('%2F','/',$file);
   */
  return $file;
}
}
if (!function_exists('utf8_decodeFN')) {
  /**
   * URL-Decode a filename
   *
   * This is just a wrapper around urldecode
   *
   * @author Andreas Gohr <andi@splitbrain.org>
   * @see urldecode
   */
  function utf8_decodeFN($file) {
    //$file = urldecode($file); //再注释掉这个语句...
    return $file;
  }
}

而生成sitemap.xml文件的是"/lib/exe/indexer.php"文件,打开这个文件,搜索runSitemapper()函数,在函数下有此语句:

print '    <loc>'.wl($id,'',true).'</loc>'.NL;

其中wl函数为重写url的,在wl函数的定义在"/inc/common.php"文件内,其中有一语句:

$id    = idfilter($id);

idfilter即是进行编码转换的,只需要在common.php中去掉那一行即可。

About the Author

在讀研究生,化學/化工專業,主要關注學佛、計算化學、C++、Python、計算機、古文化、哲學、思維方向,渴求與有共同興趣的朋友交流,詳情請查看“關于”頁面。

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*

Copyright © 2012 勿慢牛 - All Rights Reserved. - Admin - Powered by WordPress