-
Notifications
You must be signed in to change notification settings - Fork 2
Title (EN)
Table of Contents
The Title object is generated by the Parser.normalizeTitle method and represents the title of a page.
✅ Available in the Mini and Browser versions.
✅ Expand
type: boolean
Whether the title is valid according to the MediaWiki rules.
// valid
Parser.config = 'zhwiki';
assert(!Parser.normalizeTitle('<').valid);
assert(!Parser.normalizeTitle('#a').valid);
assert(Parser.normalizeTitle('mw:').valid);
✅ Expand
type: number
Namespace number.
// ns
var title = Parser.normalizeTitle('A', 10);
assert.equal(title, 'Template:A');
assert.strictEqual(title.ns, 10);
title.ns = 0;
assert.equal(title, 'A');
✅ Expand
type: string | undefined
URI fragment.
// fragment
var title = Parser.normalizeTitle('Wikitext');
assert.strictEqual(title.fragment, undefined);
title.fragment = 'Notes';
assert.equal(title, 'Wikitext#Notes');
Expand
type: string
Interwiki prefix of the title. Note that it does not contain :
and will be empty when using the default parsing configurations.
// interwiki
Parser.config = 'zhwiki';
var title = Parser.normalizeTitle('mw:Main Page');
assert.strictEqual(title.interwiki, 'mw');
title.interwiki = 'metawiki';
assert.equal(title, 'metawiki:Main_Page');
Expand
type: string
Title main part without namespace. Note that the first letter will be capitalized and underscores will be replaced with spaces.
// main
var title = Parser.normalizeTitle('template:birth_date');
assert.strictEqual(title.main, 'Birth date');
title.main = 'birth_month';
assert.strictEqual(title.main, 'Birth month');
Expand
type: string
Standard namespace prefix of the title, read-only.
// prefix
assert.strictEqual(Parser.normalizeTitle('Wikipedia:A').prefix, 'Project:');
Expand
type: string
Normalized title with namespace prefix, read-only. Note that the first letter will be capitalized and spaces will be replaced with underscores.
// title
assert.strictEqual(
Parser.normalizeTitle('template:birth date').title,
'Template:Birth_date',
);
Expand
version added: 1.1.0
type: string | undefined
Extension in lowercase.
// extension
var title = Parser.normalizeTitle('A.CSS');
assert.strictEqual(title.extension, 'css');
title.extension = 'js';
assert.equal(title, 'A.js');
Expand
Perform unidirectional conversion. This will modify the main
property.
// autoConvert
Parser.conversionTable.set('頁', '页');
var title = Parser.normalizeTitle('首頁');
assert.strictEqual(title.main, '首頁');
title.autoConvert();
assert.strictEqual(title.main, '首页');
Expand
version added: 1.1.0
Switch to the subject page.
// toSubjectPage
var title = Parser.normalizeTitle('file talk:a.jpg');
title.toSubjectPage();
assert.equal(title, 'File:A.jpg');
Expand
version added: 1.1.0
Switch to the talk page.
// toTalkPage
var title = Parser.normalizeTitle('file:a.jpg');
title.toTalkPage();
assert.equal(title, 'File_talk:A.jpg');
Expand
version added: 1.1.0
Whether it is a talk page.
// isTalkPage
var title = Parser.normalizeTitle('file talk:a.jpg');
assert(title.isTalkPage());
Expand
version added: 1.1.0
Switch to the base page.
// toBasePage
var title = Parser.normalizeTitle('A/AA/AAA');
title.toBasePage();
assert.equal(title, 'A/AA');
title.toBasePage();
assert.equal(title, 'A');
Expand
version added: 1.1.0
Switch to the root page.
// toRootPage
var title = Parser.normalizeTitle('A/AA/AAA');
title.toRootPage();
assert.equal(title, 'A');
对维基文本批量执行语法检查的命令行工具
用于维基文本的 ESLint 插件
A command-line tool that performs linting on Wikitext in bulk
ESLint plugin for Wikitext