MediaWiki REL1_30
GitHubFetcher.php
Go to the documentation of this file.
1<?php
8namespace LocalisationUpdate;
9
19 public function fetchDirectory( $pattern ) {
20 $domain = preg_quote( 'https://raw.github.com/', '~' );
21 $p = "~^$domain(?P<org>[^/]+)/(?P<repo>[^/]+)/(?P<branch>[^/]+)/(?P<path>.+)/.+$~";
22 preg_match( $p, $pattern, $m );
23
24 $apiURL = "https://api.github.com/repos/{$m['org']}/{$m['repo']}/contents/{$m['path']}";
25 $json = \Http::get( $apiURL );
26 if ( !$json ) {
27 throw new \Exception( "Unable to get directory listing for {$m['org']}/{$m['repo']}" );
28 }
29
30 $files = [];
31 $json = \FormatJson::decode( $json, true );
32 foreach ( $json as $fileinfo ) {
33 $fileurl = dirname( $pattern ) . '/' . $fileinfo['name'];
34 $file = $this->fetchFile( $fileurl );
35 if ( $file ) {
36 $files[$fileurl] = $file;
37 }
38 }
39 return $files;
40 }
41}
This class uses GitHub api to obtain a list of files present in a directory to avoid fetching files t...
fetchDirectory( $pattern)
This is horribly inefficient.
Fetches files over HTTP(s).