(Translated by https://www.hiragana.jp/)
Extension:分类树 - MediaWiki Jump to content

Extension:ぶん类树

From mediawiki.org
This page is a translated version of the page Extension:CategoryTree and the translation is 40% complete.
此扩てんずい于MediaWiki 1.31及更だか版本はんぽんよし此您无需另外载。 ただし,您仍需遵循此页面提供ていきょうてき其他使用しよう说明。
MediaWiki扩展しゅさつ
CategoryTree
发行じょう态: 稳定ばん
实现 标签 , 解析かいせき函数かんすう , 特殊とくしゅ页面
描述 以树てき形式けいしき提供ていきょうwiki类别结构てき动态视图。
作者さくしゃ Daniel Kinzler (Duesentriebとめげん)
最新さいしん版本はんぽん もち更新こうしん
けんようせい政策せいさく かいあきら跟随MediaWiki发布。 masterぶんささえこうきさきけんよう
MediaWiki 1.25+
许可协议 GNU通用つうようこう眾授けんじょう款2.0ある更新こうしん版本はんぽん
した
README
  • $wgCategoryTreeAllowTag
  • $wgCategoryTreeCategoryPageOptions
  • $wgCategoryTreePageCategoryOptions
  • $wgCategoryTreeMaxDepth
  • $wgCategoryTreeSidebarOptions
  • $wgCategoryTreeDefaultOptions
  • $wgCategoryTreeMaxChildren
  • $wgCategoryTreeSpecialPageOptions
  • $wgCategoryTreeOmitNamespace
  • $wgCategoryTreeSidebarRoot
  • $wgCategoryTreeDisableCache
  • $wgCategoryTreeCategoryPageMode
  • $wgCategoryTreeDefaultMode
  • $wgCategoryTreeUseCategoryTable
  • $wgCategoryTreeHijackPageCategories
りょう 314 (Ranked 13th)
せいざい使用しようてきおおやけ开wikiすう 10,554 (Ranked 11th)
ぜん往translatewiki.net翻譯ほんやくCategoryTree扩展
問題もんだい 开启てきにん · 报告错误

CategoryTree扩展以动态树视图てき形式けいしき提供ていきょうりょうwikiてきぶん类结构。它使用しようAJAX依據いきょ需要じゅよう载树てきぼう些部ぶん。CategoryTree最初さいしょよしDaniel Kinzlerさく为外工具こうぐ编写てきただしきさきざいTim Starlingてき帮助集成しゅうせいいたMediaWiki软件ちゅう

あんそう

  • しもぶんけん,并将かい压后てきCategoryTreeぶんけん夹移动到extensions/录中。
    开发しゃ和代かずよ码贡けんじじん员应从Gitあんそう扩展,输入:cd extensions/
    git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/CategoryTree
  • はたしも列代れつだい放置ほうちざい您的LocalSettings.php てき底部ていぶ
    wfLoadExtension( 'CategoryTree' );
    
  • Yes 完成かんせいざい您的wikiじょう导航いたりSpecial:Version,以验证已成功せいこうやすそう扩展。

用法ようほう

类别树可以下いかれつさん种方しき使用しよう

  • 直接ちょくせつよう于分类页めん
  • さく为“てい义标签”(ある解析かいせき函数かんすう”)ざいwiki页面中内なかうち联显しめせぶん类结构,
  • さく特殊とくしゅ页面。

类别树扩てん为分类页めんじょうれつてき子分こぶん添加てんかりょう以“てん开”小部こべけん

<categorytree>标签

实例结果以在下面かめんみぎ侧的かまちちゅういた

<categorytree mode="pages">Manual</categorytree>

此扩てん包含ほうがんいち个称为<categorytree>てきてい义标签。れい如,如果您将<categorytree>Foo</categorytree>添加てんかいたwiki页面じょう,它将ざい该页めんじょうしょうぶん类Fooてき内容ないよう显示为动态树(まいり见右侧示れい)。该标签使用しよう类HTMLてき语法接受せつじゅ以下いか属性ぞくせい

mode
てい义在树中显示哪些页面。这可能かのうどおり使用しようnamespaces选项被覆ひふく盖。选值ゆう
categories
ただ显示子分こぶん类(配置はいち常数じょうすう0
pages
显示子分こぶん类和页面,包括ほうかつ图像(配置はいち常数じょうすう10),最多さいた显示200个页めん
all
显示所有しょゆう页面、子分こぶん类和图片とう。(配置はいちつねりょう20
parents
れつちちぶん类而子分こぶん类(配置はいちつねりょう100)。这会让CategoryTree进入“はんむこう操作そうさ2008ねん7がつてきr36892おこり支持しじ)。
depth
确定初次はつじ显示树的多少たしょう层。だま认为1。0表示ひょうじ仅显しめせ节点。最大さいだい值取决于指定していてきmode$wgCategoryTreeMaxDepth选项。(ざい2007ねん3がつ30にちてきr20410いたr20840引入,2008ねん7がつてき%rev3おこりそく便びん开启$wgCategoryTreeDynamicTag也能正常せいじょう运行。)
onlyroot
set this to "on" to only show the "root" node of the tree initially. Equivalent to depth="0". (Introduced in r20385, March 13 2007.) Deprecated as of r36864, July 2008: use depth="0" instead.
hideroot
はた此设为“on”隐藏树的“”节点,そくhideroot=onれい如,这将かい显示ぶん类名Foo。
hideprefix
确定なん时应从树ちゅうてき条目じょうもくちゅう隐藏命名めいめいそら间前缀(2008ねん7がつてきr36864おこり)。选值ゆう
always
always hide the prefix. Should be used only if all pages come from the same namespace (configuration constant 10).
never
never hide the namespace prefix, not even for categories (configuration constant 0).
auto
hide the namespace of categories if only categories are shown, as with mode="categories" (configuration constant 30). This is equivalent to the old default behavior (before Jun 2008).
categories
always hide the namespace of categories, but show all other prefixes (configuration constant 20). This is the new default behavior (since r36864, July 2008).
showcount
set this to "on" to show the number of entries in subcategories, i.e. showcount="on" (since r36864, July 2008). This is disabled per default for category trees inlined on pages, but enabled per default in category listings and on Special:CategoryTree.
notranslations
set this to "on" to hide all translations pages corresponding to the pages pertaining to the category, i.e. notranslations="on" (since Gerrit change 526234, November 2019). This is disabled by default. If this option is set to "on", instead of the different translations (e.g. Page, Page/en, Page/fr, Page/de) only the standard translation "Page" is displayed and all translations are suppressed.
This doesn't affect "showcount", so still a bug.
namespaces
a list of namespaces from which pages should be shown in the tree (since r36864, July 2008). The entries in the list must be namespace names, separated by spaces. The main namespace can be represented by "-" or "0". Subcategories will be shown only if Category namespace is present on the list.
class, style, id, etc
The ‎<categorytree> tag supports all standard HTML attributes for block elements (since r36864, July 2008; before that, only style was supported).

“namespaces”さんすうてき注意ちゅういごと

Category is a namespace. Categories are shown in all modes by default, but specifying the namespaces parameter hides them just like any other namespace not present on the list. If you want to list pages in a given namespace, including pages in subcategories, simply add Category to the namespace list.

れい如:

  • Listing main namespace pages in Category:Manual:
<categorytree mode="pages" namespaces="Main">Manual</categorytree>
  • Listing main namespace pages and subcategories in Category:Manual:
<categorytree mode="pages" namespaces="Main Category">Manual</categorytree>

The mode parameter is overridden by namespaces:

  • if only Category namespace is asked, it's equivalent to mode=categories;
  • if file namespace is present on the list, it will imply mode=all;
  • otherwise mode=pages will be used. It means that if the site configuration hasn't been changed, the following are equivalent (the first two are always equivalent, the third only if $wgCategoryTreeDefaultMode is the default CategoryTreeMode::CATEGORIES):
<categorytree mode="categories">Manual</categorytree>
<categorytree namespaces="Category">Manual</categorytree>
<categorytree>Manual</categorytree>

{{#categorytree}}解析かいせき函数かんすう

r25825(2007ねん9がつ13にち)おこり,您还使用しよう"解析かいせき函数かんすう"语法ざい页面じょう放置ほうちぶん类树。该功のう就像<categorytree>标签いち样,使用しよう不同ふどうてき语法,れい{{#categorytree:Foo}}使用しよう命名めいめいばんさんすうてき语法指定してい选项,れい{{#categorytree:Foo|hideroot|mode=pages}}

Using the parser function syntax has the advantage that it allows you to use magic words, templates and template parameters when specifying the category to show. Some examples:

  • Using a magic variable to show this page's category tree (may be useful on category description pages): {{#categorytree:{{PAGENAME}}}}.
  • Using a template to specify the category: {{#categorytree:{{root category}}}} - the name of the root category would be defined by the contents of Template:Root_category.
  • Using a template parameter to specify the category, when using CategoryTree inside a template: {{#categorytree:{{{1}}}}} in Template:Baz can be called using {{Baz|Foo}}.

Special:CategoryTree页面

The special page is called Special:CategoryTree; there you can enter the name of a category and then browse its content.

配置はいち

There are some options you can specify in your LocalSettings.php file.

You can no longer use CT_* constants in LocalSettings.php. Instead use 0 for category mode, 10 for pages, 20 for all, 100 for parents.
$wgCategoryTreeMaxChildren
maximum number of children shown in a tree node. Default is 200.
$wgCategoryTreeAllowTag
enable <categorytree> tag. Default is true.
$wgCategoryTreeDynamicTag
loads the first level of the tree in a <categorytree> dynamically. This way, the cache does not need to be disabled. Default is false.
$wgCategoryTreeDisableCache
disables the parser cache for pages with a <categorytree> tag, or provides max cache time in seconds. Default is 21600 which is 6 hours.
$wgCategoryTreeUseCache
enable HTTP cache for anon users. Default is false.
$wgCategoryTreeOmitNamespace
do not show the namespace name for pages and categories. Default is false, namespaces are shown unless showing categories only. Deprecated as of r36864, July 2008: use $wgCategoryTreeDefaultOptions['hideprefix'] instead.
$wgCategoryTreeMaxDepth
an array defining the maximum depth for each mode, to which the tree may be expanded initially using the depth parameter in a <category> tag. By default, this is set to 2 for the "categories" mode, and 1 for other modes. To set it to 3 for categories and 2 for other modes, for example, you can use $wgCategoryTreeMaxDepth = [10 => 2, 20 => 2, 0 => 3, 100 => 2];.
$wgCategoryTreeDefaultMode
the default mode to use when no mode attribute is specified in a <categorytree> tag. May be 0 (the default - categories), 10 (pages), or 20 (all).
$wgCategoryTreeCategoryPageMode
the mode to use when rendering trees on category pages. Deprecated as of r36864, July 2008: use $wgCategoryTreeCategoryPageOptions['mode'] instead.
$wgCategoryTreeSidebarRoot
root category to use for integrating the category tree in the sidebar (since r36920, July 2008). If not set, no tree is integrated (this is the default). Integrating a CategoryTree into the sidebar only works with skins based upon SkinTemplate, that is, Modern, Monobook, Chick, Simple, and MySkin, but not Standard, Nostalgia or CologneBlue. This is currently broken for MediaWiki 1.35.1 and the vector skin, see phab:278306.
$wgCategoryTreeDefaultOptions
default options to apply, as an array (since r36864, July 2008). The available options are described above. Example: $wgCategoryTreeDefaultOptions['mode'] = 'pages';.
$wgCategoryTreeCategoryPageOptions
options to use on category pages, as an array (since r36864, July 2008).
$wgCategoryTreeSpecialPageOptions
options to use on Special:CategoryTree, as an array (since r36864, July 2008).
$wgCategoryTreeSidebarOptions
options to use when showing the tree in the sidebar, as an array (since r36920, July 2008)

けい统消いき

categorytree-member-num

By default, when listing subcategories on a category page, each subcategory is followed by an integer, indicating how many subcategories lie beneath it, how many pages it contains, and how many files are in the category (if applicable):

My category name (5 C, 2 P, 1 F)

You can change this behavior by overriding the system message MediaWiki:Categorytree-member-num. It takes five parameters:

さんすう 含义
$1 子分こぶん类数
$2 文章ぶんしょうすう包括ほうかつぶん类页めん和文わぶんけん页面)
$3 うえ传文けんてき个数
$4 なり员页めん总数,包括ほうかつぶん类页めん和文わぶんけん页面
$5 Something close to ($1 C, $2 P, $3 F) but with anything that is 0 omitted.

More precisely, a comma separated list of the number of pages (mediawiki:categorytree-num-pages), subcategories (mediawiki:categorytree-num-categories), and files (mediawiki:categorytree-num-files) in the category, or empty (mediawiki:categorytree-num-empty) in the case the category has no members. In versions prior to those around 1.19 this value was different. See older version of these docs.

だま认值为($5)

Tip: Use the ParserFunctions extension to provide if/then/else logic to display different parts conditionally. For example:

{{#ifeq:$1|0||$1 categories}}

A configuration to manage commas and spaces when outputting all info:

Abbreviation version:

({{#ifeq:$4|0|empty|{{#ifeq:$1|0||$1 C{{#ifeq:{{#expr:$3+$2}}|0||,}}}} {{#ifeq:$2|0||$2 P{{#ifeq:$3|0||,}}}} {{#ifeq:$3|0||$3 F}}}})

Full name version:

({{#ifeq:$4|0|empty|{{#ifeq:$1|0||$1 categories{{#ifeq:{{#expr:$3+$2}}|0||,}}}} {{#ifeq:$2|0||$2 pages{{#ifeq:$3|0||,}}}} {{#ifeq:$3|0||$3 files}}}})

故障こしょう排除はいじょ

あんそうCategoryTreeきさきwiki损坏

  • Turn on error reporting
  • Make sure you have all files installed
  • Make sure all of the CategoryTree extension files have mode 644, and the CategoryTree directory has mode 755.

LocalSettings.phpちゅうてき选项无效

  • Make sure you specify the options after including the extension.

<span id="Clicking_the__has_no_effect,_gives_a_JavaScript_error_or_just_sits_on_loading">

てんきさき无效,かえしかいJavaScript错误ある处于载中

  • Note that using the <categorytree> tag in system messages (MediaWiki namespace) may not work as expected - this is a known caveat. For a workaround, see Using CategoryTree in the Sidebar below.
  • Make sure you have $wgUseAjax = true; in your LocalSettings.php before including the extension.
  • If you are using rewrite rules or aliasing (e.g. to have "very short URLs" - i.e. wiki pages in the document root or perhaps redirecting to a www-version of the requested URL), make sure you have an exception in place for the /extensions directory, just like you would for the /skins directory. Also see below.

<span id="Clicking_the__shows_no_sub-categories_error">

てん显示no sub-categories错误

  • Try to fix this by adding this code to LocalSettings.php: $wgCategoryTreeDefaultOptions['namespaces'] = [ 0, NS_CATEGORY, NS_FILE ];

浏览报告CategoryTree.js/あるCategoryTree.cssてき错误MIME类型

  • Make sure your web server uses the correct MIME types for .js and .css files
  • Enter the URLs directly into the browser and see if it is serving the pages at all, and not some error page; especially:
  • If you are using rewrite rules or aliasing (e.g. to have "very short URLs" - i.e. wiki pages in the document root), make sure you have an exception in place for the /extensions directory, just like you would for the /skins directory.

<span id="Member_counts_are_wrong,_grey_arrows__are_shown_instead_of_">

なり员数错误,显示为灰しょく而非

Since MediaWiki 1.13, CategoryTree can show the number of members of a category, and can show a grey arrow for tree nodes that do not have any children based on that number. This information is based on the new category table. However, populating that table with the current values does not always work when upgrading to 1.13. In that case, run the populateCategory.php maintenance script, if necessary with the --force option.

<span id=" _toggles_shown_only_on_the_first_level_of_the_category_tree_view">

开关仅显しめせざいぶん类树视图てきだいいち层级

In case you get only one level depth while visualing the tree, try to set in modules/ext.categoryTree.styles.css file display: none; to display: inline !important;.

The JavaScript intended to switch the tag style is somehow buggy.

つくえじんよう户请注意ちゅうい

Bots and scripts that parse the HTML of category pages can use the notree URL parameter to force the traditional output. However, HTML output is generally not stable, so it is recommended to change your script to use the API to fetch category listings and similar.

“Category Not Found”消息しょうそく

After you implement the CategoryTree plugin and add the code to show the tree, if you see a message that says Category Not Found, you need to add some content in your category pages. The category pages can't be red pages, basically. Click your category names, add some text in the category page, and then your tree should work fine.

きさきめんてき200个链せっざいあんそうりょうCategoryTreeきさきおこり作用さよう

Make sure the right version of this extension is installed, relative to the version of MediaWiki you have installed. In particular, versions of this extension made for versions of MediaWiki prior to 1.17 are not compatible with MediaWiki 1.17 and greater, and will cause issues where all the paging links on category pages are broken.

使用しよう“namespaces”さんすう时不显示にんなん页面

前文ぜんぶん

Hacks

ざいけい统消いきてい义皮肤中使用しようCategoryTree

In older versions of CategoryTree, you have to modify the code to make this work: find the efCategoryTreeParserOutput function in the file CategoryTree.php, and remove the condition; i.e. it should then look like this:

function efCategoryTreeParserOutput( &$outputPage, &$parserOutput )  {
    CategoryTree::setHeaders( $outputPage );
    return true;
}

ざい侧边栏使用しようCategoryTree

つう过JavaScript

Since r36920 (July 2008) with MediaWiki 1.13 (r36917), you can integrate a CategoryTree in the sidebar simply by setting $wgCategoryTreeSidebarRoot to the category you want to use as a root. This only works with skins based upon SkinTemplate however, that is, Modern, Monobook, Chick, Simple, and MySkin, but not Standard, Nostalgia or CologneBlue.

If you want the CategoryTree on a different position in the sidebar, you can reference it on MediaWiki:Sidebar as "categorytree-portlet".

For earlier versions of CategoryTree and/or MediaWiki, you'll need to install a mod to MonoBook.php to enable normal wikitext in the sidebar, see Wikitext in side bar --DJ 19:26, 24 January 2008 (UTC)

To append a link "CategoryTree" to your toolbox (sidebar ) add following code to the JavaScript page (e.g. monobook.js) of your skin and customize the URL "w:Special:CategoryTree".

function AppendCategoryTreeToSidebar() {
    try {
        var node = document.getElementById( "p-tb" )
                           .getElementsByTagName('div')[0]
                           .getElementsByTagName('ul')[0];
 
        var aNode = document.createElement( 'a' );
        var liNode = document.createElement( 'li' );
 
        aNode.appendChild( document.createTextNode( 'CategoryTree' ) );
        aNode.setAttribute( 'href' , '[[w:Special:CategoryTree]]' );
        liNode.appendChild( aNode );
        liNode.className = 'plainlinks';
        node.appendChild( liNode );
    } catch(e) {
        // lets just ignore what's happened
        return;
    }
}
 
addOnloadHook( AppendCategoryTreeToSidebar );

A more generic version of this code can be found at Manual:Interface/Sidebar#content of sidebar and toolbox (javascript) .

Step by step if works easy:

$wgCategoryTreeSidebarRoot = 'Category:article_name';

つう过MediaWiki: 命名めいめいそら间页めん

If you want to create a link that goes to the generic categorytree (displayed as Category tree) when you're on a non-category page, and to a particular categorytree (displayed as View as category tree, with foo being the name of the category you're viewing) when you're on a category page:

  • Add to your MediaWiki:Sidebar (right above the SEARCH is a good place) a line, ** sidebarcategorytree-url|sidebarcategorytree
  • Create a [[MediaWiki:Sidebarcategorytree]] with, say: {{#ifeq: {{NAMESPACE}}|Category|View as category tree|Category tree}}
  • Create a [[MediaWiki:Sidebarcategorytree-url]] with, say: {{#ifeq: {{NAMESPACE}}|Category|Special:CategoryTree/{{BASEPAGENAME}}|Special:CategoryTree/Categories}}

See also