Manual:Interface/Sidebar/ja

From MediaWiki.org
Jump to: navigation, search
サイドバーの例

サイドバーはナビゲーションバーを定義している。ナビゲーションバーにはウィキの重要なページへのリンクが掲載され、ウィキ管理者に対して固定的なリンクの掲載場所を与えている。多くのウィキではコミュニティのディスカッションページやよく使われるページへのリンクが掲載されている。

モノブックスキンでは、ナビゲーションバーは左(右から左に書く言語では右)に、検索バーとツールボックスと共に表示されるが、位置はスキンによって変わる。

サイドバーのカスタマイズ[edit]

Wikiの MediaWiki:Sidebar をカスタマイズするためには、まず ediinterface 権限を持つ利用者としてログインする必要があります- 管理者は既定で有効化されています。(グループまたは利用者に権限を与えることに関する情報は Manual:User rights/ja を参照。)

Then, use a link to a page on your wiki, but replace your wiki page's title (e.g. Main_Page) in the URL/Address bar with MediaWiki:Sidebar and load that page - you should now see the current content of the sidebar. (You may need to use the syntax //yourdomain/yourwiki/index.php?title=MediaWiki:Sidebar&action=edit if you use long URLs.)

If the content of the sidebar has already been modified, you can simply click on the Edit or Edit source link, otherwise you may need to create the page first by clicking on Create or Create source.

Note: If you have to create a new page, you will be presented with the default content for the sidebar in the editor. In order to successfully create a MediaWiki:Sidebar page, you need to change the content before saving.

以下はサイドバーのソースコードの例です。

* navigation
** mainpage|Accueil
** Special:RecentChanges|Recent changes
* new heading
** portal-url|portal
** http://www.mediawiki.org|MediaWiki home

この例は以下のようなサイドバーを生成します:

サイドバーの例

見出し[edit]

ナビゲーションバーは、それぞれ固有のヘッディングを持つセクションごとに分割できる。それぞれのセクションのヘッディングはリスト要素の最初のレベルから取られる(上記の例では、"navigation"がその例である)。

もしも、このテキストが、システムメッセージの名前に一致するならば、すなわち、そのタイトルのページがMediaWikiの名前空間に存在するならば、メッセージのテキストはラベルとして使われ、それ以外は、タイトルはそのままで使われる。

バグ: no sidebar is shown in the Nostalgia skin (bug 10794).

リンク[edit]

2番目のレベルのリスト要素はナビゲーションバー上のリンクに一致し、形式は以下の通り:

** ''リンクするページ(ターゲット)''|''リンクの文字(ラベル)''
target
The link target can be the name of an interface message (page in the MediaWiki namespace) or wiki page, or an external link. In either case, the link can be internal, interwiki, or external. In some cases (such as links with the "&" character), an interface message is necessary. The link target cannot be made dependent on the interface language set in the preferences.
アルゴリズムは以下の通り:
  1. Get the target text.
  2. If there is an existing or default interface message with that name, use the content of that message instead of the target text.
  3. If the output from the previous step is a valid URL (beginning with http:// or other URL protocol), the link will point to that URL.
  4. Else, it will treat it as the link target of a wikilink (linking to that page name or interwiki).
  5. In case it would end up linking to '-', the whole entry is removed from the sidebar (that's useful for removing an entry on all languages by changing the message holding the link).


例:
  • "** portal-url|portal" uses the text of MediaWiki:Portal-url (which contains "Project:Community portal").
  • "** Special:RecentChanges|Recent changes" links to Special:RecentChanges, since there is no interface message of that name.
  • "** w:Foo|Some interwiki page" links to w:Foo for the same reason.
  • "** http://www.mediawiki.org|MediaWiki home" links to http://www.mediawiki.org for the same reason.


text
The link text can be the name of an interface message (page in the MediaWiki namespace) or plain text.
  • If the link text is the name of an existing or default interface message, the content of that message will be used. MediaWiki will check for localized versions; for example, if the current language is fr (French) and the link text is the interface message "forum", it will check for "forum/fr" before using "forum".
  • Otherwise, the link text is used as the target as-is.
  • Notice that the link text is not optional as in normal wiki links. If the link text is missing, the item is ignored.
例:
  • ** Homepage|mainpage uses MediaWiki:Mainpage (which contains "MediaWiki").
  • ** Special:RecentChanges|Recent changes uses "Recent changes", since there is no interface message of that name.

要素の順序[edit]

By default, the sidebar consists of elements in this order: navigation, search, toolbox, languages. The order can be changed (in MediaWiki 1.13+) by adding special keywords (SEARCH, TOOLBOX and LANGUAGES) to MediaWiki:Sidebar using the heading syntax. For example, the following code moves the search box to the top of the sidebar:

* SEARCH

* navigation
** mainpage|mainpage
** Special:RecentChanges|Recent changed
* new heading
** portal-url|portal
** http://www.mediawiki.org|MediaWiki home

翻訳[edit]

You can translate the strings, which you use, by editing the according pages in the MediaWiki namespace.

例: The string, which will replace the item named "mainpage", is taken from MediaWiki:Mainpage. To set/change this text for users, who display your wiki in German, you can put the according text on the page MediaWiki:Mainpage/de.

That way you can easily translate these texts through the MediaWiki interface.

Please note that MediaWiki will by default use the content of the Sidebar page in that language, which corresponds to the default language of your wiki. So, if your wiki e.g. uses French as its default language, edit MediaWiki:Mainpage/fr in order to show a modified sidebar to all users, who have not changed their language setting and to all anonymous users.

For more advanced translation, see Help:Extension:Translate/Unstructured element translation.

高度なカスタマイズ[edit]

The sidebar can be fully customized by implementing JavaScript or Cascading Style Sheets, or by editing the PHP files directly. Before using these methods, note that:

  • JavaScript is fragile: it will not work for users with JavaScript disabled, and scripts frequently fail in different browsers or skins.
  • Editing the PHP files can easily cause unexpected errors, and your changes will be lost in the next update unless you manually change the new files.

Force UI-messages to follow content[edit]

Some pages should sometimes follow the content language, especially for multilingual sites. This can be controlled with the setting $wgForceUIMsgAsContentMsg. Each message overridden in this way must be explicitly given, for example to let the sidebar link to versions given by the content language for the main page and the portal page add the following to LocalSettings.php

コード
$wgForceUIMsgAsContentMsg = array( 'mainpage', 'portal-url' );

ツールボックスの節の追加や削除 (JavaScript)[edit]

The toolbox, which appears under the search bar, is a dynamic element and cannot be easily customized without the use of skinning extensions (otherwise it requires programming in PHP.) If you still want to do so, you can copy skins/MonoBook.php, creating a new skin. You can then make a custom skin to generate these links in your preferred fashion.

Another JavaScript solution is below.

For this solution to work on the entire MediaWiki site, this script has to be copied to MediaWiki:Common.js (MediaWiki:Common.js is available for MediaWiki 1.9 +).

For this solution to work only for a specific user, add this script to Special:MyPage/monobook.js (or another JS page, depending on your preferred skin).

Now simply configure which link should appear in which section. You also can remove some links if you want to.

コード
function ModifySidebar( action, section, name, link ) {
	try {
		switch ( section ) {
			case 'languages':
				var target = 'p-lang';
				break;
			case 'toolbox':
				var target = 'p-tb';
				break;
			case 'navigation':
				var target = 'p-navigation';
				break;
			default:
				var target = 'p-' + section;
				break;
		}

		if ( action == 'add' ) {
			var node = document.getElementById( target )
							   .getElementsByTagName( 'div' )[0]
							   .getElementsByTagName( 'ul' )[0];

			var aNode = document.createElement( 'a' );
			var liNode = document.createElement( 'li' );

			aNode.appendChild( document.createTextNode( name ) );
			aNode.setAttribute( 'href', link );
			liNode.appendChild( aNode );
			liNode.className = 'plainlinks';
			node.appendChild( liNode );
		}

		if ( action == 'remove' ) {
			var list = document.getElementById( target )
							   .getElementsByTagName( 'div' )[0]
							   .getElementsByTagName( 'ul' )[0];

			var listelements = list.getElementsByTagName( 'li' );

			for ( var i = 0; i < listelements.length; i++ ) {
				if (
					listelements[i].getElementsByTagName( 'a' )[0].innerHTML == name ||
					listelements[i].getElementsByTagName( 'a' )[0].href == link
				)
				{
					list.removeChild( listelements[i] );
				}
			}
		}

	} catch( e ) {
		// let's just ignore what's happened
		return;
	}
}

function CustomizeModificationsOfSidebar() {
	// adds [[Special:CategoryTree]] to toolbox
	ModifySidebar( 'add', 'toolbox', 'CategoryTree', 'http://en.wikipedia.org/wiki/Special:CategoryTree' );
	// removes [[Special:Upload]] from toolbox
	ModifySidebar( 'remove', 'toolbox', 'Upload file', 'http://en.wikipedia.org/wiki/Special:Upload' );
}

jQuery( CustomizeModificationsOfSidebar );
Usage
function CustomizeModificationsOfSidebar() has to be customized for adding or removing links in specific sections:
ModifySidebar( "action", "section", "name", "link" );
parameter value
action add to add a link; remove to remove a link
section navigation, toolbox, languages but also any other existing customized section; the given link will be added to or removed from this section
name contains the text of the link
link contains the URL of the link
restricting modifications to specific usergroups

If you want to restrict the modification of the links to a specific user group (e.g. bureaucrat), change

addOnloadHook( CustomizeModificationsOfSidebar );

to

if ( isArray( wgUserGroups ) ) {
	if ( wgUserGroups.Contains( 'bureaucrat' ) ) {
		jQuery( CustomizeModificationsOfSidebar );
	}
}

and add

function isObject( obj ) {
	return typeof obj == 'object' && obj != null;
}

function isArray( obj ) {
	return isObject( obj ) && obj.constructor.toString().indexOf( 'Array' ) != -1;
}

Array.prototype.Contains = function( element, strict ) {
	for( i in this ) {
		if( this[i] == element && !strict || this[i] === element ) {
			return true;
		}
	}
	return false;
}

For restricting the modifications to IPs instead of a specific user group, use

if ( !isArray( wgUserGroups ) ) {
	jQuery( CustomizeModificationsOfSidebar );
}

ツールボックスの節の追加や削除 (PHP)[edit]

このページで説明されているフックを LocalSettings.php ファイルに追加することができます。 With this, you can modify via MediaWiki:Sidebar the links in the toolbox panel (remove some links, change their name) and add custom links (e.g. add the "Recent changes" link there instead of the navigation panel.

Remove toolbox sections (On Vector template) MW v 1.24.1[edit]

You can download the php file VectorTemplate.php from the folder /skins/Vector. Then comment out lines 270,271,272 and also lines 285,286,287 then you can re-upload the file to its original location. Remember always make a backup of the original file just incase. Also my assumption is that when you upgrade your wiki, the changes made to this file may be reverted. To then remove the text Tools on the Side bar, in your wiki, navigate to MediaWiki:Sidebar, when there, remove the text written Tools, that should remove it totally. Take note that when logged in, even as a bureaucrat, you wont be able to see the tools section, so its best you keep important links elsewhere so that you can reach the pages still.

Make expanding/collapsing sidebar for all users (Monobook skin only)[edit]

If you use the Monobook skin and don't want to miss the expandable menu bar from e.g. Vector skin, paste the following code into MediaWiki:Monobook.js of your wiki.

/////////////////////////////////////////////////////////
// Code snippet to make your sidebar items expandable  //
// Use this code ONLY for the Monobook skin.           //
/////////////////////////////////////////////////////////

$( document ).ready( function() {
	// Set the default expanded items by their headline
	var defaultExpandItems = ['Navigation', 'Orga'];
	// Set the basic-name for the cookies, which save the current state of expanding
	var expandCookieName = 'disdance_project_wiki_nav_expanded_';

	var maxHeights = [];
	var expandeds = [];
	var labels = [];
	initNav();
});

function initNav() {
	$( '#p-logo' ).css({'position': 'relative', 'display': 'block'});
	$( '.generated-sidebar h5,#p-tb h5 ').each( function( i ) {
		var id = $( this ).parent().attr( 'id' );
		maxHeights[id] = $( this ).next( 'div' ).height();
		var str = $( this ).html();
		labels[id] = str;

		if ( $.cookie( expandCookieName + id ) == 'false' ) {
			expandeds[id] = false;
			minimize( $( this ) );
		} else if ( $.cookie( expandCookieName + id ) == 'true' ) {
			expandeds[id] = true;
			maximize( $( this ) );
		} else if ( defaultExpandItems.indexOf( str ) == -1 ) {
			expandeds[id] = false;
			minimize( $( this ) );
		} else {
			expandeds[id] = true;
			maximize( $( this ) );
		}
		$( this ).css({'cursor': 'pointer'});
		$( this ).click( toggleNav );
	} );
}

function minimize( target ) {
	var id = $( target ).parent().attr( 'id' );
	// You can change the expires parameter to save the cookie longer/shorter than 7 days like in this code
	$.cookie( expandCookieName + id, 'false', { expires: 7} );
	var str = labels[id] + '  ►';
	$( target ).next( 'div' ).animate({'height': '0px'});
	$( target ).html( str );
}

function maximize( target ) {
	var id = $( target ).parent().attr( 'id' );
	// You can change the expires parameter to save the cookie longer/shorter than 7 days like in this code
	$.cookie( expandCookieName + id, 'true', { expires: 7} );
	var str = labels[id] + '  ▼';
	var newHeight = maxHeights[id];
	$( target ).next( 'div' ).animate({'height': newHeight + 'px'});
	$( target ).html( str );
}

function toggleNav( e ) {
	var id = $(e.target ).parent().attr( 'id' );
	expandeds[id] = !expandeds[id];
	if( expandeds[id] == true ) {
		maximize( e.target );
	} else {
		minimize( e.target );
	}
}

///////////////////////////////////////////////////////
///////////////////////////////////////////////////////

モノブックスキンでのサイドバーの幅 (CSS)[edit]

以下のCSS規則を MediaWiki:Monobook.cssに追加することでサイドバーの幅を変更することができます。これは記事であり、ファイルではないことに注意してください。This changes the width to 15em, the actions position and portlet width should be an em or so less, so I've set them to 14em in this example.

/* increase sidebar width */
#column-content { margin-left: -15em; }
#column-content #content { margin-left: 15em; }
#p-logo a, #p-logo a:hover { width: 15em; }
#p-cactions { left: 14.5em; }
.portlet { width: 14em; }
div#column-content { margin-left: -14em; }
div#content { margin-left: 14em; }

ベクタースキンでのサイドバーの幅 (CSS)[edit]

以下のCSS規則を MediaWiki:Vector.cssに追加することでサイドバーの幅を変更することができます。ベクター外装での標準の幅は 10em です。以下の例は幅を 12em に変更します:

/* increase Vector sidebar width */
div#mw-panel { width: 12em; }
div#footer, #mw-head-base, div#content { margin-left: 12em; }
#left-navigation { margin-left: 12em; }

ログイン時にサイドバーの内容を変更 (PHP)[edit]

You can modify the sidebar using a hook. Create a small extension of your own or put the code directly into your LocalSettings.php file.

Some example code adding a 'navigation' sidebar block with a login link for logged out users.

警告 警告: The sidebar's array is cached after this hook is run, if you use sidebar caching and do user specific things in this hook like something that only shows up when logged in or out it may end up cached and not look correctly for some users.
<?php
$wgHooks['SkinBuildSidebar'][] = 'lfHideSidebar';
function lfHideSidebar( $skin, &$bar ) {
	global $wgUser;
	// Hide sidebar for anonymous users
	if ( !$wgUser->isLoggedIn() ) {
		$bar = array(
			'navigation' => array(
				array(
					'text'   => wfMsg( 'login' ),
					'href'   => SpecialPage::getTitleFor( 'Login' )->getLocalURL(),
					'id'     => 'n-login',
					'active' => ''
				)
			)
		);
	}
	return true;
}

サイドバー内でのパーサー関数の使用[edit]

あまりおすすめできませんが、<t>**</t> がパーサー関数の外側にあり、かつパーサー関数が複数行にまたがらない場合、サイドバーはパーサー関数 (あとえば、ParserFunctionsのような) をサポートしています。たとえば:

*Heading
**{{#ifeq:{{NAMESPACE}}|User|Page-to-link-to{{!}}text-to-show-on-user-page}}
**{{#ifeq:{{NAMESPACE}}|Talk|Another-Page-to-link-to{{!}}text-to-show-on-talk-page}}

はうまく働きます。しかし以下はパーサー関数が複数行にわたっているので、動作しません。:

*Heading
{{#ifeq:1|1|
**foo{{!}}bar
|
**baz{{!}}fred
}}
警告 警告: There is a bug on 1.18 where if a line on MediaWiki:Sidebar contains pipe characters (|) before expanding parser functions, but not after expanding parser functions, an exception is thrown on all pages (bug 33321). If such a construction is accidentally introduced to the sidebar, it forces the user to revert MediaWiki:Sidebar using the API or edit.php. これは以降のバージョンのMediaWikiで修正されました。

トラブルシューティング[edit]

変更がすぐに反映されない[edit]

MediaWikiは、変更後にナビゲーションバーが反映されないということをしばしば引き起こす、いろいろなレベルで積極的なキャッシングを行なっている。キャッシュのパージに影響されるページはこの状況を修正すべきである。一回ですべてのキャッシュの大量のパージを実行するために、データベース中で、truncateobjectcacheテーブルに対して行なうか、LocalSettings.phpファイル内でtouchする(両方してもよい)。

また、$wgUseDatabaseMessages を <t>true に設定しておく必要があります。

小文字のリンクラベル[edit]

If your links are not being capitalized as intended, たとえば以下のようにバー文字の前後に空白を挿入する。例:

** http://www.example.com/download.php?file=44555 | Download

Sections disappear or show unexpected content[edit]

If a section does not display or displays unexpected content, check that the header text isn't the name of an interface message by searching Special:AllMessages. If it is, use a different header text, or create a new interface message and use it.

For example, if you want to use "Sidebar" as header text, create the interface message "MediaWiki:Sidebar-header" containing only "Sidebar". Then, use * sidebar-header as header.

Sections are not displayed if there are no links of the form ** target|link text (e.g. when the target was forgotten).

Special:Version の更新後にリンク切れが発生[edit]

This will happen e.g., each time there are newer translations for your site language's sidebar items. One could add new redirect pages each time, but a better solution would be to use one's own sidebar item names instead of trying to keep track of the current MediaWiki translations.

MediaWiki の過去のバージョン[edit]

If you have a pre-release version of 1.5 Beta, or earlier, it is still possible in some cases to edit the sidebar:

関連項目[edit]

言語:Project:Language policy English  • français • 日本語 • русский