How to become a MediaWiki hacker/pt-br

Este artigo foi escrito para ajudar os desenvolvedores iniciantes a aprender as habilidades necessárias para contribuir para o desenvolvimento do MediaWiki.

Se você é um desenvolvedor experiente, visite Developer hub em vez disso.

Visão geral
O software MediaWiki é escrito em PHP e usa o banco de dados MySQL. Ambos têm sido portado para uma variedade de sistemas operacionais, incluindo, mas não só, a maioria das variantes Unix: (Linux, Mac OS X, etc) e Microsoft Windows. É possível instalar e usar o MediaWiki no Linux, Mac OS X e Windows. Nota: se você usar o Windows, alguns recursos envolvendo utilitários externos ficarão indisponíveis ou disponíveis apenas com downloads especiais e configuração. Você vai ver, por vezes, bugs de sistema operacional, por isso é melhor ter algum conhecimento da diferença entre as várias plataformas, independentemente em qual sistema operacional que você desenvolve.

Aqui você tem uma idéia inicial da arquitetura MediaWiki.

Obtendo ajuda
A maneira mais rápida de obter ajuda neste início é em nosso canal no IRC,.

A linguagem PHP
Se você não tem conhecimento de PHP (PHP significa "PHP: Hypertext Preprocessor"), mas sabe como programar em outras línguas orientadas a objetos, não se preocupe, o PHP será fácil para você aprender.

Se você não tem conhecimento de PHP ou outras linguagens de programação orientada a objetos, você deve se familiarizar com conceitos como classes, objetos, métodos, eventos e herança.

Se você não tem conhecimento de qualquer linguagem de programação, PHP é uma linguagem boa para começar, como é razoavelmente semelhante a outras linguagens modernas, embora seja específica na forma como é executado.

Scripts PHP podem ser executados a partir da linha de comando, ou um gerenciador de janelas é suficiente para enviar para o interpretador. por exemplo, (no Linux / UNIX):

/usr/bin/php -q < phpshell.php

O script maintenance/eval.php do MediaWiki fornece um interpretador de PHP básico com objetos MediaWiki e as classes carregadas.

Normalmente, para websites, um script PHP é executado quando você solicitar um arquivo com a extensão ". php" (entre outros) a partir de um servidor web. Enquanto você faz isso, o servidor web, no nosso caso, Apache, chama o interpretador PHP (que pode ser incorporado no servidor web), interpreta o arquivo PHP e retorna o resultado ao seu navegador. O arquivo PHP pode conter código regulares HTML e PHP, o que torna relativamente simples de adicionar funcionalidade dinâmica a uma página estática.

Related links

 * PHP tutorial (available in many different languages)
 * The PHP manual (available in many different languages)
 * PHP at Wikibooks

Database
MediaWiki currently uses MySQL as the primary database backend. It also supports other DBMSes, such as PostgreSQL and SQLite. However, almost all developers use MySQL and don't test other DBs, which consequently break on a regular basis. You're therefore advised to use MySQL 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 (or write queries that are horribly inefficient in it), since that's what everybody else uses.

Although the Wikimedia Foundation has now moved on from MySQL 4.0, it's important to not intentionally break MySQL 4.0 support. MySQL 4.0 is missing a lot of features of later MySQL versions (never mind other DBMSes): if you aren't sure, double-check in the manual first! The most commonly used feature missing from MySQL 4.0 is subqueries; don't use those outside of code specific to a non-MySQL DBMS.

Installing MediaWiki
Get the latest sources from Subversion, our source control system, before creating patches. See Download from SVN for how to get the sources from SVN.

Follow the instructions in the INSTALL file in the source. You could also read the installation guide.

It's not necessary to download Wikipedia database dumps in order to develop MediaWiki features. In fact, in many cases it's easier to use a near-empty database with a few specially-crafted test pages. However, if for some reason you want to have a copy of Wikipedia, you can get a dump from data dumps.

You may also find that you get an error complaining that access was denied to the wiki database. Make sure that you have created a file AdminSettings.php in your top-level MediaWiki install directory (the same place as LocalSettings.php is found). An AdminSettings.sample file is provided for you to customise - make sure your MySQL administration username and password is set correctly. See Manual:Upgrading for more details.

Rebuilding the link tables may take a long time, particularly if you've installed the English Wikipedia database, which is quite big. (Note also that you can skip the old table if you wish.) See Manual:Database layout on what rebuildall.php is good for.

Note that if you want to create a public mirror of Wikipedia, this probably isn't the best way to go about it. If you do set up a mirror this way, please tweak the code to note that you're looking at a mirror and include links back to the main site. See Forks and Mirrors for more info.

The MediaWiki codebase
The MediaWiki codebase is large and ugly. Don't be overwhelmed by it. When you're first starting off, aim to write features or fix bugs which are constrained to a small region of code.

Browse through the list of important files at Manual:Code. For more detailed information, browse the generated documentation (warning: huge page will be loaded).

Your first feature
Here are some ideas:
 * Code something that interests you;
 * Write a simple special page to provide some handy information;
 * Write a simple extension (intro video tutorial);
 * Write a parser hook;
 * Fix an annoying little bug.

For more specific suggestions, please come and talk to the developers on. If you already have an idea for a feature you want to implement, it's also a good idea to talk to a senior developer before you start, especially if you're not sure how your feature will affect other parts of the code.

Make your changes against the trunk in Subversion, not a branch, and try to follow the coding standards (if you're writing a brand-new file, stylize.php can help).

When you have a feature ready to go, post a patch in Bugzilla, mark it with the "patch" and "need-review" keywords, and ping the Bugmeister to have it reviewed and committed. This can be a slower process than just committing it yourself, but by doing it once or twice you demonstrate your good faith, and your ability to write reasonably stable code. Relatedly, before you commit your feature, make sure it can be disabled easily.

When you are ready to write a new MediaWiki extension and you'd like to get it deployed on Wikimedia project servers, read Writing an extension for deployment.

Testing
Use E_STRICT in your php.ini to have unnecessary warnings and notices reported early.

When adding features, it's vital to verify you didn't break existing functionality. The usual tool for this is automated testing frameworks. MediaWiki's test suite is still relatively sparse. We have three kinds of tests:


 * Parser tests (see tests/parserTests.php), which only test the parser. Try running  to see how those work.  Everything should pass, in theory.  You can add new tests or fix existing ones by editing tests/parserTests.txt.
 * PHPUnit-based unit tests in the tests/phpunit directory. They are typically run through the phpunit.php script invoked from the aforementioned directory. These tests also include ordinary parser tests, though parserTests.php probably works faster. See Manual:PHP unit testing for PHPUnit setup instructions and further details.
 * Selenium tests are in directory tests/selenium</tt>.

Anyway, if you can't write an automatic test, do manual testing. If you cause breakage too often, people will get annoyed at you, especially if it isn't caught until it goes live on Wikipedia. Revocation of commit access has been threatened in the past occasionally. At the very least, expect serious indignation if you check in syntax errors – try at least loading your wiki, or php maintenance/checkSyntax.php --modified</tt>.

Turning display_startup_errors on
display_startup_errors is off by default on the toolserver. Turning it on within the program under test is too late! So create the following stub and execute that instead.

Posting a patch
If you have created and tested a patch (for example to fix an annoying little bug), get a unified diff of the modified file by using:

svn diff path/to/modified_file.php > my.patch

Then post the patch as an attachment to the appropriate bug report in Bugzilla, and add the  and   keywords to it so developers know to review it and respond to you.