Skip to content

Add more parser functions and magic words - #87

Merged
bonelifer merged 2 commits into
mainfrom
parser-functions-more
Oct 15, 2026
Merged

bonelifer merged 2 commits into
mainfrom
parser-functions-more

Conversation

@bonelifer

Copy link
Copy Markdown
Contributor

Adds the parser functions and magic words that Wikipedia's templates use and the wiki didn't have yet.

  • {{#titleparts: A/B/C | count | first}}: parts of a name split at /.
  • {{#rel2abs: ../Other | base}}: works out a name from ./, ../ and /. Without base, it uses the article being shown.
  • {{#tag: center | text | attribute=value}}: writes out an HTML tag, which is then parsed with the article. Only HTML that articles may already use takes effect; anything else, such as script, shows as text.
  • {{formatnum:}}: adds commas as thousands separators, and R removes them. {{plural:}} uses the English rule. {{gender:}} always gives the neutral form, because phpBB keeps no gender.
  • {{#timel:}}: #time in the reader's time zone, with month and day names in the reader's language. #time is unchanged (UTC, English).
  • {{LOCALYEAR}}, {{LOCALTIME}} and the other LOCAL... words: the CURRENT... words in the board's time zone.
  • {{REVISIONID}}, {{REVISIONUSER}}, {{REVISIONTIMESTAMP}} and the REVISION... date words: the article's current approved version. They are empty before the article is first approved.

Function names may now contain digits (needed for #rel2abs), in both the template engine and the article parser. The template service now gets @user for #timel. #invoke (Lua) is still not planned.

Testing:

  • Unit tests for each function were added; the suite passes on phpBB 3.3 and 4.0.
  • Claude also tried the functions in an article preview on a 3.3 and a 4.0 test board.
  • The REVISION... words gave the right number, user and time on a saved template page.

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

🤖 Generated with Claude Code

bonelifer and others added 2 commits October 15, 2026 00:35
#titleparts, #rel2abs, #tag, #timel, formatnum, plural and gender,
the LOCAL... date words in the board's time zone, and the REVISION...
words for the article's current approved version. #timel is #time in
the reader's time zone and language; #time stays UTC and English.
#tag writes HTML that is then parsed with the article, so only what
articles may use takes effect.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
phpBB 4.0's code sniffer refuses the ?Type shortcut.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bonelifer
bonelifer merged commit 74d3538 into main Oct 15, 2026
58 checks passed
@bonelifer
bonelifer deleted the parser-functions-more branch October 15, 2026 05:57
bonelifer added a commit that referenced this pull request Oct 15, 2026
A template call written in an article, and a parameter's default value
(`{{{name|...}}}`), may now hold other calls 8 levels deep. It was 3 for
calls and 1 for defaults. **Template nesting depth** under **Extensions
> Wiki > Settings** changes it, from 3 to 20. Deeper calls show as
written.

Saved articles need reparsing to follow a new depth. A new cron task
does that 50 articles at a time on ordinary page views, after this
update and after each change of the setting. The settings page shows a
note while it is running. When it finishes, the category memberships are
worked out again, since a call that is now read (or no longer read) can
add or drop a category.

The reparse can't run in the migration: the wiki's listeners aren't
loaded while the extension is being enabled, so a reparse there would
turn every article's headings and templates into plain text. The
migration only queues it. This update also gets the call forms added in
#87 (`{{formatnum:}}`, `{{#rel2abs:}}` and others) reparsed in existing
articles. The README's older "run the reparser after upgrading" notes
now point to the background reparse.

Testing:
- Unit tests for the limit at 8, the setting at 3 and 9, the depth range
and the reparse queue. The suite passes on phpBB 3.3 and 4.0.
- Claude timed the call pattern on large test articles at depths 3 to
20: under 1 ms in every case.
- On a 3.3 test board, Claude put the board back to its pre-update state
and ran the update. The reparse turned a 6-deep call into a call and
kept every other article's templates and headings. Lowering the setting
to 3 turned the call back into text, and raising it to 8 brought it
back. An article whose deep call adds a category joined that category
after the reparse.
- On a 4.0 test board, Claude ran the update and the reparse; no markup
was lost.

---

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

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 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