매뉴얼:사용자 지정 이름 공간

From MediaWiki.org
Jump to: navigation, search
This page is a translated version of the page Manual:Using custom namespaces and the translation is 34% complete.

Other languages:
Deutsch • ‎English • ‎español • ‎français • ‎galego • ‎日本語 • ‎한국어 • ‎polski • ‎русский • ‎中文

기존의 이름공간 이외에도 미디어위키에 사용자 정의 이름공간을 추가할 수 있으며, 이를 통해 컨텐츠를 나누는 것, 보다 논리적으로 위키를 구성하는 것이 가능합니다.

사용자 정의 이름공간은 $wgExtraNamespaceManual:$wgExtraNamespaces 설정 지시어(configuration directive)를 사용하여 쉽게 관리할 수 있습니다. $wgNamespaceAliasesManual:$wgNamespaceAliases 설정 지시어를 사용하여 기본 이름공간 또는 사용자 정의 이름공간에 대해 별칭(alias name)을 정의할 수 있습니다.

It's recommended to ensure there are no pending jobs in the job queue before manipulating namespaces, to avoid such jobs from failing if they target pages from namespaces you are about to delete or rename. Use runJobs.phpManual:RunJobs.php to run all pending jobs and clear the queue before manipulating namespace configuration.

사용자 정의 이름공간 만들기

$wgExtraNamespaces 전역 변수에 추가할 이름공간을 등록합니다. 모든 이름공간은 이 배열에서 사용될 유일한 숫자 인덱스가 필요합니다. 사용자 정의 이름공간을 간단하게 정의하는 예로써, 다음 코드를 LocalSettings.phpManual:LocalSettings.php에 추가하면 "Foo" 이름공간을 3000으로 정의하고 연관된(associated) "Foo talk" 이름공간도 정의합니다.

// 내가 추가할 이름공간에 대한 상수를 정의합니다.
define("NS_FOO", 3000); // 이 상수는 반드시 짝수여야 합니다.
define("NS_FOO_TALK", 3001); // 이 값은 반드시 따라나오는(following) 홀수여야 합니다. (*역주: 따라나오는 홀수란 짝수 n의 바로 다음 수인 n+1을 말합니다.)

// 이름공간을 추가합니다.
$wgExtraNamespaces[NS_FOO] = "Foo";
$wgExtraNamespaces[NS_FOO_TALK] = "Foo_talk"; // 이름공간 이름의 밑줄에 주목하십시오.
사용되지 않은 수를 고르세요
관례적으로, 100-199 숫자가 할당된 이름공간은 특수 목적(site-specific) 이름공간으로 예약되어있습니다. 어떤 확장 도구는 이 관례를 따르지 않기도 합니다. 확장 도구 개발자는 32767까지의 큰 수를 사용합니다. 인덱스를 선택할 때는 확장 도구의 기본 이름공간에 이미 정의된 수는 피해야 하는데, 왜냐하면 당신이 해당 확장 도구를 나중에 설치할 수 있기 때문입니다. 따라서 3000 이상의 수가 사용자 정의 이름공간을 정의하기에 좋은 수가 됩니다.
짝수 다음 홀수
위 예제에서 이름공간 배열의 인덱스가 3000인 것에 주목하십시오.
토론 이름공간도 같이 만드세요
You typically create a discussion "Talk" namespace along with each custom namespace. With this example, if you move a page into the "Foo" namespace, will be prompted to move its associated talk page, if any, and if you choose to do so, MediaWiki will place the talk page in "Foo talk".
공백 문자를 쓰지 마세요
이름공간 이름을 등록할 때는 공백 대신 밑줄을 사용하세요. "My Namespace"는 올바르지 않습니다. "My_Namespace"를 대신 사용하세요.
하이픈(-)을 사용하지 마세요

The uppercase part does not permit hyphens but they can still be safely added to the prefix title. 예시:

$wgExtraNamespaces[NS_FOOFOO] = "Foo-Foo";
선택한 수에 이름을 지으세요
The example defines constants for the namespace IDs, so that you can refer to these namespaces later on in the configuration, for example in $wgNamespaceProtection, $wgNamespacesWithSubpages, or $wgExtraGenderNamespaces.

새 이름공간에 대해 추가적인 설정을 계속할 수 있습니다.

$wgNamespaceProtection[NS_FOO] = array( 'editfoo' ); // foo 이름공간의 문서를 편집하려면 "editfoo" 퍼미션이 필요합니다
$wgNamespacesWithSubpages[NS_FOO] = true;            // foo 이름공간에 대해 하위 문서(subpage)를 활성화 합니다.
$wgGroupPermissions['sysop']['editfoo'] = true;      // sysop 그룹의 사용자들에 대해 "editfoo" 퍼미션을 인정합니다
일찍 하세요
$wgExtraNamespaces의 조작은 미디어위키를 초기화할 때 완료되어야 합니다. 예를 들어 $wgExtensionFunctions와 같은 post-initialization hook에서는 조작될 수 없습니다.
Watch out for collisions with URL protocols
MediaWiki's linking code knows about a number of URL protocols, defined in the $wgUrlProtocols variable. If your namespace name is identical to one of these protocols, you're going to have trouble creating [[wikilinks]] to pages in your custom namespace. This most commonly arises when someone tries to create a "News" namespace, because news: is a URL protocol for NNTP newsgroups.
To avoid this issue, you can deregister the relevant URL protocol by adding the following code to LocalSettings.php (replacing news by the lowercased name of the protocol you wish to remove):
$wgUrlProtocols = array_diff( $wgUrlProtocols, array( 'news:' ) );

확장기능에서

Extensions often add their own namespaces, such as the FlowExtension:Flow extension's "Topic" namespace. An extension can unconditionally add to $wgExtraNamespaces as described above, or if its namespace registration is conditional (for example EventLoggingExtension:EventLogging only defines its "Schema" namespace on the wiki where it stores schemas), then it can add a handler function for the CanonicalNamespacesManual:Hooks/CanonicalNamespaces hook that decides what to do.

The timing of registering extensions is subtle. Functions that extensions register with $wgExtensionFunctions are executed too late to register additional namespaces (bug T47031). So extensions should bind the CanonicalNamespaces hook at file scope (in MyExtension.php) and check there whether the wiki should activate the extra namespace or not. Extensions can configure namespace permissions and content handlers unconditionally at file scope since they do not require the namespace to actually be created.


MediaWiki version: 1.25
Gerrit change 166705

The new extension.json registration system has a namespaces key for an extension to list its namespaces that should always exist. From the GadgetsExtension:Gadgets extension:

"namespaces": [
		{
			"id": 2300,
			"constant": "NS_GADGET",
			"name": "Gadget",
			"protection": "gadgets-edit"
		},
		{
			"id": 2301,
			"constant": "NS_GADGET_TALK",
			"name": "Gadget_talk"
		},
]

It also supports the CanonicalNamespaces hook.

Content namespaces

When building the site statistics page (see Special:Statistics), MediaWiki uses values stored in the database to calculate certain totals. One particular total is the "number of articles" or "number of content pages" figure.

For a page to be considered an article, or proper content, it must:

When creating custom namespaces to hold additional content, it is a good idea to indicate this in the configuration. This is done via the $wgContentNamespacesManual:$wgContentNamespaces configuration directive.

To extend the example above, one might add the following to LocalSettings.php:

$wgContentNamespaces[] = 3000;
or
$wgContentNamespaces[] = NS_FOO;

MediaWiki will now consider pages in the "Foo" namespace to be articles, if they meet the remaining criteria, and will include them when updating the site statistics counters.

Running maintenance scripts

  • When adjusting the value of $wgContentNamespaces, it is a good idea to run either the maintenance/updateArticleCount.php or maintenance/initSiteStats.php script to update the internal statistics cache (see Manual:Maintenance scriptsManual:Maintenance scripts).

Why you would want a custom namespace

There are several reasons on why you would want this:

  • A custom namespace can be used to hold content that should not be shown on the search results page, for example pages that are used only for transclusion.
  • Certain namespace require additional privilege(s), i.e. for reading or editing
  • You want certain namespace not to be subjected to certain limitation or default settings ($wgNoFollowNsExceptionsManual:$wgNoFollowNsExceptions for example)
  • A uniform prefix for specific content(s), which is searchable for that namespace only
  • If you're an MW developer, sometimes you need to have a custom namespace for your extension(s)

Dealing with existing pages

When storing page records, MediaWiki uses a namespace's numerical index, along with the remaining title text. Thus, when a page is created in a namespace that doesn't exist, e.g. "Bar:Some page", it is treated as being in the main namespace.

This can cause problems if adding a custom namespace definition for "Bar" at a later date, as MediaWiki will look for a page indexed via the proper namespace, but won't be able to find it, thus making the content inaccessible.

To correct this problem, there are three main approaches.

Move conflicting pages

If the number of pages affected is small (e.g. "Bar" held five pages created before the namespace was defined in the site configuration), then the following approach might be suitable:

  1. Comment out the namespace definition in the configuration file
  2. Access each affected page, and move it out of the pseudo-namespace, e.g. move "Bar:Some page" to "Bar2:Some page"
  3. Un-comment the namespace definition
  4. Move the affected pages back into the new namespace

Use a maintenance script

Within the maintenance directory, there is a maintenance script which performs the above operation more effectively for a large number of pages; NamespaceDupes.phpManual:NamespaceDupes.php It is simple to use, but as with all MediaWiki maintenance scripts, consult the available usage information first (use --help as an option).

데이터베이스 쿼리 사용

To move all pages "Bar:Some page" into namespace 3000, make the following database query:

UPDATE page SET
page_title = REPLACE(page_title, 'Bar:', ''),
page_namespace = 3000
WHERE page_title LIKE 'Bar:%' AND page_namespace=0

To handle discussion pages:

UPDATE page SET
page_title = REPLACE(page_title, 'Bar:', ''),
page_namespace = 3001
WHERE page_title LIKE 'Bar:%' AND page_namespace=1

The above example is wrong. It should look for "Bar_Talk:" or "Bar_talk:" or how MediaWiki saves that inside the page_title field... After such fiddling, run the refreshLinks.phpManual:refreshLinks.php script and the updateSearchIndex.phpManual:updateSearchIndex.php script to update internal links and search results in your wiki. Note that external search engines like Google will take some time to update their index.

Removing custom namespaces

The problem addressed above also occurs when a custom namespace definition is removed; MediaWiki is no longer aware of the numerical index for the namespace, and attempts to search the main namespace for the desired pages, leading to inaccessible content. This is a rare occurrence, since most sites will not need namespaces removed, but it is a problem. (See mailing list discussion).

Example on how to remove FlowExtension:Flow and the Topic namespace:

  • Uninstall Flow
  • Temporarily add $wgExtraNamespaces[2600] = 'Topic'; to the config
  • Use deleteBatch.php to delete all pages in the Topic namespace
  • Remove the $wgExtraNamespaces config

Renaming custom namespaces

Suppose that you need to rename custom namespace "Foo" to "New" without performing a mass move of pages. The easiest way to achieve this is to preserve the namespace ID (here "3000") as well as the namespace constant (here "NS_FOO"), modify the (visible) namespace title and add the old one as an alias.

변경
define("NS_FOO", 3000);
$wgExtraNamespaces[NS_FOO] = "Foo";
-
define("NS_FOO", 3000);
$wgExtraNamespaces[NS_FOO] = "New";
$wgNamespaceAliases['Foo'] = NS_FOO;

Avoid namespace conflicts

In order for you to avoid namespace conflicts e.g. your namespace has the same number as a namespace defined by an extension, the extension namespace list shows you which numbers to avoid to prevent conflicts.

Defining $wgNamespacesToBeSearchedDefault, $wgNamespacesWithSubpages, $wgContentNamespaces or $wgNamespaceAliases for an ID not associated to any existing namespace in $wgExtraNamespaces doesn't break the wiki; MediaWiki gracefully ignores such configurations.

Styling namespaces

For example, to set the background color of pages in a particular namespace (and its associated talk namespace) you can add the following code to your common.css:

.ns-3000 #content, .ns-3001 #content { background-color: #f3f3ff; }
.ns-3000 div.thumb, .ns-3001 div.thumb { border-color: #f3f3ff; }

where 3000 is the namespace's index and #f3f3ff is the color you want as its background color.

같이 보기