2016-03-07

Created page with "기존의 이름공간 이외에도, 미디어위키에 사용자 정의 이름공간을 추가할 수 있으며, 이를 통해 컨텐츠를 나누는 것, 보다 논..."

New page

<languages/>

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

Custom namespaces are simple to manage using the <code>{{ll|Manual:$wgExtraNamespaces|$wgExtraNamespace}}</code> configuration directive.

It is also possible to define alias names for custom (and also predefined) namespaces, using the <code>{{ll|Manual:$wgNamespaceAliases|$wgNamespaceAliases}}</code> configuration directive.

== Creating a custom namespace ==

You register additional namespaces by adding them to the {{wg|ExtraNamespaces}} global variable.

All namespaces require a unique numerical index in this array.

As an example of simple custom namespace creation, adding the following lines to <code>{{ll|Manual:LocalSettings.php|LocalSettings.php}}</code> defines a "Foo" namespace 3000 and its associated "Foo talk" namespace:

<source lang="php">

// Define constants for my additional namespaces.

define("NS_FOO", 3000); // This MUST be even.

define("NS_FOO_TALK", 3001); // This MUST be the following odd integer.

// Add namespaces.

$wgExtraNamespaces[NS_FOO] = "Foo";

$wgExtraNamespaces[NS_FOO_TALK] = "Foo_talk"; // Note underscores in the namespace name.

</source>

; Pick an unused number

: As a convention, the namespaces numbered 100-199 are reserved for site-specific namespaces, although there are [[Extension default namespaces#ID_100-199|some extensions]] that don't follow this convention. Extension writers use higher numbers, up to 32767. When choosing your index, you should avoid any number already in [[extension default namespaces]], since you might want to install that extension later. Thus [[Extension default namespaces#ID_3000.2B|numbers from 3000 and higher]] are a good pick for system administrators to define their custom namespaces.

; Even then odd

:Note the namespace array index is 3000 in the above example.

:* an '''even''' namespace index denotes a [[Special:MyLanguage/Manual:Namespace#Subject and talk namespaces|subject namespace]].

:* the '''odd''' index immediately following that number denotes its associated [[Special:MyLanguage/Manual:Namespace#Subject and talk namespaces|discussion ("talk") namespace]]

; Create the talk namespace too

:You typically create a discussion "Talk" namespace along with each custom namespace. With this example, if you [[Special:MyLanguage/Help:Moving a page|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".

; No spaces

: Use underscores instead of spaces when registering namespace names. "My Namespace" is invalid here; use "My_Namespace" instead.

; No hyphens

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

Example:

<source lang=php>

$wgExtraNamespaces[NS_FOOFOO] = "Foo-Foo";

</source>

; Name the numbers you pick

:The example defines [http://php.net/manual/en/language.constants.php constants] for the namespace IDs, so that you can refer to these namespaces later on in the configuration, for example in {{wg|NamespaceProtection}}, {{wg|NamespacesWithSubpages}}, or {{wg|ExtraGenderNamespaces}}.

You could go on to configure additional settings for your new namespace.

<syntaxhighlight lang="php">

$wgNamespaceProtection[NS_FOO] = array( 'editfoo' ); // permission "editfoo" required to edit the foo namespace

$wgNamespacesWithSubpages[NS_FOO] = true; // subpages enabled for the foo namespace

$wgGroupPermissions['sysop']['editfoo'] = true; // permission "editfoo" granted to users in the "sysop" group

</syntaxhighlight>

; Do it early

: Manipulation of <code>$wgExtraNamespaces</code> must be completed during MediaWiki initialization; for instance it cannot be manipulated in a post-initialization hook like {{wg|ExtensionFunctions}}.

;Watch out for collisions with URL protocols

: MediaWiki's linking code knows about a number of URL protocols, defined in the {{$wg|UrlProtocols}} variable. If your namespace name is identical to one of these protocols, you're going to have trouble creating <nowiki>[[wikilinks]]</nowiki> to pages in your custom namespace. This most commonly arises when someone tries to create a "News" namespace, because <code>news:</code> 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 <code>news</code> by the lowercased name of the protocol you wish to remove):

<source lang="php">

$wgUrlProtocols = array_diff( $wgUrlProtocols, array( 'news:' ) );

</source>

{{Anchor|content-ns}}

=== In extensions ===

Extensions often add their own namespaces, such as the {{ll|Extension:Flow|Flow}} extension's "Topic" namespace.

An extension can unconditionally add to <code>$wgExtraNamespaces</code> as described above, or if its namespace registration is conditional (for example {{ll|Extension:EventLogging|EventLogging}} only defines its "Schema" namespace on the wiki where it stores schemas), then it can add a handler function for the {{ll|Manual:Hooks/CanonicalNamespaces|CanonicalNamespaces}} hook that decides what to do.

The timing of registering extensions is subtle.

Functions that extensions register with {{wg|ExtensionFunctions}} are executed too late to register additional namespaces ({{bug|T47031}}).

So extensions should bind the <code>CanonicalNamespaces</code>

hook at file scope (in <tt>''MyExtension''.php</tt>) 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.

{{TNT|MW version|version=1.25|comment=and after|gerrit change=166705}}

The new <tt>[[extension.json]]</tt> registration system has a <code>namespaces</code> key for an extension to list its namespaces that should always exist.

It also supports the <code>CanonicalNamespaces</code> 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:

* Be in the main namespace, or a defined '''[[Special:MyLanguage/Manual:$wgContentNamespaces|content namespace]]'''

* Not be a [[Special:MyLanguage/Help:Redirects|redirect]] page

* Contain at least one [[Special:MyLanguage/Help:Links#Internal links|internal link]]

When creating custom namespaces to hold additional content, it is a good idea to indicate this in the configuration.

This is done via the {{ll|Manual:$wgContentNamespaces|$wgContentNamespaces}} configuration directive.

To extend the example above, one might add the following to <code>'''LocalSettings.php'''</code>:

<source lang="php">

$wgContentNamespaces[] = 3000;

</source>

::or

<source lang="php">

$wgContentNamespaces[] = NS_FOO;

</source>

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 <code>$wgContentNamespaces</code>, it is a good idea to run either the <code>maintenance/updateArticleCount.php</code> or <code>maintenance/initSiteStats.php</code> script to update the internal statistics cache (see {{ll|Manual: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 ({{ll|Manual:$wgNoFollowNsExceptions|$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 [[Extension default namespaces|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:

# Comment out the namespace definition in the configuration file

# Access each affected page, and move it out of the pseudo-namespace, e.g. move "Bar:Some page" to "Bar2:Some page"

# Un-comment the namespace definition

# 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; '''{{ll|Manual:NamespaceDupes.php|NamespaceDupes.php}}'''

It is simple to use, but as with all MediaWiki maintenance scripts, consult the available usage information first (use <code>--help</code> as an option).

===Use a database query===

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

<source lang="sql">

UPDATE page SET

page_title = REPLACE(page_title, 'Bar:', ''),

page_namespace = 3000

WHERE page_title LIKE 'Bar:%' AND page_namespace=0

</source>

To handle discussion pages:

<source lang="sql">

UPDATE page SET

page_title = REPLACE(page_title, 'Bar:', ''),

page_namespace = 3001

WHERE page_title LIKE 'Bar:%' AND page_namespace=1

</source>

Note the search engine of your Wiki may take a certain time to actualise his results.

== 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 [http://old.nabble.com/Removing-a-custom-namespace--tp30762329p30762329.html mailing list discussion]).

== 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 [[Special:MyLanguage/Category:Extensions|extension]], the [[Extension namespace registration|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 following code to your [[mediawiki:common.css|common.css]]:

<source lang="css">

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

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

</source>

where <code>3000</code> is the namespace's index and <code>#f3f3ff</code> is <span style="background-color: #f3f3ff">the color you want as its background color</span>.

== See also ==

* {{ll|Manual:Configuration settings#Namespaces|Manual:Configuration settings#Namespaces}}

* {{wg|NamespacesToBeSearchedDefault}}

* [[Namespace manager]] as originally proposed for MW1.6-wikidata and its successors. Currently in use by the OmegaWiki project.

* {{ll|Extension:SkinPerNamespace}} - to use a different skin in a namespace

* {{ll|Extension:SpecialNamespaces}} - a modified version of the {{ll|Extension:Interwiki}} which changes it to provide a namespace manager as a special page.

* {{ll|Extension:Lockdown}} - to control access to namespaces

* [[Extension namespace registration|Extension namespace registration]]

* {{ll|Manual:Maintenance scripts|Maintenance scripts}}

[[Category:MediaWiki configuration{{translation}}|{{PAGENAME}}]]

[[Category:Namespace{{translation}}|{{PAGENAME}}]]

Show more