Come diventare un hacker di MediaWiki
Questo articolo è stato scritto per aiutare gli sviluppatori ad apprendere le abilità necessarie per contribuire allo sviluppo di MediaWiki core (il nucleo base) e delle estensioni aggiuntive per Mediawiki.
Il primo approccio per iniziare con lo sviluppo di Wikimedia è quello di contribuire a un progetto Wikimedia assistito da parte di utenti già esperti (progetto con mentoring). Un'alternativa senza assistenza è quella di sistemare qualche eventuale piccolo bug fastidioso
Se sei uno sviluppatore avanzato e hai già maneggiato la funzione di MediaWiki, visita la Hub degli Sviluppatori .
Per sapere altri modi di contribuire nella comunità di Wikimedia, vedi Come contribuire .
Panoramica
MediaWiki è il software che permette di lavorare su Wikipedia, su i suoi progetti collegati, e su migliaia di pagine in tutto il mondo.
Sebbene MediaWiki è scritto nel linguaggio di programmazione PHP, alcuni strumenti aggiuntivi sono scritti in altri linguaggi, tra cui file batch, script di shell, makefiles e Python. 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 è scritto principalmente per la piattaforma LAMP, [1] e gira sulla maggior parte dei sistemi operativi. MediaWiki usa principalmente server di MySQL o MariaDB.[2]
Lo sviluppo avviene nello stile open source style[3], è ampiamente coordinato online, e supportato da Wikimedia Foundation, anche se gli sviluppatori di comunità volontarie svolgono un ruolo enorme.
- La discussione sullo sviluppo avviene su diverse mailing lists e canali IRC.
L'elenco principale degli sviluppatori è wikitech-l. I canali IRC principali degli sviluppatori sono #mediawiki connect and #wikimedia-dev connect.
- La revisione del codice viene eseguita su Gerrit e può essere visualizzata qui. Segui questo tutorial per impostare Git e Gerrit allo scopo di inviare correzioni.
- Le segnalazioni di bug sono registrate e i progetti sono coordinati su Phabricator e possono essere visualizzati qui
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. This includes:
- 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.
- 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.
- 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.
Imposta il tuo ambiente di sviluppo
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.
Ambiente di sviluppo Docker
- MediaWiki Docker – Esegui MediaWiki utilizzando Docker (può essere utilizzato su host Linux, Windows, oppure macOS).
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.
Macchina virtuale con Vagrant
- Installazione di Vagrant - Questi passi installeranno il server di MediaWiki con tutti i requisiti dentro una macchina virtuale con Linux (può essere utilizzato in Linux, Windows, o Hosts di Mac).
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.
Manuale di installazione
- Local development quickstart – Run MediaWiki locally using PHP and Composer.
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 Manual:Coding conventions . 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/Tutorial .
Communication tips and guidelines
Follow these tips to communicate effectively and get help from community members.
Use Phabricator tasks effectively
When you plan to work on a Phabricator task:
- No need to ask for permission: You can work on unassigned tasks without asking someone to assign them to you. There is no authority who assigns tasks or who needs to be asked first.
- If a task already has a recent patch in Gerrit, choose a different task to work on instead.
- If an existing patch in Gerrit has not been merged and has not seen any changes for a long time, you could improve that existing patch, based on the feedback in Gerrit and in the task.
- Do your research: When you consider working on a task, do research before you start coding. Look at the code, try to understand what it is supposed to do, read related documentation, and try to find the places where you need to make code changes.
- In a Phabricator task, use the project tags in the side bar to find the code repository for the task.
- If you have no idea at all how to fix the bug, consider finding an easier one first.
- You do not need to announce your plans before you start working on a task, but you should communicate that you are working on the task.
- When you start work, set yourself as task assignee by clicking Edit Task… in Phabricator, and set your Phabricator username in the Assigned To field. This communicates to others that you are working on it, so they don't duplicate work.
- When your plans or interests change: If you are no longer working on a task, remove yourself as the assignee of the task. This tells others that they can work on the task, and they won't expect you to still work on it.
- Follow Phabricator etiquette.
- In Phabricator tasks, discuss only specific questions about the topic of that task. Don't use Phabricator to ask general questions, like how to set up a development environment or how to fix problems with Gerrit.
Compose good questions
- Don't ask to ask...just ask!.
- Be specific and provide context: Instead of simply asking "Can you give me more info?", "Please guide me", or "Please tell me how to start", include the following information in your question:
- What are you trying to achieve?
- What have you already tried? Copy and paste your commands and their output (if not too long) instead of paraphrasing in your own words.
- What have you found out already during your research? Include links to code, documentation, or other resources you already consulted.
- Use specific titles and subject lines in your communication. "Proposal draft" or "Need help" is not specific.
- Keep conversations readable: When you reply in Zulip, in Phabricator tasks, or on mailing lists, only quote sections of previous comments that are relevant to your response. If you quote a complete previous comment, it makes threads hard to read.
Follow communication policies and best practices
Before you send or post your question:
- Read and follow the code of conduct for Wikimedia technical spaces.
- Use inclusive language : Instead of using terms that assume a gender identity (like "guys", "madam", or "sir") use the name of the person instead.
Ask in the right place
- Ask in public: Do not send private messages if your conversation topic is not secret. Private messages don't help others.
- Ask and discuss in the best place:
- In Phabricator tasks, discuss only specific questions about the topic of that task.
- Ask general technical questions, like how to set up a development environment or how to fix problems with Gerrit, in the places listed on Comunicazione .
- If you take part in an outreach program, then Zulip is for discussing questions about the outreach programs themselves.
Be patient
After you post your question:
- Do not ask people for code review in a separate message. People receive Gerrit and Phabricator notifications and will respond when they can.
- When seeking input and comments, especially during weekends and holidays, you may need to wait until business hours resume. On chat channels like IRC: if nobody answers, try again at a different time; don't just give up!
- If you don't get an answer even after waiting and being patient, consider if other Communication channels might be a better place to ask your question.
Appendice
PHP
MediaWiki è programmato in PHP, perciò devi avere destrezza con il linguaggio PHP per contribuire a MediaWiki.
- Apprendere il PHP
-
- Tutorial di PHP — Disponibile in molte lingue diverse. Se non apprendi il linguaggio PHP ma sai programmare in altri linguaggi informatici, per te il PHP sarà facile da apprendere.
- PHP Programming at Wikibooks.
- PHP at Wikiversity.
- Risorse PHP
-
- Manuale del PHP — Disponibile in molte lingue diverse.
- PHP coding conventions within the MediaWiki community.
- Stuff to know
-
- The script
maintenance/eval.php
in MediaWiki provides a basic PHP interpreter with MediaWiki objects and classes loaded. - Also, the script
maintenance/shell.php
in MediaWiki is a replacement ofmaintenance/eval.php
based on PsySH, see Manual:Shell.php
- The script
Database
Many features require some amount of database manipulation, so you'll often need to be familiar with MySQL/MariaDB.
- Learn MySQL/MariaDB
-
- MySQL tutorial — From the MySQL reference manual.
- MySQL at Wikibooks.
- MySQL/MariaDB resources
-
- MySQL Reference Manuals — Available in many different languages.
- MariaDB Knowledge Base
- Database coding conventions within the MediaWiki community.
- Accessing the database
- Stuff to know
-
- Test your code with MySQL/MariaDB.
- MediaWiki currently uses MySQL and MariaDB as the primary database back-end. It also supports other DBMSes, such as PostgreSQL and SQLite. However, almost all developers use MySQL/MariaDB and don't test other DBs, which consequently break on a regular basis. You're therefore advised to use MySQL/MariaDB when testing patches, unless you're specifically trying to improve support for another DB. In the latter case, make sure you're careful not to break MySQL/MariaDB (or write queries that are horribly inefficient in it), since MySQL/MariaDB is what everybody else uses.
- Test your code with MySQL/MariaDB.
JavaScript and CSS
JavaScript and CSS have become omnipresent in front-end code. You don't have to be familiar with JavaScript, jQuery and CSS to work on MediaWiki, but you might need to, depending on what you choose to work on.
- Learn JavaScript and CSS
-
- JavaScript and CSS at Wikibooks.
- Getting Started with jQuery — A jQuery tutorial.
- Learning JavaScript — references and sources.
- JavaScript and CSS resources
-
- JavaScript coding conventions within the MediaWiki community.
- CSS coding conventions within the MediaWiki community.
MediaWiki
The MediaWiki code base is large and some parts are ugly; don't be overwhelmed by it. When you're first starting off, aim to write features or fix bugs which only touch a small region of code.
- MediaWiki basics and must-reads
-
- MediaWiki architecture — A high-level overview of the main components of MediaWiki and how they work with each other.
- Security for developers — An overview of why and how to write secure code.
- MediaWiki resources
-
- Manual:Code — A list of important files and links to more detailed information.
- Manual:Hooks — A list of hooks. If you're trying to find what part of the codebase does something, often a good place to start is by searching for the related hooks.
- Manual:Coding conventions — An overview of general coding conventions within the MediaWiki community.
- Code documentation (class reference) — Automatically generated documentation from the code and code comments.
- Manual:How to debug — A guide to debugging MediaWiki.
- Manual:Eval.php — A tool to interact with MediaWiki objects live.
MediaWiki extensions
If you choose to work on MediaWiki extensions code, the following links provide more information.
- MediaWiki extensions basics:
-
- Developing extensions — How to write an extension for MediaWiki.
- Extension writing tutorial
- MediaWiki extensions resources:
-
- Best practices for extensions
- 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. Dal febbraio 2011
- Help for extension developers on the Developer Hub
MediaWiki skins
Manual:How to make a MediaWiki skin is helpful if you choose to work on MediaWiki skins.
Vedi anche
- Search for code across repositories
- Hub degli Sviluppatori – When you've thoroughly read the information in this article, it's time to move on to the information in the developer hub.
- Codice di Condotta
Footnotes
- ↑ e gira sulla maggior parte delle piattaforme che supportano PHP. Ciò nonostante, la mancanza di alcune utility o di particolari caratteristiche del sistema operativo, possono limitare la funzionalità o rendimento di MediaWiki in piattaforme che non sono LAMP.
- ↑ MediaWiki ha supporti per DBMS oltre a MySQL e MariaDB, incluso anche Oracle, PostgreSQL, SQLite, e Microsoft SQL Server.
- ↑ Developers are a mix of volunteers and paid staff (or contractors) for various organizations. Per l'elenco completo di coloro che lavorano sul codice MediaWiki, leggere l'articolo Sviluppatori .
- ↑ Scorri il codice sorgente e le revisioni del codice in archivio su https://phabricator.wikimedia.org/diffusion/ o scarica il codice sorgente sul tuo sistema utilizzando Gerrit.