blob: ba5624dc946b21d2ffd0f2b69d8d9e6767077832 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
<?php
namespace Mediawiki\Api\Service;
use Mediawiki\Api\SimpleRequest;
use Mediawiki\Api\UsageException;
use Mediawiki\DataModel\File;
/**
* @access private
*
* @author Addshore
*/
class ImageRotator extends Service {
/**
* NOTE: This service has not been fully tested
*
* @param File $file
* @param int $rotation Degrees to rotate image clockwise, One value: 90, 180, 270
*
* @throws UsageException
* @return bool
*/
public function rotate( File $file, $rotation ) {
$params = [
'rotation' => $rotation,
'token' => $this->api->getToken(),
];
if ( !is_null( $file->getPageIdentifier()->getTitle() ) ) {
$params['titles'] = $file->getPageIdentifier()->getTitle()->getText();
} else {
$params['pageids'] = $file->getPageIdentifier()->getId();
}
$result = $this->api->postRequest( new SimpleRequest( 'imagerotate', $params ) );
// This module sometimes gives odd errors so deal with them..
if ( array_key_exists( 'imagerotate', $result ) ) {
$imageRotate = array_pop( $result['imagerotate'] );
if ( array_key_exists( 'result', $imageRotate ) &&
$imageRotate['result'] == 'Failure'
) {
throw new UsageException(
'imagerotate-Failure',
$imageRotate['errormessage'],
$result
);
}
}
return true;
}
}
|