Getting started with MediaWiki hacking Mark Holmquist Wikimedia Foundation 2014-03-22 Mark Holmquist Getting started with MediaWiki hacking
Intent of this presentation I set out to give you a comprehensive introduction to MediaWiki. While I think I’ve done a good job of presenting a lot of interesting information, I doubt we’ll be able to get through any work on it before leaving this room. If you need any help with MediaWiki hacking, or have questions about this presentation, and we don’t have time to talk here, find me later! Mark Holmquist Getting started with MediaWiki hacking
About MediaWiki MediaWiki is the wiki software that is used for Wikipedia and other Wikimedia sites. The software is sometimes referred to as a CMS, but realistically it’s a collaborative platform for authouring and displaying documents. The Wikimedia Foundation and many volunteers help maintain the large codebase of MediaWiki and its many extensions. And of course, like most free software projects, we can always use help. Mark Holmquist Getting started with MediaWiki hacking
About MediaWiki MediaWiki is written primarily in PHP, HTML, and JavaScript. We also use SQL (of MySQL, MariaDB, sqlite, and PostgreSQL varieties), though abstracted, to store and query our data. For the most part, the really complicated things like the parser and the login system are handled in PHP, with some JS augmenting parts of it. But then again, lots of complicated features like UploadWizard, VisualEditor, and Flow use really high amounts of JavaScript. So there’s something for everyone. Mark Holmquist Getting started with MediaWiki hacking
Setting up MediaWiki You’ll need the following: ◮ A web server - apache2 is good, but in theory nginx will work fine, and lighttpd is supported. ◮ A database library and backend - we use MariaDB in production, but lots of people use MySQL or sqlite for development. ◮ PHP, and support for your chosen database in it. hhvm will work in theory, but don’t count on it... ◮ The MediaWiki source code - see https://mediawiki.org/wiki/Download. ◮ (optional) Git - we use it for development, but if you’re not interested in submitting patches you don’t need it. Mark Holmquist Getting started with MediaWiki hacking
Setting up MediaWiki Once you have the MediaWiki source code in a publicly accessible directory on your webserver, the setup is pretty straightforward. Go to the MediaWiki source code base directory, and set up your language preferences. Enter an administrator credential set, set up your database, and choose a few simple configuration options. When everything is configured, you should be able to download a LocalSettings.php file for your wiki. Place this in the base directory with the rest of the source code. Mark Holmquist Getting started with MediaWiki hacking
Grand Overview Now, let’s talk about code. MediaWiki has knowledge of a few basic things: 1. Pages (or articles) that have content and revision histories 2. Namespaces that contain articles and may have configuration or styling that applies to each one 3. Users, who may be anonymous or registered, and are allowed to have watchlists that notify them of changes 4. Files, which are represented by pseudo-articles called ”description pages” 5. Special pages, which are programmatic constructs that add interesting features to the site 6. Extensions, which modify the site’s behaviour. Mark Holmquist Getting started with MediaWiki hacking
Extensions Extensions are the primary method of changing how MediaWiki behaves. Getting code into MediaWiki itself, it turns out, is really difficult, especially if your feature isn’t universally liked. Instead, we leave the core engine mostly untouched and add things through extensions, adding support in core when needed. Mark Holmquist Getting started with MediaWiki hacking
Extensions - Getting started Starting development of an extension is relatively simple - all you need is a directory and a PHP file. The directory should have the PHP file in it, and should register hooks, special pages, modules, and any meta-information about the extension. Any other files can be easily included in that file - in fact, MediaWiki has a capable autoloader that you can use to register PHP classes. Mark Holmquist Getting started with MediaWiki hacking
Extensions - Testing Testing your extensions in development is also very simple. Put your extension directory into the mediawiki/extensions/ directory. Once it’s there, require once your main PHP file from your LocalSettings.php file in the root of your MediaWiki source code. Then, navigate to the wiki, find where you put the new functionality, and ensure it works as expected. Mark Holmquist Getting started with MediaWiki hacking
Special Pages Special pages are used to provide interesting tools to users. We have diverse special pages like: 1. Special:Log, which shows events on the site 2. Special:Upload, which gives the user an upload form 3. Special:Preferences, a place to set per-user options 4. Special:Version, information about the software 5. Special:SpecialPages, a list of all special pages You can find all of these on any MediaWiki instance - even Wikia or Wikipedia. Seriously, try it out! Mark Holmquist Getting started with MediaWiki hacking
Special Pages We also have lots of extensions that use special pages to add new features. 1. Uploadwizard, a much nicer upload interface 2. Notifications, prettier notifications for users, on mentions or whatever 3. TemplateSandbox, a place to experiment with templates Mark Holmquist Getting started with MediaWiki hacking
Hooks We use hooks to give extension developers the power to change the site’s behaviour at almost any point they need to. These hooks can come from just about anywhere. 1. Parser hooks, which change the output of the wikitext parser 2. Page load hooks, which fire on different page loads at different stages and can be used to add or modify content 3. Hooks that fire when actions are taken, like articles being saved or deleted, or files getting uploaded 4. API hooks that fire when someone accesses the API Mark Holmquist Getting started with MediaWiki hacking
API Of course MediaWiki has an HTTP API. It’s a bit of a beast to handle, though, so let’s go through how to find documentation: Go to https://en.wikipedia.org/w/api.php (for example) and read the documentation there. It’s massive, so use Ctrl-F to find what you’re looking for. Mark Holmquist Getting started with MediaWiki hacking
API - Development If you want to add a module to the API, it’s actually relatively simple. Just define a class that defines your module, autoload it and register it, and it should Just Work. Getting an API module into MediaWiki core may be a lot of work, but getting it deployed on Wikimedia’s wikis may be what you need to get your bot working properly. See https://mediawiki.org/wiki/API:Extensions. Mark Holmquist Getting started with MediaWiki hacking
Tools MediaWiki developers have a few common tools between them. Most of these are web tools used to coordinate and drive development. Mark Holmquist Getting started with MediaWiki hacking
Tools - Gerrit Gerrit is a code review system we use to host and review code. Sign up and browse code reviews at https://gerrit.wikimedia.org. You’ll need git-review (in the python-pip repository) to push patches to Gerrit. See https://mediawiki.org/wiki/Gerrit. All WMF engineers have +2 on extensions and MediaWiki core, and a few volunteers can also help merge your patches. Mark Holmquist Getting started with MediaWiki hacking
Tools - Bugzilla Bugzilla is how we, like many other projects, track our issues and feature requests. Sign up and start helping at https://bugzilla.wikimedia.org. We could always use help triaging and prodding bug reports. Lots of them get stuck in the pipeline. Mark Holmquist Getting started with MediaWiki hacking
Tools - Mailing lists The developer and movement mailing lists are our primary mechanism for bikeshedding and flamewars. I wish I were kidding... Still, sign up for wikitech-l and browse the other more specialized lists. https://lists.wikimedia.org Mark Holmquist Getting started with MediaWiki hacking
Hack! OK, the remainder of this session is intended to be a hackathon of sorts. If you have questions about setting up a developer environment or how to work out a particular problem, I’ve brought a few lovely assistants who are able to help out. Also, we’ll be around the entire conference if you need any further assistance. Come to the Wikimedia booth in the exhibitor hall and we’ll help you with development or editing concerns. Mark Holmquist Getting started with MediaWiki hacking
Recommend
More recommend