Constructor
new mw.Title(title, namespaceopt)
#
Parse titles into an object structure. Note that when using the constructor
directly, passing invalid titles will result in an exception.
Use newFromText
to use the
logic directly and get null for invalid titles which is easier to work with.
Note that in the constructor and newFromText
method,
namespace
is the default namespace only, and can be overridden by a namespace
prefix in title
. If you do not want this behavior,
use makeTitle
.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
title |
string | Title of the page. If no second argument given, this will be searched for a namespace |
||
namespace |
number |
<optional> |
NS_MAIN | If given, will used as default namespace for the given title |
- Source:
Throws:
-
When the title is invalid
- Type
- Error
Properties
exist :mw.Title~TitleExistenceStorestatic
#
Methods
canHaveTalkPage() → {boolean}
#
Check the title can have an associated talk page.
- Source:
Returns:
The title can have an associated talk page
- Type
- boolean
exists() → {boolean|null
}
#
null
}
#
Whether this title exists on the wiki.
- Source:
- See:
Returns:
Boolean if the information is available, otherwise null
- Type
-
boolean
|
null
getExtension() → {string|null
}
#
null
}
#
Get the extension of the page name (if any).
- Source:
Returns:
Name extension or null if there is none
- Type
-
string
|
null
getFileNameTextWithoutExtension() → {string}
#
Get the page name as if it is a file name, without extension or namespace prefix,
in the human-readable form with spaces instead of underscores. For example, the title
File:Example_image.svg
will be returned as "Example image".
Note that this method will work for non-file titles but probably give nonsensical results.
A title like User:Dr._J._Fail
will be returned as Dr. J
! Use getMainText
instead.
- Source:
Returns:
- Type
- string
Get the page name as if it is a file name, without extension or namespace prefix, in the human-readable form with spaces instead of underscores.
getFileNameWithoutExtension() → {string}
#
Get the page name as if it is a file name, without extension or namespace prefix,
in the canonical form with underscores instead of spaces. For example, the title
File:Example_image.svg
will be returned as Example_image
.
Note that this method will work for non-file titles but probably give nonsensical results.
A title like User:Dr._J._Fail
will be returned as Dr._J
! Use getMain
instead.
- Source:
Returns:
- Type
- string
Get the page name as if it is a file name, without extension or namespace prefix, in the canonical form with underscores instead of spaces.
getFragment() → {string|null
}
#
null
}
#
Get the fragment (if any).
Note that this method (by design) does not include the hash character and the value is not url encoded.
- Source:
Returns:
- Type
-
string
|
null
getMain() → {string}
#
Get the main page name.
Example: Example_image.svg
for File:Example_image.svg
.
- Source:
Returns:
- Type
- string
getMainText() → {string}
#
Get the main page name (transformed by text()).
Example: Example image.svg
for File:Example_image.svg
.
- Source:
Returns:
- Type
- string
getName() → {string}
#
Get the page name as if it is a file name, without extension or namespace prefix. Warning,
this is usually not what you want! A title like User:Dr._J._Fail
will be returned as
Dr. J
! Use getMain
or getMainText
for the actual page name.
- Deprecated:
- since 1.40, use
getFileNameWithoutExtension
instead
- since 1.40, use
- Source:
Returns:
File name without file extension, in the canonical form with underscores
instead of spaces. For example, the title File:Example_image.svg
will be returned as
Example_image
.
- Type
- string
getNameText() → {string}
#
Get the page name as if it is a file name, without extension or namespace prefix. Warning,
this is usually not what you want! A title like User:Dr._J._Fail
will be returned as
Dr. J
! Use getMainText
for the actual page name.
- Deprecated:
- since 1.40, use
getFileNameTextWithoutExtension
instead
- since 1.40, use
- Source:
Returns:
File name without file extension, formatted with spaces instead of
underscores. For example, the title File:Example_image.svg
will be returned as
Example image
.
- Type
- string
getNamespaceId() → {number}
#
Get the namespace number.
Example: 6 for "File:Example_image.svg".
- Source:
Returns:
- Type
- number
getNamespacePrefix() → {string}
#
Get the namespace prefix (in the content language).
Example: "File:" for "File:Example_image.svg". In #NS_MAIN this is '', otherwise namespace name plus ':'
- Source:
Returns:
- Type
- string
getPrefixedDb() → {string}
#
Get the full page name.
Example: File:Example_image.svg
.
Most useful for API calls, anything that must identify the "title".
- Source:
Returns:
- Type
- string
getPrefixedText() → {string}
#
Get the full page name (transformed by text
).
Example: File:Example image.svg
for File:Example_image.svg
.
- Source:
Returns:
- Type
- string
text
).
getRelativeText(namespace) → {string}
#
Get the page name relative to a namespace.
Example:
- "Foo:Bar" relative to the Foo namespace becomes "Bar".
- "Bar" relative to any non-main namespace becomes ":Bar".
- "Foo:Bar" relative to any namespace other than Foo stays "Foo:Bar".
Parameters:
Name | Type | Description |
---|---|---|
namespace |
number | The namespace to be relative to |
- Source:
Returns:
- Type
- string
getSubjectPage() → {mw.Title|null
}
#
null
}
#
Get the title for the subject page of a talk page.
- Source:
Returns:
The title for the subject page of a talk page, null if not available
- Type
-
mw.Title
|
null
getTalkPage() → {mw.Title|null
}
#
null
}
#
Get the title for the associated talk page.
- Source:
Returns:
The title for the associated talk page, null if not available
- Type
-
mw.Title
|
null
getUrl(paramsopt) → {string}
#
Get the URL to this title.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
params |
Object |
<optional> |
A mapping of query parameter names to values,
e.g. |
- Source:
- See:
Returns:
- Type
- string
isTalkPage() → {boolean}
#
Check if the title is in a talk namespace.
- Source:
Returns:
The title is in a talk namespace
- Type
- boolean
toString()
#
Alias of getPrefixedDb
.
- Source:
getPrefixedDb
.
toText()
#
Alias of getPrefixedText
.
- Source:
getPrefixedText
.
exists(title) → {boolean|null
}static
#
null
}static
#
Whether this title exists on the wiki.
Parameters:
Name | Type | Description |
---|---|---|
title |
string | mw.Title | prefixed db-key name (string) or instance of Title |
- Source:
Throws:
-
If title is not a string or mw.Title
- Type
- Error
Returns:
Boolean if the information is available, otherwise null
- Type
-
boolean
|
null
isTalkNamespace(namespaceId) → {boolean}static
#
Check if a given namespace is a talk namespace.
See NamespaceInfo::isTalk in PHP
Parameters:
Name | Type | Description |
---|---|---|
namespaceId |
number | Namespace ID |
- Source:
Returns:
Namespace is a talk namespace
- Type
- boolean
makeTitle(namespace, title) → {mw.Title|null
}static
#
null
}static
#
Constructor for Title objects with predefined namespace.
Unlike newFromText
or the constructor, this function doesn't allow the given namespace
to be
overridden by a namespace prefix in title
. See the constructor documentation for details about this behavior.
The single exception to this is when namespace
is 0, indicating the main namespace. The
function behaves like newFromText
in that case.
Parameters:
Name | Type | Description |
---|---|---|
namespace |
number | Namespace to use for the title |
title |
string |
- Source:
Returns:
A valid Title object or null if the title is invalid
- Type
-
mw.Title
|
null
newFromFileName(uncleanName) → {mw.Title|null
}static
#
null
}static
#
Sanitizes a file name as supplied by the user, originating in the user's file system so it is most likely a valid MediaWiki title and file name after processing. Returns null on fatal errors.
Parameters:
Name | Type | Description |
---|---|---|
uncleanName |
string | The unclean file name including file extension but without namespace |
- Source:
Returns:
A valid Title object or null if the title is invalid
- Type
-
mw.Title
|
null
Sanitizes a file name as supplied by the user, originating in the user's file system so it is most likely a valid MediaWiki title and file name after processing.
newFromImg(img) → {mw.Title|null
}static
#
null
}static
#
Get the file title from an image element.
Example
var title = mw.Title.newFromImg( imageNode );
Parameters:
Name | Type | Description |
---|---|---|
img |
HTMLElement | jQuery | The image to use as a base |
- Source:
Returns:
The file title or null if unsuccessful
- Type
-
mw.Title
|
null
newFromText(title, namespaceopt) → {mw.Title|null
}static
#
null
}static
#
Constructor for Title objects with a null return instead of an exception for invalid titles.
Note that namespace
is the default namespace only, and can be overridden by a namespace
prefix in title
. If you do not want this behavior, use #makeTitle. See #constructor for
details.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
title |
string | |||
namespace |
number |
<optional> |
NS_MAIN | Default namespace |
- Source:
Returns:
A valid Title object or null if the title is invalid
- Type
-
mw.Title
|
null
newFromUserInput(title, defaultNamespaceopt, optionsopt) → {mw.Title|null
}static
#
null
}static
#
Constructor for Title objects from user input altering that input to produce a title that MediaWiki will accept as legal.
Parameters:
Name | Type | Attributes | Default | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
title |
string | |||||||||||||
defaultNamespace |
number |
<optional> |
NS_MAIN | If given, will used as default namespace for the given title. |
||||||||||
options |
Object |
<optional> |
additional options Properties
|
- Source:
Returns:
A valid Title object or null if the input cannot be turned into a valid title
- Type
-
mw.Title
|
null
Constructor for Title objects from user input altering that input to produce a title that MediaWiki will accept as legal.
normalizeExtension(extension) → {string}static
#
Normalize a file extension to the common form, making it lowercase and checking some synonyms, and ensure it's clean. Extensions with non-alphanumeric characters will be discarded. Keep in sync with File::normalizeExtension() in PHP.
Parameters:
Name | Type | Description |
---|---|---|
extension |
string | File extension (without the leading dot) |
- Source:
Returns:
File extension in canonical form
- Type
- string
Normalize a file extension to the common form, making it lowercase and checking some synonyms, and ensure it's clean.
phpCharToUpper(chr) → {string}static
#
PHP's strtoupper differs from String.toUpperCase in a number of cases (T147646).
Parameters:
Name | Type | Description |
---|---|---|
chr |
string | Unicode character |
- Source:
Returns:
Unicode character, in upper case, according to the same rules as in PHP
- Type
- string
wantSignaturesNamespace(namespaceId) → {boolean}static
#
Check if signature buttons should be shown in a given namespace.
See NamespaceInfo::wantSignatures in PHP
Parameters:
Name | Type | Description |
---|---|---|
namespaceId |
number | Namespace ID |
- Source:
Returns:
Namespace is a signature namespace
- Type
- boolean
Type Definitions
TitleExistenceStore
#
Type:
- Object
Properties:
Name | Type | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
pages |
Object | Keyed by title. Boolean true value indicates page does exist. |
|||||||||||||||
set |
function | The setter function. Returns a boolean. Example to declare existing titles:
Example to declare titles nonexistent:
Properties
|
- Source: