手册:维护脚本
维护脚本用于进行各种管理、导入、维护、汇报与升级任务。这些脚本用PHP编写,位于MediaWiki安装目录下的maintenance
子目录。
There are dozens of scripts with varying degrees of general utility and quality. You should carefully read the documentation on a script before using it; if a script isn't documented, take additional care running it.
配置
The $wgDBadminuser
and $wgDBadminpassword
configuration variables must be set in order to run maintenance scripts that need to alter the structure of the database (like 手册:update.php ) if the user configured in 手册:$wgDBuser doesn't have enough permissions.
Alternatively, you can pass the --dbuser and --dbpass parameters to the script.
The values for these variables differ based on the database engine that is being used to power your installation of MediaWiki.
如果未配置,它会使用手册:$wgDBuser 配置的用户。
MySQL
出于安全原因,某些维护脚本需要数据库权限,主MediaWiki数据库帐户不应具有该数据库权限。
如果尚不存在为MediaWiki数据库创建的“超级用户”特权的单独数据库帐户,那么你应该创建一个。
如果您用于MediaWiki的数据库称为wikidb
,则以下SQL将创建这样的用户,该用户可以在localhost上行使超级用户特权:
GRANT ALL PRIVILEGES ON wikidb.* TO 'wikidbadmin'@'localhost' IDENTIFIED BY 'strong-password';
创建账户后,你应在 $wgDBadminuser
配置用户名。
变量$wgDBadminuser
应该和一般配置那样放在LocalSettings.php 。
$wgDBadminuser
的密码必须在$wgDBadminpassword
配置变量中设置。
PostgreSQL
PostgreSQL uses a different security model than MySQL and the same PostgreSQL server account used for day-to-day operation of the MediaWiki installation must also be used for running the maintenance scripts.
This is necessary to ensure that the owner for new tables created by the maintenance scripts is set correctly.
You don't need to set $wgDBadminuser
or $wgDBadminpassword
at all.
运行脚本
The maintenance scripts must then be run from the command line. Users who do not access the server directly from its terminal will usually establish a connection through ssh. For Linux/Unix users this is by using the ssh client in a shell. For Windows users, one can use the SSH command line tool introduced in Windows 10 or alternatively use a third-party tool such as PuTTY shown below or use Windows Subsystem for Linux.
Required program for Windows users: PuTTY or any terminal emulator

- 步骤2:在PuTTy,在Host Name (或IP地址)后输入主机的IP地址(必要情况下请联系网站提供商)并点击打开。

- 步骤3:一个命令行窗口将会弹出。在login as:后输入FTP 用户名
- 步骤4:输入FTP密码
- Step 5: Change the current directory to the maintenance subdirectory. You can type
pwd
to see what folder you are currently in. The maintenance folder is in the root mediawiki folder.
$ cd maintenance
- 步骤6:执行需要运行的维护脚本
$ php rebuildall.php
- 如果发生错误(例如:“php.exe is no valid Win32 application”)可以尝试下面的措施:
$ php-cgi rebuildall.php
- 在Windows中,命令为:
$ C:\path\to\php\php-win.exe C:\path\to\mediawiki\maintenance\rebuildall.php
MW_INSTALL_PATH
environment variable to point to the root of your MediaWiki installation. This will help scripts to find the necessary files, and is particularly relevant when running maintenance scripts provided by third-party extensions.
标准命令行选项
几乎在/maintenance
中的所有PHP脚本都支持几个标准选项:
- --help
- 显示帮助信息
- --conf <path>
- Location of LocalSettings.php, if not default (at parent directory of the script)
- --dbuser <username>
- Database account to use instead of the one specified in LocalSettings.php, not used for scripts that don't require a database connection or when SQLite database backend is used
- --dbpass <password>
- Database password to use instead of the one specified in LocalSettings.php, not used for scripts that don't require a database connection or when SQLite database backend is used
- --globals
- Output globals at the end of processing for debugging
- --memory-limit <value>
- Set memory limit for the script. Accepts ordinary numbers, standard php.ini abbreviations (1024K, 20M, 1G),
max
for no limit (will be used by default if omitted) anddefault
for no change. (引入 自 1.17) - --quiet
- 屏蔽非错误输出
- --wiki <id>
- Wiki ID for wiki farms. This may be of the form
dbname
ordbname-prefix
. LocalSettings.php will be run with theMW_DB
andMW_PREFIX
constants defined accordingly. - --profiler
- Profiler output format (usually "text"). (引入 自 1.22)
- --mwdebug
- 启用内置的MediaWiki开发选项。 (引入 自 1.31)
使用symlinks来安装MediaWiki
In cases where the MediaWiki php files are symlinked to a central installation, you will need to specify to the maintenance script the path of the LocalSettings.php file. For example:
php maintenance/importImages.php --conf /var/wwwdata/website.org/wiki/LocalSettings.php /tmp/wikiimages .jpg .png .svg
否则会发生如下错误:
A copy of your installation's LocalSettings.php must exist and be readable in the source directory.
Sometimes MediaWiki is installed as a family for many languages and settings (LocalSettings.php) are split to common part and language parts (see Manual:Wiki family#Shared Settings ) where common part is located outside of /w directory and accessed using relative link (require_once "../ExtensionSettings.php";
).
In this case maintenance scripts will not work when running them in /w/maintenance directory.
改从/w目录中运行:
$ php maintenance/rebuildall.php
无shell访问权
On many shared hosts, you won't have shell access. The following extensions may be useful to run maintenance scripts via the web: Maintenance and MaintenanceShell .
维护脚本列表
除了这个可能已经过时的列表,您可以
- 浏览
maintenance
目录的最新内容。 - https://doc.wikimedia.org/mediawiki-core/master/php/ - 查看它生成的文档摘要。 (Files > File List > maintenance in the tabs or left-hand navigation sidebar)
Here is the list of files included in the maintenance
subdirectory located at the root of a MediaWiki installation.
You can contribute to this manual by keeping this list up to date, adding a description of these files' specific purpose and of how an administrator should use them (command line examples, etc.).
Be aware that these were created and named on an ad hoc basis so have some usability issues.
maintenance/
maintenance/archives
maintenance/benchmarks
- Benchmarker.php
- bench_HTTP_HTTPS.php
- bench_delete_truncate.php
- bench_if_switch.php
- bench_strtr_str_replace.php
- bench_utf8_title_check.php
- bench_wfBaseConvert.php
- bench_wfIsWindows.php
- benchmarkHooks.php
- benchmarkParse.php
- benchmarkPurge.php
maintenance/dev/includes
maintenance/language
- StatOutputs.php
- alltrans.php
- checkDupeMessages.php
- checkExtensions.php
- checkLanguage.inc
- checkLanguage.php
- countMessages.php
- date-formats.php
- digit2html.php
- dumpMessages.php
- generateCollationData.php
- generateNormalizerDataAr.php
- generateNormalizerDataMl.php
- langmemusage.php
- listVariants.php
- languages.inc
- transstat.php
maintenance/oracle
maintenance/storage
- checkStorage.php
- compressOld.php
- dumpRev.php
- moveToExternal.php
- orphanStats.php
- recompressTracked.php
- resolveStubs.php
- storageTypeStats.php
- testCompression.php
- trackBlobs.php