Background
While working on the table of contents @bwang noticed some issues with the data format we landed on as part of T287767. Specifically the nesting level for lists is incorrect. In the example below, each li element of the same level (i.e. "sidebar-toc-level-1") should be siblings in the same list.
<nav> <ul id="table-of-contents"> <li class="sidebar-toc-level-1"> <a href="#Heading">Heading</a> <ul> <li class="sidebar-toc-level-2"> <a href="#Subheading_1">Subheading 1</a> <ul> <li class="sidebar-toc-level-3"> <a href="#Subheading_2">Subheading 2</a> </li> </ul> </li> <li class="sidebar-toc-level-1"> <a href="#Heading_2">Heading</a> </li> </ul> </li> </ul> </nav>
Given MediaWiki 1.38 hasn't been released yet we are likely to make potentially breaking changes to the format prior to the release. We are not aware of anyone using this yet so that should be fine.
A better format would allow recursive access
Acceptance criteria
- Data returned in the required format
- Make sure unit tests cover the function
Developer notes
- Modify the private Skin::getSectionsData to change the return value.
e.g.
Section = { Section[]: subsections, string: heading }
QA steps
- Add some test headings to a local sample page - snippet below has a sampling of embedded sections:
== Plot summary == the Plot == Heading == Macaroon tiramisu sesame snaps gummies cheesecake tart chocolate tootsie roll chocolate cake. Tart brownie oat cake chocolate bar muffin gummi bears fruitcake. Topping bonbon candy canes tootsie roll tart. === Sub Heading === Donut toffee danish bonbon bonbon shortbread cupcake croissant marzipan. Cheesecake gummi bears cotton candy liquorice sesame snaps liquorice marshmallow macaroon. === Another Sub Heading === Jelly-o dessert gummi bears cotton candy candy caramels chocolate cake cotton candy. Donut cookie sweet roll cupcake cotton candy icing croissant chupa chups soufflé. ==== Sub Sub Heading 1 ==== Jelly cheesecake chocolate jujubes dragée wafer candy jelly. Sesame snaps bear claw fruitcake bonbon carrot cake apple pie. ===== Sub Sub Sub Heading 1 ===== Carrot cake icing icing chupa chups cake toffee topping shortbread. Cotton candy jelly-o donut pie sesame snaps dessert pie oat cake. ===== Sub Sub Sub Heading 2 ===== Cake sugar plum candy canes lollipop donut tootsie roll chocolate bar pudding macaroon. Ice cream powder carrot cake bear claw chocolate caramels cheesecake. ====== Sub Sub Sub Sub Heading 1 ====== Cake sugar plum candy canes lollipop donut tootsie roll chocolate bar pudding macaroon. Ice cream powder carrot cake bear claw chocolate caramels cheesecake. Candy canes lollipop brownie lemon drops croissant tart lollipop cake chocolate bar. ===== Sub Sub Sub Heading 3 ===== Candy canes lollipop brownie lemon drops croissant tart lollipop cake chocolate bar. ==== Sub Sub Heading 2 ==== Topping bonbon candy canes tootsie roll tart.Jelly cheesecake chocolate jujubes dragée wafer candy jelly. Sesame snaps bear claw fruitcake bonbon carrot cake apple pie. Donut toffee danish bonbon bonbon shortbread cupcake croissant marzipan. == Another Heading == Bonbon jelly soufflé cake shortbread halvah. Chupa chups chocolate cookie cupcake cake. Marzipan caramels shortbread chocolate cake bear claw muffin. Sweet roll macaroon biscuit halvah sugar plum cotton candy. Oat cake pudding wafer oat cake chocolate cake marzipan dragée. == Yet Another Heading == Gummi bears pudding tootsie roll tootsie roll sweet roll tart jelly-o topping sweet. Dragée soufflé tiramisu candy bonbon oat cake. Lemon drops pie sesame snaps cake sweet roll jelly-o croissant sweet. Sweet roll biscuit ice cream gummies muffin tiramisu dragée. Cake sweet roll soufflé croissant dessert ice cream jelly beans. Lollipop soufflé cupcake gummies apple pie sugar plum. Pie jelly croissant dragée dragée. === Sub Heading 1 === Dragée sweet shortbread brownie pastry tart apple pie shortbread chocolate. Candy canes cheesecake ice cream chupa chups chocolate bear claw wafer. Ice cream gingerbread pudding tart sweet roll. Sweet marzipan pastry chupa chups carrot cake powder candy soufflé. Apple pie jujubes powder cheesecake chupa chups shortbread. Gummies topping cupcake cake oat cake tart chupa chups dragée cookie. ==== Sub Sub Heading 1 ==== Jelly cheesecake chocolate jujubes dragée wafer candy jelly. Sesame snaps bear claw fruitcake bonbon carrot cake apple pie. Donut toffee danish bonbon bonbon shortbread cupcake croissant marzipan. Cheesecake gummi bears cotton candy liquorice sesame snaps liquorice marshmallow macaroon. ===== Sub Sub Sub Heading 1 ===== Carrot cake icing icing chupa chups cake toffee topping shortbread. Cotton candy jelly-o donut pie sesame snaps dessert pie oat cake. Jelly-o dessert gummi bears cotton candy candy caramels chocolate cake cotton candy. Donut cookie sweet roll cupcake cotton candy icing croissant chupa chups soufflé. ===== Sub Sub Sub Heading 2 ===== Cake sugar plum candy canes lollipop donut tootsie roll chocolate bar pudding macaroon. Ice cream powder carrot cake bear claw chocolate caramels cheesecake. ====== Sub Sub Sub Sub Heading 1 ====== Cake sugar plum candy canes lollipop donut tootsie roll chocolate bar pudding macaroon. === Sub Heading 2 === Marzipan gummies sesame snaps marshmallow muffin. Croissant danish liquorice ice cream soufflé tiramisu pie cake cupcake. == Heading Again == Dragée soufflé tiramisu candy bonbon oat cake. Lemon drops pie sesame snaps cake sweet roll jelly-o croissant sweet. Sweet roll biscuit ice cream gummies muffin tiramisu dragée. Cake sweet roll soufflé croissant dessert ice cream jelly beans. Lollipop soufflé cupcake gummies apple pie sugar plum. == More Headings == Jelly cheesecake chocolate jujubes dragée wafer candy jelly. Sesame snaps bear claw fruitcake bonbon carrot cake apple pie. == heading 1 == === heading 2 === ==== heading 3 ==== ===== heading 4 ===== ====== heading 5 ====== ====== heading 6 ===== === heading 7 (2) === == test 1 == === test 2 === ==== test 3 ==== ===== test 4 ===== ====== test 5 ====== ====== test 6 ====== ====== test 7 ====== ==== test 8 (3) ==== == test 9 (1) ==
- The snippet above will produce a TOC like so:
- Set a breakpoint (or var_dump the value) on the return of Skin::getSectionsData() to look at the updated, nested TOC data array.
- Child sections should be nested under their parent sections inside the parent's array-sections key and sections without child sections should have an empty array-sections array: