Completed
Pull Request — newinternal (#285)
by Simon
07:17 queued 04:17
created

WikiTextHelper   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 51
ccs 0
cts 22
cp 0
rs 10
c 0
b 0
f 0
wmc 2
lcom 1
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getHtmlForWikiText() 0 20 1
1
<?php
2
/******************************************************************************
3
 * Wikipedia Account Creation Assistance tool                                 *
4
 *                                                                            *
5
 * All code in this file is released into the public domain by the ACC        *
6
 * Development Team. Please see team.json for a list of contributors.         *
7
 ******************************************************************************/
8
9
namespace Waca\Helpers;
10
11
use Waca\SiteConfiguration;
12
13
class WikiTextHelper
14
{
15
    /**
16
     * @var SiteConfiguration
17
     */
18
    private $configuration;
19
    /**
20
     * @var HttpHelper
21
     */
22
    private $http;
23
24
    /**
25
     * WikiTextHelper constructor.
26
     *
27
     * @param SiteConfiguration $configuration
28
     * @param HttpHelper        $http
29
     */
30
    public function __construct(SiteConfiguration $configuration, HttpHelper $http)
31
    {
32
        $this->configuration = $configuration;
33
        $this->http = $http;
34
    }
35
36
    /**
37
     * Gets the HTML for the provided wiki-markup from the MediaWiki service endpoint
38
     *
39
     * @param string $wikiText
40
     *
41
     * @return string
42
     */
43
    public function getHtmlForWikiText($wikiText)
44
    {
45
        $endpoint = $this->configuration->getMediawikiWebServiceEndpoint();
46
47
        $parameters = array(
48
            'action'             => 'parse',
49
            'pst'                => true,
50
            'contentmodel'       => 'wikitext',
51
            'disablelimitreport' => true,
52
            'disabletoc'         => true,
53
            'disableeditsection' => true,
54
            'format'             => 'php',
55
            'text'               => $wikiText,
56
        );
57
58
        $apiResult = $this->http->get($endpoint, $parameters);
59
        $parseResult = unserialize($apiResult);
60
61
        return $parseResult['parse']['text']['*'];
62
    }
63
}