見出しの HTML の変更
ウィキテキスト ページの見出しの HTML マークアップは、MediaWiki 1.43 の一環として2024年に変更されました。 各見出しの周囲にラッパーが追加され、テキスト以外の要素 (節編集リンクなど) は見出し自体からラッパー内へ移動されました。 この変更は T13555 で追跡されていました。
変更点
編集者と閲覧者には視覚的な変更は生じないはずです。 ただし、見出しに影響する外装、拡張機能、ガジェットの保守担当者は、その利用者に問題が生じるのを避けるために、それらを更新する必要があります。
| ウィキテキスト | 旧 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>
<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 2023 – As a trial for this change, “hybrid” markup with wrappers is introduced for level-2 headings on discussion pages using DiscussionTools (T314714)
- December 2023 – Implementation of wrappers is corrected (T353489)
- February 2024 – New markup enabled for users testing the new Parsoid parser (T269630)
- May 21–23, 2024 – New markup enabled for users of skins: MonoBook, Timeless, Modern, CologneBlue, Nostalgia (T365078)
- June 4–6, 2024 – New markup enabled for users of the Vector legacy skin (T365736)
- June 11–13, 2024 – New markup enabled for users of the MinervaNeue skin (T365736)
- July 16–18, 2024 – New markup enabled for users of the Vector 2022 skin. At this point all major skins have been changed. (T367601)
MediaWiki releases
- MediaWiki 1.43 –
- Config option $wgParserEnableLegacyHeadingDOM added, defaults to legacy markup (change 842859)
- Bundled skins MonoBook and Timeless support the new markup
- MediaWiki 1.44 –
- Config option $wgParserEnableLegacyHeadingDOM changed, it now defaults to the new markup if the skin indicates support (change 1023980)
- Bundled skins MinervaNeue, Vector legacy and Vector 2022 also support the new markup
- Headings written using the HTML syntax in wikitext (e.g.
<h2 class="myclass">Heading</h2>) now have themw-html-headingclass automatically added, to make it easier to distinguish them in CSS and JS selectors
- MediaWiki 1.45 –
- Config option $wgParserEnableLegacyHeadingDOM removed, new markup is always used regardless of the skin (change 1143895)
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:
- Wherever you used a selector like
h1, h2, h3, h4, h5, h6, add.mw-heading. - Wherever you used a selector like
hN, add.mw-headingN. - Wherever you used the selector
.mw-headline, addh1, h2, h3, h4, h5, h6. - For any styles applied to both
hNand.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).
| 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:
- https://gerrit.wikimedia.org/r/c/mediawiki/skins/Timeless/+/857770/10/resources/screen-common.less
- https://fr.wikipedia.org/w/index.php?title=MediaWiki:Common.css&diff=prev&oldid=212874402
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:
- https://gerrit.wikimedia.org/r/c/mediawiki/core/+/1009803/1/resources/src/mediawiki.misc-authed-pref/rightClickEdit.js
- https://gerrit.wikimedia.org/r/c/mediawiki/extensions/VisualEditor/+/859139/12/modules/ve-mw/init/targets/ve.init.mw.ArticleTarget.js
- https://gerrit.wikimedia.org/r/c/mediawiki/extensions/MobileFrontend/+/857772/12/src/mobile.init/editor.js
- https://gerrit.wikimedia.org/r/c/mediawiki/skins/Vector/+/860583/9/resources/skins.vector.js/setupIntersectionObservers.js
- https://ru.wikipedia.org/w/index.php?title=MediaWiki:Gadget-edittop.js&diff=prev&oldid=136450234
- https://en.wiktionary.org/w/index.php?title=MediaWiki:Gadget-TabbedLanguages.js&diff=prev&oldid=78700885
- https://en.wikivoyage.org/w/index.php?title=MediaWiki:Gadget-ListingEditor2023.js&diff=prev&oldid=4832346
- https://fr.wikipedia.org/w/index.php?title=MediaWiki:Gadget-AncreTitres.js&diff=215319381&oldid=213586059
- https://commons.wikimedia.org/w/index.php?title=MediaWiki:Gadget-DelReqHandler.js&diff=prev&oldid=879159945
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: