[ Index ]

PHP Cross Reference of MediaWiki-1.24.0

title

Body

[close]

/extensions/LocalisationUpdate/fetcher/ -> GitHubFetcher.php (source)

   1  <?php
   2  /**
   3   * @file
   4   * @author Niklas Laxström
   5   * @license GPL-2.0+
   6   */
   7  
   8  /**
   9   * This class uses GitHub api to obtain a list of files present in a directory
  10   * to avoid fetching files that don't exist.
  11   *
  12   * @todo Could use file hashes to 1) avoid fetching files with same hash as
  13   * the source. 2) avoid fetching files which haven't changed since last check
  14   * if we store them.
  15   */
  16  class LU_GitHubFetcher extends LU_HttpFetcher {
  17  
  18  	public function fetchDirectory( $pattern ) {
  19          $p =  '~^https://raw.github\.com/(?P<org>[^/]+)/(?P<repo>[^/]+)/(?P<branch>[^/]+)/(?P<path>.+)/.+$~';
  20          preg_match( $p, $pattern, $m );
  21  
  22          $json = Http::get( "https://api.github.com/repos/{$m['org']}/{$m['repo']}/contents/{$m['path']}" );
  23          if ( !$json ) {
  24              throw new MWException( "Unable to get directory listing for {$m['org']}/{$m['repo']}" );
  25          }
  26  
  27          $files = array();
  28          $json = FormatJson::decode( $json, true );
  29          foreach ( $json as $fileinfo ) {
  30              $fileurl = dirname( $pattern ) . '/' . $fileinfo['name'];
  31              $file = $this->fetchFile( $fileurl );
  32              if ( $file ) {
  33                  $files[$fileurl] = $file;
  34              }
  35          }
  36          return $files;
  37      }
  38  }


Generated: Fri Nov 28 14:03:12 2014 Cross-referenced by PHPXref 0.7.1