How to become a MediaWiki hacker/zh

这篇文章用以帮助开发者学习开发MediaWik 内核和MediaWiki扩展的基础技能.

入门Wikimedia开发的主要方式就是给那些有新手指导的Wikimedia项目做贡献. 另一种毋须指导的替代方案则是去debug.

如果你是一个有经验的开发者，已经熟悉了使用MediaWiki，请访问.

对于其他的方式涉足维基媒体社区，参见.

概覽
MediaWiki是维基百科，與其姐妹项目，还有世界各地数以千计的维基网站使用的软件.

雖然MediaWiki是由PHP语言编写，有些支持性工具由其他语言编写，他们包括批处理文件、shell脚本、makefiles和Python.

Some supporting tools are written in other languages, including batch files, shell scripts, makefiles and Python.

MediaWiki首先是为LAMP平台编写 ，并且在多数操作系统中是可用的. MediaWiki首要使用MySQL与MariaDB数据库服务器.

MediaWiki在开源环境下开发. 代码的调整大多在网上完成，并受到维基媒体基金会的支持，不过志愿者为之付出甚多.


 * 开发讨论可以在、各种和IRC 频道中进行. 主要开发者名单在此：wikitech-l.  主要的开发者IRC频道为和.
 * 源代码保存在上並由Git版本控制系统管理的.
 * 代码审查在中进行，可以在此处查看. 按照教程来安装Git与Gerrit以提交补丁.
 * 漏洞报告提交与功能请求協調在上，可以在此处查看.

Find or create a task
Before you ever develop a feature or fix a bug in a MediaWiki project, it is important that you do your research about it. 这包括：


 * 1) Search Phabricator if an open or closed Task (Document Types field) already exists. If it doesn't, create one. If this is a very small change, don't create one.
 * 2) Find and investigate the code that needs to be changed to implement the feature. Comment your findings on the Phabricator Task if they might be helpful to others who implement it or review your changes.
 * 3) Determine if you can likely add the feature or fix the bug based the code you investigated and the changes needed. If the task is large or complex, you should find something easier and work your way up to eventually be able to handle tasks of that size. If you believe you can complete it, assign yourself to the Task and begin working on it.



配置您的开发环境
Once you have found something you can work on, the next step to developing MediaWiki or an extension is creating an environment to run MediaWiki, its database, and any other external features so that you can develop and test them.

You can install and develop MediaWiki on Linux, Windows, or macOS using any of the three solutions below.

Docker

 * MediaWiki Docker – 利用Docker运行MediaWiki.

Docker is a good option if you want to setup a MediaWiki installation quickly and are not planning on installing many extensions.

You can also try the mwcli tool which sets up Docker with a few simple commands and provides basic orchestration functionality between MediaWiki, MySQL, ElasticSearch, Memcached, and other types of containers.

Vargant

 * MediaWiki Vagrant – Run MediaWiki on a Linux virtual machine using Vagrant.

Vagrant allows you start a MediaWiki instance you can develop as well as allowing you to add and develop any of 250+ extensions - all with a single command.

This saves you installation and configuration time compared to manually adding extensions in a Docker or local installation, but it runs a bit slower than the other two options.



手动安装
MediaWiki can be developed by installing it and its dependencies locally on your system.

It will take much more time to set up than Docker or Vagrant.


 * 1)  — 检查硬件要求并安装依赖
 * 2)  — 於Git下載最新版的原始碼.
 * 3)  — 繼續安裝與初始化設定.
 * 4) 架設不同的偵錯模式於您的環境，以提早顯示警告與錯誤.

Open a code editor
The two recommended code editors for editing MediaWiki are VSCode and PhpStorm. VSCode is free and PhpStorm is paid, however, you can acquire a PhpStorm license for free if you are a student by linking your GitHub Education account to your JetBrains account, or by requesting a license granted to Wikimedia.

To determine which editor you should install and use, know that all-around, PhpStorm has more and more-powerful features than VSCode. However, PhpStorm takes significantly longer to load on start than VSCode as it builds an index of the entire repository whereas VSCode progressively loads. Therefore, VSCode is typically useful for file-viewing sessions or small changes and PhpStorm for larger changes. It makes sense to have both installed for these reasons.

To develop the MediaWiki codebase that is inside a Docker container you can establish a remote connection to it and open the MediaWiki folder inside it using VSCode or PhpStorm.

Change and test the code
Change the code and view your changes by reloading your MediaWiki browser tab. Make sure to follow. Write and run tests on your code to make sure it works and is formatted properly.

Note, you can save time by ensuring your changes will be accepted before taking the time to write tests. Create a patch without needed tests and ask for someone to review it stating that you will add tests after they review it.

Create a patch
Finally, to submit your code to be reviewed and added to the repository you are contributing to, follow.



PHP
MediaWiki由PHP编写,所以你需要了解并熟悉PHP才可以熟练使用MediaWiki的核心代码.


 * 學習PHP
 * PHP指导 — 在许多不同语言中都可用. 如果你完全不会PHP，但是知道在其他面向对象编程语言中如何编程，那么PHP对你来说会易学一些.
 * 维基教科书上的PHP编程.
 * PHP at Wikiversity.


 * PHP资源:
 * PHP手册 — 在许多不同语言里可用.
 * MediaWiki社区内部的PHP编程条例.


 * 需要知道的东西:
 * MediaWiki中的脚本 提供了一个基本的包含MediaWiki对象与分级的PHP编译器.
 * 此外，MediaWiki中的脚本 是基于PsySH的 的替代，参见

資料庫
许多特性需要对数据库做出一定程度的修改，所以你常常需要熟悉MySQL/MariaDB.


 * 学习MySQL或MariaDB
 * MySQL指导 — 来自MySQL参考手册.
 * 维基学院上的MySQL.


 * MySQL/MariaDB资源
 * MySQL参考手册 — 在许多不同语言里可用.
 * MariaDB知识库
 * MediaWiki社区内部的数据库编码条例.


 * 要知道的东西:
 * 用MySQL/MariaDB測試你的代碼.
 * MediaWiki目前使用MySQL和MariaDB作为主数据库后端. 它同样支持其他DBMS,例如PostgreSQL和SQLite.  但是，几乎所有开发人员都使用MySQL/MariaDB而不测试其他数据库，因此会定期中断.  因此，建议您在测试补丁时使用MySQL/MariaDB，除非您专门尝试改进对其他数据库的支持.  在后一种情况下，请确保您小心不要破坏MySQL/MariaDB（或编写非常低效的查询），因为MySQL/MariaDB是其他人使用的.



JavaScript和CSS
JavaScript和CSS在前端代码中无处不在. 您不必熟悉使用MediaWiki的JavaScript、jQuery和CSS，但您可能需要，具体取决于您选择的工作方式.


 * 学习JavaScript和CSS
 * 维基教科书上的JavaScript和CSS.
 * 入门jQuery — jQuery指导
 * Learning JavaScript — references and sources.


 * JavaScript和CSS资源
 * MediaWiki社区中的JavaScript编码约定.
 * MediaWiki社区中的CSS编码约定.

MediaWiki
MediaWiki代码库很大，有些部分很难看，不要被它淹没. 当您第一次开始时，目标是编写功能或修复只触及一小部分代码的错误.


 * MediaWiki基礎知識和必讀內容:
 *  — MediaWiki的主要元件及它們之間如何相互配合的高級概述.
 *  — 為何要以及如何編寫安全代碼的概述.


 * MediaWiki资源:
 * — 重要文件和更多细节的列表
 * — 钩子列表. 如您正尝试寻找是代码库的哪个部分执行某个操作，通常可以从搜索相关钩子开始.
 * — MediaWiki社区代码编写规范的概述.


 * -{zh-hans:代码文档; zh-hant:程式碼文件;}- (類別參考) — Automatically generated documentation from the code and code comments.
 * — 调试MediaWiki的指南.
 * — 实时与MediaWiki对象交互的工具.



MediaWiki扩展
如您选择在MediaWiki扩展的代码建设上添砖加瓦，下列链接能提供更多信息.


 * MediaWiki擴充功能基礎知識：
 * 開發擴充功能 — 如何撰寫MediaWiki的擴充功能.
 * 扩展写作教程


 * MediaWiki扩展手册：
 * 最佳实践活动
 * A brief introduction to MediaWiki extension development — A video presentation about how to create a MediaWiki extension (slides).
 * Making a MediaWiki extension — Covers how to develop an extension for MediaWiki, best practices, and how to engage the MediaWiki community. 从2011年2月开始.
 * 开发者小屋中的开发者帮助



MediaWiki皮肤
is helpful if you choose to work on MediaWiki skins.



參見

 * Search for code across repositories
 * – 如果你已经把这篇文章读完了，是时候去看看开发者小屋了.