User:Novem Linguae/Essays/MediaWiki extension cleanup checklist
Appearance
Ideas for how to methodically upgrade an old MediaWiki extension to modern standards.
If you are new to MediaWiki, try writing tests! These are safe, easy to review, and MediaWiki provides lots of good seams so you usually don't have to do refactoring before writing said tests.
PHP
[edit]- Move any .php files not in the /includes/ or /maintenance/ folders into those folders (fixes code coverage report, is normal spot for these)
- Comment any maintenance files that are run by Puppet cron jobs, so that people are less likely to rename them and break the cron job. Use codesearch. Example.
- Move all phpunit tests into /unit/ and /integration/ folders, so that phpunit:unit and phpunit:integration work correctly
- Write tests for every .php file. Get code coverage to >70% for each file. Every method with logic should have at least one test.
- Once tests are in place, you can begin refactoring
- Add "use" statements, so that intellisense works correctly. May need to bump the version number of the extension.
- Add namespaces to every file (
namespace MediaWiki\Extension\FlaggedRevs;
)- And change corresponding
@covers
anduse
statements, including in other repos
- And change corresponding
- In extension.json, search for
Hooks::
. Convert to HookHandlers. Example. Video tutorial. - Fix all deprecations (once
use
statements are all in place, you can see these in VS Code by opening a file and looking in the "problems" pane) - Linter / phpcs: make sure MediaWiki ruleset is loaded, enable any disabled rules, and fix associated errors.
- Search for
global
, replace withMediaWikiServices::getInstance()->getMainConfig()->
or$this->getServiceContainer()->getMainConfig()->
- Search for
MediaWikiServices::getInstance(
, replace with injection or$this->getServiceContainer()
. Makes testing easier. Example. - Search for
list( $result ) = somethingThatReturnsAnArray()
, convert to[ $result ] = somethingThatReturnsAnArray();
- SQL
- Search for
->addQuotes(
,NULL
,AND
,OR
,'!='
,'>'
, and'<'
. These can usually be refactored to->expr(
- Search for
ASC
andDESC
. These can usually be replaced withSelectQueryBuilder::SORT_ASC
andSelectQueryBuilder::SORT_DESC
. - Replace old style SQL queries with
newXQueryBuilder
- Search for
- Split big classes
- Split big methods
- Switch to the Record/Lookup/Manager pattern
JavaScript
[edit]- Linter / eslint: make sure MediaWiki ruleset is loaded, enable any disabled rules, and fix associated errors.
- Migrate front ends from jquery.ui/mustache/ooui to vue/codex? Is vue/codex ready for mass deployment to non-SPA type pages?