Page MenuHomePhabricator

Include HTML template in a wiki page
Closed, DeclinedPublic

Description

Author: apb

Description:
For the www.wikipedia.org portal, we want to include a search form in
the middle of a page. See [[meta:Www.wikipedia.org portal/Catherine]]
for a non-functional mockup.

Please add a way to include a template as HTML rather than as
wikitext. For example, {{msghtml:name of template}}, by analogy with
{{mshnw:name of template}}. For safety, it should not work unless
both the template itself and the page that uses {{msghtml:}} are
protected. However, it should work if a non-protected page includes a
protected notmal template, which in turn includes a protected msghtml
template.

If the above is implemented, then we will be able to:

  1. create a protected HTML template "template:search box html"

containing raw HTML code to display a search box.

  1. create a protected normal template "template:search box", which

uses "{{msghtml:search box html}}".

  1. on any protected or unprotected page, use "{{search box}}" to get a

search box.


Version: unspecified
Severity: enhancement

Details

Reference
bz1561
TitleReferenceAuthorSource BranchDest Branch
Migrate and refactor Refine into Airflow dynamic DAGrepos/data-engineering/airflow-dags!617aquT356362_dynamic_dag_pocmain
Guard against failed initial importsrepos/mediawiki/services/ipoid!223stranmain-I53c4b418a231762c7c0220cc8e23f26f0f8dcaa9main
drop_cl_collation_ext_T356166.py: New schema changerepos/sre/schema-changes!5marosteguiT356166main
Update function-schemata sub-module to HEAD (bd1742b)repos/abstract-wiki/wikifunctions/wikilambda-cli!28jforrestersync-function-schematamain
Update function-schemata sub-module to HEAD (bd1742b)repos/abstract-wiki/wikifunctions/function-evaluator!146jforrestersync-function-schematamain
Update function-schemata sub-module to HEAD (bd1742b)repos/abstract-wiki/wikifunctions/function-orchestrator!125jforrestersync-function-schematamain
Simplify Docker configrepos/cloud/toolforge/lima-kilo!96fnegrivz-dockermain
definitions: Add Z1920/igb ZNaturalLanguagerepos/abstract-wiki/wikifunctions/function-schemata!80jforresterlanguage-igbmain
Customize query in GitLab

Event Timeline

bzimport raised the priority of this task from to Lowest.Nov 21 2014, 8:16 PM
bzimport set Reference to bz1561.
bzimport added a subscriber: Unknown Object (MLST).

rowan.collins wrote:

(In reply to comment #0)

However, it should work if a non-protected page includes a
protected notmal template, which in turn includes a protected msghtml
template.

I don't get the purpose of the intermediate step here: if Template:bar includes
nothing but {{msghtml:foo}}, and I use {{bar}}, how is that different (and,
specifically, safer) than me just using {{msghtml:foo}} directly?

I also think doing this generically would be rather difficult, whereas the
www.wikipedia.org portal (as I understand it) already involves magic pages which
are interpretted as HTML rather than wikicode, so that special case code could
probably be extended to have a few extra levels of abstraction if necessary. :)
[But then, I *don't* know how the current setup works, so I probably shouldn't
interfere.]

apb wrote:

(In reply to comment #1)

I don't get the purpose of the intermediate step here: if Template:bar
includes nothing but {{msghtml:foo}}, and I use {{bar}}, how is that
different (and, specifically, safer) than me just using {{msghtml:foo}}
directly?

Postulate a protected page {{baz}}, which is not written in HTML, but which
would cause bad effects if treated as if it were written in HTML. Now let an
untrusted user says {{msghtml:baz}} on an unprotected page. Then the bad
effects happen. If non-protected pages were not allowed to use {{msghtml:}},
this problem would not arise.

I also think doing this generically would be rather difficult, whereas the
www.wikipedia.org portal (as I understand it) already involves magic pages
which are interpretted as HTML rather than wikicode, so that special case
code could probably be extended to have a few extra levels of abstraction
if necessary. :)

The special case code currently has exactly two levels. A "portal" page is
written in wikicode, and a "template" page is written in HTML. The HTML
template is allowed to contain a magic "$1" which means "insert HTML equivalent
of portal page here. Something in the apache config invokes extract2.php to mix
everything together.

apb wrote:

(In reply to comment #1)

I also think doing this generically would be rather difficult

If it's difficult to do generically, would it be feasible to have a few
predefined HTML templates? For example, could "Mediawiki:Search form for www.
wikipedia.org portal" be treated as a special case (via some sort of list of
special cases in the software config)? Even better, could any page that matches
the pattern "Mediawiki:HTML template/*" be treated as HTML? If so, then one
could have a protected page like "Mediawiki:HTML template/Search form for www.
wikipedia.org portal" with the right HTML code, and just say "{{Mediawiki:HTML
template/Search form for www.wikipedia.org portal}}" in the wikicode for the
portal.

Having well-known names for all HTML templates would remove the need to prohibit
non-protected pages from using HTML templates, because it would be impossible to
cause a non-HTML template to be treated as an HTML template.

Even if the list of HTML templates did not have any scope for wildcard patterns,
it would be good enough to use.

apb wrote:

How about using the extension mechanism ([[meta:
Write_your_own_MediaWiki_extension]]) to define a <rawhtml>...</
rawhtml> extension? Can an extension figure out whether it is be
ing invoked on a protected page? I imagine something like

function renderRawhtml($input) {

if ($page_is_protected) {
    return $input;
} else {
    return treat_like_nowiki_text($input);
}

}

apb wrote:

Or what if Sanitizer::removeHTMLtags() in phase3/includes/Sanitizer.php just
allowed a few extra things (like <form>, <input>, <button>) on protected pages,
perhaps under control of yet another site config option?

Or what if the definition of $wgRawHtml was changed to allow it to work on
protected pages even if $wgWhitelistEdit was false (see strip() in phase3/
includes/Parser.php)?

apb wrote:

I am still trawling the source code for ideas.

Would it work to just put some HTML code in a protected page named "Mediawiki:
searchbox", and use "{{int:searchbox}}" from any other page? The code in
Parser.php that handles MAG_INT calls wfMsgReal(), which seems to look up the
message in the mediawiki namespace and treat it as raw html. But I am not sure
whether it gets sanitised later (which would break it).

As has been explained several times, linking HTML execution to page protection is extremely unsafe.

A page's being protected does *not* mean it was written and vetted by a trusted administrator; many
protected pages are involved in edit wars for instance, and contain whatever someone left them as.
Template inclusions from there make it a huge security risk.

I'm not sure what this has to do with the magic portal page. If a special case is required, a parser extension
is my strong recommendation.

apb wrote:

(In reply to comment #7)

A page's being protected does *not* mean it was written and vetted by a
trusted administrator;

Good point. But does that also apply to text on pages in the mediawiki
namespace? (Is it possible to have a page in the mediawiki namespace that was
not written by a trusted administrator?)

a parser extension is my strong recommendation.

I'd prefer it if somebody who was familiar with the code did the work, but I am
willing to look into doing it myself. Do you have any suggestions?

Reassigned to enhancement severity, as this is a feature request.

apb wrote:

Could the new <inputbox> extension be enhanced to
support what is wanted at www.wikipedia.org?
Something like <inputbox>type=search</inputbox>,
but with more parameters (to control layout and the
presence of a language selection fiels).

Marking WONTFIX. The HTML that is already allowed in pages/templates/etc can be transcluded as needed. No additional HTML should be allowed (directly or indirectly) simply because it's been protected (per comment #7).

The www.wikipedia.org template works just fine on meta, and doesn't need this anyway.