* (bug 11795) Be more paranoid about confirming accept-encoding header is present
[lhc/web/wiklou.git] / includes / Metadata.php
index 3a939d1..f5b0b24 100644 (file)
  *
  *  You should have received a copy of the GNU General Public License
  *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  *
  * @author Evan Prodromou <evan@wikitravel.org>
- * @package MediaWiki
  */
 
 /**
- *
+ * TODO: Perhaps make this file into a Metadata class, with static methods (declared 
+ * as private where indicated), to move these functions out of the global namespace?
  */
 define('RDF_TYPE_PREFS', "application/rdf+xml,text/xml;q=0.7,application/xml;q=0.5,text/rdf;q=0.1");
 
@@ -68,26 +68,28 @@ function wfCreativeCommonsRdf($article) {
 }
 
 /**
- * @access private
+ * @private
  */
 function rdfSetup() {
        global $wgOut, $_SERVER;
 
-       $rdftype = wfNegotiateType(wfAcceptToPrefs($_SERVER['HTTP_ACCEPT']), wfAcceptToPrefs(RDF_TYPE_PREFS));
+       $httpaccept = isset($_SERVER['HTTP_ACCEPT']) ? $_SERVER['HTTP_ACCEPT'] : null;
+
+       $rdftype = wfNegotiateType(wfAcceptToPrefs($httpaccept), wfAcceptToPrefs(RDF_TYPE_PREFS));
 
        if (!$rdftype) {
                wfHttpError(406, "Not Acceptable", wfMsg("notacceptable"));
                return false;
        } else {
                $wgOut->disable();
-               header( "Content-type: {$rdftype}" );
+               header( "Content-type: {$rdftype}; charset=utf-8" );
                $wgOut->sendCacheControl();
                return true;
        }
 }
 
 /**
- * @access private
+ * @private
  */
 function dcPrologue($url) {
        global $wgOutputEncoding;
@@ -104,7 +106,7 @@ function dcPrologue($url) {
 }
 
 /**
- * @access private
+ * @private
  */
 function dcEpilogue() {
        print "
@@ -114,7 +116,7 @@ function dcEpilogue() {
 }
 
 /**
- * @access private
+ * @private
  */
 function dcBasics($article) {
        global $wgContLanguageCode, $wgSitename;
@@ -142,11 +144,11 @@ function dcBasics($article) {
                dcPerson('contributor', $user_parts[0], $user_parts[1], $user_parts[2]);
        }
 
-       dcRights($article);
+       dcRights();
 }
 
 /**
- * @access private
+ * @private
  */
 function ccPrologue() {
        global $wgOutputEncoding;
@@ -160,7 +162,7 @@ function ccPrologue() {
 }
 
 /**
- * @access private
+ * @private
  */
 function ccSubPrologue($type, $url) {
        $url = htmlspecialchars( $url );
@@ -168,14 +170,14 @@ function ccSubPrologue($type, $url) {
 }
 
 /**
- * @access private
+ * @private
  */
 function ccSubEpilogue($type) {
        echo "  </cc:{$type}>\n";
 }
 
 /**
- * @access private
+ * @private
  */
 function ccLicense($terms) {
 
@@ -202,21 +204,21 @@ function ccLicense($terms) {
 }
 
 /**
- * @access private
+ * @private
  */
 function ccTerm($term, $name) {
        print "    <cc:{$term} rdf:resource=\"http://web.resource.org/cc/{$name}\" />\n";
 }
 
 /**
- * @access private
+ * @private
  */
 function ccEpilogue() {
        echo "</rdf:RDF>\n";
 }
 
 /**
- * @access private
+ * @private
  */
 function dcElement($name, $value) {
        $value = htmlspecialchars( $value );
@@ -224,7 +226,7 @@ function dcElement($name, $value) {
 }
 
 /**
- * @access private
+ * @private
  */
 function dcDate($timestamp) {
        return substr($timestamp, 0, 4) . '-'
@@ -233,14 +235,14 @@ function dcDate($timestamp) {
 }
 
 /**
- * @access private
+ * @private
  */
 function dcReallyFullUrl($title) {
        return $title->getFullURL();
 }
 
 /**
- * @access private
+ * @private
  */
 function dcPageOrString($name, $page, $str) {
        $nt = Title::newFromText($page);
@@ -253,14 +255,14 @@ function dcPageOrString($name, $page, $str) {
 }
 
 /**
- * @access private
+ * @private
  */
 function dcPage($name, $title) {
        dcUrl($name, dcReallyFullUrl($title));
 }
 
 /**
- * @access private
+ * @private
  */
 function dcUrl($name, $url) {
        $url = htmlspecialchars( $url );
@@ -268,7 +270,7 @@ function dcUrl($name, $url) {
 }
 
 /**
- * @access private
+ * @private
  */
 function dcPerson($name, $id, $user_name='', $user_real_name='') {
        global $wgContLang;
@@ -289,9 +291,9 @@ function dcPerson($name, $id, $user_name='', $user_real_name='') {
 /**
  * Takes an arg, for future enhancement with different rights for
  * different pages.
- * @access private
+ * @private
  */
-function dcRights($article) {
+function dcRights() {
 
        global $wgRightsPage, $wgRightsUrl, $wgRightsText;
 
@@ -307,7 +309,7 @@ function dcRights($article) {
 }
 
 /**
- * @access private
+ * @private
  */
 function ccGetTerms($url) {
        global $wgLicenseTerms;
@@ -316,12 +318,16 @@ function ccGetTerms($url) {
                return $wgLicenseTerms;
        } else {
                $known = getKnownLicenses();
-               return $known[$url];
+               if( isset( $known[$url] ) ) {
+                       return $known[$url];
+               } else {
+                       return array();
+               }
        }
 }
 
 /**
- * @access private
+ * @private
  */
 function getKnownLicenses() {
 
@@ -359,4 +365,4 @@ function getKnownLicenses() {
        return $knownLicenses;
 }
 
-?>
+