如何成为MediaWiki开发者

本頁使用了標題或全文手工轉換
From mediawiki.org
This page is a translated version of the page How to become a MediaWiki hacker and the translation is 67% complete.
Outdated translations are marked like this.

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

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

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

对于其他的方式涉足维基媒体社区,参见如何贡献

概覽

MediaWiki是驱动维基百科及其姊妹项目,以及全世界数以千计的wiki网站的软件。

MediaWiki及扩展大部分以PHP编程语言编写。JavaScript用于提供交互界面元素,配合jQueryVue.js作为客户端JavaScript库。 JavaScript is used for providing interactive interface elements along with jQuery and Vue.js as client JavaScript libraries.

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

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

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

  • 开发讨论可以在Phabricator 、各种邮件列表 IRC 频道中进行。 主要开发者名单在此:wikitech-l。 主要的开发者IRC频道为#mediawiki connect#wikimedia-dev connect
  • 源代码保存在Gerrit 上並由Git版本控制系统管理的。[4]

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

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

  • 安裝Vagrant——這些步驟會安裝MediaWiki伺服器於所有符合需求的Linux虛擬機器(可用於Linux、Windows,或Mac hosts)

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.

本地安装

Local installation is a good option if you want to set up a simple development environment quickly without using Docker.

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 Gerrit/教程 .

沟通技巧和准则

当一个开发者修复MediaWiki的漏洞时,你可以观察他,包括他如何开展调查,执行git commit命令,如何使漏洞被再查以及修复,如何关闭Bugzilla表单或者现在取代Bugzilla的Phabricator

这些技巧能让你有效地与他人沟通,得到社区中其他成员的帮助。

高效率地使用Phabricator任务

当您准备着手处理一个Phabricator任务时:

  • 无需请求许可: 您无需请求任何人将任务分配给您即可开始进行任务。 不存在谁能分配任务或是需要先问谁的权威人士。
    • 如果一个任务在Gerrit中已经有了一个最近的补丁,请选择一个不同的任务作為替代。
    • 如果Gerrit中的一个现有补丁還没有被合并,而且很长时间都没有任何改动,你可以根据Gerrit裏和任务裏的反馈,改进那個现有补丁
  • 自行研究: 当您考虑进行某个任务时,在开始敲代码前先研究一番。仔細看看代码,試著去理解这些代码本该达到什么目的,閱讀相關的文件,然后尽量找到应该作出修改的地方。
    • 在一個Phabricator 任务中,使用侧边栏中的项目标签,找到任务的代码库。
    • 如果您对修复某个漏洞的办法毫无头绪,考虑先找个更简单的。
  • 你不需要在开始工作之前宣佈你的计划,但你应该传达你正在进行的任务。
    • 当你开始工作时,通过点击Phabricator中的「编辑任务...」将自己设置为任务分配人,并在「分配给」字段中设置你的Phabricator用户名。 这就向其他人传达了你正在工作,所以他们不会重复工作。
    • 当你的计划或兴趣改变时: 如果你不再从事某项工作,请将你自己作为该任务的分配人删除。 这告诉其他人,他们可以从事这项工作,而他们不会期望你仍然在从事这项工作。
  • 遵守Phabricator礼仪.
    • 在Phabricator任务中,只讨论有关该任务主题的具体问题。 別拿Phabricator来问一般的问题,比如如何建立一个开发环境或如何修复Gerrit的问题。

撰写好的问题

  • 不要讓他人還要從你的提問裏面再提問...只要讓他人看你的提問一次就好!
  • 要具体,并提供來龍去脈: 不要只是简单地问:「你能给我更多信息吗?」、「请指导我」、或「请告诉我如何开始」,而是在你的问题中包括以下信息:
    • 你想要达到什么?
    • 你已經試過什麼? 复制和粘贴你的命令和它们的输出(如果不是太长),而不是用你自己的话进行转述。
    • 在你的研究中,你已经发现了什么? 包括代码的链接、文档的链接、或其他你已经咨询过的资源的链接。
  • 在你的通信中使用具体的标题和主题行。 「提案的草案」或「我需要帮助」并不具体。
  • 保持对话的可读性: 当你在Zulip、Phabricator任务或邮件列表中回复时,只引用与你的回复相关的先前评论部分。 如果你引用一整個「完整的」以前的评论,它使线程难以阅读。

遵循沟通政策與最佳做法

在你发送或张贴你的问题之前:

在正确的地方提问

  • 公开询问:如果你谈话的主题不是什麼秘密,就不要发送私人信息。 私人信息对他人没有作用。
  • 在最好的地方提问和讨论:
    • 在Phabricator任务中,只讨论有关该任务主题的具体问题。
    • 联系交流 列出的地方裏面询问一般的技术问题,例如:如何建立一个开发环境或如何解决Gerrit的问题。
    • 如果你参加了拓展计划,那么Zulip是用来讨论关于拓展计划本身的问题。

请耐心等待

在你发布你的问题之后:

  • 不要在单独的信息中要求别人进行代码审查。 人们会收到Gerrit和Phabricator的通知,并会在他们可以的时候做出回应。
  • 在征求意见和评论时,特别是在周末和节假日,你可能需要等到恢复工作时间。 在像IRC这样的聊天频道中:如果没有人回答,在不同的时间再试一次;別这样就放弃了。
  • 如果你在等待和耐心等待之后仍然没有得到答案,请考虑其他沟通渠道是否是一个更好的地方来提出你的问题。

附录

MediaWiki贡献者在印度班加罗尔办公。

PHP

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

學習PHP
  • PHP指导 — 在许多不同语言中都可用。 如果你完全不会PHP,但是知道在其他面向对象编程语言中如何编程,那么PHP对你来说会易学一些。
  • 维基教科书上的PHP编程
  • PHP at Wikiversity.
PHP资源
需要知道的东西
  • MediaWiki中的脚本maintenance/eval.php提供了一个基本的包含MediaWiki对象与分级的PHP编译器。
  • 此外,MediaWiki中的脚本maintenance/shell.php是基于PsySH的maintenance/eval.php的替代,参见手册:Shell.php

資料庫

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

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

JavaScript和CSS

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

学习JavaScript和CSS
JavaScript和CSS资源

MediaWiki

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

MediaWiki基礎知識和必讀內容
MediaWiki资源

MediaWiki扩展

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

MediaWiki擴充功能基礎知識:
MediaWiki扩展手册:

MediaWiki皮肤

手册:如何制作MediaWiki皮肤 is helpful if you choose to work on MediaWiki skins.

参阅

Footnotes

  1. MediaWiki在多数支持PHP的平台上都能运行,但在非LAMP上,MediaWiki的表现与功能可能会因为特定操作系统属性与特定实用工具的缺失大打折扣。
  2. MediaWiki此外支持DBMS,包括PostgreSQLSQLite
  3. 开发者中既有志愿者,也有如承包商之类各行各业的工薪者。他们的全部姓名被列在了开发者
  4. 可以在此处浏览源代码、修改代码库,或者你也可以用Gerrit下载源代码到你的电脑。