Index: includes/common.inc
===================================================================
--- includes/common.inc	(revision 33681)
+++ includes/common.inc	(working copy)
@@ -5,6 +5,7 @@
 # Copyright (c) 2004, OpenDarwin.
 # Copyright (c) 2004-2007, The MacPorts Project.
 
+require_once 'lib/AcceptMime.class.php';
 
 ######################################################################
 
@@ -42,8 +43,14 @@
 # Page header:
 function print_header($title, $encoding) {
     global $MPWEB, $trac_url, $svn_url, $downloads, $guide_url;
-    
-    header("Content-Type: application/xhtml+xml; charset=$encoding");
+
+    $accept_mime = new AcceptMime();
+    $mime_type = "text/html";
+    if ($accept_mime->acceptable("application/xhtml+xml")) {
+        $mime_type = "application/xhtml+xml";
+    }
+    header("Content-Type: $mime_type; charset=$encoding");
+
     include("$MPWEB/includes/header.inc");
     print_warnings();
 }
Index: lib/AcceptEncoding.class.php
===================================================================
--- lib/AcceptEncoding.class.php	(revision 0)
+++ lib/AcceptEncoding.class.php	(revision 0)
@@ -0,0 +1,11 @@
+<?php
+
+require_once 'AcceptAbstract.class.php';
+
+class AcceptEncoding extends AcceptAbstract {
+	function AcceptEncoding() {
+		parent::AcceptAbstract(isset($_SERVER['HTTP_ACCEPT_ENCODING']) ? $_SERVER['HTTP_ACCEPT_ENCODING'] : 'identity');
+	}
+}
+
+?>

Property changes on: lib/AcceptEncoding.class.php
___________________________________________________________________
Name: svn:keywords
   + Id Author

Index: lib/AcceptMime.class.php
===================================================================
--- lib/AcceptMime.class.php	(revision 0)
+++ lib/AcceptMime.class.php	(revision 0)
@@ -0,0 +1,11 @@
+<?php
+
+require_once 'AcceptAbstract.class.php';
+
+class AcceptMime extends AcceptAbstract {
+	function AcceptMime() {
+		parent::AcceptAbstract(isset($_SERVER['HTTP_ACCEPT']) ? $_SERVER['HTTP_ACCEPT'] : '*');
+	}
+}
+
+?>

Property changes on: lib/AcceptMime.class.php
___________________________________________________________________
Name: svn:keywords
   + Id Author

Index: lib/AcceptCharset.class.php
===================================================================
--- lib/AcceptCharset.class.php	(revision 0)
+++ lib/AcceptCharset.class.php	(revision 0)
@@ -0,0 +1,11 @@
+<?php
+
+require_once 'AcceptAbstract.class.php';
+
+class AcceptCharset extends AcceptAbstract {
+	function AcceptCharset() {
+		parent::AcceptAbstract(isset($_SERVER['HTTP_ACCEPT_CHARSET']) ? $_SERVER['HTTP_ACCEPT_CHARSET'] : '*');
+	}
+}
+
+?>

Property changes on: lib/AcceptCharset.class.php
___________________________________________________________________
Name: svn:keywords
   + Id Author

Index: lib/AcceptAbstract.class.php
===================================================================
--- lib/AcceptAbstract.class.php	(revision 0)
+++ lib/AcceptAbstract.class.php	(revision 0)
@@ -0,0 +1,70 @@
+<?php
+
+class AcceptAbstract {
+	
+	function AcceptAbstract($accept_header) {
+		$this->accept = array();
+		
+		if (empty($accept_header)) {
+			return;
+		}
+		
+		$fudge_factor = 0.00001;
+		
+		$components = preg_split('%\s*,\s*%', $accept_header);
+		$temp = array();
+		foreach ($components as $i => $component) {
+			
+			// Find the parts of the string.
+			preg_match('%^
+				([^\s;]+)            # one or more chars -- the value -- match 1
+				(?:                  # begin group (optional)
+					\s*;\s*              # semicolon optionally surrounded by whitespace
+					q=                   # literal text "q="
+					([01](?:\.\d+)?)     # floating-point number, 0 >= n >= 1 -- the quality -- match 2
+				)?                   # end group
+				$%ix',
+				$component, $matches
+			);
+			
+			$value = $matches[1];
+			
+			// If no quality is given, quality 1 is assumed.
+			$q = isset($matches[2]) ? (float)$matches[2] : (float)1;
+			
+			// Stuff it in the array, if the quality is non-zero.
+			if ($q > 0) {
+				$temp[$value] = array(
+					'value' => $value,
+					'q' => $q - ($i * $fudge_factor),
+					'i' => $i,
+				);
+			}
+			
+		}
+		
+		// Sort descending by quality.
+		usort($temp, create_function('$a, $b', 'return ($a["q"] == $b["q"]) ? 0 : ($a["q"] > $b["q"]) ? -1 : 1;'));
+		
+		// Unfudge the quality parameter and simplify the array.
+		foreach ($temp as $x) {
+			$this->accept[$x['value']] = $x['q'] + $x['i'] * $fudge_factor;
+		}
+	}
+	
+	function getPreferred() {
+		if (empty($this->accept)) {
+			return false;
+		} else {
+			$keys = array_keys($this->accept);
+			return $this->accept[$keys[0]];
+		}
+	}
+	
+	function acceptable($value) {
+		return array_key_exists($value, $this->accept);
+	}
+	
+}
+
+?>

Property changes on: lib/AcceptAbstract.class.php
___________________________________________________________________
Name: svn:keywords
   + Id Author

Index: lib/AcceptLanguage.class.php
===================================================================
--- lib/AcceptLanguage.class.php	(revision 0)
+++ lib/AcceptLanguage.class.php	(revision 0)
@@ -0,0 +1,11 @@
+<?php
+
+require_once 'AcceptAbstract.class.php';
+
+class AcceptLanguage extends AcceptAbstract {
+	function AcceptLanguage() {
+		parent::AcceptAbstract(isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : '*');
+	}
+}
+
+?>

Property changes on: lib/AcceptLanguage.class.php
___________________________________________________________________
Name: svn:keywords
   + Id Author


