Page MenuHomePhabricator

noreferences.py incorrectly inserts references template below footer templates
Open, Needs TriagePublic

Description

Steps to replicate:

What happens?:
The script matches and skips portal/footer templates (like {{portal bar}}, {{commons category}} and/or navigation templates) immediately under the heading because the templates_or_comments regex matches all templates. This pushes {{reflist}} to the bottom of the section, below those templates.

What should happen?:
The references list should be placed immediately under the heading (skipping HTML comments). Why was the original regex designed to match and skip templates in a references section?

Software version: 11.3.0

Proposed solution:
Modify the regex to only match and skip HTML comments instead of templates:

-     r'^((?:\s*(?:\{\{[^\{\}]*?\}\}|<!--.*?-->))*)',
+     r'^((?:\s*(?:<!--.*?-->))*)',

Also, please find templates_or_comments (2 matches) and replace them with comments, or whatever you think fits best.

Event Timeline

Aram renamed this task from noreferences.py incorrectly inserts references template below portal/footer templates to noreferences.py incorrectly inserts references template below footer templates.May 20 2026, 7:43 PM
Gkm563 subscribed.

I would like to work on this task. I am investigating the regex behavior and testing the proposed fix.

Submitted a patch for review:

https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1290141

The fix updates the regex so only HTML comments are skipped when inserting references, preventing footer templates from being skipped.

Why was the original regex designed to match and skip templates in a references section?

See T159307 (noreferences.py should add <references /> under templates), rPWBCa769fb6e, changed with Pywikibot 3.0.20200306

The current request would revert this previous issue.

@JAnD: Do you have any idea how to resolve the contradiction?

Xqt changed the subtype of this task from "Bug Report" to "Task".
Xqt moved this task from Backlog to references on the Pywikibot-Scripts board.

Change #1290141 had a related patch set uploaded (by Gkm563; author: Gkm563):

[pywikibot/core@master] Add regression test for comments in noreferences section

https://gerrit.wikimedia.org/r/1290141

@Gkm563 : Thank you for the additional test method. Please add yourself to the AUTHORS.rst file.

@Gkm563 Thanks for taking care of the task. I also updated the proposed solution to change the missing templates_or_comments to comments.

See T159307 (noreferences.py should add <references /> under templates), rPWBCa769fb6e, changed with Pywikibot 3.0.20200306
The current request would revert this previous issue.

@Xqt Thanks for finding the old task. I completely understand the need for the Překlad template on that wiki. However, the current logic affects all templates globally. When == References == is the last section, noreferences.py breaks the layout for other wikis by adding <references /> at the very bottom.
Perhaps it would be better to place the Překlad template in a different section rather than References? Alternatively, we could use a skip list for specific wikis. This way, we can support that specific wiki without accidentally breaking the layout for everyone else.

Change #1290141 merged by Xqt:

[pywikibot/core@master] Add regression test for comments in noreferences section

https://gerrit.wikimedia.org/r/1290141