Skip to content

Add Wikipedia-style headings, section links and a table of contents - #39

Merged
bonelifer merged 3 commits into
mainfrom
feature/wikitext-headings
Oct 12, 2026
Merged

bonelifer merged 3 commits into
mainfrom
feature/wikitext-headings

Conversation

@bonelifer

Copy link
Copy Markdown
Contributor

What this does

First step of the Wikipedia-syntax work in docs/TODO/todo-wiki-markup.md: headings and a table of contents, plus the links that point at them. It also closes the "Table of contents" item in docs/TODO.md.

  • Headings. == Heading == to ====== Heading ====== on a line of their own become h2 to h6 with an anchor. Repeated headings get _2, _3. A line that does not match exactly (a == b, == unfinished, seven =) stays text.
  • Table of contents. A numbered "Contents" box (1, 1.1, 1.2, 2 …) shows after the intro and before the first heading when an article has four or more headings, as in MediaWiki. __TOC__ places it where it is written and shows it for any number of headings, __FORCETOC__ shows it for any number, __NOTOC__ hides it. Its title is translated (English and German).
  • Section links. [[Article#Section]], [[Article#Section|text]] and [[#Section]] (a link into the same page) point at the heading's anchor. They also work in forum posts, as [[links]] already do.
  • #REDIRECT [[Article]]. A first line like this sets the article's redirect, for members who may set redirects; for everyone else it stays text.
  • Wiki articles only. The parser reads headings and the __…__ words only while a wiki article is saved or previewed: the tags are switched on in core.text_formatter_s9e_parse_before and off again straight after, so in a forum post, private message or signature == text == and __TOC__ stay plain text. The anchors and the table of contents are built when the article is shown, from the rendered headings, so they never go stale.
  • BBCode is unchanged. The new syntax is an addition; articles written only in BBCode behave as before, except that a line that is only == text ==, or one of the __…__ words, now means what it means in MediaWiki.
  • Existing articles. A migration rebuilds the text formatter's tag list and reparses the saved articles in steps of 50, and the extension's text reparser (reparser:reparse) now reads the same markup, so == lines in older articles become headings.
  • Styles for headings and the contents box, a README paragraph, and updated TODO notes.

Not in this PR: text styles ('''bold''', lists), references, tables, categories and templates, and a setting to turn the Wikipedia markup off for a whole board.

Testing

Claude ran a 13-check browser script on a phpBB 4.0 (master) board seeded with the wiki fixtures, and again on fresh phpBB 3.3.19 boards with MySQL 8.0 and with PostgreSQL 16 (13 of 13 on each):

  • headings become h2/h3 with anchors, a repeated heading gets _2, the box lists 1 History / 1.1 Early years / 1.2 Later years / 2 History / 3 See also, sits after the intro and before the first heading, and its links jump to the headings;
  • two headings give no box; __TOC__ places it and shows it for two headings; __NOTOC__ hides it with five headings;
  • section links carry the right anchors, including [[#Early years]] as a same-page link;
  • #REDIRECT [[Main Page]] sets the redirect for a moderator and sets nothing for an editor who may not set redirects;
  • the edit preview renders headings;
  • in a forum post == Not a heading == and __TOC__ stay plain text while [[Main Page#Part]] still links.

On the 4.0 and 3.3 boards the reparser was run on an article saved before the change, and its == line became a heading; screenshots of the contents box on both boards look right. 31 new unit tests cover anchors, the redirect line, the contents markup (balanced when levels jump), __TOC__/__NOTOC__/__FORCETOC__, and the parser configuration with the real s9e library (heading levels, near-misses that stay text, tags off when the markup is off, magic words, section links, broken links, [[File:]] unchanged). All 109 wiki unit tests pass, and the new and changed PHP files lint clean on PHP 8.5.


Investigated and written by Claude on behalf of William Jacoby (bonelifer).

bonelifer and others added 3 commits October 12, 2026 14:13
== Heading == to ====== Heading ====== become h2 to h6 with anchors, a
table of contents shows after the intro for four or more headings (__TOC__
places it, __FORCETOC__ forces it, __NOTOC__ hides it), [[Article#Section]]
and [[#Section]] link to a heading, and a first line #REDIRECT [[Article]]
sets the redirect. The text parser reads this only while a wiki article is
saved or previewed, so forum posts are unchanged. A migration rebuilds the
text formatter and reparses saved articles.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@bonelifer
bonelifer force-pushed the feature/wikitext-headings branch from 74bbffa to 256dfd8 Compare October 12, 2026 19:14
@bonelifer

Copy link
Copy Markdown
Contributor Author

Rebased onto main after the Watch PR (#38) merged: link.php in both languages and the README each had both sides' additions, kept together. Nothing else changed. The branch was force-pushed with a lease; the three commits are the same changes as before.


Investigated and written by Claude on behalf of William Jacoby (bonelifer).

@bonelifer
bonelifer merged commit b5fe64c into main Oct 12, 2026
58 checks passed
@bonelifer
bonelifer deleted the feature/wikitext-headings branch October 12, 2026 19:23
bonelifer added a commit that referenced this pull request Oct 12, 2026
…t changes columns (#40)

Three fixes found while taking screenshots for the update post. All
three come from #39 (headings and table of contents).

**Section links showed no text.** `[[#Section]]` rendered an empty link,
so "See [[Getting Started#Editing]] and [[#Publishing]]" read "See
Getting Started and ." They now show the article name plus `#section`,
as MediaWiki does: `[[#Publishing]]` shows "#Publishing" and `[[A#B]]`
shows "A#B". An explicit label (`[[A#B|label]]`) is unchanged.

**Fresh CLI installs had no wiki tags.** `add_wiki_markup` rebuilds the
text formatter cache while the extension is being enabled, before the
extension's listeners are registered. The cache it stored had no wiki
tags, so `[[links]]`, `[[File:]]` embeds and headings did not parse
until something purged the cache. The new migration
`purge_text_formatter_cache` runs after it and clears the cache, so
phpBB rebuilds it with the wiki's tags on the next page.
`add_wiki_markup` itself is untouched, because it may already have been
applied on existing boards.

**Correction to #39:** its description said a migration reparses saved
articles. It does not. Articles saved earlier are converted with `php
bin/phpbbcli.php reparser:reparse phpbbmodders_wiki_article`. The README
already said this; `docs/TODO/todo-wiki-markup.md` now matches it.

**Recent changes columns.** The Reason and Status headers had the `big`
class, which squeezed the Article column. Status is now `middle` and
Reason has no width class.

**Screenshots.** `docs/update/2026-10-12/` holds the screenshots for the
update post, plus a `README.md` that shows them all. The folder is
export-ignored, so it is not in the release zip.

**Tests**
- Unit tests: 124 tests, 257 assertions, all pass. They include a new
`link_texts` data provider with five cases.
- Fresh install with no manual cache purge, then fixtures seeded: MySQL
8.0 and PostgreSQL 16 both show 48 of 86 articles with `WIKILINK` tags
and 2 with `WIKIFILE`.
- `wiki-markup-test.js` browser run: 13 of 13 on phpBB 4.0.0-a3-dev with
SQLite. On 3.3.19 with SQLite the first 10 checks pass. I stopped it
there because the next check needs a user without the redirect
permission, and that board only has `admin`.

---

Investigated and written by [Claude](https://www.anthropic.com/claude)
on behalf of William Jacoby ([bonelifer](https://github.com/bonelifer)).

---------

Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant