r7790 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r7789‎ | r7790 | r7791 >
Date:00:28, 21 March 2005
Author:vibber
Status:old
Tags:
Comment:
User agent limit option for the pilot program
Modified paths:
  • /trunk/extensions/OAI/OAIHarvest.php (modified) (history)
  • /trunk/extensions/OAI/OAIRepo.php (modified) (history)

Diff [purge]

Index: trunk/extensions/OAI/OAIRepo.php
@@ -31,6 +31,12 @@
3232 die();
3333 }
3434
 35+/**
 36+ * To limit access to specific user-agents
 37+ */
 38+global $oaiAgentRegex;
 39+$oaiAgentRegex = false;
 40+
3541 $wgExtensionFunctions[] = 'oaiSetupRepo';
3642
3743 function oaiSetupRepo() {
@@ -219,6 +225,16 @@
220226
221227
222228 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+
223239 global $wgUseLatin1;
224240 if( $wgUseLatin1 ) {
225241 # OAI requires UTF-8 output
Index: trunk/extensions/OAI/OAIHarvest.php
@@ -41,11 +41,13 @@
4242 require_once( 'OAIRepo.php' );
4343
4444 global $oaiSourceRepository;
 45+global $oaiAgentExtra;
4546
4647 /**
4748 * Set to the repository URL,
4849 */
4950 $oaiSourceRepository = null;
 51+$oaiUserAgent = 'MediaWiki/OAI 0.1';
5052
5153 class OAIError {
5254 function OAIError( $message ) {
@@ -206,7 +208,12 @@
207209 }
208210
209211 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;
211218 }
212219
213220

Status & tagging log