Debian Codegraph @

vendor/wikimedia/parsoid/tools/FetchWmfSitematrix.php

raw
1 <?php
2
3 namespace Wikimedia\Parsoid\Tools;
4
5 use Wikimedia\Parsoid\Config\Api\ApiHelper;
6
7 require_once __DIR__ . '/Maintenance.php';
8
9 /**
10 * Class FetchWmfSitematrix
11 * Simple script to update sitematrix.json
12 */
13 class FetchWmfSitematrix extends Maintenance {
14
15 /**
16 * Updates sitematrix.json
17 */
18 public function execute() {
19 $apiHelperOpts = [
20 'apiEndpoint' => 'https://en.wikipedia.org/w/api.php'
21 ];
22 $apiHelper = new ApiHelper( $apiHelperOpts );
23 $apiParams = [
24 'action' => 'sitematrix',
25 'format' => 'json',
26 'formatversion' => 1
27 ];
28 $response = $apiHelper->makeRequest( $apiParams );
29
30 $fileName = __DIR__ . '/data/wmf.sitematrix.json';
31 $resultStr = json_encode( $response,
32 JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES );
33 file_put_contents( $fileName, $resultStr );
34 }
35 }
36
37 $maintClass = FetchWmfSitematrix::class;
38 require_once PARSOID_RUN_MAINTENANCE_IF_MAIN;