Skip to content

Commit a9abc1b

Browse files
committed
Update RELNOTES + some other stuff
Also: - Fixes some indenting - Removes some pointless specificity in @SInCE tags - Adds some @SInCE tags
1 parent 0563f0b commit a9abc1b

File tree

5 files changed

+66
-49
lines changed

5 files changed

+66
-49
lines changed

RELEASENOTES.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
These are the release notes for the [mediawiki-api-base](README.md).
22

3+
## Version 2.3.0 (No yet released)
4+
5+
* All guzzle configuration settings can now be overridden in `ClientFactory`
6+
* Requests that fail due to maxlag will be automatically retried
7+
* Added `MediawikiApi::getApiUrl`
8+
39
## Version 2.2.1 (3 August 2016)
410

511
* Cast SimpleXMLElements attributes as string in `MediawikiApi::newFromPage()`

src/Guzzle/ClientFactory.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use Psr\Log\NullLogger;
1111

1212
/**
13-
* @since 2.1.0
13+
* @since 2.1
1414
*
1515
* @author Addshore
1616
*/
@@ -21,9 +21,9 @@ class ClientFactory implements LoggerAwareInterface {
2121
private $config;
2222

2323
/**
24-
* @since 2.1.0
24+
* @since 2.1
2525
*
26-
* @param array $config All configurtion settings supported by Guzzle, and these:
26+
* @param array $config All configuration settings supported by Guzzle, and these:
2727
* middleware => array of extra middleware to pass to guzzle
2828
* user-agent => string default user agent to use for requests
2929
*/
@@ -33,7 +33,7 @@ public function __construct( array $config = array() ) {
3333
}
3434

3535
/**
36-
* @since 2.1.0
36+
* @since 2.1
3737
*
3838
* @return Client
3939
*/
@@ -83,7 +83,7 @@ private function newClient() {
8383
/**
8484
* Sets a logger instance on the object
8585
*
86-
* @since 2.1.0
86+
* @since 2.1
8787
*
8888
* @param LoggerInterface $logger
8989
*

src/MediawikiApi.php

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class MediawikiApi implements MediawikiApiInterface, LoggerAwareInterface {
5555
private $apiUrl;
5656

5757
/**
58-
* @since 2.0.0
58+
* @since 2.0
5959
*
6060
* @param string $apiEndpoint e.g. https://en.wikipedia.org/w/api.php
6161
*
@@ -66,7 +66,7 @@ public static function newFromApiEndpoint( $apiEndpoint ) {
6666
}
6767

6868
/**
69-
* @since 2.0.0
69+
* @since 2.0
7070
*
7171
* @param string $url e.g. https://en.wikipedia.org OR https://de.wikipedia.org/wiki/Berlin
7272
*
@@ -106,6 +106,9 @@ public function __construct( $apiUrl, ClientInterface $client = null, MediawikiS
106106
/**
107107
* Get the API URL (the URL to which API requests are sent, usually ending in api.php).
108108
* This is useful if you've created this object via MediawikiApi::newFromPage().
109+
*
110+
* @since 2.3
111+
*
109112
* @return string The API URL.
110113
*/
111114
public function getApiUrl() {
@@ -252,29 +255,37 @@ private function getPostRequestEncoding( Request $request ) {
252255
* @return array as needed by ClientInterface::get and ClientInterface::post
253256
*/
254257
private function getClientRequestOptions( Request $request, $paramsKey ) {
255-
$params = array_merge( $request->getParams(), array( 'format' => 'json' ) );
256-
if ( $paramsKey === 'multipart' ) {
257-
$params = $this->encodeMultipartParams( $params );
258-
}
258+
259+
$params = array_merge( $request->getParams(), array( 'format' => 'json' ) );
260+
if ( $paramsKey === 'multipart' ) {
261+
$params = $this->encodeMultipartParams( $params );
262+
}
259263

260264
return array(
261265
$paramsKey => $params,
262266
'headers' => array_merge( $this->getDefaultHeaders(), $request->getHeaders() ),
263267
);
264268
}
265269

266-
/**
267-
* @param array $params
268-
* @return array
269-
*/
270+
/**
271+
* @param array $params
272+
*
273+
* @return array
274+
*/
270275
private function encodeMultipartParams( $params ) {
271-
return array_map( function( $name, $value ) {
272-
return array(
273-
'name' => $name,
274-
'contents' => $value
275-
);
276-
}, array_keys( $params ), $params );
277-
}
276+
277+
return array_map(
278+
function ( $name, $value ) {
279+
280+
return array(
281+
'name' => $name,
282+
'contents' => $value,
283+
);
284+
},
285+
array_keys( $params ),
286+
$params
287+
);
288+
}
278289

279290
/**
280291
* @return array

tests/unit/Guzzle/ClientFactoryTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Mediawiki\Api\Test\Unit\Guzzle;
44

5-
use GuzzleHttp\Client;
65
use GuzzleHttp\HandlerStack;
76
use Mediawiki\Api\Guzzle\ClientFactory;
87
use Psr\Http\Message\RequestInterface;

tests/unit/MediawikiApiTest.php

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -144,32 +144,33 @@ public function testPostActionReturnsResult( $expectedResult, $action, $params =
144144
$this->assertEquals( $expectedResult, $result );
145145
}
146146

147-
public function testPostActionWithFileReturnsResult() {
148-
$dummyFile = fopen( '/dev/null', 'r' );
149-
$params = [
150-
'filename' => 'foo.jpg',
151-
'file' => $dummyFile
152-
];
153-
$client = $this->getMockClient();
154-
$client->expects( $this->once() )
155-
->method( 'request' )
156-
->with( 'POST', null, array(
157-
'multipart' => array(
158-
array( 'name' => 'action', 'contents' => 'upload' ),
159-
array( 'name' => 'filename', 'contents' => 'foo.jpg' ),
160-
array( 'name' => 'file', 'contents' => $dummyFile ),
161-
array( 'name' => 'format', 'contents' => 'json' ),
162-
),
163-
'headers' => array( 'User-Agent' => 'addwiki-mediawiki-client' ),
164-
) )
165-
->will( $this->returnValue( $this->getMockResponse( array( 'success ' => 1 ) ) ) );
166-
$api = new MediawikiApi( '', $client );
167-
168-
$result = $api->postRequest( new SimpleRequest( 'upload', $params ) );
169-
170-
$this->assertEquals( array( 'success ' => 1 ), $result );
171-
172-
}
147+
public function testPostActionWithFileReturnsResult() {
148+
149+
$dummyFile = fopen( '/dev/null', 'r' );
150+
$params = [
151+
'filename' => 'foo.jpg',
152+
'file' => $dummyFile,
153+
];
154+
$client = $this->getMockClient();
155+
$client->expects( $this->once() )->method( 'request' )->with(
156+
'POST',
157+
null,
158+
array(
159+
'multipart' => array(
160+
array( 'name' => 'action', 'contents' => 'upload' ),
161+
array( 'name' => 'filename', 'contents' => 'foo.jpg' ),
162+
array( 'name' => 'file', 'contents' => $dummyFile ),
163+
array( 'name' => 'format', 'contents' => 'json' ),
164+
),
165+
'headers' => array( 'User-Agent' => 'addwiki-mediawiki-client' ),
166+
)
167+
)->will( $this->returnValue( $this->getMockResponse( array( 'success ' => 1 ) ) ) );
168+
$api = new MediawikiApi( '', $client );
169+
170+
$result = $api->postRequest( new SimpleRequest( 'upload', $params ) );
171+
172+
$this->assertEquals( array( 'success ' => 1 ), $result );
173+
}
173174

174175
public function provideActionsParamsResults() {
175176
return array(

0 commit comments

Comments
 (0)