Page MenuHomePhabricator

Create PageURLLookup service
Open, Needs TriagePublic

Description

The PageURLLookup service should provide a new home for the URL related methods in the Title class.

Rough interface draft:

class PageURLLookup {
    public function getPrefixedURL( $page );
    public function getFullURL( $page, $query = '', $query2 = false, $proto = PROTO_RELATIVE )( $page );
    public function getFullUrlForRedirect( $page, $query = '', $proto = PROTO_CURRENT );
    public function getLocalURL( $page, $query = '', $query2 = false );
    public function getLinkURL(  $page, $query = '', $query2 = false, $proto = false );
    public function getInternalURL(  $page, $query = '', $query2 = false );
    public function getCanonicalURL(  $page, $query = '', $query2 = false );
}

We can make $page be of type PageReference|LinkTarget for convenience.

Alternative Design
We can make a Linkable entity that has all the getter from Title. Title could even implement that interface. And we could have two new implementations, one wrapping a Pagereference, the other wrapping a LinkTarget.

We's then need a factory for such Linkable entities, though.

Event Timeline

I think that we need to return PSR-7 URIInterface.

Proposal:

/**
  * UriInterface with nice utility and MW-specific features. Not sure it's needed.
  */
class MWUriInterface extends UriInterface {
   
   public function __construct( UriInterface $uri );

   public function withQueryArray( array $query ): MWUriInterface;
   public function addQuery( string $additionalQuery ): MWUriInterface;
   public function addQueryArray( array $additionalQuery): MWUriInterface;
   // Override all mutator methods to return MWUriInterface
}

// Lazily parses the URI if any of the parts accessors are called.
class LazyUri implements UriInterface {
   public function __construct( string $uri )
   public function __toString() {
     return $this->uri;
  }
}

interface PageUriResolver {
    public function getAbsoluteURL( LinkTarget|PageReference $page ): MWUriInterface;
    public function getLocalURL( LinkTarget|PageReference $page): MWUriInterface;
    public function getInternalURL( LinkTarget|PageReference $page ): MWUriInterface;
    public function getCanonicalURL( LinkTarget|PageReference $page ): MWUriInterface;
}

Open questions:

  • Should we pass $query right away, or should we call URIInterface query manipulation methods on the result? I like the latter.
  • Same with fragment - some of the methods are only different in whether fragment is provided.
  • $proto - many alternatives. Can use UriInterface::withScheme to set the protocol, can pass the desired protocol in a constructor and make a factory. Need to assess the callers.

Change 700251 had a related patch set uploaded (by Daniel Kinzler; author: Daniel Kinzler):

[mediawiki/core@master] WIP: Introduce LinkUrlResolver

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

Change 715308 had a related patch set uploaded (by Daniel Kinzler; author: Daniel Kinzler):

[mediawiki/core@master] Introduce LinkUrlResolver

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

Change 700251 abandoned by Daniel Kinzler:

[mediawiki/core@master] WIP: Introduce LinkUrlResolver

Reason:

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

Change 731165 had a related patch set uploaded (by Daniel Kinzler; author: Daniel Kinzler):

[mediawiki/core@master] Add benchmark for Title URL mapping

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