Protect private wikis by providing basic read restrictions, closely following the example of the action API. The BasicAccess module provides a narrow interface for this functionality, without exposing the whole session/user concept to the router. Also, add RouterTest and fix a bug in Router::getRelativePath() thus discovered. Change-Id: I82319d56f08b2eec4a585ff6dbd348ccdbadc5b5
30 lines
726 B
PHP
30 lines
726 B
PHP
<?php
|
|
|
|
namespace MediaWiki\Rest\BasicAccess;
|
|
|
|
use MediaWiki\Rest\Handler;
|
|
use MediaWiki\Rest\RequestInterface;
|
|
|
|
/**
|
|
* An authorizer which returns a value from authorize() which is given in the constructor.
|
|
*
|
|
* @internal
|
|
*/
|
|
class StaticBasicAuthorizer implements BasicAuthorizerInterface {
|
|
private $value;
|
|
|
|
/**
|
|
* @see BasicAuthorizerInterface::authorize()
|
|
*
|
|
* @param string|null $value The value returned by authorize(). If the
|
|
* request is denied, this is the string error code. If the request is
|
|
* allowed, it is null.
|
|
*/
|
|
public function __construct( $value = null ) {
|
|
$this->value = $value;
|
|
}
|
|
|
|
public function authorize( RequestInterface $request, Handler $handler ) {
|
|
return $this->value;
|
|
}
|
|
}
|