diff options
Diffstat (limited to 'www/wiki/extensions/SemanticMediaWiki/src/MediaWiki/Api/Browse/ArticleAugmentor.php')
-rw-r--r-- | www/wiki/extensions/SemanticMediaWiki/src/MediaWiki/Api/Browse/ArticleAugmentor.php | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/www/wiki/extensions/SemanticMediaWiki/src/MediaWiki/Api/Browse/ArticleAugmentor.php b/www/wiki/extensions/SemanticMediaWiki/src/MediaWiki/Api/Browse/ArticleAugmentor.php new file mode 100644 index 00000000..aa58bdeb --- /dev/null +++ b/www/wiki/extensions/SemanticMediaWiki/src/MediaWiki/Api/Browse/ArticleAugmentor.php @@ -0,0 +1,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; + } + +} |