r2970 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r2969‎ | r2970 | r2971 >
Date:22:33, 4 April 2004
Author:vibber
Status:old
Tags:
Comment:
Whitespace & coding standards adjustments to Evan's last commits.
Metadata.php seems to be missing, so the new code doesn't work yet.
Modified paths:
  • /trunk/phase3/includes/GlobalFunctions.php (modified) (history)
  • /trunk/phase3/includes/OutputPage.php (modified) (history)
  • /trunk/phase3/index.php (modified) (history)

Diff [purge]

Index: trunk/phase3/index.php
@@ -108,22 +108,22 @@
109109 case "print":
110110 $wgArticle->view();
111111 break;
112 - case "dublincore":
113 - if (!$wgEnableDublinCoreRdf) {
114 - wfHttpError(403, "Forbidden", wfMsg("nodublincore"));
115 - } else {
116 - include_once("Metadata.php");
117 - wfDublinCoreRdf($wgArticle);
118 - }
119 - break;
120 - case "creativecommons":
121 - if (!$wgEnableCreativeCommonsRdf) {
122 - wfHttpError(403, "Forbidden", wfMsg("nocreativecommons"));
123 - } else {
124 - include_once("Metadata.php");
125 - wfCreativeCommonsRdf($wgArticle);
126 - }
127 - break;
 112+ case "dublincore":
 113+ if( !$wgEnableDublinCoreRdf ) {
 114+ wfHttpError( 403, "Forbidden", wfMsg( "nodublincore" ) );
 115+ } else {
 116+ include_once( "Metadata.php" );
 117+ wfDublinCoreRdf( $wgArticle );
 118+ }
 119+ break;
 120+ case "creativecommons":
 121+ if( !$wgEnableCreativeCommonsRdf ) {
 122+ wfHttpError( 403, "Forbidden", wfMsg("nocreativecommons") );
 123+ } else {
 124+ include_once( "Metadata.php" );
 125+ wfCreativeCommonsRdf( $wgArticle );
 126+ }
 127+ break;
128128 case "edit":
129129 case "submit":
130130 if( !$wgCommandLineMode && !$wgRequest->checkSessionCookie() ) {
Index: trunk/phase3/includes/GlobalFunctions.php
@@ -845,101 +845,96 @@
846846 }
847847 }
848848
849 -/* Provide a simple HTTP error. */
850 -
851 -function wfHttpError($code, $label, $desc) {
852 -
853 - global $wgOut;
854 - $wgOut->disable();
855 - header("HTTP/1.0 $code $label");
856 - header("Status: $code $label");
857 - $wgOut->sendCacheControl();
858 -
859 - /* Don't send content if it's a HEAD request. */
860 -
861 - if (strcmp($HTTP_SERVER_VARS['REQUEST_METHOD'],'HEAD') != 0) {
862 - header("Content-type: text/plain");
863 - print "$desc\n";
864 - }
 849+# Provide a simple HTTP error.
 850+function wfHttpError( $code, $label, $desc ) {
 851+ global $wgOut;
 852+ $wgOut->disable();
 853+ header( "HTTP/1.0 $code $label" );
 854+ header( "Status: $code $label" );
 855+ $wgOut->sendCacheControl();
 856+
 857+ # Don't send content if it's a HEAD request.
 858+ if( $_SERVER['REQUEST_METHOD'] == 'HEAD' ) {
 859+ header( "Content-type: text/plain" );
 860+ print "$desc\n";
 861+ }
865862 }
866863
867864 # Converts an Accept-* header into an array mapping string values to quality factors
868 -
869 -function wfAcceptToPrefs($accept, $def = "*/*") {
870 - # No arg means accept anything (per HTTP spec)
871 - if (!$accept) {
872 - return array($def => 1);
873 - }
874 -
875 - $prefs = array();
876 -
877 - $parts = explode(",", $accept);
878 -
879 - foreach ($parts as $part) {
880 - #FIXME: doesn't deal with params like 'text/html; level=1'
881 - list($value, $qpart) = explode(";", $part);
882 - if (!isset($qpart)) {
883 - $prefs[$value] = 1;
884 - } else if (preg_match('/q\s*=\s*(\d*\.\d+)/', $qpart, $match)) {
885 - $prefs[$value] = $match[1];
 865+function wfAcceptToPrefs( $accept, $def = "*/*" ) {
 866+ # No arg means accept anything (per HTTP spec)
 867+ if( !$accept ) {
 868+ return array( $def => 1 );
886869 }
887 - }
888 -
889 - return $prefs;
 870+
 871+ $prefs = array();
 872+
 873+ $parts = explode( ",", $accept );
 874+
 875+ foreach( $parts as $part ) {
 876+ # FIXME: doesn't deal with params like 'text/html; level=1'
 877+ list( $value, $qpart ) = explode( ";", $part );
 878+ if( !isset( $qpart ) ) {
 879+ $prefs[$value] = 1;
 880+ } elseif( preg_match( '/q\s*=\s*(\d*\.\d+)/', $qpart, $match ) ) {
 881+ $prefs[$value] = $match[1];
 882+ }
 883+ }
 884+
 885+ return $prefs;
890886 }
891887
892 -/* private */ function mimeTypeMatch($type, $avail) {
893 - if (array_key_exists($type, $avail)) {
894 - return $type;
895 - } else {
896 - $parts = explode('/', $type);
897 - if (array_key_exists($parts[0] . '/*', $avail)) {
898 - return $parts[0] . '/*';
899 - } else if (array_key_exists('*/*', $avail)) {
900 - return '*/*';
 888+/* private */ function mimeTypeMatch( $type, $avail ) {
 889+ if( array_key_exists($type, $avail) ) {
 890+ return $type;
901891 } else {
902 - return NULL;
 892+ $parts = explode( '/', $type );
 893+ if( array_key_exists( $parts[0] . '/*', $avail ) ) {
 894+ return $parts[0] . '/*';
 895+ } elseif( array_key_exists( '*/*', $avail ) ) {
 896+ return '*/*';
 897+ } else {
 898+ return NULL;
 899+ }
903900 }
904 - }
905901 }
906902
907 -#FIXME: doesn't handle params like 'text/plain; charset=UTF-8'
908 -#XXX: generalize to negotiate other stuff
909 -
910 -function wfNegotiateType($cprefs, $sprefs) {
911 - $combine = array();
912 -
913 - foreach (array_keys($sprefs) as $type) {
914 - $parts = explode('/', $type);
915 - if ($parts[1] != '*') {
916 - $ckey = mimeTypeMatch($type, $cprefs);
917 - if ($ckey) {
918 - $combine[$type] = $sprefs[$type] * $cprefs[$ckey];
919 - }
 903+# FIXME: doesn't handle params like 'text/plain; charset=UTF-8'
 904+# XXX: generalize to negotiate other stuff
 905+function wfNegotiateType( $cprefs, $sprefs ) {
 906+ $combine = array();
 907+
 908+ foreach( array_keys($sprefs) as $type ) {
 909+ $parts = explode( '/', $type );
 910+ if( $parts[1] != '*' ) {
 911+ $ckey = mimeTypeMatch( $type, $cprefs );
 912+ if( $ckey ) {
 913+ $combine[$type] = $sprefs[$type] * $cprefs[$ckey];
 914+ }
 915+ }
920916 }
921 - }
922 -
923 - foreach (array_keys($cprefs) as $type) {
924 - $parts = explode('/', $type);
925 - if ($parts[1] != '*' && !array_key_exists($type, $sprefs)) {
926 - $skey = mimeTypeMatch($type, $sprefs);
927 - if ($skey) {
928 - $combine[$type] = $sprefs[$skey] * $cprefs[$type];
929 - }
 917+
 918+ foreach( array_keys( $cprefs ) as $type ) {
 919+ $parts = explode( '/', $type );
 920+ if( $parts[1] != '*' && !array_key_exists( $type, $sprefs ) ) {
 921+ $skey = mimeTypeMatch( $type, $sprefs );
 922+ if( $skey ) {
 923+ $combine[$type] = $sprefs[$skey] * $cprefs[$type];
 924+ }
 925+ }
930926 }
931 - }
932 -
933 - $bestq = 0;
934 - $besttype = NULL;
935 -
936 - foreach (array_keys($combine) as $type) {
937 - if ($combine[$type] > $bestq) {
938 - $besttype = $type;
939 - $bestq = $combine[$type];
 927+
 928+ $bestq = 0;
 929+ $besttype = NULL;
 930+
 931+ foreach( array_keys( $combine ) as $type ) {
 932+ if( $combine[$type] > $bestq ) {
 933+ $besttype = $type;
 934+ $bestq = $combine[$type];
 935+ }
940936 }
941 - }
942 -
943 - return $besttype;
 937+
 938+ return $besttype;
944939 }
945940
946941 ?>
Index: trunk/phase3/includes/OutputPage.php
@@ -46,11 +46,11 @@
4747 function addKeyword( $text ) { array_push( $this->mKeywords, $text ); }
4848 function addLink( $rel, $rev, $target, $type="", $media="" ) { array_push( $this->mLinktags, array( $rel, $rev, $target, $type, $media ) ); }
4949
50 - function addMetadataLink( $type, $target ) {
51 - static $haveMeta = false;
52 - $this->addLink(($haveMeta) ? "alternate meta" : "meta", "", $target, $type);
53 - $haveMeta = true;
54 - }
 50+ function addMetadataLink( $type, $target ) {
 51+ static $haveMeta = false;
 52+ $this->addLink( ($haveMeta) ? "alternate meta" : "meta", "", $target, $type );
 53+ $haveMeta = true;
 54+ }
5555
5656 # checkLastModified tells the client to use the client-cached page if
5757 # possible. If sucessful, the OutputPage is disabled so that

Status & tagging log