“安装MW:初始化配置”的版本间差异

来自Wikioe
跳到导航 跳到搜索
 
(未显示同一用户的25个中间版本)
第1行: 第1行:
[[category:MediaWiki]]
[[category:MediaWiki]]


== 下载 ==
关于新的MediaWiki文件下载:
* 可以在服务器安装git后直接拉取GitHub的相关项目分支[https://github.com/wikimedia/mediawiki GitHub的MediaWiki项目地址]。但是对于服务器链接Github不方便的还是算了。
* 通过下载到各种方式(git、下载release包)到本地,再通过Xftp等工具上传到Server。如果不是服务器不能联网或要替换文件重新打包,则显得多余。
* 通过包的Linux的包管理工具拉取(<code>wget -P /www/wwwroot/ https://releases.wikimedia.org/mediawiki/1.35/mediawiki-1.35.0-rc.3.tar.gz</code>)。


关于获取MediaWiki的站点:
== 配置文件 ==
* [https://github.com/wikimedia/mediawiki GitHub:MediaWiki]
MediaWiki 的配置文件有两处:
* [https://releases.wikimedia.org/mediawiki/ MediaWiki Releases]
* [https://lists.wikimedia.org/pipermail/mediawiki-announce/2020-September/000258.html MediaWiki消息站点]:发布时间会早一点。
1、<span style="color: blue; font-size: 150%">'''DefaultSettings.php'''</span>:系统默认的配置文件,位于“<span style="color: green">'''./includes/DefaultSettings.php'''</span>”;
2、<span style="color: blue; font-size: 150%">'''LocalSettings.php'''</span>:用户设置的配置文件,位于“<span style="color: green">'''./LocalSettings.php'''</span>”;


注意:
以下主要在 '''LocalSettings.php''' 中进行增加、覆盖、设置相应配置。
# 通过<code>git clone</code>或download code zip的时候,子模块可能不能下载下拉,需要<code>git submodule update</code>或单独去download那些(对应分支)子模块的代码,子模块的信息在<code>.gitmodules</code>文件中。
# 下载或拉取发布包,若为核心包(如:mediawiki-core-1.35.0-rc.3.tar.gz)则包内不包含扩展。


== 更新 ==
=== '''配置:短链接'''<ref>[[配置MW:短链接]]</ref> ===
小版本的更新,如1.34.0 → 1.34.2 一般更新系统文件就可以了,不需要对服务器的基础支持相关进行安装或升级。<br/>


=== 备份 ===
=== 修改:Logo、Favicon ===
# LocalSettings.php;
可以使用“<span style="color: green; font-size: 120%">'''Axialis IconWorkshop'''</span>”制作图标(Favicon)。
# images文件夹(上传的文件);
# extensions(扩展);
# 添加或修改过的文件(如includes/efaultSettings.php);
# 自定义添加的(如:logo、skins[皮肤]、vendor[依赖])等。
=== 安装 ===
安装:
# Linux中解压 mediawiki-1.35.0-rc.2.tar.gz:
#:<code>tar -zxvf mediawiki-1.35.0-rc.2.tar.gz</code>
#:或
#:<code>unzip mediawiki-REL1_35.zip -d /www/wwwroot/</code>
# 移除旧版本;
#:<code>rm -rf wiki.eijux.com/</code>
# 移动或复制覆盖mediawiki-1.35.0-rc.2内容到网站文件夹:
#:移动:<code>mv -f mediawiki-1.35.0-rc.2/* wiki.eijux.com/</code>
#:或
#:复制覆盖:<code>yes|cp -rf mediawiki-REL1_35/* wiki.eijux.com/</code>
# 替换备份文件
# 更新网站文件归属及读写权限:
#:<code>chown -Rf www:www wiki.eijux.com/*</code>
#:并
#:<code>chmod -Rf 775 wiki.eijux.com/*</code>


== 升级 ==
LocalSettings.php 设置:
大版本的升级,如1.34.2 → 1.35.0,需要PHP7.3的支持(现用PHP7.2):
: <syntaxhighlight lang="PHP" highlight="">
<pre>
## The URL path to the logo. Make sure you change this from the default,
MediaWiki 1.35 internal error
## or else you'll overwrite your logo when you upgrade!
MediaWiki 1.35 requires at least PHP version 7.3.00; you are using PHP 7.2.33.
# $wgLogo = "$wgResourceBasePath/resources/assets/wiki.png";
# $wgLogos = [ '1x' => "$wgResourceBasePath/resources/assets/wiki.png" ];
$wgLogo = "$wgResourceBasePath/resources/assets/wikioe.png";
$wgFavicon = "$wgResourceBasePath/resources/assets/wikioe.ico";
</syntaxhighlight>


Supported PHP versions
=== 修改:移除底部的“Powered by”图标 ===
Please consider upgrading your copy of PHP. PHP versions less than v7.3.0 are no longer supported by the PHP Group and will not receive security or bugfix updates.
LocalSettings.php 设置:
: <syntaxhighlight lang="PHP" highlight="">
unset($wgFooterIcons['poweredby']);
</syntaxhighlight>


If for some reason you are unable to upgrade your PHP version, you will need to download an older version of MediaWiki from our website. See our compatibility page for details of which versions are compatible with prior versions of PHP.
=== 修改:皮肤 ===
</pre>
MediaWiki 的皮肤位于“./skins”中,可在网络下载并上传至服务器中(注意:修改皮肤文件读写权限及所有者)。
站点利用宝塔面板,可以很方便的安装PHP7.3,完成后需在网站设置中切换PHP版本;<br/>
并需安装PHP扩展<code>fileinfo</code>、<code>opcache</code>、<code>memcached</code>,禁用函数<code>proc_open</code><code>symlink</code>等。
<span style="color: blue">'''$wgDefaultSkin'''</span> 用于加载皮肤,<span style="color: blue">'''$wgDefaultSkin'''</span> 用于设置皮肤。


== 问题 ==
LocalSettings.php 设置:
: <syntaxhighlight lang="PHP" highlight="">
## Default skin: you can change the default skin. Use the internal symbolic
## names, ie 'vector', 'monobook', 'timeless':
$wgDefaultSkin = "vector";


=== 站点路径的问题: ===
# Enabled skins.
站点目录结构的不同,则配置文件的<code>$wgScriptPath</code>配置不同,网站的访问路径不同:
# The following skins were automatically enabled:
* 如果站点目录为<code>"/www/wwwroot/wiki.eijux.com/wiki"</code>:
wfLoadSkin( 'MinervaNeue' );
*: LocalSettings.PHP的配置为:<code>$wgScriptPath = ""</code>;
wfLoadSkin( 'MonoBook' );
*: 网站的访问路径为:<code>http://wiki.eijux.com/index.php?title=%E9%A6%96%E9%A1%B5</code>
wfLoadSkin( 'Timeless' );
* 如果站点目录为<code>"/www/wwwroot/wiki.eijux.com/wiki"</code>:
wfLoadSkin( 'Vector' );
*: LocalSettings.PHP的配置为:<code>$wgScriptPath = "/wiki"</code>;
</syntaxhighlight>
*: 网站的访问路径为:<code>http://wiki.eijux.com/wiki/index.php?title=%E9%A6%96%E9%A1%B5</code>


=== 从“mediawiki-1.34.2”升级到“mediawiki-1.35.0-rc.3”时,VisualEditor扩展的问题: ===
=== 配置:上传文件限制<ref>参考:[https://www.mediawiki.org/wiki/Manual:Configuring_file_uploads Manual:Configuring file uploads]</ref> ===
1.35.0版本之前,VisualEditor需要Parsoid/Js的支持,不仅需要单独安装独立运行的Parsoid服务,还需要Nodejs、NPM等基础包。而1.35.0版本之后,Parsoid/Js被以PHP语言重写并集成到MediaWiki内(Parsoid/PHP),所以,不需要任何额外的安装,仅需要修改<code>LocalSettings.php</code>以加载和设置VirsualEditor扩展。<br/>
DefaultSettings.php 中设置了:
1、默认允许上传的文件类型;(<span style="color: blue">'''png,gif,jpg,jpeg,webp'''</span>
2、默认不允许上传的文件类型;(“'''$wgProhibitedFileExtensions'''”在 1.37 版本之前为“'''$wgFileBlacklist'''”)


==== “mediawiki-1.35.0-rc.3.tar.gz”安装包的问题 ====
DefaultSettings.php:【不建议更改】
本次使用<code>mediawiki-1.35.0-rc.3.tar.gz</code>安装到服务器之后,通过比较服务器安装目录<code>/www/wwwroot/wiki.eijux.com/vendor/wikimedia/parsoid</code>和[https://github.com/wikimedia/parsoid.git git项目Paroid]目录,发现在服务器"/www/wwwroot/wiki.eijux.com/vendor/wikimedia/parsoid"下缺少"<code>lib</code>"文件夹。故而单独拉取Paroid项目的"<code>lib</code>"文件夹上传到服务器,并修改其所有者和读写权限(单独拉取Paroid项目"git clone https://github.com/wikimedia/parsoid.git D:\Documents\GitHub\parsoid",才能得到"lib"文件夹,其他git拉取Mediawiki的Paroid子模块、下载rc预览包(通过<code>composer.json</code>自动下载)等方式均无"lib")。<br/>
: <syntaxhighlight lang="PHP" highlight="">
使用VisualEditor时,只需要[加载和设置VisualEditor]即可,不需要<code>Parsoid</code>、<code>RESTBase</code>的加载和设置,不需要额外安装<code>Node.js</code>。<br/>
/**
点击“编辑”之后无报错即可。如果没反应等待稍后再试(可能是Parsoid等某服务加载延迟?)目前能正常显示VisualEditor页面,并加载内容。<br/>
* This is the list of preferred extensions for uploading files. Uploading files
'''使用'''
* with extensions not in this list will trigger a warning.
但在VisualEditor中保存内容时,出现“服务器没有在预期时间内响应。”,还不知道具体情况,[s]只知道和修改页面内容多少无关[s]。<br/>
*
“计算您的更改花费了太长时间,因此下方的描述可能并不理想。”真他娘和页面内容多少有关,太多的东西还是用WikiEditor改吧。坑!<br/>
* @warning If you add any OpenOffice or Microsoft Office file formats here,
又他妈能使了……<br/>
* such as odt or doc, and untrusted users are allowed to upload files, then
* your wiki will be vulnerable to cross-site request forgery (CSRF).
*/
$wgFileExtensions = [ 'png', 'gif', 'jpg', 'jpeg', 'webp' ];


==== Error contacting the Parsoid/RESTBase server (HTTP 500) ====
/**
# 1.34:配置错误。
* Files with these extensions will never be allowed as uploads.
# 1.35:依赖的Parsoid文件内容缺失?,对比服务器路径<code>/www/wwwroot/wiki.eijux.com/vendor/wikimedia/parsoid</code>和[https://github.com/wikimedia/parsoid.git GitHub]的内容。
* An array of file extensions to prevent being uploaded. You should
==== Error contacting the Parsoid/RESTBase server (HTTP 404) ====
* append to this array if you want to prevent additional file extensions.
# 1.34:配置错误。
*
# 1.35:配置多余。
* @since 1.37; previously $wgFileBlacklist
*/
$wgProhibitedFileExtensions = [
# HTML may contain cookie-stealing JavaScript and web bugs
'html', 'htm', 'js', 'jsb', 'mhtml', 'mht', 'xhtml', 'xht',
# PHP scripts may execute arbitrary code on the server
'php', 'phtml', 'php3', 'php4', 'php5', 'phps', 'phar',
# Other types that may be interpreted by some servers
'shtml', 'jhtml', 'pl', 'py', 'cgi',
# May contain harmful executables for Windows victims
'exe', 'scr', 'dll', 'msi', 'vbs', 'bat', 'com', 'pif', 'cmd', 'vxd', 'cpl'
];
</syntaxhighlight>


==== 1.35.0-rc.3 的配置代码 =====
<pre>
wfLoadExtension( 'VisualEditor' );


# VisualEditor Settings
LocalSettings.php 中可以:
# Enable by default for everybody
1、开启文件上传;
$wgDefaultUserOptions['visualeditor-enable'] = 1;
2、增加文件类型;    —— <span style="color: blue">'''可以与 DefaultSettings.php 类似地增加“允许的”、“不允许的”文件类型。'''</span>
# Don't allow users to disable it
$wgHiddenPrefs[] = 'visualeditor-enable';
# OPTIONAL: Enable VisualEditor's experimental code features
#$wgDefaultUserOptions['visualeditor-enable-experimental'] = 1;
# OPTIONAL: Enable VisualEditor in other namespaces
# (By default, VE is only enabled in NS_MAIN)
#$wgVisualEditorNamespaces[] = NS_USER;
</pre>


==== 尝试过的配置代码1,参考[https://www.mediawiki.org/wiki/Parsoid/PHP 官网Parsoid/PHP页面] ====
LocalSettings.php:【可以更改】
<pre>
: <syntaxhighlight lang="PHP" highlight="">
## Parsoid required configuration
...
AutoLoader::$psr4Namespaces += [
$wgEnableUploads = true;
    'Wikimedia\\Parsoid\\' => 'vendor/wikimedia/parsoid/src',
 
];
...
# Make sure exists of this line, if you want to use VE:
$wgFileExtensions[] = 'svg';
wfLoadExtension('Parsoid','vendor/wikimedia/parsoid/extension.json');
$wgFileExtensions[] = 'pdf';
# Enable Parsoid
</syntaxhighlight>
$wgEnableRestAPI = true;
 
$wgParsoidSettings = [
 
    'useSelser' => true,
设置后:
    'rtTestMode' => false,
1、可以通过导航栏或特殊页面中的上传文件链接上传文件。
    'linting' => false,
2、可以用 <code><span style="color: blue"><nowiki>[[File:文件名]]</nowiki></span></code> 在页面中引用文件
];
    —— 如果引入的是图片文件,还可以指定图片宽度:<code><span style="color: blue"><nowiki>[[File:Example.jpg|200px]]</nowiki></span></code>,加入图片说明:<code><span style="color: blue"><nowiki>[[File:Example.jpg|图片1]]</nowiki></span></code>,设置方框效果:<code><span style="color: blue"><nowiki>[[File:Filename.jpg|thumb]]</nowiki></span></code>。
## Enable VisualEditor
 
wfLoadExtension('VisualEditor');
=== 清除页面缓存 ===
# Enable by default for everybody
'''DefaultSettings.php''' 中,找到参数 <span style="color: blue">'''$wgCacheEpoch'''</span>,将参数值置为服务器的当前时间,可以取消全部已经缓存的页面(包括客户端和服务器端)。
$wgDefaultUserOptions['visualeditor-enable'] = 1;
#Optional: Set VisualEditor as the default for anonymous users
# otherwise they will have to switch to VE
$wgDefaultUserOptions['visualeditor-editor'] = "visualeditor";
# Don't allow users to disable it
#$wgHiddenPrefs[] = 'visualeditor-enable';
# OPTIONAL: Enable VisualEditor's experimental code features
$wgVisualEditorEnableExperimentalCode = true;
# OPTIONAL: Enable VisualEditor in other namespaces
# (By default, VE is only enabled in NS_MAIN)
$wgVisualEditorNamespaces[] = NS_USER;


$wgVirtualRestConfig['modules']['parsoid'] = array(
DefaultSettings.php 设置:
    'url' => $wgServer . $wgScriptPath . '/rest.php',
: <syntaxhighlight lang="PHP" highlight="">
    'domain' => $wgServer,
/**
    'prefix' => $wgServer
* Set this to current time to invalidate all prior cached pages. Affects both
);
* client-side and server-side caching.
$wgVirtualRestConfig['modules']['restbase'] = array(
* You can get the current date on your server by using the command:
    'url' => $wgServer . $wgScriptPath . '/rest.php',
* @verbatim
    'domain' => $wgServer,
*  date +%Y%m%d%H%M%S
    'forwardCookies' => false,
* @endverbatim
    'parsoidCompat' => false
*/
);
$wgCacheEpoch = '20030516000000';
$wgVisualEditorFullRestbaseURL = '$wgServer/$wgServer/';
</syntaxhighlight>
</pre>


==== 尝试过的配置代码2,参考[https://www.mediawiki.org/wiki/Parsoid#Linking_a_developer_checkout_of_Parsoid 官网Parsoid页面#Linking a developer checkout of Parsoid] ====
== 其他配置 ==
<pre>
=== 修改:用户组 ===
# Make sure exists of this line, if you want to use VE:
MediaWiki 中有3个用户组:<span style="color: blue">'''机器人'''</span> / <span style="color: blue">'''管理员'''</span> / <span style="color: blue">'''行政员'''</span>,每个用户组的具体权限可通过“<span style="color: green">'''特殊页面 -> 用户组权限'''</span>”查看;
wfLoadExtension('Parsoid', 'vendor/wikimedia/parsoid/extension.json');
Note:
1、通过首页中“创建用户”注册的用户默认不属于任何用户组;
2、从属于行政员用户组的用户,可通过“<span style="color: green">'''特殊页面 -> 用户权限管理'''</span>”给其他用户分配用户组。


# Enable Parsoid
=== 修改:左侧导航栏<ref>[[配置MW:左侧导航栏]]</ref> ===
$wgVisualEditorParsoidAutoConfig = false;
$wgParsoidSettings = [
    'useSelser' => true,
    'rtTestMode' => false,
    'linting' => false
];


# Enable VisualEditor
== 参考 ==
wfLoadExtension('VisualEditor');
<references/>
#
$wgDefaultUserOptions['visualeditor-enable'] = 1;
$wgVirtualRestConfig['modules']['parsoid'] = [
    'url' => $wgServer . $wgScriptPath . '/rest.php',
    'domain' => $wgServer
];
# OPTIONAL: Enable VisualEditor's experimental code features
$wgVisualEditorEnableExperimentalCode = true;
# OPTIONAL: Enable VisualEditor in other namespaces
# (By default, VE is only enabled in NS_MAIN)
$wgVisualEditorNamespaces[] = NS_USER;
</pre>

2022年8月23日 (二) 22:42的最新版本


配置文件

MediaWiki 的配置文件有两处:

1、DefaultSettings.php:系统默认的配置文件,位于“./includes/DefaultSettings.php”;

2、LocalSettings.php:用户设置的配置文件,位于“./LocalSettings.php”;

以下主要在 LocalSettings.php 中进行增加、覆盖、设置相应配置。

配置:短链接[1]

修改:Logo、Favicon

可以使用“Axialis IconWorkshop”制作图标(Favicon)。

LocalSettings.php 设置:

## The URL path to the logo.  Make sure you change this from the default,
## or else you'll overwrite your logo when you upgrade!
# $wgLogo = "$wgResourceBasePath/resources/assets/wiki.png";
# $wgLogos = [ '1x' => "$wgResourceBasePath/resources/assets/wiki.png" ];
$wgLogo = "$wgResourceBasePath/resources/assets/wikioe.png";
$wgFavicon = "$wgResourceBasePath/resources/assets/wikioe.ico";

修改:移除底部的“Powered by”图标

LocalSettings.php 设置:

unset($wgFooterIcons['poweredby']);

修改:皮肤

MediaWiki 的皮肤位于“./skins”中,可在网络下载并上传至服务器中(注意:修改皮肤文件读写权限及所有者)。

$wgDefaultSkin 用于加载皮肤,$wgDefaultSkin 用于设置皮肤。

LocalSettings.php 设置:

## Default skin: you can change the default skin. Use the internal symbolic
## names, ie 'vector', 'monobook', 'timeless':
$wgDefaultSkin = "vector";

# Enabled skins.
# The following skins were automatically enabled:
wfLoadSkin( 'MinervaNeue' );
wfLoadSkin( 'MonoBook' );
wfLoadSkin( 'Timeless' );
wfLoadSkin( 'Vector' );

配置:上传文件限制[2]

DefaultSettings.php 中设置了:
1、默认允许上传的文件类型;(png,gif,jpg,jpeg,webp)
2、默认不允许上传的文件类型;(“$wgProhibitedFileExtensions”在 1.37 版本之前为“$wgFileBlacklist”)

DefaultSettings.php:【不建议更改】

/**
 * This is the list of preferred extensions for uploading files. Uploading files
 * with extensions not in this list will trigger a warning.
 *
 * @warning If you add any OpenOffice or Microsoft Office file formats here,
 * such as odt or doc, and untrusted users are allowed to upload files, then
 * your wiki will be vulnerable to cross-site request forgery (CSRF).
 */
$wgFileExtensions = [ 'png', 'gif', 'jpg', 'jpeg', 'webp' ];

/**
 * Files with these extensions will never be allowed as uploads.
 * An array of file extensions to prevent being uploaded. You should
 * append to this array if you want to prevent additional file extensions.
 *
 * @since 1.37; previously $wgFileBlacklist
 */
$wgProhibitedFileExtensions = [
	# HTML may contain cookie-stealing JavaScript and web bugs
	'html', 'htm', 'js', 'jsb', 'mhtml', 'mht', 'xhtml', 'xht',
	# PHP scripts may execute arbitrary code on the server
	'php', 'phtml', 'php3', 'php4', 'php5', 'phps', 'phar',
	# Other types that may be interpreted by some servers
	'shtml', 'jhtml', 'pl', 'py', 'cgi',
	# May contain harmful executables for Windows victims
	'exe', 'scr', 'dll', 'msi', 'vbs', 'bat', 'com', 'pif', 'cmd', 'vxd', 'cpl'
];


LocalSettings.php 中可以:
1、开启文件上传;
2、增加文件类型;    —— 可以与 DefaultSettings.php 类似地增加“允许的”、“不允许的”文件类型。

LocalSettings.php:【可以更改】

...
$wgEnableUploads = true;

...
$wgFileExtensions[] = 'svg';
$wgFileExtensions[] = 'pdf';


设置后:
1、可以通过导航栏或特殊页面中的上传文件链接上传文件。
2、可以用 [[File:文件名]] 在页面中引用文件 
    —— 如果引入的是图片文件,还可以指定图片宽度:[[File:Example.jpg|200px]],加入图片说明:[[File:Example.jpg|图片1]],设置方框效果:[[File:Filename.jpg|thumb]]

清除页面缓存

DefaultSettings.php 中,找到参数 $wgCacheEpoch,将参数值置为服务器的当前时间,可以取消全部已经缓存的页面(包括客户端和服务器端)。

DefaultSettings.php 设置:

/**
 * Set this to current time to invalidate all prior cached pages. Affects both
 * client-side and server-side caching.
 * You can get the current date on your server by using the command:
 * @verbatim
 *   date +%Y%m%d%H%M%S
 * @endverbatim
 */
$wgCacheEpoch = '20030516000000';

其他配置

修改:用户组

MediaWiki 中有3个用户组:机器人 / 管理员 / 行政员,每个用户组的具体权限可通过“特殊页面 -> 用户组权限”查看;

Note:
1、通过首页中“创建用户”注册的用户默认不属于任何用户组;
2、从属于行政员用户组的用户,可通过“特殊页面 -> 用户权限管理”给其他用户分配用户组。

修改:左侧导航栏[3]

参考