解决MediaWiki: File(/gitinfo/info.json) is not within the allowed path(s)

今日在 MediaWiki中安装了扩展,执行 更新脚本后,访问 特殊页面:版本 时报错:

Warning: is_readable(): open_basedir restriction in effect. File(/gitinfo/info.json) is not within the allowed path(s): (/{webroot}/:/tmp/) in {webroot}/includes/utils/GitInfo.php on line 165

其中将站点目录替换成了 {webroot} ,因为每个人的可能都不一样。

所以查看 GitInfo.php 第165行,位于此函数中:

    /**
     * Compute the path to the cache file for a given directory.
     *
     * @param string $repoDir The root directory of the repo where .git can be found
     * @return string Path to GitInfo cache file in $wgGitInfoCacheDirectory or
     * fallback in the extension directory itself
     * @since 1.24
     */
    private function getCacheFilePath( $repoDir ) {
        $gitInfoCacheDirectory = $this->options->get( MainConfigNames::GitInfoCacheDirectory );

        if ( $gitInfoCacheDirectory === false ) {
            $gitInfoCacheDirectory = $this->options->get( MainConfigNames::CacheDirectory ) . '/gitinfo';
        }
        if ( $gitInfoCacheDirectory ) {
            // Convert both MW_INSTALL_PATH and $repoDir to canonical paths
            $repoName = realpath( $repoDir );
            if ( $repoName === false ) {
                // Unit tests use fake path names
                $repoName = $repoDir;
            }
            $realIP = realpath( MW_INSTALL_PATH );
            if ( str_starts_with( $repoName, $realIP ) ) {
                // Strip MW_INSTALL_PATH from path
                $repoName = substr( $repoName, strlen( $realIP ) );
            }
            // Transform git repo path to something we can safely embed in a filename
            // Windows supports both backslash and forward slash, ensure both are substituted.
            $repoName = strtr( $repoName, [ '/' => '-' ] );
            $repoName = strtr( $repoName, [ DIRECTORY_SEPARATOR => '-' ] );
            $fileName = 'info' . $repoName . '.json';
            $cachePath = "{$gitInfoCacheDirectory}/{$fileName}";
            if ( is_readable( $cachePath ) ) {
                return $cachePath;
            }
        }

        return "$repoDir/gitinfo.json";
    }

其中第165行是: if ( is_readable( $cachePath ) ), 说明问题出在 $cachePath 这个变量上,var_dump 结果是 /gitinfo/info.json ,这也与报错信息吻合。

继续查看其他变量,得知,$gitInfoCacheDirectory 在第一次赋值时,得到 false,在第二次赋值时,得到 /gitinfo,所以才有了 /gitinfo/info.json。那么我们只需要知道 /gitinfo 的来源便可以知道问题所在了。

这是因为 $this->options->get( MainConfigNames::CacheDirectory ) 的值为空,也就是全局变量 $wgCacheDirectory 的值为空。

然后查阅 MediaWiki官方对于此值的解释如下:

说建议将此值设置为 "$IP/cache",而对 wiki farm 建议设为 "$IP/cache/$wgDBname", 再来看 LocalSettings.php ,此行默认被注释:

## Set $wgCacheDirectory to a writable directory on the web server
## to make your wiki go slightly faster. The directory should not
## be publicly accessible from the web.
#$wgCacheDirectory = "$IP/cache";

它说这个目录是wiki的缓存,需要可写权限,但不要让它公开访问,会让你的网站 'go slightly faster', 这个就很有意思了。

如果按照 '$IP/cache' 设置,肯定不合适,因为 IP 不同,会产生很多IP文件夹,因此,将其设为 'cache' ,即在网站根目录下创建一个 cache 文件夹,集中管理才比较好。

至此,问题解决。

如果要追问下去,还会有其他的问题,比如 /gitinfo/info.json 到底是个什么,以及为何以前没出现这个问题,而今天出现了。

/gitinfo/info.json好像是MW当前提交的git的版本信息,内容如下:

{
    "head": "refs/heads/master",
    "headSHA1": "0123456789abcdef0123456789abcdef01234567",
    "headCommitDate": "1070884800",
    "branch": "master",
    "remoteURL": "https://gerrit.wikimedia.org/r/mediawiki/core"
}

MW为什么要访问它的提交信息,经过一番探索后,我没有找到答案。

先到这里吧,还有其他事情要做。

暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇