Page MenuHomePhabricator

Value of $wgDocType has no effect in default 1.16.2 install
Closed, ResolvedPublic

Description

Author: srainwater

Description:
The MediaWiki documentation suggests that $wgDocType defaults to XHTML Transitional and that changing the value of this variable with alter the doctype that appears in the live pages. Neither of these things is correct in the default install.

In actuality, there is another config value, $wgHtml5, which defaults to True and overrides the value $wgDocType. The actual doctype value will always be XHTML Strict regardless of what is set in $wgDocType unless you first set $wgHtml5 to false.

I'm not certain what the intended behavior is here. Since I'd like to have the XHTML Transitional doctype, which is described by the documentation as the default, this seems like a bug in MediaWiki to me. But if the intended behavior is to support only XHTML strict, then the bug is possibly in the documentation, which should say that $wgDocType is deprecated.


Version: 1.16.x
Severity: minor

Details

Reference
bz28350

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 11:27 PM
bzimport set Reference to bz28350.
bzimport added a subscriber: Unknown Object (MLST).

srainwater wrote:

Yes, also in the DefaultSettings.php, $wgDocType is set to XHTML transitional, which suggests to a new MediaWiki user that you'll see that doctype in the web pages. A comment by that setting saying it doesn't do anything if $wgHtml5 is set might be helpful.

ayg wrote:

This is not a bug in the software. The semantics of $wgDocType don't make sense for HTML5, because it's used to output a doctype like

<!DOCTYPE html PUBLIC "$wgDocType" "$wgDTD">

while the HTML5 doctype is just

<!DOCTYPE html>

so there's nothing you could set $wgDocType or $wgDTD to to get the default doctype we want. So by default I just ignored it in $wgHtml5.

If doctype overriding is actually useful, we could add a new configuration option like $wgDocTypeOverride that sets the whole doctype as one string, so by default it could be "<!DOCTYPE html>" but wiki operators could customize it to whatever they felt like. This might be useful for Wikimedia deployment of $wgHtml5 = true, as I remarked recently on wikitech-l.

Note that in 1.17 and later, the default doctype is "<!DOCTYPE html>". The default doctype in 1.16 is different for tiresome reasons that I won't bother explaining, but that's irrelevant for bug-tracking purposes, since branches are mostly only maintained for security and so we aren't going to be changing around how 1.16 works.

Why do you want an XHTML Transitional doctype?

The doc comment on $wgDocType and $wgDTD don't mention that they have no effect if $wgHtml5 is set, so this is definitely a documentation bug:

/** The HTML document type. */
$wgDocType = '-//W3C//DTD XHTML 1.0 Transitional//EN';

/** The URL of the document type declaration. */
$wgDTD = 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd';

/** The default xmlns attribute. */
$wgXhtmlDefaultNamespace = 'http://www.w3.org/1999/xhtml';

/**
 * Should we output an HTML5 doctype?  If false, use XHTML 1.0 Transitional
 * instead, and disable HTML5 features.  This may eventually be removed and set
 * to always true.
 */
$wgHtml5 = true;

If $wgHtml5 being on disables the three other settings, then they should all be updated to indicate this.

srainwater wrote:

As I said, the bug may be in the *documentation* rather than the code. If
$wgDocType id deprecated or conflicts with $wgHtml5, then the docs need
updating.

My experience was that once I set $wgHtml5 to false, the behavior of the
software matched the explanation in the docs (e.g. changing $wgDocType changed
the doctype value in the generated page).

I wanted to set the doctype to XHTML transitional because I'm working on
getting the mediawiki generated pages to validate. With the strict doctype I
get a lot of errors when validating through the W3C checker. Many of those
issues are not errors under XHTML transitional.

$wgXhtmlNamespaces appears to also be disabled when $wgHtml5 is enabled.

ayg wrote:

Documentation updated in r85124. If there's anything I missed, reopen, or file a new bug and CC me.