Topic on Talk:Best practices for extensions

Jump to navigation Jump to search

Namespacing extensions

6
Summary by Legoktm

Clarified acceptable namespaces in the document.

SamanthaNguyen (talkcontribs)

I see that the best practice for namespacing extensions would be MediaWiki\Extensions\ExtensionName, but I'm aware that there's also extensions that follow this pattern: MediaWiki\ExtensionName (skips the Extensions namespace prefix).

Examples include Linter (MediaWiki\Linter) and GlobalUserPage (MediaWiki\GlobalUserPage).

Which convention out of the two should people follow (or is it simply a recommendation/suggestion?)

Samwilson (talkcontribs)

I thought the convention was MediaWiki\Extension\ExtensionName (i.e. singular), and that's what I've been following (it seems least likely to result in collisions or confusion). There's some discussion in phab:T166010 of the options.

SamanthaNguyen (talkcontribs)

Can’t believe I’ve actually been misreading it this whole time, so thanks. :P Thanks for the link too, that seems to clear it up a bit for me :) I’ll go with MediaWiki\Extension\ExtensionName too.

Legoktm (talkcontribs)

The current consensus is that if the extension name is something unique and unlikely to be ever used in core (e.g. GlobalUserPage), then it's ok to be directly under MediaWiki. But if it's a generic-ish word like "Translate" then it should be disambiguated with MediaWiki\Extension\Translate.

Nikerabbit (talkcontribs)

Hint taken :) Apropos, hopefully not too much off-topic, are there any recommendations for how to preserve some backwards compatibility (or not) when moving classes inside a namespace? I know that at least TranslateSVG and CentralNotice use some Translate classes.

Legoktm (talkcontribs)

For the record, I was just quoting Tim about "Translate" :)

I'm not sure if we've documented this anywhere, but you should add a class_alias to the bottom of the file containing the new class (e.g. https://phabricator.wikimedia.org/source/mediawiki/browse/master/includes/libs/rdbms/database/Database.php;e1aabf2f24aef20adc72db8a750704cbb33236c6$3786) and then make sure the autoloader mapping still has the old class name pointing to the new file location.

Also, Tim is currently working on a tool to automatically namespaceize core that should also be useable for extensions, so it might make sense to wait for that instead of doing it manually.