MediaWiki  1.23.15
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 = array();
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  return $files;
50  } else {
51  return array();
52  }
53  } else {
54  return array();
55  }
56 }
57 
64 function splitFilename( $filename ) {
65  $parts = explode( '.', $filename );
66  $ext = $parts[ count( $parts ) - 1 ];
67  unset( $parts[ count( $parts ) - 1 ] );
68  $fname = implode( '.', $parts );
69  return array( $fname, $ext );
70 }
71 
86 function findAuxFile( $file, $auxExtension, $maxStrip = 1 ) {
87  if ( strpos( $auxExtension, '.' ) !== 0 ) {
88  $auxExtension = '.' . $auxExtension;
89  }
90 
91  $d = dirname( $file );
92  $n = basename( $file );
93 
94  while ( $maxStrip >= 0 ) {
95  $f = $d . '/' . $n . $auxExtension;
96 
97  if ( file_exists( $f ) ) {
98  return $f;
99  }
100 
101  $idx = strrpos( $n, '.' );
102  if ( !$idx ) {
103  break;
104  }
105 
106  $n = substr( $n, 0, $idx );
107  $maxStrip -= 1;
108  }
109 
110  return false;
111 }
112 
113 # FIXME: Access the api in a saner way and performing just one query (preferably batching files too).
114 function getFileCommentFromSourceWiki( $wiki_host, $file ) {
115  $url = $wiki_host . '/api.php?action=query&format=xml&titles=File:' . rawurlencode( $file ) . '&prop=imageinfo&&iiprop=comment';
116  $body = Http::get( $url );
117  if ( preg_match( '#<ii comment="([^"]*)" />#', $body, $matches ) == 0 ) {
118  return false;
119  }
120 
121  return html_entity_decode( $matches[1] );
122 }
123 
124 function getFileUserFromSourceWiki( $wiki_host, $file ) {
125  $url = $wiki_host . '/api.php?action=query&format=xml&titles=File:' . rawurlencode( $file ) . '&prop=imageinfo&&iiprop=user';
126  $body = Http::get( $url );
127  if ( preg_match( '#<ii user="([^"]*)" />#', $body, $matches ) == 0 ) {
128  return false;
129  }
130 
131  return html_entity_decode( $matches[1] );
132 }
133 
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
$files
$files
Definition: importImages.php:67
$f
$f
Definition: UtfNormalTest2.php:38
$n
$n
Definition: RandomTest.php:76
$fname
if(!defined( 'MEDIAWIKI')) $fname
This file is not a valid entry point, perform no further processing unless MEDIAWIKI is defined.
Definition: Setup.php:35
splitFilename
splitFilename( $filename)
Split a filename into filename and extension.
Definition: importImages.inc:64
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
list
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
Http\get
static get( $url, $timeout='default', $options=array())
Simple wrapper for Http::request( 'GET' )
Definition: HttpFunctions.php:98
findFiles
findFiles( $dir, $exts, $recurse=false)
Search a directory for files with one of a set of extensions.
Definition: importImages.inc:34
$matches
if(!defined( 'MEDIAWIKI')) if(!isset( $wgVersion)) $matches
Definition: NoLocalSettings.php:33
getFileUserFromSourceWiki
getFileUserFromSourceWiki( $wiki_host, $file)
Definition: importImages.inc:124
$file
if(PHP_SAPI !='cli') $file
Definition: UtfNormalTest2.php:30
$dir
if(count( $args)==0) $dir
Definition: importImages.php:49
$ext
$ext
Definition: NoLocalSettings.php:34
getFileCommentFromSourceWiki
getFileCommentFromSourceWiki( $wiki_host, $file)
Definition: importImages.inc:114
findAuxFile
findAuxFile( $file, $auxExtension, $maxStrip=1)
Find an auxilliary file with the given extension, matching the give base file path.
Definition: importImages.inc:86