Manual:$wgReadOnly/zh

From Linux Web Expert

<translate> Maintenance scripts setting</translate>: $wgReadOnly
禁止编辑,显示给出的字符串作为原因。

<translate> Introduced in version:</translate>pre 1.1.0
<translate> Removed in version:</translate><translate> still in use</translate>
<translate> Allowed values:</translate>(字符串),null/false
<translate> Default value:</translate>null (1.5.7+)
false (1.1.0-1.5.6)

细节

在功能上,这个设置与$wgReadOnlyFile 相同,但使用的是变量而不是文件。

如果在LocalSettings.php文件中将其设置为字符串,则$wgReadOnly将不允许编辑,并显示指定的字符串作为原因。 The reason provided is preceded by the contents of MediaWiki:Readonlywarning.

$wgReadOnly = '本Wiki正在升级软件版本。请过几个小时再回来查看。';

The above example locks the wiki and provides a default statement on edit pages and also gives the included string as an explanation for why the wiki was locked. Wikitext is allowed in this string and will be rendered when the read-only warning is shown which can be used to provide links or highlight upgrade notifications.

File:OOjs UI icon notice-destructive.svg <translate> Warning:</translate> In contrast to its name, this settings does not make the database read only! Even if $wgReadOnly is set, extensions, API scripts and other cacheable events can write data nonetheless.

升级

从MediaWiki 1.27开始,升级脚本$wgReadOnly设置的时候不会工作。

一个简单的解决方案是将其设置成仅在非命令行运行时才只读,这不会影响命令行更新脚本:

$wgReadOnly = ( PHP_SAPI === 'cli' ) ? false : 'This wiki is currently being upgraded to a newer software version. Please check back in a couple of hours.';

会话

如果会话不是存储在外部缓存系统类似Redis或Memcached,用户可能会登出并且在Wiki只读期间,不会再进行任何登录尝试,还会收到类似以下消息:

There seems to be a problem with your login session; this action has been canceled as a precaution against session hijacking. Please resubmit the form.

数据库缓存

Caches that use the database cannot be written to during read only mode, which could prevent more than just editing (depending on the configuration, logging in or even viewing pages). This can be avoided by disabling cache, albeit at the cost of making your wiki slow. This can be accomplished with the following settings in LocalSettings.php:

$wgMessageCacheType = $wgMainCacheType = $wgParserCacheType = $wgSessionCacheType = CACHE_NONE;
$wgLocalisationCacheConf['storeClass'] = 'LCStoreNull';

If you want your wiki to be fast, while still not using the DB, you should consider using something like Memcached. 参见$wgMainCacheType $wgLocalisationCacheConf 获取更多信息 If you want to enable logins while the database is readonly, at least $wgSessionCacheType needs to be set to some real non-DB caching mechanism.

Thumbnails

When in read-only mode, images which need to be transformed or scaled will be shown as an error message instead of as an image. To avoid this problem, put the following in the "LocalSettings.php" file:

$wgIgnoreImageErrors = true;