Page MenuHomePhabricator

Deprecate public access to properties in Title
Closed, ResolvedPublic

Description

Curiously, I couldn't find a task for this. The Title class declares several public properties, e.g.

/** @var string Text form (spaces not underscores) of the main part */
public $mTextform = '';
/** @var string URL-encoded form of the main part */
public $mUrlform = '';
/** @var string Main part with underscores */
public $mDbkeyform = '';
/** @var int Namespace index, i.e. one of the NS_xxxx constants */
public $mNamespace = NS_MAIN;
/** @var string Interwiki prefix */
public $mInterwiki = '';
/** @var string Title fragment (i.e. the bit after the #) */
public $mFragment = '';

These are documented as private/internal:

/** @name   Private member variables
 * Please use the accessor functions instead.
 * @internal
 * @{
 */

but this is not enforced by the interpreter. In fact, usages of these properties exist in the wild, according to codesearch. Also, IDEs (PHPStorm at least) are not correctly parsing the group annotation, and do not highlight these properties as internal.

Although the Title class is eventually going to be replaced by narrow interfaces like PageIdentity and LinkTarget, it should be possible to complete this deprecation at a relatively low cost, since I think it would fall under the Stable Interface Policy.

Having these properties private would likely ease the transition to the new interfaces, and could also help with keeping the Title class backwards-compatible and performant (for instance, it's not possible to cache the result of prefix() because there's no guarantee of immutability).

Event Timeline

Change 703765 had a related patch set uploaded (by D3r1ck01; author: Derick A):

[mediawiki/core@master] Title: Avoid accessing class members directly & use accessor methods

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

@Daimona, I've proposed a patch to first of all deprecate the public members and also updated some extensions that use these members - I've tagged you on the patches for review.

The next step will be to make these members private and also post-replace (if forgotten) usage with the corresponding accessor methods. Let me know if there is something I'm missing here, thanks!

Change 703765 merged by jenkins-bot:

[mediawiki/core@master] Title: Avoid accessing class members directly & use accessor methods

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

Change 704971 had a related patch set uploaded (by D3r1ck01; author: Derick A):

[mediawiki/core@master] EditPage: Avoid direct access of mTitle and mArticle, use accessors

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

Change 704974 had a related patch set uploaded (by D3r1ck01; author: Derick A):

[mediawiki/core@master] Title: Make members private after removing all direct member access

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

Change 704971 abandoned by D3r1ck01:

[mediawiki/core@master] EditPage: Avoid direct access of mTitle and mArticle, use accessors

Reason:

Thank you DannyS712. I'll go ahead and drop this then.

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

Change 704974 abandoned by D3r1ck01:

[mediawiki/core@master] Title: Make members private after removing all direct member access

Reason:

will revisit

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

Change 739549 had a related patch set uploaded (by D3r1ck01; author: Derick Alangi):

[mediawiki/core@master] WIP: Stop accessing members of the Title class publicly

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

Change 739549 merged by jenkins-bot:

[mediawiki/core@master] Stop accessing members of the Title class publicly

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

@Daimona, can this be resolved or is something still left to be done? The members you mentioned in the description now are private :)

xSavitar claimed this task.