Index: trunk/extensions/OAI/OAIRepo.php |
— | — | @@ -31,6 +31,12 @@ |
32 | 32 | die(); |
33 | 33 | } |
34 | 34 | |
| 35 | +/** |
| 36 | + * To limit access to specific user-agents |
| 37 | + */ |
| 38 | +global $oaiAgentRegex; |
| 39 | +$oaiAgentRegex = false; |
| 40 | + |
35 | 41 | $wgExtensionFunctions[] = 'oaiSetupRepo'; |
36 | 42 | |
37 | 43 | function oaiSetupRepo() { |
— | — | @@ -219,6 +225,16 @@ |
220 | 226 | |
221 | 227 | |
222 | 228 | function respond() { |
| 229 | + global $oaiAgentRegex; |
| 230 | + if( $oaiAgentRegex ) { |
| 231 | + if( !isset( $_SERVER['HTTP_USER_AGENT'] ) |
| 232 | + || !preg_match( $oaiAgentRegex, $_SERVER['HTTP_USER_AGENT'] ) ) { |
| 233 | + header( 'HTTP/1.x 403 Unauthorized' ); |
| 234 | + echo "<p>Sorry, this resource is presently restricted-access.</p>"; |
| 235 | + return; |
| 236 | + } |
| 237 | + } |
| 238 | + |
223 | 239 | global $wgUseLatin1; |
224 | 240 | if( $wgUseLatin1 ) { |
225 | 241 | # OAI requires UTF-8 output |
Index: trunk/extensions/OAI/OAIHarvest.php |
— | — | @@ -41,11 +41,13 @@ |
42 | 42 | require_once( 'OAIRepo.php' ); |
43 | 43 | |
44 | 44 | global $oaiSourceRepository; |
| 45 | +global $oaiAgentExtra; |
45 | 46 | |
46 | 47 | /** |
47 | 48 | * Set to the repository URL, |
48 | 49 | */ |
49 | 50 | $oaiSourceRepository = null; |
| 51 | +$oaiUserAgent = 'MediaWiki/OAI 0.1'; |
50 | 52 | |
51 | 53 | class OAIError { |
52 | 54 | function OAIError( $message ) { |
— | — | @@ -206,7 +208,12 @@ |
207 | 209 | } |
208 | 210 | |
209 | 211 | function userAgent() { |
210 | | - return 'MediaWiki OAI Harvester 0.1 (http://www.mediawiki.org/)'; |
| 212 | + global $oaiAgentExtra; |
| 213 | + $agent = 'MediaWiki OAI Harvester 0.1 (http://www.mediawiki.org/)'; |
| 214 | + if( $oaiAgentExtra ) { |
| 215 | + $agent .= ' ' . $oaiAgentExtra; |
| 216 | + } |
| 217 | + return $agent; |
211 | 218 | } |
212 | 219 | |
213 | 220 | |