Experimentally enable HTML 5 doctype
authorAryeh Gregor <simetrical@users.mediawiki.org>
Fri, 10 Jul 2009 04:19:51 +0000 (04:19 +0000)
committerAryeh Gregor <simetrical@users.mediawiki.org>
Fri, 10 Jul 2009 04:19:51 +0000 (04:19 +0000)
Per wikitech-l discussion.  This also removes a <meta> tag that was
completely pointless, but theoretically required by XHTML 1, yet causes
the HTML 5 validator to complain.

Together with a few other recent commits, this should cause at least
Special:BlankPage to validate as HTML 5.  Real pages may still have some
invalid markup that should be fixed -- in a large majority of cases,
markup that was poor practice in XHTML as well.  (The Wikimedia
copyright icon needs to have border="0" removed for everything to
validate 100% on Wikipedia.)

By Brion's request, this is still behind a config option, and can be
disabled with $wgHtml5 = false;.  I expect we'll be able to remove that
option in the near future, once everyone is satisfied that changing two
lines of HTML output that all browsers have demonstrably ignored since
the Paleolithic won't cause all Wikipedia users' computers to undergo a
spontaneous uncontrolled fission reaction or something.

includes/DefaultSettings.php
includes/OutputPage.php

index 0b499bf..8e1bbb1 100644 (file)
@@ -874,6 +874,14 @@ $wgDocType                 = '-//W3C//DTD XHTML 1.0 Transitional//EN';
 $wgDTD                         = 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd';
 $wgXhtmlDefaultNamespace       = 'http://www.w3.org/1999/xhtml';
 
+/**
+ * Temporary setting to disable HTML 5 for the unlikely event that it causes 
+ * everything to blow up.  If all goes well, should be removed (and forced 
+ * true) well before it ever makes it into a release.  If set to false, go back 
+ * to serving an XHTML 1.0 Transitional doctype (per $wgDocType et al. above).
+ */
+$wgHtml5 = true;
+
 /**
  * Permit other namespaces in addition to the w3.org default.
  * Use the prefix for the key and the namespace for the value. For
index a05867d..3eabf63 100644 (file)
@@ -1547,7 +1547,7 @@ class OutputPage {
        public function headElement( Skin $sk ) {
                global $wgDocType, $wgDTD, $wgContLanguageCode, $wgOutputEncoding, $wgMimeType;
                global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces;
-               global $wgContLang, $wgUseTrackbacks, $wgStyleVersion;
+               global $wgContLang, $wgUseTrackbacks, $wgStyleVersion, $wgHtml5;
 
                $this->addMeta( "http:Content-Type", "$wgMimeType; charset={$wgOutputEncoding}" );
                if ( $sk->commonPrintStylesheet() ) {
@@ -1561,7 +1561,11 @@ class OutputPage {
                        $ret .= "<?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?" . ">\n";
                }
 
-               $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\" \"$wgDTD\">\n";
+               if ( $wgHtml5 ) {
+                       $ret .= '<!doctype html>';
+               } else {
+                       $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\" \"$wgDTD\">\n";
+               }
 
                if ( '' == $this->getHTMLTitle() ) {
                        $this->setHTMLTitle(  wfMsg( 'pagetitle', $this->getPageTitle() ));
@@ -1592,7 +1596,7 @@ class OutputPage {
        }
        
        protected function addDefaultMeta() {
-               global $wgVersion;
+               global $wgVersion, $wgHtml5;
 
                static $called = false;
                if ( $called ) {
@@ -1601,7 +1605,9 @@ class OutputPage {
                }
                $called = true;
 
-               $this->addMeta( 'http:Content-Style-Type', 'text/css' ); //bug 15835
+               if ( !$wgHtml5 ) {
+                       $this->addMeta( 'http:Content-Style-Type', 'text/css' ); //bug 15835
+               }
                $this->addMeta( 'generator', "MediaWiki $wgVersion" );
                
                $p = "{$this->mIndexPolicy},{$this->mFollowPolicy}";