Manual:Title.php

This page is a translated version of the page Manual:Title.php and the translation is 34% complete.

MediaWiki ソフトウェアの Title クラスは LinkTarget および IDBAccessObject のインターフェイスを実装します。 このクラスは記事名を表し、様々な目的で使用されます。例えば:

  • 人間に読めるテキスト形式の記事名として
  • 記事にアクセスする際に使用する URL 内で
  • 記事へのウィキテキスト リンク
  • 記事データベースへのキー

このクラスは、これらのいずれかの書式でインスタンスが生成されます。 インスタンスが生成されると、ページ名を属性に応じて他の書式またはクエリとして取得できます。 Title は、不変 "値" クラスとして設計されているため、ミューテーター関数は存在しません。[1][2]

Title のインスタンスを生成するには、以下のいずれかの静的ファクトリーメソッドを呼び出します:

  • Title::newFromDBKey( $key )
  • Title::newFromID( ($id, $flags=0) )
  • Title::newFromText( $text, $defaultNamespace=NS_MAIN )
  • Title::newFromURL( $url ) - This is not the function you want. Title::newFromText() を使用してください。
  • Title::newFromIDs( $ids ) - returns an array of Titles
  • Title::newFromRedirect( $text )
  • Title::makeTitleSafe( $ns, $title, $fragment= '', $interwiki= '') - Create a new Title from a namespace index and a DB key. エラー時は null を返します。
  • Title::newFromRedirectArray( $text )
  • Title::newFromRedirectRecurse( $text )
  • Title::newFromRow( $row )
  • Title::newMainPage()

インスタンスが生成されると、他の非静的アクセサーメソッドを使用できるようになります。 例えば、getText()getDBKey()getNamespace() などです。

If you have a Title object, you can get a:

  • Article オブジェクト、Article::newFromTitle ( $title, IContextSource $context ) を使用
  • WikiPage オブジェクト、WikiPage::factory ( Title $title ) を使用

This class can fetch various kinds of data from the database; however, it does so inefficiently. Consider using a TitleValue object instead. TitleValue is more lightweight and does not rely on global state or the database.

ページ名の構造

ページ名は、省略可能なインターウィキ接頭辞 (例えば、mediawiki.org ページを指す "mw:" や、ウィキペディア記事を指す "w:")、省略可能な名前空間 (例えば "Manual:")、ページ名、の順序で構成されます。

接頭辞: 名前空間: ページ名
省略可能 省略可能 必須

インターウィキ接頭辞と名前空間

インターウィキ接頭辞と名前空間は、どちらも同じ記述規則に従います:

  • 先頭は文字であること
  • 末尾はコロンであること
  • 数字、文字、空白、アンダースコアのみ使用可能
  • 空白とアンダースコアは区別されない
  • 大小文字は区別されない

インターウィキ接頭辞および名前空間は、既定値または設定値として MediaWiki インストレーションに対して指定されたもののみ認識されます。

For example: On this wiki, "w:Name" is a link to the article "Name" on Wikipedia, because "w" is recognized as one of the allowable interwiki prefixes. The title "talk:Name" is a link to the article "name" in the "talk" namespace of the current wiki, because "talk" is a recognized namespace. Both may be present, and if so, the interwiki must come first, for example, "w:talk:name".

If a title begins with a colon as its first character, no prefixes are scanned for, and the colon is removed before the title is processed. Because of this rule, it is possible to have articles with colons in their names. "E. Coli 0157:H7" is a valid title, as is "Commandos: Behind Enemy Lines", because "E. Coli 0157" and "Commandos" are not valid interwikis or namespaces.

記事名

In the article name, spaces and underscores are treated as equivalent and each is converted to the other in the appropriate context (underscore in URL and database keys, spaces in plain text). "Extended" characters in the 0x80..0xFF range are allowed in all places, and are valid characters. They are encoded in URLs. Extended characters are not urlencoded when used as text or database keys. Other characters may be ASCII letters, digits, hyphen, comma, period, apostrophe, parentheses and colon. No other ASCII characters are allowed, and will be deleted if found (they will probably cause a browser to misinterpret the URL).

Canonical forms

The canonical form of a title will always be returned by the object. Canonicalization involves the following:

  • Certain Unicode directional characters (left-to-right mark, etc.) are stripped, since that usually results from errant copy-and-paste.
  • Everything from # onward is stripped, since that's used for section links.
  • Sequences of underscores and/or certain whitespace characters are collapsed into a single underscore (for the URL and DBkey forms) or a single space (for the text form). At the beginning or end of the title (or namespace or interwiki prefix), these are stripped.
  • Recognized interwiki prefixes are canonicalized, meaning that they're put entirely in lowercase.
  • Recognized namespace-names are canonicalized, meaning that the first character is capitalized and subsequent characters are put in lowercase. (This is not done for interwiki-links, however.)
  • Depending on the wiki and the namespace, the first character of a title may be capitalized. (This is not done for interwiki-links, however.)
  • For links to user-pages of anonymous users, the IP address is canonicalized.
  • The canonicalization process also includes some validation logic to reject various kinds of invalid titles (such as ones that are too long, or that contain illegal characters).

Diagrams for MediaWikiTitleCodec Class

A codec for MediaWiki page titles: [code link]

To check and see if a given page already exists:

$titleObject = Title::newFromText( 'Talk:Your desired title here' );
if ( !$titleObject->exists() ) echo "There is no page with that name.";

Create a new Title from text, such as what one would find in a link. Decodes any HTML entities in the text. Spaces, prefixes, and an initial ':' indicating the main namespace are accepted. Note that if the page does not exist, this will not create it. For that, see Manual:Article.php.

Functions

Many of these functions are used by Manual:CoreParserFunctions.php to generate magic words.

getArticleID()

Get the article ID for this Title from the link cache, adding it if necessary.

For "internal" articles, it should return the "page_id" field if the article exists, else it returns 0.

For all external articles it returns 0. All of the IDs for all instances of Title created during a request are cached, so they can be looked up quickly while rendering wikitext with lots of internal links.

getBaseText()

Get the base page name, i.e. the leftmost part excluding namespace and before any slashes, without converting spaces to underscores. See magic words {{BASEPAGENAME }} and {{BASEPAGENAMEE }}.

getText()

Gets the text form (spaces not underscores) of the main part, i.e. the title excluding namespace, but including slashes and everything after. See magic word {{PAGENAME }}.

getDBKey()

Get the main part (i.e. the title excluding namespace) with underscores.

getPrefixedDBKey()

Get the prefixed database key form with underscores.

getFragment()

Get the Title fragment (i.e. the bit after the #) in text form.

getFullText()

Get the prefixed title with spaces, plus any fragment (part beginning with '#').

getPartialURL()

Get the URL-encoded form of the main part. See magic word {{PAGENAMEE }}.

getFullURL()

Get a real URL referring to this title, with interwiki link and fragment.

getLocalURL()

Get a URL with no fragment or server name.

getPrefixedText()

Get the prefixed title with spaces. This is the form usually used for display. See magic word {{FULLPAGENAME }}.

getPrefixedUrl()

Get a URL-encoded title (not an actual URL) including interwiki. See magic word {{FULLPAGENAMEE }}.

getSubjectNsText()

Get the namespace text of the subject (rather than talk) page. See magic words {{SUBJECTSPACE }} and {{SUBJECTSPACEE }}.

getSubjectPage()

Get a title object associated with the subject page of this talk page. See magic word {{SUBJECTPAGENAME }}.

getSubpageText()

Get the lowest-level subpage name, i.e. the rightmost part after any slashes. See magic word {{SUBPAGENAME }}.

getSubpageUrlForm()

Get a URL-encoded form of the subpage text. See magic word {{SUBPAGENAMEE }}.

getTalkNsText()

Get the namespace text of the talk page. See magic word {{TALKSPACE }} and {{TALKSPACEE }}.

getTalkPage()

Get a Title object associated with the talk page of this article. See {{TALKPAGENAME }} and {{TALKPAGENAMEE }}.

getNamespace()

Get the namespace index. See {{NAMESPACENUMBER }}.

関連項目

References

  1. Mutable is a key word of the norm saying that even a const object can modify this variable. A mutable attribute can be private or public. It can always be modified even when the object is in a constant context.
  2. Mutator is the general name of a member function which can modify one or more object private variables from outside. It is useless to set it private.