/** * Return the full filesystem path to the file. Note that this does * not mean that a file actually exists under that location. * * This path depends on whether directory hashing is active or not, * i.e. whether the images are all found in the same directory, * or in hashed paths like /images/3/3c. * * @access public * @param boolean $fromSharedDirectory Return the path to the file * in a shared repository (see $wgUseSharedRepository and related * options in DefaultSettings.php) instead of a local one. * */ function getFullPath($fromSharedRepository = false) { global $wgUploadDirectory, $wgSharedUploadDirectory; global $wgHashedUploadDirectory, $wgHashedSharedUploadDirectory; $dir = $fromSharedRepository ? $wgSharedUploadDirectory : $wgUploadDirectory; // $wgSharedUploadDirectory may be false, if thumb.php is used if ($dir) { $fullpath = $dir . wfGetHashPath($this->name, $fromSharedRepository) . $this->name; } else { $fullpath = false; } return $fullpath; }
# Set up a fake user for this operation $wgUser = User::newFromName('Image import script'); $wgUser->setLoaded(true); # Batch "upload" operation foreach ($files as $file) { $base = basename($file); # Validate a title $title = Title::makeTitleSafe(NS_IMAGE, $base); if (is_object($title)) { # Check existence $image = new Image($title); if (!$image->exists()) { global $wgUploadDirectory; # copy() doesn't create paths so if the hash path doesn't exist, we # have to create it makeHashPath(wfGetHashPath($image->name)); # Stash the file echo "Saving {$base}..."; if (copy($file, $image->getFullPath())) { echo "importing..."; # Grab the metadata $image->loadFromFile(); # Record the upload if ($image->recordUpload('', 'Importing image file')) { # We're done! echo "done.\n"; } else { echo "failed.\n"; } } else { echo "failed.\n";
function outputItem($name, $directory, $shared) { $filename = $directory . wfGetHashPath($name, $shared) . $name; $rel = $this->relativePath($filename, $this->mBasePath); echo "{$rel}\n"; }