Selainruang nama bawaan, juga mungkin untuk menambahkan ruang nama buatan sendiri ke sebuah instalasi MediaWiki, untuk memperinci pemisahan konten dan membuat organisasi yang lebih logis.
Ruang nama buatan sendiri mudah dikelola menggunakan perintah konfigurasi$wgExtraNamespaces.Juga mungkin untuk mendefinisikan nama alias untuk ruang nama buatan sendiri (dan juga ruang nama bawaan), menggunakan perintah konfigurasi$wgNamespaceAliases.Some extensions make it easy for you to create custom namespaces.Examples includeNamespaceManager andBlueSpiceNamespaceManager.
Anda mendaftarkan ruang nama tambahan dengan menambahkannya ke variabel global$wgExtraNamespaces ke berkas"LocalSettings.php" Anda.Semua ruang nama membutuhkan sebuah indeks numerik unik di dalam larik ini.Sebagai contoh sederhana pembuatan ruang nama buatan sendiri, menambahkan baris-baris berikut ke berkas"LocalSettings.php" akan mendefinisikan sebuah ruang nama "Foo" 3000 dan ruang nama terkaitnya "Foo_talk":Note that having a talk namespace associated with your custom namespace is currently ahard requirement.
// Definisikan konstanta untuk ruang nama tambahanku.define("NS_FOO",3000);// Ini HARUS genap.define("NS_FOO_TALK",3001);// Ini HARUS bilangan ganjil berikutnya.// Tambahkan ruang nama.$wgExtraNamespaces[NS_FOO]="Foo";$wgExtraNamespaces[NS_FOO_TALK]="Foo_talk";// Perhatikan tanda garis bawah di nama ruang nama.
Bagian huruf kapital tidak membolehkan tanda hubung tetapi tanda hubung masih bisa ditambahkan ke judul prefiks.Contoh:
$wgExtraNamespaces[NS_FOOFOO]="Foo-Foo";
$wgNamespaceProtection,$wgNamespacesWithSubpages, atau$wgExtraGenderNamespaces.Anda bisa mengonfigurasi pengaturan tambahan untuk ruang nama baru Anda.
$wgNamespaceProtection[NS_FOO]=['editfoo'];// izin "editfoo" diperlukan untuk menyunting ruang nama foo$wgNamespacesWithSubpages[NS_FOO]=true;// subhalaman dinyalakan untuk ruang nama foo$wgGroupPermissions['sysop']['editfoo']=true;// izin "editfoo" diberikan kepada pengguna di kelompok "sysop"
$wgExtraNamespaces perlu diselesaikan ketika inisialisasi MediaWiki, jika ekstensi seharusnya bekerja dengan ruang nama yang baru dibuat, pastikan Anda mendefinisikan dan menamainya sebelum memanggil ekstensinya. Sebagai contoh pengaturan tersebut tidak bisa diubah di dalamhook pascainisialisasi seperti$wgExtensionFunctions.news: adalah sebuah protokol URL untuk grup berita NNTP.news dengan nama huruf kecil dari protokol yang Anda ingin hapus):$wgUrlProtocols=array_diff($wgUrlProtocols,array('news:'));
| Versi MediaWiki: | ≥ 1.25 Gerrit change 166705 |
Extensions often add their own namespaces, such as theFlow extension's "Topic" namespace.Theextension.json registration system has anamespaces key for an extension to list its namespaces.From theGadgets extension:
"namespaces":[{"id":2300,"constant":"NS_GADGET","name":"Gadget","protection":"gadgets-edit"},{"id":2301,"constant":"NS_GADGET_TALK","name":"Gadget_talk"},]
You can also set other namespace-related settings here, such as whether it should be a content namespace or not; seeManual:Extension.json/Schema#namespaces for the available properties.
If namespace registration is conditional (for exampleEventLogging only defines its "Schema" namespace on the wiki where it stores schemas), the extension should add"conditional": true to the namespace definition inextension.json, and also register a handler for theCanonicalNamespaces hook there which decides whether to register the namespace or not.The hook handler should only change the$namespaces with which it is called; all other settings of the namespace should still be registered in theextension.json.If those settings should also be dynamic, do not change$wgContentNamespaces,$wgNamespaceContentModels etc. in the CanonicalNamespaces hook handler (it will have no effect –T288819); instead, you will have to set them earlier, such as in acallback (not in$wgExtensionFunctions).
Note that adding an extension to LocalSettings.php does not necessarily make relevant namespace constants available as globals for other extensions.
When building the site statistics page (seeSpecial: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:
$wgArticleCountMethod.When creating custom namespaces to hold additional content, it is a good idea to indicate this in the configuration.This is done via the$wgContentNamespaces configuration directive.
To extend the example above, one might add the following to the "LocalSettings.php" file:
$wgContentNamespaces[]=3000;
$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.
When adjusting the value of configuration parameter$wgContentNamespaces, it is a good idea to run either the "path/to/maintenance/updateArticleCount.php or "path/to/maintenance/initSiteStats.php" script to update the internal statistics cache (seeManual:Maintenance scripts).
There are several reasons you might want this:
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.
You can use theNamespaceDupes maintenance script to correct this problem.It will find pages in the main namespace with a prefix matching any of the defined namespaces, and update their records.
If you are not able to run maintenance scripts, then the following approach might be suitable:
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 namespacesremoved, but it is a problem.
| Versi MediaWiki: | ≥ 1.43 Gerrit change 1052196 |
You can use theCleanupTitles maintenance script to correct this problem.It will find pages any namespace that is no longer defined, and update their records.The pages will be moved to the main namespace with an added prefix likeNS123:, unless specified otherwise by parameters to the script.
As above, you can also temporarily restore the namespace configuration and move the pages from the user interface (or delete them).
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;
Note that some extensions store namespace names in plain text instead of their internal IDs, and should therefore be dealt with extra care.Examples include:
In order for you to avoid namespace conflicts e.g. your namespace has the same number as a namespace defined by anextension, theextension 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.
The simplest way of setting the background color of pages in a particular namespace (and its associated talk namespace) is by adding the following code to yourcommon.css:
.ns-3000#content,.ns-3001#content{background-color:#f3f3ff;}.ns-3000div.thumb,.ns-3001div.thumb{border-color:#f3f3ff;}
where3000 is the namespace's index and#f3f3ff is the color you want as its background color.However, unless your needs are very basic you will probably want to support night mode as it is expected by modern standards, and avoid accessibility problems derived from using fixed colors.SeeRecommendations for night mode compatibility on Wikimedia wikis for details.
You might also want to change the name of the tab from its default (the namespace's name).This is located in your system messages at MediaWiki:nstab-namespace.