Skip to content
This repository was archived by the owner on Jan 25, 2023. It is now read-only.

Commit d853bbc

Browse files
committed
Added wikipedia as edge versions source
1 parent 910f635 commit d853bbc

File tree

3 files changed

+132
-0
lines changed

3 files changed

+132
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
class Wikipedia
4+
{
5+
const URL = 'https://en.wikipedia.org/w/api.php?action=query&titles=Microsoft_Edge&prop=revisions&rvprop=content&rvsection=4&format=xml';
6+
7+
private static $errors = array(
8+
'fetch_error' => 'Unable to fetch content',
9+
'parse_error' => 'Unable to parse content',
10+
);
11+
12+
public static function fetch()
13+
{
14+
$content = file_get_contents(self::URL);
15+
if (!$content) throw new Exception(self::$errors['fetch_error']);
16+
$content = explode('===Release history===', $content);
17+
if (!isset($content[1])) throw new Exception(self::$errors['parse_error']);
18+
$table = explode('|-', $content[1]);
19+
if (!isset($table[1])) throw new Exception(self::$errors['parse_error']);
20+
$table = array_slice($table, 1);
21+
$versions = array_map(array('Wikipedia', 'extractVersion'), $table);
22+
self::writeEdgeVersions($versions);
23+
}
24+
25+
private static function extractVersion($content)
26+
{
27+
$lines = array_slice(array_filter(
28+
explode(PHP_EOL, $content),
29+
function ($val) { return trim($val) && strpos($val, '|') === 0; }
30+
), 0, 2);
31+
32+
preg_match("/{[^}{]*Version[^}{]*\| ?([\d\.]+)}/", $lines[0], $edgeVersion);
33+
preg_match("/\| *(\d*\.\d*)/", $lines[1], $edgeHtmlVersion);
34+
35+
if (!isset($edgeVersion[1])) throw new Exception(self::$errors['parse_error']);
36+
if (!isset($edgeHtmlVersion[1])) throw new Exception(self::$errors['parse_error']);
37+
38+
return array($edgeHtmlVersion[1], $edgeVersion[1]);
39+
}
40+
41+
private static function writeEdgeVersions($versions)
42+
{
43+
$file = __DIR__ . '/../../src/edgeVersionMap.php';
44+
$currentVersions = require $file;
45+
46+
foreach ($versions as $version) {
47+
$currentVersions[$version[0]] = $version[1];
48+
}
49+
ksort($currentVersions);
50+
51+
$content = '';
52+
foreach ($currentVersions as $edgeHtml => $edge) {
53+
$content .= " '{$edgeHtml}' => '{$edge}'," . PHP_EOL;
54+
}
55+
$data = <<<PHP
56+
<?php
57+
58+
return array(
59+
%s
60+
);
61+
62+
PHP;
63+
file_put_contents($file, sprintf($data, trim($content)));
64+
}
65+
}

scripts/fetchEdgeVersions/index.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
<?php
22

3+
require_once __DIR__ . '/ChangeWindows.php';
4+
require_once __DIR__ . '/Wikipedia.php';
5+
6+
Wikipedia::fetch();
7+
ChangeWindows::fetchVersions();

src/edgeVersionMap.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,68 @@
11
<?php
22

33
return array(
4+
'12.10049' => '0.10.10049',
5+
'12.10051' => '0.11.10051',
6+
'12.10052' => '0.11.10052',
7+
'12.10061' => '0.11.10061',
8+
'12.10074' => '0.11.10074',
9+
'12.10080' => '0.11.10080',
10+
'12.10122' => '13.10122',
11+
'12.10130' => '15.10130',
12+
'12.10136' => '16.10136',
13+
'12.10149' => '19.10149',
14+
'12.10158' => '20.10158',
15+
'12.10159' => '20.10159',
16+
'12.10162' => '20.10162',
17+
'12.10166' => '20.10166',
18+
'12.10240' => '20.10240',
19+
'12.10512' => '20.10512',
20+
'12.10514' => '20.10514',
21+
'12.10525' => '20.10525',
22+
'12.10532' => '20.10532',
23+
'12.10536' => '20.10536',
24+
'13.10547' => '21.10547',
25+
'13.10549' => '21.10549',
26+
'13.10565' => '23.10565',
27+
'13.10572' => '25.10572',
28+
'13.10576' => '25.10576',
29+
'13.10581' => '25.10581',
30+
'13.10586' => '25.10586',
31+
'13.11082' => '25.11082',
32+
'13.11099' => '27.11099',
33+
'13.11102' => '28.11102',
34+
'13.14251' => '28.14251',
35+
'13.14257' => '28.14257',
36+
'14.14267' => '31.14267',
37+
'14.14271' => '31.14271',
38+
'14.14279' => '31.14279',
39+
'14.14283' => '31.14283',
40+
'14.14291' => '34.14291',
41+
'14.14295' => '34.14295',
42+
'14.14300' => '34.14300',
43+
'14.14316' => '37.14316',
44+
'14.14322' => '37.14322',
45+
'14.14327' => '37.14327',
46+
'14.14328' => '37.14328',
47+
'14.14332' => '37.14332',
48+
'14.14342' => '38.14342',
49+
'14.14352' => '38.14352',
50+
'14.14393' => '38.14393',
51+
'14.14901' => '39.14901',
52+
'14.14905' => '39.14905',
53+
'14.14915' => '39.14915',
54+
'14.14926' => '39.14926',
55+
'14.14931' => '39.14931',
56+
'14.14936' => '39.14936',
57+
'15.14942' => '39.14942',
58+
'15.14946' => '39.14946',
59+
'15.14951' => '39.14951',
60+
'15.14955' => '39.14955',
61+
'15.14959' => '39.14959',
62+
'15.14965' => '39.14965',
63+
'15.14971' => '39.14971',
64+
'15.14977' => '39.14977',
65+
'15.14986' => '39.14986',
466
'15.15002' => '39.15002',
567
'15.15007' => '39.15007',
668
'15.15019' => '40.15019',

0 commit comments

Comments
 (0)