Jump to content

見出しの HTML の変更

From mediawiki.org
This page is a translated version of the page Heading HTML changes and the translation is 27% complete.

ウィキテキスト ページの見出しの HTML マークアップは、MediaWiki 1.43 の一環として2024年に変更されました。 各見出しの周囲にラッパーが追加され、テキスト以外の要素 (節編集リンクなど) は見出し自体からラッパー内へ移動されました。 この変更は T13555 で追跡されていました。

変更点

編集者と閲覧者には視覚的な変更は生じないはずです。 ただし、見出しに影響する外装、拡張機能、ガジェットの保守担当者は、その利用者に問題が生じるのを避けるために、それらを更新する必要があります。

見出しタグの古い HTML ソースと新しい HTML ソースの例
ウィキテキスト 旧 HTML 新 HTML
== Heading ==
<h2>
    <span class="mw-headline" id="...">Heading</span>
    <span class="mw-editsection">...</span>
</h2>
<div class="mw-heading mw-heading2">
    <h2 id="...">Heading</h2>
    <span class="mw-editsection">...</span>
</div>
<h2 class="myclass">
  Heading
</h2>
<h2 class="myclass">
    <span class="mw-headline" id="...">Heading</span>
</h2>
<h2 id="..." class="myclass">Heading</h2>
MediaWiki 1.44 以降 (T68637)
<h2 id="..." class="myclass mw-html-heading">Heading</h2>

この変更は、大半の特別ページにも、Parsoid の編集モードのコンテンツにも適用されません。これらは引き続き単純な <h2>...</h2> マークアップを使用します。

この変更をする理由

この変更により、スクリーン リーダー利用者のアクセシビリティが向上します。 自動生成される目次のように、ページ上にある見出しを使ってページ内を移動することは一般的な操作方法です。 古いマークアップでは、節編集リンクのようなインターフェイス要素が各見出しの一部となっていたため、それらも各見出しのテキストとともに読み上げられていました。 この問題は、ビジュアルエディターの「ソースを編集」リンクや議論ツールの「購読」ボタンなど、見出しにさらにインターフェイス要素を追加する拡張機能によって、さらに悪化していました。

オプトアウト

この動作を制御するための利用者個人設定は提供されていません。

In MediaWiki 1.43 and 1.44, site owners may use the config option $wgParserEnableLegacyHeadingDOM to control which markup is used. This option was removed in MediaWiki 1.45.

Skin developers targeting MediaWiki 1.43 and 1.44 may use the supportsMwHeading skin option to control which markup is used. This option was removed in MediaWiki 1.45.

When using Parsoid for page views, the new markup is used unconditionally.

Timeline

Wikimedia wikis

  • January 2023As a trial for this change, “hybrid” markup with wrappers is introduced for level-2 headings on discussion pages using DiscussionTools (T314714)
  • December 2023Implementation of wrappers is corrected (T353489)
  • February 2024New markup enabled for users testing the new Parsoid parser (T269630)
  • May 21–23, 2024New markup enabled for users of skins: MonoBook, Timeless, Modern, CologneBlue, Nostalgia (T365078)
  • June 4–6, 2024New markup enabled for users of the Vector legacy skin (T365736)
  • June 11–13, 2024New markup enabled for users of the MinervaNeue skin (T365736)
  • July 16–18, 2024New markup enabled for users of the Vector 2022 skin. At this point all major skins have been changed. (T367601)

MediaWiki releases

Instructions for updating code

Skins and sitewide styles

Skins that use ResourceLoaderSkinModule configured with "features": { "elements": true } may not need any changes at all, since the built-in heading styles were updated.

Your styles should be compatible with three kinds of markup at the same time: the new markup, the old markup (because site owners may choose to use it), and the simple markup with no wrappers (used by most special pages and Parsoid edit-mode content).

As a general guideline, styles for the heading blocks (e.g. background or borders) need to apply to both .mw-heading and h1-h6 (except when nested in .mw-heading), while styles for heading text (e.g. fonts and text colors) need to apply to h1-h6 and .mw-headline.

MediaWiki 1.44 以降 The .mw-html-heading selector can be used to match headings written using the HTML syntax in wikitext (e.g. <h2 class="myclass">Heading</h2>). A selector like .mw-heading, .mw-html-heading can be used to match all wikitext headings on the page.

You can follow these rules of thumb to update your code:

  1. Wherever you used a selector like h1, h2, h3, h4, h5, h6, add .mw-heading.
  2. Wherever you used a selector like hN, add .mw-headingN.
  3. Wherever you used the selector .mw-headline, add h1, h2, h3, h4, h5, h6.
  4. For any styles applied to both hN and .mw-headingN, unset them when the heading is nested in the wrapper, using a selector like .mw-heading hN.

Once the config option for site owners is removed in a future release of MediaWiki, you will be able to remove selectors that were only needed to support the old markup (such as .mw-headline or hN .mw-editsection).

Example changes
Old CSS Upgraded CSS Upgraded CSS MediaWiki 1.44 以降
h2 {
    border: 1px solid black;
    background-color: red;
    color: white;
    font-size: 2em;
}
.mw-heading2, h2 {
    border: 1px solid black;
    background-color: red;
    color: white;
    font-size: 2em;
}
.mw-heading2 h2 {
    border: none;
    font-size: inherit;
}
.mw-heading2,
h2.mw-html-heading {
    border: 1px solid black;
    background-color: red;
    color: white;
    font-size: 2em;
}

Example changes:

Extensions and gadgets

There isn't a simple pattern like for styles, but in general you'll need to update your code to work with either of the HTML structures. Sometimes it can be as easy as changing the selectors, similar to the section above.

Example changes:

Wiki content

TemplateStyles targeting plain h2 etc. selectors need to be updated similarly to skins, see above. Once all skins in your wiki use the new markup, you will be able to remove selectors that were only needed to support the old markup (such as .mw-headline or hN .mw-editsection).

Inline styles, and TemplateStyles targeting custom CSS classes, do not require any changes, because the wrappers are not added on headings written using HTML-style <h2> markup if there are attributes. Doing so caused too many issues with existing markup, and the motivation for the change does not apply, because these headings do not have interface elements like section edit links (T353489#9416500).

Example changes: