Page MenuHomePhabricator

Feature request: Turn /includes/media in to a PSR-4 composer package
Open, Needs TriagePublic

Description

This folder is full of code that the global open source PHP community could benefit from. Especially the WebP component since PHP does not fully support WebP yet (see https://bugs.php.net/bug.php?id=65038).

If there are no plans for it I'm asking permission (I know the license allows this technically speaking, but I thought it would be polite to at least ask) to create it myself.
The source code would be largely the same, although would be converted to PSR-4

Event Timeline

Legoktm subscribed.

Yes, please, we'd love to make our code more reusable by other PHP projects! Currently I'm working on extracting our XMP parsing code (T100922: Create separate XMP parsing library).

The typical process is to slowly remove dependencies upon MediaWiki code by using dependency injection, or replacing things like wfDebug calls with a PSR-3 logger, which a separate library could use. I'm not very familiar with the WebP code, but you could give it a shot :) See also https://www.mediawiki.org/wiki/Manual:Developing_libraries#Tips_for_extracting_a_library.

Ok so if I understand correctly, that code should first be moved to includes/lib (while removing the MediaWiki dependencies) and after that is done extract it as a composer package?

Most of the media handlers are glue code converting generic interfaces to mediawiki specific abstractions. There is certainly non-media handler code in /media that might be useful, but im really unsure how useful the actual media handlers would be.

@Bawolff: Yeah I just noticed. I saw the code in WebP and thought all classes in that folder were to read metadata from image files.

So I guess this has turned in to just me asking if I can reuse parts of the code in WebP?

Ok so if I understand correctly, that code should first be moved to includes/lib (while removing the MediaWiki dependencies) and after that is done extract it as a composer package?

Yes, this is the basic approach for creating a reusable component from MediaWiki's core. Fully doing this would look something like:

  1. One or more Gerrit patches that move the classes into includes/lib and replace direct dependencies on other MediaWiki core classes and functions with more generic equivalents.
  2. Create a new Gerrit project to host the library
  3. Populate the new Gerrit project with code taken from includes/lib and associated tests
  4. Publish the new library on Packagist
  5. A wiki page on mediawiki.org describing the library
  6. A Gerrit patch to add the new library to our composer/vendor.git repo
  7. A gerrit patch to remove the includes/lib files and add the new library as a dependency in MediaWiki's core composer.json

It sounds like a lot of stuff to do, but in practice it can be accomplished pretty quickly at least once the move to includes/lib has been merged.

I'd be glad to help with code review and other logistics for doing this for just about any code in MediaWiki.

I think its totally reasonable to split the generic parts out.

I think the metadata extraction code would be a great candidate for a library. It performs generic functionality, and most of it is in self-contained separate classes (*MetadataExtractor and IPTC) which do not rely on other MediaWiki classes at all. A few pieces are in MediaHandler subclasses and those would have to be moved.

MediaHandler and MediaTransformOutput should be left where they are, IMO; they are mostly just adapters between MediaWiki and PHP interfaces, as Bawolff said. Maybe something that generates imagemagick etc. shell command arguments could also be extracted from them, but that seems more complex.