MediaWiki  1.27.2
importImages.inc
Go to the documentation of this file.
1 <?php
34 function findFiles( $dir, $exts, $recurse = false ) {
35  if ( is_dir( $dir ) ) {
36  $dhl = opendir( $dir );
37  if ( $dhl ) {
38  $files = [];
39  while ( ( $file = readdir( $dhl ) ) !== false ) {
40  if ( is_file( $dir . '/' . $file ) ) {
41  list( /* $name */, $ext ) = splitFilename( $dir . '/' . $file );
42  if ( array_search( strtolower( $ext ), $exts ) !== false ) {
43  $files[] = $dir . '/' . $file;
44  }
45  } elseif ( $recurse && is_dir( $dir . '/' . $file ) && $file !== '..' && $file !== '.' ) {
46  $files = array_merge( $files, findFiles( $dir . '/' . $file, $exts, true ) );
47  }
48  }
49 
50  return $files;
51  } else {
52  return [];
53  }
54  } else {
55  return [];
56  }
57 }
58 
65 function splitFilename( $filename ) {
66  $parts = explode( '.', $filename );
67  $ext = $parts[count( $parts ) - 1];
68  unset( $parts[count( $parts ) - 1] );
69  $fname = implode( '.', $parts );
70 
71  return [ $fname, $ext ];
72 }
73 
88 function findAuxFile( $file, $auxExtension, $maxStrip = 1 ) {
89  if ( strpos( $auxExtension, '.' ) !== 0 ) {
90  $auxExtension = '.' . $auxExtension;
91  }
92 
93  $d = dirname( $file );
94  $n = basename( $file );
95 
96  while ( $maxStrip >= 0 ) {
97  $f = $d . '/' . $n . $auxExtension;
98 
99  if ( file_exists( $f ) ) {
100  return $f;
101  }
102 
103  $idx = strrpos( $n, '.' );
104  if ( !$idx ) {
105  break;
106  }
107 
108  $n = substr( $n, 0, $idx );
109  $maxStrip -= 1;
110  }
111 
112  return false;
113 }
114 
115 # @todo FIXME: Access the api in a saner way and performing just one query
116 # (preferably batching files too).
117 function getFileCommentFromSourceWiki( $wiki_host, $file ) {
118  $url = $wiki_host . '/api.php?action=query&format=xml&titles=File:'
119  . rawurlencode( $file ) . '&prop=imageinfo&&iiprop=comment';
120  $body = Http::get( $url, [], __METHOD__ );
121  if ( preg_match( '#<ii comment="([^"]*)" />#', $body, $matches ) == 0 ) {
122  return false;
123  }
124 
125  return html_entity_decode( $matches[1] );
126 }
127 
128 function getFileUserFromSourceWiki( $wiki_host, $file ) {
129  $url = $wiki_host . '/api.php?action=query&format=xml&titles=File:'
130  . rawurlencode( $file ) . '&prop=imageinfo&&iiprop=user';
131  $body = Http::get( $url, [], __METHOD__ );
132  if ( preg_match( '#<ii user="([^"]*)" />#', $body, $matches ) == 0 ) {
133  return false;
134  }
135 
136  return html_entity_decode( $matches[1] );
137 }
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition: deferred.txt:11
if(count($args)==0) $dir
splitFilename($filename)
Split a filename into filename and extension.
getFileCommentFromSourceWiki($wiki_host, $file)
$files
getFileUserFromSourceWiki($wiki_host, $file)
findFiles($dir, $exts, $recurse=false)
Search a directory for files with one of a set of extensions.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
if(!defined( 'MEDIAWIKI')) $fname
This file is not a valid entry point, perform no further processing unless MEDIAWIKI is defined...
Definition: Setup.php:35
findAuxFile($file, $auxExtension, $maxStrip=1)
Find an auxilliary file with the given extension, matching the give base file path.
static get($url, $options=[], $caller=__METHOD__)
Simple wrapper for Http::request( 'GET' )
$matches