Page MenuHomePhabricator

Introduce ContentHandlerFactory
Closed, ResolvedPublic

Description

NOTE: THis task was updated 2020-01-20 to remove the "registry" aspect, and focus on the "factory" aspect.

ContentHandler instances are currently instantiated by the static method ContentHandler::getForModelID(). Instead, ContentHandlerFactory should be introduced as a service object, to act as a factory for ContentHandler instances.

Rationale:

  • avoiding reliance on global state as a matter of general best practice
  • avoiding reliance on global state to improve testability of code that needs to look up ContentHandler instances

Acceptance criteria:

  • ContentHandlerFactory shall be managed by MediaWikiServices
  • ContentHandlerFactory shall not access global variables, all necessary information shall be injected.
  • ContentHandlerFactory shall have an ObjectFactory, and use it to create ContentHandler instances from "specs" that come from the ContentHandler array.
  • ContentHandlerFactory shall expose the functionality of ContentHandler::getForModelId as getContentHandler( $modelName ).
  • ContentHandler::getForModelID() shall be deprecated in favor of ContentHandlerFactory::getContentHandler
  • ContentHandler::getForTitle() shall be deprecated without replacement
  • ContentHandler::cleanupHandlersCache() shall be deprecated and converted into a noop. The single usage of this method will be made redundant, because services get reset automatically between test runs.
  • The following static methods in ContentHandler shall be ported to ContentHandlerFactory and deprecated in ContentHandler:
    • getContentModels()
    • getAllContentFormats()

Caveat:
Copying $wgContentHandlers into a member variable in ContentHandlerFactory means that extensions that add handlers to $wgContentHandlers later on have no effect. This issue is mitigated by the fact that the global ServiceContainer is reset after initial setup is complete. This in turn may mean that handlers registered by calling the new defineContentHandler() method may be lost; to avoid this, ContentHandlerFactory may need to implement SalvageableService logic. In any case, code that manipulates $wgContentHandlers needs to be surveyed to avoid problems with the order of initialization. In particular, it may be necessary to introduce special handling into ExtensionProcessor.

Outlook:
Survey the remaining static methods in ContentHandler, and decide on a suitable replacement.

Event Timeline

@Art-Baltai: Welcome to Phabricator and Wikimedia. Do you plan to work on fixing this task, as you assigned this to yourself?

Edit: Sorry, was told by Daniel that this is intentional. Please ignore!

On the subject of using php interfaces, as briefly discussed on slack: I'm not opposed to introducing IContentHandler, but I don't see much value in it. I do see the value in having a narrow IContentHandlerFactory interface that is implemented by ContentHandlerRegistry.

Change 565559 had a related patch set uploaded (by Art-Baltai; owner: Art-Baltai):
[mediawiki/core@master] component: Introduce ContentHandlerRegistry

https://gerrit.wikimedia.org/r/565559

Change 565722 had a related patch set uploaded (by Art-Baltai; owner: Art-Baltai):
[mediawiki/core@master] component: Introduce ContentHandlerRegistry Not ready yet

https://gerrit.wikimedia.org/r/565722

Change 565739 had a related patch set uploaded (by Art-Baltai; owner: Art-Baltai):
[mediawiki/core@master] component: Introduce ContentHandlerRegistry Not ready yet

https://gerrit.wikimedia.org/r/565739

Change 565746 had a related patch set uploaded (by Art-Baltai; owner: Art-Baltai):
[mediawiki/core@master] component: Introduce ContentHandlerRegistry Not ready yet

https://gerrit.wikimedia.org/r/565746

daniel renamed this task from Introduce ContentHandlerRegistry to Introduce ContentHandlerFactory.Jan 21 2020, 11:32 AM

Change 566276 had a related patch set uploaded (by Art-Baltai; owner: Art-Baltai):
[mediawiki/core@master] component: Introduce ContentHandlerRegistry Not ready yet

https://gerrit.wikimedia.org/r/566276

Change 565746 abandoned by Art-Baltai:
component: Introduce ContentHandlerRegistry Not ready yet

Reason:
https://gerrit.wikimedia.org/r/c/mediawiki/core/ /566276

https://gerrit.wikimedia.org/r/565746

Change 565722 abandoned by Art-Baltai:
component: Introduce ContentHandlerRegistry Not ready yet

Reason:
https://gerrit.wikimedia.org/r/c/mediawiki/core/ /566276

https://gerrit.wikimedia.org/r/565722

Change 565739 abandoned by Art-Baltai:
component: Introduce ContentHandlerRegistry Not ready yet

Reason:
https://gerrit.wikimedia.org/r/c/mediawiki/core/ /566276

https://gerrit.wikimedia.org/r/565739

Change 565559 abandoned by Art-Baltai:
component: Introduce ContentHandlerRegistry

Reason:
https://gerrit.wikimedia.org/r/c/mediawiki/core/ /566276

https://gerrit.wikimedia.org/r/565559

Change 568508 had a related patch set uploaded (by Art-Baltai; owner: Art-Baltai):
[mediawiki/extensions/TwoColConflict@master] omponent: Introduce ContentHandlerFactory

https://gerrit.wikimedia.org/r/568508

Change 568508 abandoned by Art-Baltai:
omponent: Introduce ContentHandlerFactory

Reason:
test

https://gerrit.wikimedia.org/r/568508

Change 568508 restored by Art-Baltai:
omponent: Introduce ContentHandlerFactory

https://gerrit.wikimedia.org/r/568508

Change 570322 had a related patch set uploaded (by Daniel Kinzler; owner: Art-Baltai):
[mediawiki/core@master] TextConflictHelper: deprecate old constructor signature

https://gerrit.wikimedia.org/r/570322

Change 566276 merged by jenkins-bot:
[mediawiki/core@master] Introduce ContentHandlerFactory

https://gerrit.wikimedia.org/r/566276

Change 570322 had a related patch set uploaded (by Art-Baltai; owner: Art-Baltai):
[mediawiki/core@master] TextConflictHelper: deprecate old constructor signature

https://gerrit.wikimedia.org/r/570322

Change 568508 merged by jenkins-bot:
[mediawiki/extensions/TwoColConflict@master] SplitTwoColConflictHelper: pass in ContentHandlerFactory

https://gerrit.wikimedia.org/r/568508

Change 570322 merged by jenkins-bot:
[mediawiki/core@master] TextConflictHelper: deprecate old constructor signature

https://gerrit.wikimedia.org/r/570322

@Art-Baltai since the patch to actually introduce the factory was merged and is live, can this be resolved?