X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=resources%2Fsrc%2Fmediawiki.Title%2FTitle.js;h=0bcb2b654fb21118220f3fc7d90d6d22d2b99857;hp=33e5fbf93ca22e6c7fef0ac63e7b6d9e0f23b7ba;hb=8fb14da2d28a2b39197c83db8c66daad0e397298;hpb=9aa6ed11908a818833b274bd4c7e239be3e6ea54 diff --git a/resources/src/mediawiki.Title/Title.js b/resources/src/mediawiki.Title/Title.js index 33e5fbf93c..0bcb2b654f 100644 --- a/resources/src/mediawiki.Title/Title.js +++ b/resources/src/mediawiki.Title/Title.js @@ -662,12 +662,22 @@ return null; }; + /** + * Check if a given namespace is a talk namespace + * @param {number} namespaceId Namespace ID + * @return {boolean} Namespace is a talk namespace + */ + Title.isTalkNamespace = function ( namespaceId ) { + return !!( namespaceId > NS_MAIN && namespaceId % 2 ); + }; + /** * Whether this title exists on the wiki. * * @static * @param {string|mw.Title} title prefixed db-key name (string) or instance of Title * @return {boolean|null} Boolean if the information is available, otherwise null + * @throws {Error} If title is not a string or mw.Title */ Title.exists = function ( title ) { var match, @@ -931,6 +941,49 @@ } }, + /** + * Check if the title is in a talk namespace + * + * @return {boolean} The title is in a talk namespace + */ + isTalkPage: function () { + return Title.isTalkNamespace( this.getNamespaceId() ); + }, + + /** + * Get the title for the associated talk page + * + * @return {mw.Title|null} The title for the associated talk page, null if not available + */ + getTalkPage: function () { + if ( !this.canHaveTalkPage() ) { + return null; + } + return this.isTalkPage() ? + this : + Title.makeTitle( this.getNamespaceId() + 1, this.getMainText() ); + }, + + /** + * Get the title for the subject page of a talk page + * + * @return {mw.Title|null} The title for the subject page of a talk page, null if not available + */ + getSubjectPage: function () { + return this.isTalkPage() ? + Title.makeTitle( this.getNamespaceId() - 1, this.getMainText() ) : + this; + }, + + /** + * Check the the title can have an associated talk page + * + * @return {boolean} The title can have an associated talk page + */ + canHaveTalkPage: function () { + return this.getNamespaceId() >= NS_MAIN; + }, + /** * Whether this title exists on the wiki. *