0.7.5 • Published 3 years ago

mediawiki-title v0.7.5

Weekly downloads
424
License
Apache-2.0
Repository
github
Last release
3 years ago

mediawiki-title npm version Build Status Coverage Status Dependencies

Mediawiki title normalization, that conforms to the normalization rules used in MediaWiki Core. In general, the page title is converted to the mediawiki DB key format by trimming spaces, replacing whitespace symbols to underscores and applying wiki-specific capitalization rules. The namespace name is converted to a localized canonical name.

Classes

Typedefs

Namespace

Kind: global class

new Namespace(id, siteInfo)

Represents a wiki namespace

ParamTypeDescription
idnumberThe namespace identifier
siteInfoSiteInfoThe site metadata information.

namespace.getId() ⇒ number

Returns the numeric namespace identifier

Kind: instance method of Namespace

namespace.isMedia() ⇒ boolean

Checks whether namespace is Media

Kind: instance method of Namespace

namespace.isSpecial() ⇒ boolean

Checks whether namespace is Special

Kind: instance method of Namespace

namespace.isMain() ⇒ boolean

Checks whether namespace is Main

Kind: instance method of Namespace

namespace.isTalk() ⇒ boolean

Checks whether namespace is Talk

Kind: instance method of Namespace

namespace.isUserTalk() ⇒ boolean

Checks whether namespace is UserTalk

Kind: instance method of Namespace

namespace.getNormalizedText() ⇒ string

Get the canonical name string for this namespace.

Kind: instance method of Namespace

namespace.equals(ns) ⇒ boolean

Determines whether this namespace is equal to the given ns, based on the numeric namespace identifier.

Kind: instance method of Namespace

Namespace.fromText(text, siteInfo) ⇒ Namespace | undefined

Creates a namespace instance from namespace text or a namespace alias

Kind: static method of Namespace
Returns: Namespace | undefined - a namespace or undefined if it wasn't found.

ParamTypeDescription
textstringNamespace name text.
siteInfoSiteInfothe site information.

Namespace.main(siteInfo) ⇒ Namespace

Creates a namespace object for a Main namespace.

Kind: static method of Namespace

ParamTypeDescription
siteInfoSiteInfothe site information.

Title

Kind: global class

new Title(key, namespace, siteInfo, fragment)

Creates a new title object with article the dbKey and namespace

ParamTypeDescription
keystringThe article title in a form of the dbKey.
namespaceNamespace | numberThe article namespace.
siteInfoSiteInfoThe site metadata.
fragmentstringThe fragment of the title.

title.getPrefixedDBKey() ⇒ string

Returns the normalized article title and namespace.

Kind: instance method of Title

title.getFragment() ⇒ string | undefined

Returns the normalized fragment part of the original title

Kind: instance method of Title

title.getNamespace() ⇒ Namespace

Returns the namespace of an article.

Kind: instance method of Title

title.equals(title2) ⇒ boolean

Determines whether this title is equals to the given title2, based on comparing namespace and key.

Kind: instance method of Title

Title.newFromText(title, siteInfo, defaultNs) ⇒ Title

Normalize a title according to the rules of siteInfo

Kind: static method of Title
Returns: Title - The resulting title object.

ParamTypeDescription
titlestringThe page title to normalize.
siteInfoSiteInfoThe site information.

TitleError

Kind: global exception class

TitleError should be considered an opaque exception class, which is thrown by the various methods in this library. It is exported so that it can be identified if caught by the caller.

SiteInfo : Object

Information about a wikimedia site required to make correct normalization. This information matches the format used by the PHP API response, however not all of the fields are required for library operation.

The list of required properties is documented here, others can be removed.

Kind: global typedef
Properties

NameTypeDescription
generalObjectGeneral information about the site
general.langstringSite language code.
general.legaltitlecharsstringA perl-like regex for characters allowed in the page title.
general.casestringWhether to capitalize the first letter of the title. Could be obtained from the general section of the siteInfo php API response.
namespacesObjectSite namespaces info in the same format as returned by PHP api.
namespacealiasesObjectSite namespace aliases in the same format as returned by PHP api.
specialpagealiasesObjectSite special page aliases in the same format as returned by PHP api.

Usage

The library synchronously returns a normalized title. Wiki-specific rules should be fetched from the MediaWiki API, and cached outside of the library. The description of the required properties is available in the SiteInfo object docs.

var result = Title.newFromText('some_title', {
    		general: {
        	lang: 'en',
        	legaltitlechars: " %!\"$&'()*,\\-.\\/0-9:;=?@A-Z\\\\^_`a-z~\\x80-\\xFF+",
        	case: 'first-letter'
    	},
	namespaces: {
		"0": {
			id: 0,
			case: "first-letter",
			content: "",
			"*": ""
			},
		}
});
console.log(result.getPrefixedDBKey());

Bug reporting

For bug reporting please use Phabricator and mark the bugs with Services label or contact directly in IRC in the #wikimedia-services channel.

0.7.5

3 years ago

0.7.4

3 years ago

0.7.3

4 years ago

0.7.2

5 years ago

0.7.1

5 years ago

0.6.5

7 years ago

0.6.4

7 years ago

0.6.3

7 years ago

0.6.2

8 years ago

0.6.1

8 years ago

0.6.0

8 years ago

0.5.6

8 years ago

0.5.5

8 years ago

0.5.4

8 years ago

0.5.3

8 years ago

0.5.2

9 years ago

0.5.1

9 years ago

0.5.0

9 years ago

0.4.2

9 years ago

0.4.1

9 years ago

0.4.0

9 years ago

0.3.3

9 years ago

0.3.1

9 years ago

0.3.0

9 years ago

0.2.4

9 years ago

0.2.3

9 years ago

0.2.2

9 years ago

0.2.1

9 years ago

0.2.0

9 years ago

0.1.2

9 years ago

0.1.1

9 years ago

0.1.0

9 years ago