From: Brion Vibber Date: Sun, 4 Apr 2004 22:33:11 +0000 (+0000) Subject: Whitespace & coding standards adjustments to Evan's last commits. X-Git-Tag: 1.3.0beta1~597 X-Git-Url: http://git.cyclocoop.org/%7B%24admin_url%7Dmes_infos.php?a=commitdiff_plain;h=33821336ba02013d1a1af90566bffaa01bf62a9f;p=lhc%2Fweb%2Fwiklou.git Whitespace & coding standards adjustments to Evan's last commits. Metadata.php seems to be missing, so the new code doesn't work yet. --- diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index e6a05527b4..c64bce53be 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -845,101 +845,96 @@ function wfVarDump( $var ) } } -/* Provide a simple HTTP error. */ - -function wfHttpError($code, $label, $desc) { - - global $wgOut; - $wgOut->disable(); - header("HTTP/1.0 $code $label"); - header("Status: $code $label"); - $wgOut->sendCacheControl(); - - /* Don't send content if it's a HEAD request. */ - - if (strcmp($HTTP_SERVER_VARS['REQUEST_METHOD'],'HEAD') != 0) { - header("Content-type: text/plain"); - print "$desc\n"; - } +# Provide a simple HTTP error. +function wfHttpError( $code, $label, $desc ) { + global $wgOut; + $wgOut->disable(); + header( "HTTP/1.0 $code $label" ); + header( "Status: $code $label" ); + $wgOut->sendCacheControl(); + + # Don't send content if it's a HEAD request. + if( $_SERVER['REQUEST_METHOD'] == 'HEAD' ) { + header( "Content-type: text/plain" ); + print "$desc\n"; + } } # Converts an Accept-* header into an array mapping string values to quality factors +function wfAcceptToPrefs( $accept, $def = "*/*" ) { + # No arg means accept anything (per HTTP spec) + if( !$accept ) { + return array( $def => 1 ); + } + + $prefs = array(); + + $parts = explode( ",", $accept ); + + foreach( $parts as $part ) { + # FIXME: doesn't deal with params like 'text/html; level=1' + list( $value, $qpart ) = explode( ";", $part ); + if( !isset( $qpart ) ) { + $prefs[$value] = 1; + } elseif( preg_match( '/q\s*=\s*(\d*\.\d+)/', $qpart, $match ) ) { + $prefs[$value] = $match[1]; + } + } + + return $prefs; +} -function wfAcceptToPrefs($accept, $def = "*/*") { - # No arg means accept anything (per HTTP spec) - if (!$accept) { - return array($def => 1); - } - - $prefs = array(); - - $parts = explode(",", $accept); - - foreach ($parts as $part) { - #FIXME: doesn't deal with params like 'text/html; level=1' - list($value, $qpart) = explode(";", $part); - if (!isset($qpart)) { - $prefs[$value] = 1; - } else if (preg_match('/q\s*=\s*(\d*\.\d+)/', $qpart, $match)) { - $prefs[$value] = $match[1]; - } - } - - return $prefs; -} - -/* private */ function mimeTypeMatch($type, $avail) { - if (array_key_exists($type, $avail)) { - return $type; - } else { - $parts = explode('/', $type); - if (array_key_exists($parts[0] . '/*', $avail)) { - return $parts[0] . '/*'; - } else if (array_key_exists('*/*', $avail)) { - return '*/*'; +/* private */ function mimeTypeMatch( $type, $avail ) { + if( array_key_exists($type, $avail) ) { + return $type; } else { - return NULL; - } - } -} - -#FIXME: doesn't handle params like 'text/plain; charset=UTF-8' -#XXX: generalize to negotiate other stuff - -function wfNegotiateType($cprefs, $sprefs) { - $combine = array(); - - foreach (array_keys($sprefs) as $type) { - $parts = explode('/', $type); - if ($parts[1] != '*') { - $ckey = mimeTypeMatch($type, $cprefs); - if ($ckey) { - $combine[$type] = $sprefs[$type] * $cprefs[$ckey]; - } - } - } - - foreach (array_keys($cprefs) as $type) { - $parts = explode('/', $type); - if ($parts[1] != '*' && !array_key_exists($type, $sprefs)) { - $skey = mimeTypeMatch($type, $sprefs); - if ($skey) { - $combine[$type] = $sprefs[$skey] * $cprefs[$type]; - } - } - } - - $bestq = 0; - $besttype = NULL; - - foreach (array_keys($combine) as $type) { - if ($combine[$type] > $bestq) { - $besttype = $type; - $bestq = $combine[$type]; - } - } - - return $besttype; + $parts = explode( '/', $type ); + if( array_key_exists( $parts[0] . '/*', $avail ) ) { + return $parts[0] . '/*'; + } elseif( array_key_exists( '*/*', $avail ) ) { + return '*/*'; + } else { + return NULL; + } + } +} + +# FIXME: doesn't handle params like 'text/plain; charset=UTF-8' +# XXX: generalize to negotiate other stuff +function wfNegotiateType( $cprefs, $sprefs ) { + $combine = array(); + + foreach( array_keys($sprefs) as $type ) { + $parts = explode( '/', $type ); + if( $parts[1] != '*' ) { + $ckey = mimeTypeMatch( $type, $cprefs ); + if( $ckey ) { + $combine[$type] = $sprefs[$type] * $cprefs[$ckey]; + } + } + } + + foreach( array_keys( $cprefs ) as $type ) { + $parts = explode( '/', $type ); + if( $parts[1] != '*' && !array_key_exists( $type, $sprefs ) ) { + $skey = mimeTypeMatch( $type, $sprefs ); + if( $skey ) { + $combine[$type] = $sprefs[$skey] * $cprefs[$type]; + } + } + } + + $bestq = 0; + $besttype = NULL; + + foreach( array_keys( $combine ) as $type ) { + if( $combine[$type] > $bestq ) { + $besttype = $type; + $bestq = $combine[$type]; + } + } + + return $besttype; } ?> diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 908205ae63..4c11403168 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -46,11 +46,11 @@ class OutputPage { function addKeyword( $text ) { array_push( $this->mKeywords, $text ); } function addLink( $rel, $rev, $target, $type="", $media="" ) { array_push( $this->mLinktags, array( $rel, $rev, $target, $type, $media ) ); } - function addMetadataLink( $type, $target ) { - static $haveMeta = false; - $this->addLink(($haveMeta) ? "alternate meta" : "meta", "", $target, $type); - $haveMeta = true; - } + function addMetadataLink( $type, $target ) { + static $haveMeta = false; + $this->addLink( ($haveMeta) ? "alternate meta" : "meta", "", $target, $type ); + $haveMeta = true; + } # checkLastModified tells the client to use the client-cached page if # possible. If sucessful, the OutputPage is disabled so that diff --git a/index.php b/index.php index 6906028279..9793044043 100644 --- a/index.php +++ b/index.php @@ -108,22 +108,22 @@ if ( $search = $wgRequest->getText( 'search' ) ) { case "print": $wgArticle->view(); break; - case "dublincore": - if (!$wgEnableDublinCoreRdf) { - wfHttpError(403, "Forbidden", wfMsg("nodublincore")); - } else { - include_once("Metadata.php"); - wfDublinCoreRdf($wgArticle); - } - break; - case "creativecommons": - if (!$wgEnableCreativeCommonsRdf) { - wfHttpError(403, "Forbidden", wfMsg("nocreativecommons")); - } else { - include_once("Metadata.php"); - wfCreativeCommonsRdf($wgArticle); - } - break; + case "dublincore": + if( !$wgEnableDublinCoreRdf ) { + wfHttpError( 403, "Forbidden", wfMsg( "nodublincore" ) ); + } else { + include_once( "Metadata.php" ); + wfDublinCoreRdf( $wgArticle ); + } + break; + case "creativecommons": + if( !$wgEnableCreativeCommonsRdf ) { + wfHttpError( 403, "Forbidden", wfMsg("nocreativecommons") ); + } else { + include_once( "Metadata.php" ); + wfCreativeCommonsRdf( $wgArticle ); + } + break; case "edit": case "submit": if( !$wgCommandLineMode && !$wgRequest->checkSessionCookie() ) {