User:Novem Linguae/Essays/MediaWiki extension cleanup checklist

From Wikipedia, the free encyclopedia

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 and use statements, including in other repos
    • 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 with MediaWikiServices::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 and DESC. These can usually be replaced with SelectQueryBuilder::SORT_ASC and SelectQueryBuilder::SORT_DESC.
      • Replace old style SQL queries with newXQueryBuilder
    • 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?