Completed
Pull Request — newinternal (#285)
by Simon
03:26
created

WikiTextHelper::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 5
ccs 0
cts 5
cp 0
crap 2
rs 9.4285
c 0
b 0
f 0
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
}