指南:升级

From MediaWiki.org
Jump to: navigation, search
This page is a translated version of the page Manual:Upgrading and the translation is 55% complete.

Other languages:
العربية • ‎беларуская • ‎български • ‎català • ‎dansk • ‎Deutsch • ‎Zazaki • ‎Ελληνικά • ‎English • ‎español • ‎فارسی • ‎français • ‎हिन्दी • ‎magyar • ‎Bahasa Indonesia • ‎italiano • ‎日本語 • ‎한국어 • ‎Nederlands • ‎polski • ‎português do Brasil • ‎русский • ‎sicilianu • ‎سنڌي • ‎Türkçe • ‎中文

概要

檔案轉送

選擇一種傳送檔案的方法

初步措施

閱讀包含在MediaWiki中的UPGRADE文件

  1. 檢查需求
  2. 閱讀發行說明
  3. 備份現有檔案和資料庫
  4. 解壓新文件
  5. 升級外掛
  6. 運行更新程式以檢查資料庫
  7. 測試更新

檢查需求

MediaWiki 1.30需求:

  • PHP 5.5.9+
  • 以下之一:
    • MySQL 5.5.8+ (或者相同的MariaDB
    • PostgreSQL 8.3+
    • SQLite 3.3.7+
    • Oracle 9.0.1+

如果你在使用PostgreSQL,請同時閱讀Manual:Upgrading PostgresManual:Upgrading Postgres

更多資訊請閱讀手册:安装要求Manual:Installation requirements兼容性Compatibility

閱讀發行版本說明

藉由解壓縮壓縮檔,或是由Git的檔案檢查/匯出, 裡面有一些檔案的檔名為大寫字母, 其中之個包含了RELEASE-NOTES (wiki). 現在打開它,並看看這個版本改變了些什麼。

清空等待中的工作

出于性能原因,数据库中的某些操作被延迟,并由作业队列管理。 这些作业存储在数据库中,并包含有关应执行的操作的信息参数。 强烈建议在升级Wiki前运行这些待处理的作业,以避免这些参数在新版本中发生变化而失败。 在执行升级前,可使用runJobs.phpManual:RunJobs.php运行所有挂起的作业并清除队列。

備份現有檔案和資料庫

完整說明: 手册:备份一个wikiManual:Backing up a wiki

虽然升级脚本维护良好且功能强大,但仍可能出错。在更新数据库之前,请对Wiki进行一个完整备份,包括数据库和文件:

  • the wiki's content, from the database, (make sure you get the character set specified correctly, first check LocalSettings.php). It may be a good idea to create an XML dump in addition to the SQL database dump.
  • MySQL, both SQL dump and XML dump are for use with the mysql command:
mysqldump --user=wikidb_user --password=wikidb_userpassword wikidb > file.sql
mysqldump --user=wikidb_user --password=wikidb_userpassword wikidb --xml > file.xml
  • PostgreSQL, database dump for use with pg_restore command:
pg_dump --create -Fc wikidb > file.db.dump
  • SQLite, you use a MediaWiki script for making a backup:
php wikifolder/maintenance/sqlite.php --backup-to file
  • 图片和其他媒体文件(images目录下的内容,自定义logo /skins/common/images/wiki.png)
  • 配置文件,例如:LocalSettings.php.htaccess (若存在)
  • MediaWiki的程序文件,包括所有的皮肤和扩展,特别是如果您修改了它们。

解压新文件

使用tarball打包

您可以通过FTP或者是命令行来放置新文件。若您可以使用命令行,请使用命令行。使用命令行要比使用FTP将数千个文件的每个文件上传要快得多。

注意 注意: 您应该将解压后的文件放到服务器上的一个新的空文件夹内。如果您直接在旧版本的目录中解压了新版本的文件,而不是在新文件夹中解压,您应遵循在备份现有文件和数据库章节的说明。否则,如果您做的自定义改动将被抹掉,而无法重新应用它们。 Extracting a tarball over top of your live copy of MediaWiki can also leave behind files from the old version of MediaWiki which may interfere with the upgraded code. It's recommended that you unpack the new files into a new directory, and then apply customizations to the new directory (restoring LocalSettings.php, images folder, extensions, and other customizations like custom skins)

FTP或图形界面

如果您不能够在服务器上访问命令行,下载MediaWiki tarball 到您的本地计算机并使用7zip解压该文件到本地计算机上。

在本地解压该文件后,使用您喜爱的FTP客户端软件上传目录和文件到服务器上。

命令行

若您当前用户下对Wiki安装目录没有完全的写入权限,则可能需要以sudo身份运行该命令。在解压缩tar包时,通常会为新的Wiki版本创建一个新的目录,您需要从旧安装目录中复制之前配置文件和媒体文件目录:

$ cd /path/to/your/new/installation/  
$ wget https://releases.wikimedia.org/mediawiki/1.30/mediawiki-1.30.0.tar.gz
$ tar -xvzf mediawiki-1.30.0.tar.gz 
$ rm mediawiki-1.30.0.tar.gz

(Open)Solaris用户应使用gtar,或:

$ gzip -dc mediawiki-1.30.0.tar.gz | tar xf -

其他文件

在解压压缩包后,您应该从旧安装目录中复制或者移动一些文件和文件到新安装目录下:

  • LocalSettings.php 文件包含了您旧的配置设置。
  • images(或在旧版本中uploads)目录,包含所有上传至wiki的文件,除非您已选择不同的上传目录,并更改所有权和权限。find ./images -type d -exec chmod 755 {} \;chgrp -R apache images(例如如果您的web用户是“apache”)。
  • extensions目录下的扩展。您应该经常更新扩展,旧扩展不能够保证在新版本的MediaWiki下工作。
  • 如果您使用了自定义logo,则还需要从备份中恢复该文件。在1.24版本之前通常在skins/common/images/ 目录下。在1.24版本之后在resources/assets/images/ 目录下,取决于您选择使用的目录。之后在LocalSettings.php文件中添加例如如下内容$wgLogo = "$wgScriptPath/images/logo.png";
  • skins 目录下的自定义皮肤。
  • 对旧安装文件或扩展所做的任何修改。
  • 任何 .htaccess 文件(若您使用Apache并定义了规则)。

一旦完成,将这个新文件夹设为Web服务器上的发布文件夹。或者将旧安装目录重命名,然后将新文件夹重命名为先前的旧安装目录的名字。

使用Git

If using GitDownload from Git, export the files into a clean location, and then copy the old customized files into the new location as described in the previous section.

If you are upgrading to MediaWiki 1.25 or later, you will also need to install some external PHP libraries using Composer or a provided collection maintained for the Wikimedia wiki farm. More details on installing and updating external libraries can be found in the Git download documentation.

使用补丁

A small patch file is usually made available for a minor version upgrade. Manually download and extract the patch file from the dumps site or follow the directions with wget below. Patches are incremental, you can not skip a version.

  1. cd定位到您MediaWiki的主目录下(存有LocalSettings.php文件的目录)
  2. 下载补丁文件,并用gunzip命令解压它。
  3. 使用patch -p1 --dry-run检查什么被修改了(例如patch -p1 --dry-run -i mediawiki-x.xx.x.patch
  4. If all is well, run patch again without --dry-run.
  5. Check your Special:Version and you should see the new version number in place.

可能导致错误的剩余文件

If you unpacked over the old installation directory, some old files can cause problems with the new version.


MediaWiki版本: 1.18

If you are not using profiling, but have a StartProfiler.php file in the MediaWiki root folder, you may receive errors referring to /includes/Profiler.php. Deleting, or renaming, the StartProfiler.php file will resolve this error. The StartProfiler.sample file, also in the MediaWiki root folder, can serve as a template should you enable profiling in the future.


MediaWiki版本: 1.23

MediaWiki 1.23 deprecates the skin autodiscovery mechanism of core skin files. After upgrading to this version, you should ensure that the old files Chick.php, Nostalgia.php, Simple.php and Standard.php directly in the skins/ directory as well as the according subfolders inside the skins/ directory got removed. MediaWiki will log warnings if any of them are still found to help you remember. (You will also need to adjust any custom skins to follow a similar convention.) See Manual:Skin autodiscoveryManual:Skin autodiscovery for details.


MediaWiki版本: 1.24

MediaWiki 1.24 changes the paths of core skin files. After upgrading to this version, you should ensure that the old files CologneBlue.php, Modern.php, MonoBook.php and Vector.php directly in the skins/ directory are no longer present. See Manual:Skin autodiscoveryManual:Skin autodiscovery for details.

升级扩展

Certain extensions have been updated in order to work with the new version of MediaWiki. Be sure to upgrade to the latest versions of such extensions. You might need to perform manual updates to custom extensions.

Different tarballs include some subsets of extensions and have versioning which helps you upgrade choosing the right one for your MediaWiki core release.

Extension Distributor works well for most people who want a snapshot of extensions that will work with their supported versions of MediaWiki.

If you want a lot of extensions then downloading from Git is probably best.

修改 LocalSettings.php 文件

如果你使用来自旧版本的LocalSettings.php文件,你可能需要修改这个文件使其能够在新版本上使用。

皮肤注册

从MediaWiki 1.24版本开始Vector,Monobook,Modern和CologneBlue等捆绑的皮肤不再是MediaWiki核心的一部分,使用这些皮肤需要在LocalSettings.php中注册,否则MediaWiki会向你提示没有安装这些皮肤。

若您希望这些皮肤可用,这是您升级到1.24版本后需要添加到LocalSettings.php的内容:

wfLoadSkin( 'Vector' );
wfLoadSkin( 'MonoBook' );
wfLoadSkin( 'Modern' );
wfLoadSkin( 'CologneBlue' );

此代码用于MediaWiki 1.25和更新版本。 对于MediaWiki 1.24您需要使用以下代码:

require_once "$IP/skins/Vector/Vector.php";
require_once "$IP/skins/MonoBook/MonoBook.php";
require_once "$IP/skins/Modern/Modern.php";
require_once "$IP/skins/CologneBlue/CologneBlue.php";

其他皮肤可能并不适应新的皮肤注册系统,所以请参阅有关每个皮肤的文档页面,了解如何在遇到问题时正确地注册它。

扩展注册

从MediaWiki 1.25版开始,扩展使用新的扩展注册系统。

您之前的LocalSettings.php会包含这些内容:

require_once "$IP/extensions/Cite/Cite.php";
require_once "$IP/extensions/Gadgets/Gadgets.php";
require_once "$IP/extensions/ImageMap/ImageMap.php";
require_once "$IP/extensions/InputBox/InputBox.php";
require_once "$IP/extensions/Nuke/Nuke.php";
require_once "$IP/extensions/ParserFunctions/ParserFunctions.php";
require_once "$IP/extensions/Poem/Poem.php";
require_once "$IP/extensions/SyntaxHighlight_GeSHi/SyntaxHighlight_GeSHi.php";
require_once "$IP/extensions/WikiEditor/WikiEditor.php";

这些可以转换为:

wfLoadExtension( 'Cite' );
wfLoadExtension( 'Gadgets' );
wfLoadExtension( 'ImageMap' );
wfLoadExtension( 'InputBox' );
wfLoadExtension( 'Nuke' );
wfLoadExtension( 'ParserFunctions' );
wfLoadExtension( 'Poem' );
wfLoadExtension( 'SyntaxHighlight_GeSHi' );
wfLoadExtension( 'WikiEditor' );

Extensions are being adapted to use the new extension registration system. Extensions that are not adapted should use the old way of installing them. Refer to the installation instructions on the extension's page for more information.

其他变量

一些变量可能已过时,或甚至被移除。 Having them in LocalSettings.php usually won't have any effect. New variables may be added in newer versions, or some existing variables changed their type. We usually try to use sane defaults for them, and in case of type change, be backwards compatible. In any case, take a look to the release notes to see those changes.

运行更新脚本

You can upgrade the MediaWiki database in two ways: Either from the command line or from the web browser. If you have shell access to your server, upgrading from the command line is recommended, since this reduces the risk of the upgrade process being interrupted by a timeout or connection reset.

The script will also attempt to download any missing dependency which MediaWiki needs.

命令行

Access the command line of your server or an SSH shell or similar. You can access the command line by connecting to your server via SSH. If the local PC you are working on runs Microsoft Windows, you will need a tool like PuTTY to use SSH. From the command line or the Shell, change to the maintenance directory and execute the update script:

$ php update.php

On a Linux server if you get an error try performing the same command as root (sudo php maintenance/update.php). Note for simple installations on Windows (e.g. with XAMPPManual:Installing MediaWiki on XAMPP): First make sure that your web server (such as Apache) and your database (such as MySQL) are running. Then run update.php: right-click it, select Open With, and browse to PHP.exe. The resulting command prompt window will likely autoclose when the schema upgrade completes.

You might see a message that your PHP version is too old and that MediaWiki needs a newer version. After that message the update aborts. Reason for this error is that the command line can use another PHP version than that one which you have when you execute MediaWiki from the web server. When you get this message you should check, if you can execute a newer PHP version on the shell by using a different command: That might e.g. be php5 or php56. If another version is available and - if so - under which name, depends on the setup of your server. If it does not work, ask your hoster; he will surely know.

MediaWiki will inspect the existing schema and update it to work with the new code, adding tables and columns as needed.

If you use a Shared database, you should pass the --doshared parameter if you want the shared tables to be updated. Otherwise they won't be touched by the update script.

当发生“ALTER命令对用户拒绝”错误(或类似错误)时应做什么

In case the scripts abort with a message similar to:

Error: 1142 ALTER command denied to user 'wiki'@'localhost' for table 'mytable' (localhost)
ERROR: must be the owner of the mytable relation 

This means that you should check that you have defined $wgDBadminuserManual:$wgDBadminuser and $wgDBadminpasswordManual:$wgDBadminpassword in your LocalSettings.phpManual:LocalSettings.php file (in the main directory). These are the user and password needed by this script in order to access to the database.

当发生“意外的T_STRING”错误时应做什么

Individuals running update.php from the command line may encounter the following error:

syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' \
in ~/maintenance/commandLine.inc on line 13

This error occurs when update.php is run from php4.

Individuals who have their site hosted by providers who provide both php4 and php5 should take the following steps:

  1. from the command line, enter the command 'whereis php5'
  2. once you have discerned the location of the php5 path, list the contents of php5/bin directory
  3. once you've determined the name of the php executable (either php or php5), type in the entire path to execute update.php

以下是个例子:

$ whereis php5
$ ls -la /usr/local/php5/bin
$ /usr/local/php5/bin/php update.php

当发生“register_argc_argv被设定为假”错误时应做什么

您可能遭遇这样的错误:

Cannot get command line arguments, register_argc_argv is set to false
  1. Go to ~/maintenance. Either edit an existing 'php.ini' file, or create one.
  2. 添加下面一行:
register_argc_argv=true
  1. 重新运行php update.php

Web浏览器

MediaWiki版本: 1.17
参见update.phpManual:update.php

If your database is already big and in high production usage, then you should not be using the Web updater, e.g. because the update process will time out when the maximum_execution_time is reached. In that case you should use update.php from the command-line interface (not from the web). What exactly is "too big" depends on your server (e.g. on its performance, the load and on how long the maximum execution time of PHP allows the script to run). If your wiki is too big for the web updater and your hosting provider does not allow command-line access, then you need to migrate your wiki to another hosting account, preferably to one that does have shell access.

  1. Always backup before performing database maintenance.
  2. Navigate your webbrowser to /mw-config/. For example, if your wiki is at http://example.org/w/index.php, then navigate to http://example.org/w/mw-config/.
  3. 选择您的语言并点击继续。
  4. The existing installation should be detected. Follow the instructions on the screen to upgrade it.
    If asked for the "upgrade key", open your LocalSettings.phpManual:LocalSettings.php file and look for the key assigned to $wgUpgradeKeyManual:$wgUpgradeKey.

It might happen that the web-updater does not seem to work: Instead of seeing the initial language selection screen, you might see an empty wiki page, possibly with some error message. In this case it is most likely that your webserver uses Rewrite Rules (most likely for short URLs), which do not show you the updater at mw-config/, but a wiki page at Mw-config/, with capital "M". In this case, rename the .htaccess file for the time of the update. Then you should be able to access the web-updater.

警告 警告: If you use this method, make sure to change the name of the .htaccess file back after running the upgrade script! Otherwise short URLs and possibly other stuff will be broken!

测试更新

Once the upgrade has been completed, browse to the wiki and check that the following operations work as expected:

  • Viewing pages
  • Editing pages
  • Uploading a file
  • Visit Special:Version and check that the version shown is correct and that the extensions are present.

常见问题

更新有多难?

If the only file you have modified is LocalSettings.phpManual:LocalSettings.php, and you are upgrading from 1.5 or later, the process is very simple. The amount of human work involved is only a few minutes. The database schema changes will take an amount of time proportional to the size of your database — potentially hours for wikis with millions of pages, but for a more typical size of a few thousand pages, it is usually done in seconds.

Minor upgrades, within the same major version, say from 1.13.0 to 1.13.1, do not require any schema changes at all. You can just update the files. The database needs no update, hence it is not necessary to run the installer script.

Upgrading from 1.4 or earlier is potentially complicated because support for character sets other than UTF-8 was dropped, and the schema for storing bulk text changed. Please read the relevant section in the UPGRADE file.

Upgrading becomes difficult if you have modified our source code, and you don't want your changes to be overwritten. Tools such as diff, patch, Meld or WinMerge may be useful. There is also potential for trouble if you are using unmaintained extensions. Upgrade your extensions at the same time as you upgrade MediaWiki.

If you have modified the skin or use a custom skin you very likely will have to adjust it to work again with the new version of MediaWiki.

注意 注意: Instead of patching your "global" css and js (javascript) files everytime you can simply add the code to your MediaWiki:Common.js and MediaWiki:Common.css pages. As these are part of the database which will be reused when you upgrade, you will not have to patch the MediaWiki core files any more.

我如何从一个非常老的版本升级?只需一步还是需要很多步?

It depends: If you are upgrading from MediaWiki 1.4 or older, you should upgrade to MediaWiki 1.5 first. If you are upgrading from a Latin-1 wiki, use upgrade1_5.php (found in MediaWiki 1.5) to convert the relevant parts of the database to UTF-8 ($wgUseLatin1Manual:$wgUseLatin1 needs to be set to true in your LocalSettings.phpManual:LocalSettings.php for this to work). Next, run update.php, and then set the $wgLegacyEncodingManual:$wgLegacyEncoding option in LocalSettings.php to the encoding previously used by the wiki (e.g. windows-1252). This is basically how Wikipedia and other Wikimedia Foundation sites were upgraded from MediaWiki 1.4 to 1.5 – see the relevant settings file (warning: huge page!) and some related notes at Wikitech. You may need to upgrade to MediaWiki 1.4 before running the upgrade1.5 script. If you want to make a database dump (e.g. MySQL) of your Latin-1 wiki, make sure the type of the old_text field in the textManual:Text table table is mediumblob, not mediumtext, to avoid character encoding issues.

If you are upgrading from MediaWiki 1.5 or newer, you can upgrade in one step, from your old version to the latest stable version. The vast majority of reports, as well as automated testing, indicate that doing it in one step works just fine. If you have trouble believing this, read this mailing list post. However, please note that when you update from old versions, chances that you will encounter PHP errors are bigger than when you upgrade from the version directly previous to the new version. You would have received these errors anyway, also if you had not skipped versions, but if you had each time done each single update. Only will you - when you skipped versions - get them all at the same time. This will make the upgrade more difficult, but do not forget that you did not have the trouble updating to the intermediate versions, which you skipped!

我是否应该首先备份?

一个字:是。

Long answer: It depends on a) how much you value your data, b) how hard it is to create a backup and c) how confident you are with MySQL maintenance and administration.

An upgrade failure may leave your database in an inconsistent state, in between two versions. A PHP or MySQL error might happen during upgrade leaving your database partly upgraded. In such situations it may be possible to somehow fix this problem with much manual work. However, it will be way easier to just put a database backup from before running update.php in place and to continue with that. Otherwise you might have hours of - needless - work.

Recovery is often complex. Volunteers on the support forums are unlikely to be impressed if you neglect to make a backup and then need help to recover from upgrade-related corruption. A better outcome is if you can revert to your backup, and then report the bug against the corresponding MediaWiki project in the upgrade process which caused the corruption.

我可以保留我的LocalSettings.php么?

Yes, but you may have to make some minor changes. The format of LocalSettings.phpManual:LocalSettings.php is largely backwards compatible. Changes which break LocalSettings.php compatibility will be documented in the "configuration changes" section of the release notes.

我的wiki可以在更新时保持在线么?

Generally yes, however Git may temporarily (for a few seconds) break it.

If you are upgrading between minor releases of MediaWiki, all you need to do is update the source files.

Note: the following assumes you have command line access. If you are upgrading between major releases of MediaWiki, the preferred procedure is as follows:

  1. Unpack the new version of MediaWiki into a new directory
  2. Prepare that new directory: copy your current LocalSettings.php from the old directory, copy any installed extensions and custom skins (if any). Check $wgLogo setting in LocalSettings.php and if necessary copy logo file from the old directory to the new directory.
  3. In the release notes for the new version, see if any changes need to be made to LocalSettings.php.
  4. Place the database in read-only mode by inserting the following variable into LocalSettings.php in the old directory - users will see this message if they attempt an edit during the upgrade process:
    $wgReadOnlyManual:$wgReadOnly = 'Upgrading to MediaWiki 1.30.0';
    • This no longer works since MediaWiki 1.27, which also prevents running the update script. See 任务T151833.
  5. Run the update script or the web updater in the new directory.
  6. Copy the images from the images sub-directory from the old directory to the new directory.
  7. Swap the old directory and the new directory.

为什么升级?

订阅mediawiki-announce以获取新发行版本的通知。

Because it's usually easy enough, a single step from your version to latest and also via web.

Recent releases receive security fixes to keep your wiki and your host safe from vandals, while old releases don't (see 版本生命周期Version lifecycle). That makes dozens good reasons to upgrade!

New major releases come with new features, which you might want to use: see the release notes for details. In case you need additional arguments to convince your bosses to let you upgrade from a pretty old version, here is a summary:

  • In 1.24, password storage was improved to allow for better security.
  • In 1.27, the session management was reworked as well as the user authentication management completely modernized.
  • Since 1.29, the Action API was reworked and improved. Also user group assignments may now be done for a selectable period.

参见直到2014年,在BugzillaBugzilla拥有最多投票的已修复问题列表

Also, in MediaWiki 1.18 we started bundling some vital extensions, like a better editor and anti-vandalism tools ConfirmEdit and Nuke; more have been added in later releases.

参见