Index: trunk/phase3/index.php |
— | — | @@ -108,22 +108,22 @@ |
109 | 109 | case "print": |
110 | 110 | $wgArticle->view(); |
111 | 111 | 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; |
128 | 128 | case "edit": |
129 | 129 | case "submit": |
130 | 130 | if( !$wgCommandLineMode && !$wgRequest->checkSessionCookie() ) { |
Index: trunk/phase3/includes/GlobalFunctions.php |
— | — | @@ -845,101 +845,96 @@ |
846 | 846 | } |
847 | 847 | } |
848 | 848 | |
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 | + } |
865 | 862 | } |
866 | 863 | |
867 | 864 | # 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 ); |
886 | 869 | } |
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; |
890 | 886 | } |
891 | 887 | |
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; |
901 | 891 | } 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 | + } |
903 | 900 | } |
904 | | - } |
905 | 901 | } |
906 | 902 | |
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 | + } |
920 | 916 | } |
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 | + } |
930 | 926 | } |
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 | + } |
940 | 936 | } |
941 | | - } |
942 | | - |
943 | | - return $besttype; |
| 937 | + |
| 938 | + return $besttype; |
944 | 939 | } |
945 | 940 | |
946 | 941 | ?> |
Index: trunk/phase3/includes/OutputPage.php |
— | — | @@ -46,11 +46,11 @@ |
47 | 47 | function addKeyword( $text ) { array_push( $this->mKeywords, $text ); } |
48 | 48 | function addLink( $rel, $rev, $target, $type="", $media="" ) { array_push( $this->mLinktags, array( $rel, $rev, $target, $type, $media ) ); } |
49 | 49 | |
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 | + } |
55 | 55 | |
56 | 56 | # checkLastModified tells the client to use the client-cached page if |
57 | 57 | # possible. If sucessful, the OutputPage is disabled so that |