Manual:インターフェイス/サイドバー

From mediawiki.org
This page is a translated version of the page Manual:Interface/Sidebar and the translation is 53% complete.
サイドバーの例
See also: Manual:Remove Tabs

MediaWiki:Sidebar は、利用者がナビゲーション バーを変更できるようにします。 サイドバーはウィキの最も重要な場所へのリンクを提供し、サイト管理者にリンクの重要なコレクションを追加する場所を提供します。 例えば、ほとんどのウィキはコミュニティの議論ページやいくつかの便利なツールページにリンクしています。

モノブックおよび Vector 外装の場合、サイドバーが検索バーやツールボックスとともに左上 (右横書きの言語の場合は右上) に配置されますが、他の外装では配置が異なる場合があります。 このサイドバーはモバイル サイト利用者には非表示です (Extension:MobileFrontend / Skin:MinervaNeue で生成される版のこと - 表示するには MobileMenu フックで対応できます。)

サイドバーをカスタマイズする

ウィキで MediaWiki:Sidebar をカスタマイズするには、まず最初に「インターフェイス編集」(editinterface)権限のある利用者 (管理者であれば既定で権限がある) としてログインします。[1]

You can access MediaWiki:Sidebar by either:

  • Going to http://yourdomain/wiki/index.php?title=MediaWiki:Sidebar&action=edit in your browser.
  • Typing MediaWiki:Sidebar in search bar, and validating with Enter.
  • From Special:AllMessages, searching for "side".

以下は、サイドバーのためにMediaWiki:Sidebarで追加されたコード例です:

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

上記の記述のサンプルは下記のサイドバーを表示します。

サイドバーの例
ページを新しく作ることになった場合、エディター画面に既定のサイドバーが表示されます。「MediaWiki:Sidebar」というページをきちんと作成するには、内容を変更してから保存してください。

ナビゲーションバーを新しいセクションに分割

サイドバーを区切り、個別の見出しを作ることができます。 This is done by adding one asterisk.

区切りごとの見出しは1番目のレベルの要素から拾います(上記のサンプルでは「navigation」と「new heading」)。 もし見出しの語句がインタフェースのメッセージ(MediaWikiの名前空間にある同名のページ)と一致する場合は、そのページ名がラベルとなります。その他の場合、区切りの見出しは指定どおりです。 Please note the {{int:}} magic word does not work since it is useless: MediaWiki automatically looks for a translation to display before to fallback to the default message.

In the example above, * navigation and * new heading are section headings.

Creating links in the sidebar

Links are created with 2 asterisks (called Second-level list elements). For example:

** <span lang="en" dir="ltr" class="mw-content-ltr">target</span>|<span lang="en" dir="ltr" class="mw-content-ltr">link text</span>
ターゲット
リンク先はインターフェースメッセージ(MediaWiki名前空間内のページ)またはwikiページの名前、または外部リンクになります。どちらの場合でも、リンクは内部、インターウィキ、外部のいずれかになります。[2]
Do the following to determine the target:
  1. 対象のテキストを取得。
  2. その名前の既存または既定のインターフェイス メッセージがある場合、対象のテキストの代わりにそのメッセージの内容を使用します。
  3. 出力が有効な URL である場合(http:// または他の URL プロトコルで始まる)は、リンクはその URL を指す。
  4. そうでない場合は、ウィキリンクのリンク先として扱われます (そのページ名またはインターウィキにリンクします)。
  5. '-' へのリンクになってしまう場合は、エントリ全体がサイドバーから除去されます。(これはリンクを保持するメッセージを変更することですべての言語のエントリを除去するのに便利です)。
例:
  • "** portal-url|portal" MediaWiki:Portal-url のテキストを使用 (内容は「Project:Community portal」)
  • "** https://www.mediawiki.org|MediaWiki home" links to https://www.mediawiki.org since this is a valid URL.
  • "** Special:RecentChanges|Recent changes" リンク先は Special:RecentChanges。名前が一致するインタフェース メッセージがなく、有効な URL ではないため。
  • "** w:Foo|Some interwiki page" 同じ理由でw:Fooにリンク。
リンクの文字列
インタフェースメッセージの名称と同じ(MediaWiki 名前空間のページ)または平文(プレーンテキスト)でよい。
  • リンクの文字列が既存もしくは既定のインタフェースメッセージと一致すると、メッセージの内容を使用。MediaWiki は自動で地域化バージョンを照会する。例えば使用言語がfr(フランス語)でリンクの文字列がインタフェースメッセージ「forum」だったと仮定すると、「forum/fr」を照会してから「forum」を使用する。
  • それ以外の場合には、リンクの文字列をそのまま使用。
  • 通常のウィキリンクと異なり、リンクの文字列は必須。リンクの文字列がないとその項目は無視されることに注意。
例:
  • ** Homepage|mainpageMediaWiki:Mainpageを使用 ("MediaWiki"を入力。)
  • ** Special:Recentchanges|Recent changes にはインターフェースに該当するメッセージがないため「最近の更新」を使用。

節の順序 (要素)

Some skins allow customizing the order of some special elements, like the search bar, toolbox, and languages. That can be done by adding the special keywords SEARCH, TOOLBOX and LANGUAGES respectively, to MediaWiki:Sidebar using the heading syntax.

However, some skins like MonoBook no longer support defining the position of the search element, and the search element is placed right after the first section of the sidebar instead. In that case, to move the search element at the top, the workaround is to define an empty leading section. For example:

* empty section
* navigation
** mainpage|mainpage
** Special:Recentchanges|Recent changed
* new heading
** portal-url|portal
** https://www.mediawiki.org|MediaWiki home

Note that some skins may display the first section differently, or place some element between the first and the second section (if any).

ツールチップとアクセスキー

A tooltip is a message which appears when a cursor is positioned over an icon, image, hyperlink, or other element in a graphical user interface.

自分で何か項目をサイドバーに追加した場合、「ツールチップ」がありません。ただしツールチップは自作でき、以下の手順があります[3]:

  • 「MediaWiki:Tooltip-n-<項目のid>」という名前のウィキページを作成
  • 作成したツールチップをその新しいページに格納。

An access key or accesskey allows a computer user to immediately jump to a specific part of a web page via the keyboard.

アクセスキーも同様に、次の手順で自作できます。

  • 「MediaWiki:Accesskey-n-<id of the item>」という名前のウィキページを作成
  • 自作したアクセスキーをその新しいページに格納。

例:

翻訳

文字列を翻訳して使用するには、MediaWiki 名前空間で該当するページを編集します。

例: 「メインページ」という名の項目を置換する文字列は、MediaWiki:Mainpageから取ります。ドイツ語版ウィキを使用するユーザーのために文字列を設定/変更するには、使いたい文字列をMediaWiki:Mainpage/deに記入します。

これでMediaWikiのインタフェースを使ってリンクの文字列を簡単に置換できます。

注意事項としてMediaWikiが既定で使用するサイドバーページは、その 言語つまりあなたのウィキの既定の使用言語のものです。例えば仮にフランス語が既定の使用言語だとすると、MediaWiki:Mainpage/frを編集すると、個人で言語設定を変更していなくても、あるいは匿名の利用者を含むすべての利用者に対し、フランス語版のサイドバーが表示されます。

さらに高度な翻訳の解説は Help:Extension:Translate/構造化されていない要素の翻訳 を参照してください。

高度なカスタマイズ

サイドバーを思い通りにカスタマイズするにはJavaScriptもしくはCascading Style Sheetsを実行、あるいは直接、PHPファイルを編集します。これらの方法に取りかかる前に以下の注意点に目を通してください。

  • 壊れやすい JavaScript の扱い: JavaScript を無効にした利用者には役立たないほか、ブラウザや外装によりうまく作動しない頻度が高まります。
  • PHP ファイルを編集すると予想外のエラーを招きやすく、新規ファイルを手動で書き換えない限り、変更箇所は次回の更新で失われます。

Remove the Sidebar and main logo at MediaWiki:Sidebar

To completely remove the sidebar and logo:

Blank the MediaWiki:Sidebar page and save.

Then add:

#column-content { margin: 0 0 1em 0; }
#content { margin: 0 0 0 0; }
#p-cactions { left: .1em; }

This moves the main text of your wiki to the left.

Completely remove the sidebar, tabs and search bar

See also: Manual:Remove Tabs

Deletes the logo, and the entire sidebar:

#p-logo, .generated-sidebar, #p-lang, #p-tb  { display:none; }

Deletes the search bar:

#p-search { display:none; }

Deletes the talk tab:

#ca-talk { display:none!important; }

Deletes the Page tab:

#ca-nstab-main { display:none!important; }

UI メッセージを強制的に内容に沿わせる

特に多言語版の場合、ページによっては時により内容の言語に合わせて調整する必要があります。その実現には $wgForceUIMsgAsContentMsg の設定を変えます。この方法でそれぞれのメッセージを上書きする場合には、メインページの内容の言語のバージョンに対してサイドバーからリンクを貼り、かつポータルページから以下を渡すように個別に調整します。

LocalSettings.php

code
$wgForceUIMsgAsContentMsg = [ 'mainpage', 'portal-url' ];

ツールボックスのセクションを追加または削除する(JavaScript)

The toolbox appears on the left under MediaWiki:Sidebar. The toolbox is a dynamic element requiring programmatic methods such as skin extensions, PHP (see skins/MonoBook.php and creating a new skin) or JavaScript.

The JavaScript solution uses User:{username}/common.js / MediaWiki:Common.js, available for MediaWiki 1.9+.

次に、どのセクションにどのリンクを表示するかを設定するだけです。また、必要に応じていくつかのリンクを削除することもできます。

code

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|Special:CategoryTree]] to toolbox
	ModifySidebar( 'add', 'toolbox', 'CategoryTree', 'https://en.wikipedia.org/wiki/Special:CategoryTree' );
	// removes [[Special:Upload|Special:Upload]] from toolbox
	ModifySidebar( 'remove', 'toolbox', 'Upload file', 'https://en.wikipedia.org/wiki/Special:Upload' );
}

jQuery( CustomizeModificationsOfSidebar );
使用法
function CustomizeModificationsOfSidebar() has to be customized for adding or removing links in specific sections:
ModifySidebar( "action", "section", "name", "link" );
パラメーター
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

特定の利用者グループへの変更制限

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

jQuery( CustomizeModificationsOfSidebar );

to

if ( mw.config.get( 'wgUserGroups', [] ).indexOf( 'bureaucrat' ) !== -1 ) {
	jQuery( CustomizeModificationsOfSidebar );
}

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

if ( mw.config.get( 'wgUserGroups', [] ).indexOf( 'user' ) === -1 ) {
	jQuery( CustomizeModificationsOfSidebar );
}

ツールボックスのセクションを追加または削除する(PHP)

You can add in your file LocalSettings.php the hook described on this page. 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).

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

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 );
	}
}

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

Sidebar width in Monobook skin (CSS)

You can change the width of your sidebar by adding the following CSS rules to your MediaWiki:Monobook.css

note that this is an article, not a file. 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; }
#column-content { margin-left: -14em; }
#content.mw-body { margin-left: 14em; }

Change sidebar content when logged in (PHP)

Install and configure the DynamicSidebar extension.

Parser functions in sidebar

Although it is not exactly recommended, the sidebar does support parser functions (such as ParserFunctions ), provided the ** is outside the parser function, and the parser function does not span multiple lines. For example:

*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}}

works. However the following would not work since the parser function spans multiple lines:

*Heading
{{#ifeq:1|1|
**foo{{!}}
bar
|
**baz{{!}}fred
}}

トラブルシューティング

変更点が表示に反映されない

MediaWiki aggressively caches content if possible, which often causes the navigation bar to persist after changes. 影響を受けるページ群でキャッシュをパージすると、問題が解決かもしれません。 すべてのキャッシュを大量に一括パージするには、ご利用のデータベースでLocalSettings.php ファイルの改変もしくはobjectcache 表の切り詰めが必要です (両方が必要な場合もあり)。

trueに設定するには、$wgUseDatabaseMessages も必要です。 Also, if your links don't have a | in them, they will not show up because of this line of code in Skin.php: if ( strpos( $line, '|' ) !== false ) {

一般利用者もしくは特別な権限のない管理者には、上記の変更点が表示されるよう、前述の上記の高度な処理をすることができないかもしれません。あるいはページの再読み込み(パージ)をしても表示が変わらない場合にも、プレビュー画面で CSS の変更を確認できることがあります (特に個人用の CSS の変更。) たとえば サイドバーの幅や輪郭線とラベル文字の余白もしくはマージンを変更した場合。ただし変更を保存しても、画面表示への反映までに時差が発生することがあります。数時間後でも何も表示されない場合には、ウィキ全体もしくはウィキファームの管理者に相談する必要があるかもしれません。

リンクラベルが小文字になる

もしも大文字になるはずのリンクが小文字で表示される場合は、縦棒記号の前後に半角開きスペースを記入してみます。例:

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

Sections 節が非表示もしくは想定外の文字列に変わった

もし特定の節が非表示もしくは想定外のコンテンツが表示される場合は、見出しの文字列がインターフェースのメッセージ名と重複していないか、 Special:AllMessagesを検索して調べます。もしそうだった場合は、ヘッダー名を変更するか、インターフェースのメッセージを新しく作り、それを使います。

たとえば見出しの文字列として 「Sidebar」を使いたい場合、 インターフェースのメッセージ「MediaWiki:Sidebar-header」として「Sidebar」のみ記入します。その後、見出しには * sidebar-header を使います。

** リンク先 | リンク テキスト の形式でリンクされていないと、節は非表示になります (たとえばリンク先の記入を忘れた場合。)

Special:Versionの更新後、リンクが切れた

この現象は、たとえばサイト言語用のサイドバーの項目に新しい翻訳が付くたびに発生します。毎回、新しいリダイレクトのページを作成すればよいのですが、よりよい対策としては、MediaWiki 翻訳の最新版を常に追跡するよりも、サイドバーの項目名を自作する方法があります。

関連項目

References

  1. (グループまたは利用者への権限付与についての情報は、Manual:利用者権限 を参照。) 次に、自分のウィキのページへのリンクを開き、URL/アドレスバーに書かれたウィキページ名(例:Main_Page)を MediaWiki:Sidebar に書き換えてから、ページを読み込みます - すると変更後のサイドバーが表示されるはずです。(URLが長文の場合は //yourdomain/yourwiki/index.php?title=MediaWiki:Sidebar&action=edit の構文を使用する必要があります。) もしサイドバーの内容が既に変更してある場合は、 EditEdit source(編集/ソースを編集)リンクをクリックします。あるいは CreateCreate source(作成/ソースを作成)を押してページを最初から作成します。
  2. 場合によっては (「&」文字を含むリンクなど)、インターフェイス メッセージが必要です。リンク先を個人設定で設定されたインターフェイス言語に依存させることはできません。
  3. http://www.kaarebmikkelsen.dk/?p=174