Index: trunk/phase3/includes/AjaxDispatcher.php |
— | — | @@ -47,7 +47,7 @@ |
48 | 48 | |
49 | 49 | function performAction() { |
50 | 50 | global $wgAjaxExportList, $wgOut; |
51 | | - |
| 51 | + |
52 | 52 | if ( empty( $this->mode ) ) { |
53 | 53 | return; |
54 | 54 | } |
— | — | @@ -59,7 +59,7 @@ |
60 | 60 | } else { |
61 | 61 | try { |
62 | 62 | $result = call_user_func_array($this->func_name, $this->args); |
63 | | - |
| 63 | + |
64 | 64 | if ( $result === false || $result === NULL ) { |
65 | 65 | header( 'Status: 500 Internal Error', true, 500 ); |
66 | 66 | echo "{$this->func_name} returned no data"; |
— | — | @@ -68,7 +68,7 @@ |
69 | 69 | if ( is_string( $result ) ) { |
70 | 70 | $result= new AjaxResponse( $result ); |
71 | 71 | } |
72 | | - |
| 72 | + |
73 | 73 | $result->sendHeaders(); |
74 | 74 | $result->printText(); |
75 | 75 | } |
— | — | @@ -82,7 +82,7 @@ |
83 | 83 | } |
84 | 84 | } |
85 | 85 | } |
86 | | - |
| 86 | + |
87 | 87 | wfProfileOut( __METHOD__ ); |
88 | 88 | $wgOut = null; |
89 | 89 | } |
Index: trunk/phase3/includes/AjaxFunctions.php |
— | — | @@ -45,7 +45,7 @@ |
46 | 46 | if ($iconv_to != "UTF-8") { |
47 | 47 | $decodedStr = iconv("UTF-8", $iconv_to, $decodedStr); |
48 | 48 | } |
49 | | - |
| 49 | + |
50 | 50 | return $decodedStr; |
51 | 51 | } |
52 | 52 | |
— | — | @@ -71,7 +71,7 @@ |
72 | 72 | function wfSajaxSearch( $term ) { |
73 | 73 | global $wgContLang, $wgOut; |
74 | 74 | $limit = 16; |
75 | | - |
| 75 | + |
76 | 76 | $l = new Linker; |
77 | 77 | |
78 | 78 | $term = str_replace( ' ', '_', $wgContLang->ucfirst( |
— | — | @@ -109,7 +109,7 @@ |
110 | 110 | $subtitle = $wgOut->parse( wfMsg( $subtitlemsg, wfEscapeWikiText($term) ) ); #FIXME: parser is missing mTitle ! |
111 | 111 | |
112 | 112 | $term = htmlspecialchars( $term ); |
113 | | - $html = '<div style="float:right; border:solid 1px black;background:gainsboro;padding:2px;"><a onclick="Searching_Hide_Results();">' |
| 113 | + $html = '<div style="float:right; border:solid 1px black;background:gainsboro;padding:2px;"><a onclick="Searching_Hide_Results();">' |
114 | 114 | . wfMsg( 'hideresults' ) . '</a></div>' |
115 | 115 | . '<h1 class="firstHeading">'.wfMsg('search') |
116 | 116 | . '</h1><div id="contentSub">'. $subtitle . '</div><ul><li>' |
— | — | @@ -121,11 +121,11 @@ |
122 | 122 | "search=$term&go=Go" ) |
123 | 123 | . "</li></ul><h2>" . wfMsg( 'articletitles', $term ) . "</h2>" |
124 | 124 | . '<ul>' .$r .'</ul>'.$more; |
125 | | - |
| 125 | + |
126 | 126 | $response = new AjaxResponse( $html ); |
127 | | - |
| 127 | + |
128 | 128 | $response->setCacheDuration( 30*60 ); |
129 | | - |
| 129 | + |
130 | 130 | return $response; |
131 | 131 | } |
132 | 132 | |
Index: trunk/phase3/includes/AjaxResponse.php |
— | — | @@ -6,7 +6,7 @@ |
7 | 7 | class AjaxResponse { |
8 | 8 | var $mCacheDuration; |
9 | 9 | var $mVary; |
10 | | - |
| 10 | + |
11 | 11 | var $mDisabled; |
12 | 12 | var $mText; |
13 | 13 | var $mResponseCode; |
— | — | @@ -16,13 +16,13 @@ |
17 | 17 | function AjaxResponse( $text = NULL ) { |
18 | 18 | $this->mCacheDuration = NULL; |
19 | 19 | $this->mVary = NULL; |
20 | | - |
| 20 | + |
21 | 21 | $this->mDisabled = false; |
22 | 22 | $this->mText = ''; |
23 | 23 | $this->mResponseCode = '200 OK'; |
24 | 24 | $this->mLastModified = false; |
25 | 25 | $this->mContentType= 'text/html; charset=utf-8'; |
26 | | - |
| 26 | + |
27 | 27 | if ( $text ) { |
28 | 28 | $this->addText( $text ); |
29 | 29 | } |
— | — | @@ -39,15 +39,15 @@ |
40 | 40 | function setResponseCode( $code ) { |
41 | 41 | $this->mResponseCode = $code; |
42 | 42 | } |
43 | | - |
| 43 | + |
44 | 44 | function setContentType( $type ) { |
45 | 45 | $this->mContentType = $type; |
46 | 46 | } |
47 | | - |
| 47 | + |
48 | 48 | function disable() { |
49 | 49 | $this->mDisabled = true; |
50 | 50 | } |
51 | | - |
| 51 | + |
52 | 52 | function addText( $text ) { |
53 | 53 | if ( ! $this->mDisabled && $text ) { |
54 | 54 | $this->mText .= $text; |
— | — | @@ -59,62 +59,62 @@ |
60 | 60 | print $this->mText; |
61 | 61 | } |
62 | 62 | } |
63 | | - |
| 63 | + |
64 | 64 | function sendHeaders() { |
65 | 65 | global $wgUseSquid, $wgUseESI; |
66 | | - |
| 66 | + |
67 | 67 | if ( $this->mResponseCode ) { |
68 | 68 | $n = preg_replace( '/^ *(\d+)/', '\1', $this->mResponseCode ); |
69 | 69 | header( "Status: " . $this->mResponseCode, true, (int)$n ); |
70 | 70 | } |
71 | | - |
| 71 | + |
72 | 72 | header ("Content-Type: " . $this->mContentType ); |
73 | | - |
| 73 | + |
74 | 74 | if ( $this->mLastModified ) { |
75 | 75 | header ("Last-Modified: " . $this->mLastModified ); |
76 | 76 | } |
77 | 77 | else { |
78 | 78 | header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); |
79 | 79 | } |
80 | | - |
| 80 | + |
81 | 81 | if ( $this->mCacheDuration ) { |
82 | | - |
| 82 | + |
83 | 83 | # If squid caches are configured, tell them to cache the response, |
84 | 84 | # and tell the client to always check with the squid. Otherwise, |
85 | 85 | # tell the client to use a cached copy, without a way to purge it. |
86 | | - |
| 86 | + |
87 | 87 | if( $wgUseSquid ) { |
88 | | - |
| 88 | + |
89 | 89 | # Expect explicite purge of the proxy cache, but require end user agents |
90 | 90 | # to revalidate against the proxy on each visit. |
91 | 91 | # Surrogate-Control controls our Squid, Cache-Control downstream caches |
92 | | - |
| 92 | + |
93 | 93 | if ( $wgUseESI ) { |
94 | 94 | header( 'Surrogate-Control: max-age='.$this->mCacheDuration.', content="ESI/1.0"'); |
95 | 95 | header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' ); |
96 | 96 | } else { |
97 | 97 | header( 'Cache-Control: s-maxage='.$this->mCacheDuration.', must-revalidate, max-age=0' ); |
98 | 98 | } |
99 | | - |
| 99 | + |
100 | 100 | } else { |
101 | | - |
| 101 | + |
102 | 102 | # Let the client do the caching. Cache is not purged. |
103 | 103 | header ("Expires: " . gmdate( "D, d M Y H:i:s", time() + $this->mCacheDuration ) . " GMT"); |
104 | 104 | header ("Cache-Control: s-max-age={$this->mCacheDuration},public,max-age={$this->mCacheDuration}"); |
105 | 105 | } |
106 | | - |
| 106 | + |
107 | 107 | } else { |
108 | 108 | # always expired, always modified |
109 | 109 | header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past |
110 | 110 | header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 |
111 | 111 | header ("Pragma: no-cache"); // HTTP/1.0 |
112 | 112 | } |
113 | | - |
| 113 | + |
114 | 114 | if ( $this->mVary ) { |
115 | 115 | header ( "Vary: " . $this->mVary ); |
116 | 116 | } |
117 | 117 | } |
118 | | - |
| 118 | + |
119 | 119 | /** |
120 | 120 | * checkLastModified tells the client to use the client-cached response if |
121 | 121 | * possible. If sucessful, the AjaxResponse is disabled so that |
— | — | @@ -154,9 +154,9 @@ |
155 | 155 | $this->setResponseCode( "304 Not Modified" ); |
156 | 156 | $this->disable(); |
157 | 157 | $this->mLastModified = $lastmod; |
158 | | - |
| 158 | + |
159 | 159 | wfDebug( "$fname: CACHED client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp ; site $wgCacheEpoch\n", false ); |
160 | | - |
| 160 | + |
161 | 161 | return true; |
162 | 162 | } else { |
163 | 163 | wfDebug( "$fname: READY client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp ; site $wgCacheEpoch\n", false ); |
— | — | @@ -167,11 +167,11 @@ |
168 | 168 | $this->mLastModified = $lastmod; |
169 | 169 | } |
170 | 170 | } |
171 | | - |
| 171 | + |
172 | 172 | function loadFromMemcached( $mckey, $touched ) { |
173 | 173 | global $wgMemc; |
174 | 174 | if ( !$touched ) return false; |
175 | | - |
| 175 | + |
176 | 176 | $mcvalue = $wgMemc->get( $mckey ); |
177 | 177 | if ( $mcvalue ) { |
178 | 178 | # Check to see if the value has been invalidated |
— | — | @@ -183,20 +183,20 @@ |
184 | 184 | wfDebug( "$mckey has expired\n" ); |
185 | 185 | } |
186 | 186 | } |
187 | | - |
| 187 | + |
188 | 188 | return false; |
189 | 189 | } |
190 | | - |
| 190 | + |
191 | 191 | function storeInMemcached( $mckey, $expiry = 86400 ) { |
192 | 192 | global $wgMemc; |
193 | | - |
194 | | - $wgMemc->set( $mckey, |
| 193 | + |
| 194 | + $wgMemc->set( $mckey, |
195 | 195 | array( |
196 | 196 | 'timestamp' => wfTimestampNow(), |
197 | 197 | 'value' => $this->mText |
198 | 198 | ), $expiry |
199 | 199 | ); |
200 | | - |
| 200 | + |
201 | 201 | return true; |
202 | 202 | } |
203 | 203 | } |