blob: aa58bdeb4b916a88635a5a33725ac7686f9a1f9e (
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
57
58
59
60
61
62
63
64
65
66
67
68
|
<?php
namespace SMW\MediaWiki\Api\Browse;
use SMW\MediaWiki\TitleFactory;
use Title;
/**
* @license GNU GPL v2+
* @since 3.0
*
* @author mwjames
*/
class ArticleAugmentor {
/**
* @var TitleFactory
*/
private $titleFactory;
/**
* @since 3.0
*
* @param TitleFactory $titleFactory
*/
public function __construct( TitleFactory $titleFactory ) {
$this->titleFactory = $titleFactory;
}
/**
* @since 3.0
*
* @param array &$res
* @param array $parameters
*
* @return array
*/
public function augment( array &$res, array $parameters ) {
if ( !isset( $res['query'] ) && $res['query'] === [] ) {
return;
}
if ( isset( $parameters['fullText' ] ) || isset( $parameters['fullURL' ] ) ) {
foreach ( $res['query'] as $key => &$value ) {
$title = $this->titleFactory->newFromID( $value['id'] );
if ( isset( $parameters['fullText' ] ) ) {
$value['fullText'] = $title->getFullText();
}
if ( isset( $parameters['fullURL' ] ) ) {
$value['fullURL'] = $title->getFullURL();
}
}
}
// Remove the internal ID, no external consumer should rely on it
foreach ( $res['query'] as $key => &$value ) {
unset( $value['id'] );
}
return $res;
}
}
|