本文整理汇总了PHP中wfBaseName函数的典型用法代码示例。如果您正苦于以下问题:PHP wfBaseName函数的具体用法?PHP wfBaseName怎么用?PHP wfBaseName使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wfBaseName函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testBasename
function testBasename()
{
$sets = array('' => '', '/' => '', '\\' => '', '//' => '', '\\\\' => '', 'a' => 'a', 'aaaa' => 'aaaa', '/a' => 'a', '\\a' => 'a', '/aaaa' => 'aaaa', '\\aaaa' => 'aaaa', '/aaaa/' => 'aaaa', '\\aaaa\\' => 'aaaa', '\\aaaa\\' => 'aaaa', '/mnt/upload3/wikipedia/en/thumb/8/8b/Zork_Grand_Inquisitor_box_cover.jpg/93px-Zork_Grand_Inquisitor_box_cover.jpg' => '93px-Zork_Grand_Inquisitor_box_cover.jpg', 'C:\\Progra~1\\Wikime~1\\Wikipe~1\\VIEWER.EXE' => 'VIEWER.EXE', 'Östergötland_coat_of_arms.png' => 'Östergötland_coat_of_arms.png');
foreach ($sets as $from => $to) {
$this->assertEquals($to, wfBaseName($from), "wfBaseName('{$from}') => '{$to}'");
}
}
示例2: wfStripIllegalFilenameChars
/**
* Replace all invalid characters with '-'.
* Additional characters can be defined in $wgIllegalFileChars (see T22489).
* By default, $wgIllegalFileChars includes ':', '/', '\'.
*
* @param string $name Filename to process
* @return string
*/
function wfStripIllegalFilenameChars($name)
{
global $wgIllegalFileChars;
$illegalFileChars = $wgIllegalFileChars ? "|[" . $wgIllegalFileChars . "]" : '';
$name = preg_replace("/[^" . Title::legalChars() . "]" . $illegalFileChars . "/", '-', $name);
// $wgIllegalFileChars may not include '/' and '\', so we still need to do this
$name = wfBaseName($name);
return $name;
}
示例3: makeThumbs
private static function makeThumbs($local_file, $sample)
{
global $wgImageMagickConvertCommand, $wgUseOptiPng, $wgOptiPngCommand;
$comment = 'Auto-uploaded for the Samples page.';
$license = 'cc-by-sa-nc-2.5-self';
//PNG the file name
$img_file = preg_replace('@.pdf@', '.png', $local_file);
//make an image out of a pdf (add an [0] so we only get the first page)
$cmd = $wgImageMagickConvertCommand . ' ' . escapeshellarg($local_file) . '[0] ' . escapeshellarg($img_file);
exec($cmd);
//optimize that bad boy
if ($wgUseOptiPng) {
$cmd = $wgOptiPngCommand . ' ' . escapeshellarg($img_file);
exec($cmd);
}
//put the new image into the system
$title = Title::makeTitleSafe(NS_IMAGE, wfBaseName($img_file));
if (!is_object($title)) {
self::error_log($sample, 'Image could not be imported; a valid title cannot be produced.');
return false;
}
$image = wfLocalFile($title);
$archive = $image->publish($img_file);
//remove the temp image file
@unlink($img_file);
if (WikiError::isError($archive) || !$archive->isGood()) {
self::error_log($sample, 'Image archive publish failed.');
return false;
}
if ($image->recordUpload($archive->value, $comment, $license)) {
//yay!
return true;
} else {
self::error_log($sample, 'Image record upload failed.');
return false;
}
}
示例4: file_get_contents
if (isset($options['comment-file'])) {
$comment = file_get_contents($options['comment-file']);
if ($comment === false || $comment === null) {
die("failed to read comment file: {$options['comment-file']}\n");
}
} elseif (isset($options['comment'])) {
$comment = $options['comment'];
}
$commentExt = isset($options['comment-ext']) ? $options['comment-ext'] : false;
# Get the license specifier
$license = isset($options['license']) ? $options['license'] : '';
# Batch "upload" operation
$count = count($files);
if ($count > 0) {
foreach ($files as $file) {
$base = wfBaseName($file);
# Validate a title
$title = Title::makeTitleSafe(NS_FILE, $base);
if (!is_object($title)) {
echo "{$base} could not be imported; a valid title cannot be produced\n";
continue;
}
if ($from) {
if ($from == $title->getDBkey()) {
$from = null;
} else {
$ignored++;
continue;
}
}
if ($checkUserBlock && $processed % $checkUserBlock == 0) {
示例5: getLocalCopy
/**
* @see FileBackendStore::getLocalCopy()
*/
public function getLocalCopy(array $params)
{
list($srcCont, $srcRel) = $this->resolveStoragePathReal($params['src']);
if ($srcRel === null) {
return null;
}
/*if ( !$this->fileExists( $params ) ) {
return null;
}*/
$tmpFile = null;
try {
$sContObj = $this->getContainer($srcCont);
$obj = new CF_Object($sContObj, $srcRel, false, false);
// skip HEAD
// Get source file extension
$ext = FileBackend::extensionFromPath($srcRel);
// Create a new temporary file...
$tmpFile = TempFSFile::factory(wfBaseName($srcRel) . '_', $ext);
if ($tmpFile) {
$handle = fopen($tmpFile->getPath(), 'wb');
if ($handle) {
$obj->stream($handle, $this->headersFromParams($params));
fclose($handle);
} else {
$tmpFile = null;
// couldn't open temp file
}
}
} catch (NoSuchContainerException $e) {
$tmpFile = null;
$this->logException($e, __METHOD__, $params);
} catch (NoSuchObjectException $e) {
$tmpFile = null;
$this->logException($e, __METHOD__, $params);
} catch (InvalidResponseException $e) {
$tmpFile = null;
$this->logException($e, __METHOD__, $params);
} catch (Exception $e) {
// some other exception?
$tmpFile = null;
$this->logException($e, __METHOD__, $params);
}
return $tmpFile;
}
示例6: wfStripIllegalFilenameChars
/**
* Replace all invalid characters with -
* Additional characters can be defined in $wgIllegalFileChars (see bug 20489)
* By default, $wgIllegalFileChars = ':'
*
* @param string $name Filename to process
* @return string
*/
function wfStripIllegalFilenameChars($name)
{
global $wgIllegalFileChars;
$illegalFileChars = $wgIllegalFileChars ? "|[" . $wgIllegalFileChars . "]" : '';
$name = wfBaseName($name);
$name = preg_replace("/[^" . Title::legalChars() . "]" . $illegalFileChars . "/", '-', $name);
return $name;
}
示例7: wfImageAuthMain
function wfImageAuthMain()
{
global $wgImgAuthPublicTest, $wgRequest;
// See if this is a public Wiki (no protections).
if ($wgImgAuthPublicTest && in_array('read', User::getGroupPermissions(array('*')), true)) {
// This is a public wiki, so disable this script (for private wikis only)
wfForbidden('img-auth-accessdenied', 'img-auth-public');
return;
}
// Get the requested file path (source file or thumbnail)
$matches = WebRequest::getPathInfo();
if (!isset($matches['title'])) {
wfForbidden('img-auth-accessdenied', 'img-auth-nopathinfo');
return;
}
$path = $matches['title'];
if ($path && $path[0] !== '/') {
// Make sure $path has a leading /
$path = "/" . $path;
}
// Check for bug 28235: QUERY_STRING overriding the correct extension
$whitelist = array();
$dotPos = strrpos($path, '.');
if ($dotPos !== false) {
$whitelist[] = substr($path, $dotPos + 1);
}
if (!$wgRequest->checkUrlExtension($whitelist)) {
return;
}
// Get the local file repository
$repo = RepoGroup::singleton()->getRepo('local');
// Get the full file storage path and extract the source file name.
// (e.g. 120px-Foo.png => Foo.png or page2-120px-Foo.png => Foo.png).
// This only applies to thumbnails, and all thumbnails should
// be under a folder that has the source file name.
if (strpos($path, '/thumb/') === 0) {
$name = wfBaseName(dirname($path));
// file is a thumbnail
$filename = $repo->getZonePath('thumb') . substr($path, 6);
// strip "/thumb"
} else {
$name = wfBaseName($path);
// file is a source file
$filename = $repo->getZonePath('public') . $path;
}
// Check to see if the file exists
if (!$repo->fileExists($filename)) {
wfForbidden('img-auth-accessdenied', 'img-auth-nofile', $filename);
return;
}
$title = Title::makeTitleSafe(NS_FILE, $name);
if (!$title instanceof Title) {
// files have valid titles
wfForbidden('img-auth-accessdenied', 'img-auth-badtitle', $name);
return;
}
// Run hook for extension authorization plugins
/** @var $result array */
$result = null;
if (!wfRunHooks('ImgAuthBeforeStream', array(&$title, &$path, &$name, &$result))) {
wfForbidden($result[0], $result[1], array_slice($result, 2));
return;
}
// Check user authorization for this title
// Checks Whitelist too
if (!$title->userCan('read')) {
wfForbidden('img-auth-accessdenied', 'img-auth-noread', $name);
return;
}
// Stream the requested file
wfDebugLog('img_auth', "Streaming `" . $filename . "`.");
$repo->streamFile($filename, array('Cache-Control: private', 'Vary: Cookie'));
}
示例8: file_get_contents
$comment = file_get_contents($options['comment-file']);
if ($comment === false || $comment === null) {
die("failed to read comment file: {$options['comment-file']}\n");
}
} elseif (isset($options['comment'])) {
$comment = $options['comment'];
}
$commentExt = isset($options['comment-ext']) ? $options['comment-ext'] : false;
$summary = isset($options['summary']) ? $options['summary'] : '';
# Get the license specifier
$license = isset($options['license']) ? $options['license'] : '';
# Batch "upload" operation
$count = count($files);
if ($count > 0) {
foreach ($files as $file) {
$base = UtfNormal\Validator::cleanUp(wfBaseName($file));
# Validate a title
$title = Title::makeTitleSafe(NS_FILE, $base);
if (!is_object($title)) {
echo "{$base} could not be imported; a valid title cannot be produced\n";
continue;
}
if ($from) {
if ($from == $title->getDBkey()) {
$from = null;
} else {
$ignored++;
continue;
}
}
if ($checkUserBlock && $processed % $checkUserBlock == 0) {
示例9: checkMissingImage
function checkMissingImage($fullpath)
{
$filename = wfBaseName($fullpath);
if (is_dir($fullpath)) {
return;
}
if (is_link($fullpath)) {
$this->output("skipping symlink at {$fullpath}\n");
return;
}
$row = $this->dbw->selectRow('image', array('img_name'), array('img_name' => $filename), __METHOD__);
if ($row) {
// already known, move on
return;
} else {
$this->addMissingImage($filename, $fullpath);
}
}
示例10: __construct
/**
* Constructor
*
* @param $file String: filename.
*/
function __construct($file)
{
/**
* Page numbers here refer to pages in the EXIF 2.2 standard
*
* @link http://exif.org/Exif2-2.PDF The Exif 2.2 specification
*/
$this->mExifTags = array('tiff' => array('structure' => array('ImageWidth' => Exif::SHORT . ',' . Exif::LONG, 'ImageLength' => Exif::SHORT . ',' . Exif::LONG, 'BitsPerSample' => Exif::SHORT, 'Compression' => Exif::SHORT, 'PhotometricInterpretation' => Exif::SHORT, 'Orientation' => Exif::SHORT, 'SamplesPerPixel' => Exif::SHORT, 'PlanarConfiguration' => Exif::SHORT, 'YCbCrSubSampling' => Exif::SHORT, 'YCbCrPositioning' => Exif::SHORT, 'XResolution' => Exif::RATIONAL, 'YResolution' => Exif::RATIONAL, 'ResolutionUnit' => Exif::SHORT), 'offset' => array('StripOffsets' => Exif::SHORT . ',' . Exif::LONG, 'RowsPerStrip' => Exif::SHORT . ',' . Exif::LONG, 'StripByteCounts' => Exif::SHORT . ',' . Exif::LONG, 'JPEGInterchangeFormat' => Exif::SHORT . ',' . Exif::LONG, 'JPEGInterchangeFormatLength' => Exif::SHORT . ',' . Exif::LONG), 'characteristics' => array('TransferFunction' => Exif::SHORT, 'WhitePoint' => Exif::RATIONAL, 'PrimaryChromaticities' => Exif::RATIONAL, 'YCbCrCoefficients' => Exif::RATIONAL, 'ReferenceBlackWhite' => Exif::RATIONAL), 'other' => array('DateTime' => Exif::ASCII, 'ImageDescription' => Exif::ASCII, 'Make' => Exif::ASCII, 'Model' => Exif::ASCII, 'Software' => Exif::ASCII, 'Artist' => Exif::ASCII, 'Copyright' => Exif::ASCII)), 'exif' => array('version' => array('ExifVersion' => Exif::UNDEFINED, 'FlashpixVersion' => Exif::UNDEFINED), 'characteristics' => array('ColorSpace' => Exif::SHORT), 'configuration' => array('ComponentsConfiguration' => Exif::UNDEFINED, 'CompressedBitsPerPixel' => Exif::RATIONAL, 'PixelYDimension' => Exif::SHORT . ',' . Exif::LONG, 'PixelXDimension' => Exif::SHORT . ',' . Exif::LONG), 'user' => array('MakerNote' => Exif::UNDEFINED, 'UserComment' => Exif::UNDEFINED), 'related' => array('RelatedSoundFile' => Exif::ASCII), 'dateandtime' => array('DateTimeOriginal' => Exif::ASCII, 'DateTimeDigitized' => Exif::ASCII, 'SubSecTime' => Exif::ASCII, 'SubSecTimeOriginal' => Exif::ASCII, 'SubSecTimeDigitized' => Exif::ASCII), 'conditions' => array('ExposureTime' => Exif::RATIONAL, 'FNumber' => Exif::RATIONAL, 'ExposureProgram' => Exif::SHORT, 'SpectralSensitivity' => Exif::ASCII, 'ISOSpeedRatings' => Exif::SHORT, 'OECF' => Exif::UNDEFINED, 'ShutterSpeedValue' => Exif::SRATIONAL, 'ApertureValue' => Exif::RATIONAL, 'BrightnessValue' => Exif::SRATIONAL, 'ExposureBiasValue' => Exif::SRATIONAL, 'MaxApertureValue' => Exif::RATIONAL, 'SubjectDistance' => Exif::RATIONAL, 'MeteringMode' => Exif::SHORT, 'LightSource' => Exif::SHORT, 'Flash' => Exif::SHORT, 'FocalLength' => Exif::RATIONAL, 'SubjectArea' => Exif::SHORT, 'FlashEnergy' => Exif::RATIONAL, 'SpatialFrequencyResponse' => Exif::UNDEFINED, 'FocalPlaneXResolution' => Exif::RATIONAL, 'FocalPlaneYResolution' => Exif::RATIONAL, 'FocalPlaneResolutionUnit' => Exif::SHORT, 'SubjectLocation' => Exif::SHORT, 'ExposureIndex' => Exif::RATIONAL, 'SensingMethod' => Exif::SHORT, 'FileSource' => Exif::UNDEFINED, 'SceneType' => Exif::UNDEFINED, 'CFAPattern' => Exif::UNDEFINED, 'CustomRendered' => Exif::SHORT, 'ExposureMode' => Exif::SHORT, 'WhiteBalance' => Exif::SHORT, 'DigitalZoomRatio' => Exif::RATIONAL, 'FocalLengthIn35mmFilm' => Exif::SHORT, 'SceneCaptureType' => Exif::SHORT, 'GainControl' => Exif::RATIONAL, 'Contrast' => Exif::SHORT, 'Saturation' => Exif::SHORT, 'Sharpness' => Exif::SHORT, 'DeviceSettingDescription' => Exif::UNDEFINED, 'SubjectDistanceRange' => Exif::SHORT), 'other' => array('ImageUniqueID' => Exif::ASCII)), 'gps' => array('GPSVersionID' => Exif::BYTE, 'GPSLatitudeRef' => Exif::ASCII, 'GPSLatitude' => Exif::RATIONAL, 'GPSLongitudeRef' => Exif::ASCII, 'GPSLongitude' => Exif::RATIONAL, 'GPSAltitudeRef' => Exif::BYTE, 'GPSAltitude' => Exif::RATIONAL, 'GPSTimeStamp' => Exif::RATIONAL, 'GPSSatellites' => Exif::ASCII, 'GPSStatus' => Exif::ASCII, 'GPSMeasureMode' => Exif::ASCII, 'GPSDOP' => Exif::RATIONAL, 'GPSSpeedRef' => Exif::ASCII, 'GPSSpeed' => Exif::RATIONAL, 'GPSTrackRef' => Exif::ASCII, 'GPSTrack' => Exif::RATIONAL, 'GPSImgDirectionRef' => Exif::ASCII, 'GPSImgDirection' => Exif::RATIONAL, 'GPSMapDatum' => Exif::ASCII, 'GPSDestLatitudeRef' => Exif::ASCII, 'GPSDestLatitude' => Exif::RATIONAL, 'GPSDestLongitudeRef' => Exif::ASCII, 'GPSDestLongitude' => Exif::RATIONAL, 'GPSDestBearingRef' => Exif::ASCII, 'GPSDestBearing' => Exif::RATIONAL, 'GPSDestDistanceRef' => Exif::ASCII, 'GPSDestDistance' => Exif::RATIONAL, 'GPSProcessingMethod' => Exif::UNDEFINED, 'GPSAreaInformation' => Exif::UNDEFINED, 'GPSDateStamp' => Exif::ASCII, 'GPSDifferential' => Exif::SHORT));
$this->file = $file;
$this->basename = wfBaseName($this->file);
$this->makeFlatExifTags();
$this->debugFile($this->basename, __FUNCTION__, true);
wfSuppressWarnings();
$data = exif_read_data($this->file);
wfRestoreWarnings();
/**
* exif_read_data() will return false on invalid input, such as
* when somebody uploads a file called something.jpeg
* containing random gibberish.
*/
$this->mRawExifData = $data ? $data : array();
$this->makeFilteredData();
$this->makeFormattedData();
$this->debugFile(__FUNCTION__, false);
}
示例11: internalProcessUpload
function internalProcessUpload(&$resultDetails)
{
global $wgUser;
/* Check for PHP error if any, requires php 4.2 or newer */
if ($this->mCurlError == 1) {
return self::LARGE_FILE_SERVER;
}
/**
* If there was no filename or a zero size given, give up quick.
*/
if (trim($this->mSrcName) == '' || empty($this->mFileSize)) {
return self::EMPTY_FILE;
}
# Chop off any directories in the given filename
if ($this->mDesiredDestName) {
$basename = $this->mDesiredDestName . '.' . $this->mParameterExt;
$this->mStoredDestName = $this->mDesiredDestName;
} else {
$basename = $this->mSrcName;
}
$filtered = wfBaseName($basename);
/**
* We'll want to blacklist against *any* 'extension', and use
* only the final one for the whitelist.
*/
list($partname, $ext) = $this->splitExtensions($filtered);
if (count($ext)) {
$finalExt = $ext[count($ext) - 1];
} else {
$finalExt = '';
}
# If there was more than one "extension", reassemble the base
# filename to prevent bogus complaints about length
if (count($ext) > 1) {
for ($i = 0; $i < count($ext) - 1; $i++) {
$partname .= '.' . $ext[$i];
}
}
if (strlen($partname) < 1) {
return self::MIN_LENGTH_PARTNAME;
}
/**
* Filter out illegal characters, and try to make a legible name
* out of it. We'll strip some silently that Title would die on.
*/
$filtered = preg_replace("/[^" . Title::legalChars() . "]|:/", '-', $filtered);
$nt = Title::makeTitleSafe(NS_IMAGE, $filtered);
if (is_null($nt)) {
$resultDetails = array('filtered' => $filtered);
return self::ILLEGAL_FILENAME;
}
$this->mLocalFile = wfLocalFile($nt);
$this->mDestName = $this->mLocalFile->getName();
/**
* If the image is protected, non-sysop users won't be able
* to modify it by uploading a new revision.
*/
if (!$nt->userCan('edit')) {
return self::PROTECTED_PAGE;
}
/**
* In some cases we may forbid overwriting of existing files.
*/
// here starts the interesting part...
// we overwrite mDestName and give it a new twist
$timestamp = '';
$img_found = wfFindFile($this->mDestName);
if ($img_found) {
// ehhh...
// we'll do it hard way then...
$timestamp = $this->mDestName;
} else {
// this timestamp should not repeat...
$timestamp = 'invalid';
}
$tempname = '';
$tmpcount = 0;
while ($img_found && $timestamp != $this->mLastTimestamp) {
$tmpcount++;
$file_ext = explode('.', $this->mDestName);
$file_ext = $file_ext[0];
$tmpdestname = $file_ext;
$tempname = $tmpdestname . $tmpcount . '.' . $this->mParameterExt;
$timestamp = $tempname;
$img_found = wfFindFile($tempname);
}
if ($tmpcount > 0) {
wfLocalFile($title);
$tempname = preg_replace("/[^" . Title::legalChars() . "]|:/", '-', $tempname);
$nt = Title::makeTitleSafe(NS_FILE, $tempname);
$this->mLocalFile = wfLocalFile($nt);
$this->mDestName = $this->mLocalFile->getName();
$this->mDesiredDestName = $this->mStoredDestName . $tmpcount . '.' . $this->mParameterExt;
} else {
// append the extension anyway
$this->mDesiredDestName = $this->mStoredDestName . '.' . $this->mParameterExt;
}
$overwrite = $this->checkOverwrite($this->mDestName);
if ($overwrite !== true) {
$resultDetails = array('overwrite' => $overwrite);
//.........这里部分代码省略.........
示例12: wfProfileIn
* directory, and $wgUploadPath to point to this file. Also set $wgWhitelistRead
* to an array of pages you want everyone to be able to access. Your server must
* support PATH_INFO, CGI-based configurations generally don't.
*/
require_once './includes/WebStart.php';
wfProfileIn('img_auth.php');
require_once './includes/StreamFile.php';
if (!isset($_SERVER['PATH_INFO'])) {
wfDebugLog('img_auth', "missing PATH_INFO");
wfForbidden();
}
# Get filenames/directories
wfDebugLog('img_auth', "PATH_INFO is: " . $_SERVER['PATH_INFO']);
$filename = realpath($wgUploadDirectory . $_SERVER['PATH_INFO']);
$realUploadDirectory = realpath($wgUploadDirectory);
$imageName = $wgContLang->getNsText(NS_IMAGE) . ":" . wfBaseName($_SERVER['PATH_INFO']);
# Check if the filename is in the correct directory
if (substr($filename, 0, strlen($realUploadDirectory)) != $realUploadDirectory) {
wfDebugLog('img_auth', "requested path not in upload dir: {$filename}");
wfForbidden();
}
if (is_array($wgWhitelistRead) && !in_array($imageName, $wgWhitelistRead) && !$wgUser->getID()) {
wfDebugLog('img_auth', "not logged in and requested file not in whitelist: {$imageName}");
wfForbidden();
}
if (!file_exists($filename)) {
wfDebugLog('img_auth', "requested file does not exist: {$filename}");
wfForbidden();
}
if (is_dir($filename)) {
wfDebugLog('img_auth', "requested file is a directory: {$filename}");
示例13: importImages
/**
* This method imports all images given in $images.
* A page that reports the results and failures can be created if
* you call startReport() before and createReport() after this method.
*
* @param array(string) $images
* Names of the images that will be imported from the source wiki.
* If no namespace is given it will be appended automatically.
* @param bool $createReport (default: false)
* If <true>, a report for this operation is created.
*
* @throws
* IAIException(IAIException::HTTP_ERROR)
* if the HTTP request fails
*
*/
public function importImages($images)
{
// Add namespace if necessary
global $wgContLang, $iaigTempDir;
$imgNs = $wgContLang->getNsText(NS_IMAGE) . ":";
foreach ($images as $k => $i) {
if (strpos($i, $imgNs) === false) {
$images[$k] = $imgNs . $i;
}
}
$imageURLs = $this->getImageURLs($images);
foreach ($imageURLs as $img) {
$base = urldecode(wfBaseName($img));
$title = Title::makeTitleSafe(NS_FILE, $base);
if (!is_object($title)) {
echo "{$base} could not be imported; a valid title cannot be produced\n";
continue;
}
# Check existence
$image = wfLocalFile($title);
//TODO replace $options['overwrite'] with a field in this class
if ($image->exists()) {
// if( isset( $options['overwrite'] ) ) {
// echo( "{$base} exists, overwriting..." );
// } else {
echo "{$base} exists, skipping\n";
$this->mSkippedImages[] = $base;
continue;
// }
} else {
echo "Importing {$base}...";
}
// Read image from source wiki
$contents = Http::get($img, self::HTTP_TIMEOUT);
if ($contents === false) {
// HTTP-Timeout
$this->mSkippedImages[] = $base;
echo "HTTP timeout for {$base}; skipping\n";
continue;
// throw new IAIException(IAIException::HTTP_ERROR, $img);
}
$handle = fopen($iaigTempDir . $base, "wb");
fwrite($handle, $contents);
fclose($handle);
$this->mImportedImages[] = $base;
$archive = $image->publish($iaigTempDir . $base);
if (WikiError::isError($archive) || !$archive->isGood()) {
echo "failed.\n";
continue;
} else {
echo "success.\n";
}
$image->recordUpload($archive->value, "Imported with IAI Article Importer", "No license information");
unlink($iaigTempDir . $base);
}
}
示例14: wfImageAuthMain
function wfImageAuthMain()
{
global $wgImgAuthPublicTest, $wgImgAuthUrlPathMap, $wgRequest;
// See if this is a public Wiki (no protections).
if ($wgImgAuthPublicTest && in_array('read', User::getGroupPermissions(array('*')), true)) {
// This is a public wiki, so disable this script (for private wikis only)
wfForbidden('img-auth-accessdenied', 'img-auth-public');
return;
}
// Get the requested file path (source file or thumbnail)
$matches = WebRequest::getPathInfo();
if (!isset($matches['title'])) {
wfForbidden('img-auth-accessdenied', 'img-auth-nopathinfo');
return;
}
$path = $matches['title'];
if ($path && $path[0] !== '/') {
// Make sure $path has a leading /
$path = "/" . $path;
}
// Check for bug 28235: QUERY_STRING overriding the correct extension
$whitelist = array();
$extension = FileBackend::extensionFromPath($path, 'rawcase');
if ($extension != '') {
$whitelist[] = $extension;
}
if (!$wgRequest->checkUrlExtension($whitelist)) {
return;
}
// Various extensions may have their own backends that need access.
// Check if there is a special backend and storage base path for this file.
foreach ($wgImgAuthUrlPathMap as $prefix => $storageDir) {
$prefix = rtrim($prefix, '/') . '/';
// implicit trailing slash
if (strpos($path, $prefix) === 0) {
$be = FileBackendGroup::singleton()->backendFromPath($storageDir);
$filename = $storageDir . substr($path, strlen($prefix));
// strip prefix
// Check basic user authorization
if (!RequestContext::getMain()->getUser()->isAllowed('read')) {
wfForbidden('img-auth-accessdenied', 'img-auth-noread', $path);
return;
}
if ($be->fileExists(array('src' => $filename))) {
wfDebugLog('img_auth', "Streaming `" . $filename . "`.");
$be->streamFile(array('src' => $filename), array('Cache-Control: private', 'Vary: Cookie'));
} else {
wfForbidden('img-auth-accessdenied', 'img-auth-nofile', $path);
}
return;
}
}
// Get the local file repository
$repo = RepoGroup::singleton()->getRepo('local');
// Get the full file storage path and extract the source file name.
// (e.g. 120px-Foo.png => Foo.png or page2-120px-Foo.png => Foo.png).
// This only applies to thumbnails, and all thumbnails should
// be under a folder that has the source file name.
if (strpos($path, '/thumb/') === 0) {
$name = wfBaseName(dirname($path));
// file is a thumbnail
$filename = $repo->getZonePath('thumb') . substr($path, 6);
// strip "/thumb"
} else {
$name = wfBaseName($path);
// file is a source file
$filename = $repo->getZonePath('public') . $path;
}
// Check to see if the file exists
if (!$repo->fileExists($filename)) {
wfForbidden('img-auth-accessdenied', 'img-auth-nofile', $filename);
return;
}
$title = Title::makeTitleSafe(NS_FILE, $name);
if (!$title instanceof Title) {
// files have valid titles
wfForbidden('img-auth-accessdenied', 'img-auth-badtitle', $name);
return;
}
// Run hook for extension authorization plugins
/** @var $result array */
$result = null;
if (!wfRunHooks('ImgAuthBeforeStream', array(&$title, &$path, &$name, &$result))) {
wfForbidden($result[0], $result[1], array_slice($result, 2));
return;
}
// Check user authorization for this title
// Checks Whitelist too
if (!$title->userCan('read')) {
wfForbidden('img-auth-accessdenied', 'img-auth-noread', $name);
return;
}
if ($wgRequest->getCheck('download')) {
header('Content-Disposition: attachment');
}
// Stream the requested file
wfDebugLog('img_auth', "Streaming `" . $filename . "`.");
$repo->streamFile($filename, array('Cache-Control: private', 'Vary: Cookie'));
}
示例15: checkMissingImage
function checkMissingImage($fullpath)
{
$fname = 'ImageBuilder::checkMissingImage';
$filename = wfBaseName($fullpath);
if (is_dir($fullpath)) {
return;
}
if (is_link($fullpath)) {
$this->log("skipping symlink at {$fullpath}");
return;
}
$row = $this->dbw->selectRow('image', array('img_name'), array('img_name' => $filename), $fname);
if ($row) {
// already known, move on
return;
} else {
$this->addMissingImage($filename, $fullpath);
}
}