本文整理汇总了PHP中wfMkdirParents函数的典型用法代码示例。如果您正苦于以下问题:PHP wfMkdirParents函数的具体用法?PHP wfMkdirParents怎么用?PHP wfMkdirParents使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wfMkdirParents函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: doSingleLock
/**
* Lock a single resource key
*
* @param $path string
* @param $type integer
* @return Status
*/
protected function doSingleLock($path, $type)
{
$status = Status::newGood();
if (isset($this->locksHeld[$path][$type])) {
++$this->locksHeld[$path][$type];
} elseif (isset($this->locksHeld[$path][self::LOCK_EX])) {
$this->locksHeld[$path][$type] = 1;
} else {
wfSuppressWarnings();
$handle = fopen($this->getLockPath($path), 'a+');
wfRestoreWarnings();
if (!$handle) {
// lock dir missing?
wfMkdirParents($this->lockDir);
$handle = fopen($this->getLockPath($path), 'a+');
// try again
}
if ($handle) {
// Either a shared or exclusive lock
$lock = $type == self::LOCK_SH ? LOCK_SH : LOCK_EX;
if (flock($handle, $lock | LOCK_NB)) {
// Record this lock as active
$this->locksHeld[$path][$type] = 1;
$this->handles[$path][$type] = $handle;
} else {
fclose($handle);
$status->fatal('lockmanager-fail-acquirelock', $path);
}
} else {
$status->fatal('lockmanager-fail-openlock', $path);
}
}
return $status;
}
示例2: doTransform
function doTransform($image, $dstPath, $dstUrl, $params, $flags = 0)
{
global $wgSVGConverters, $wgSVGConverter, $wgSVGConverterPath;
if (!$this->normaliseParams($image, $params)) {
return new TransformParameterError($params);
}
$clientWidth = $params['width'];
$clientHeight = $params['height'];
$physicalWidth = $params['physicalWidth'];
$physicalHeight = $params['physicalHeight'];
$srcPath = $image->getPath();
if ($flags & self::TRANSFORM_LATER) {
return new ThumbnailImage($image, $dstUrl, $clientWidth, $clientHeight, $dstPath);
}
if (!wfMkdirParents(dirname($dstPath))) {
return new MediaTransformError('thumbnail_error', $clientWidth, $clientHeight, wfMsg('thumbnail_dest_directory'));
}
$status = $this->rasterize($srcPath, $dstPath, $physicalWidth, $physicalHeight);
if ($status === true) {
return new ThumbnailImage($image, $dstUrl, $clientWidth, $clientHeight, $dstPath);
} else {
return $status;
// MediaTransformError
}
}
示例3: doTransform
function doTransform($image, $dstPath, $dstUrl, $params, $flags = 0)
{
global $wgFLVConverters, $wgFLVConverter, $wgFLVConverterPath;
if (!$this->normaliseParams($image, $params)) {
return new TransformParameterError($params);
}
$clientWidth = $params['width'];
$clientHeight = $params['height'];
$physicalWidth = $params['physicalWidth'];
$physicalHeight = $params['physicalHeight'];
$srcPath = $image->getPath();
if ($flags & self::TRANSFORM_LATER) {
return new ThumbnailImage($image, $dstUrl, $clientWidth, $clientHeight, $dstPath);
}
if (!wfMkdirParents(dirname($dstPath), null, __METHOD__)) {
return new MediaTransformError('thumbnail_error', $clientWidth, $clientHeight, wfMsg('thumbnail_dest_directory'));
}
$err = false;
if (isset($wgFLVConverters[$wgFLVConverter])) {
$cmd = str_replace(array('$path/', '$width', '$height', '$input', '$output'), array($wgFLVConverterPath ? wfEscapeShellArg("{$wgFLVConverterPath}/") : "", intval($physicalWidth), intval($physicalHeight), wfEscapeShellArg($srcPath), wfEscapeShellArg($dstPath)), $wgFLVConverters[$wgFLVConverter]) . " 2>&1";
wfProfileIn('rsvg');
wfDebug(__METHOD__ . ": {$cmd}\n");
$err = wfShellExec($cmd, $retval);
wfProfileOut('rsvg');
}
$removed = $this->removeBadFile($dstPath, $retval);
if ($retval != 0 || $removed) {
wfDebugLog('thumbnail', sprintf('thumbnail failed on %s: error %d "%s" from "%s"', wfHostname(), $retval, trim($err), $cmd));
return new MediaTransformError('thumbnail_error', $clientWidth, $clientHeight, $err);
} else {
return new ThumbnailImage($image, $dstUrl, $clientWidth, $clientHeight, $dstPath);
}
}
示例4: dataDirOKmaybeCreate
private static function dataDirOKmaybeCreate($dir, $create = false)
{
if (!is_dir($dir)) {
if (!is_writable(dirname($dir))) {
$webserverGroup = Installer::maybeGetWebserverPrimaryGroup();
if ($webserverGroup !== null) {
return Status::newFatal('config-sqlite-parent-unwritable-group', $dir, dirname($dir), basename($dir), $webserverGroup);
} else {
return Status::newFatal('config-sqlite-parent-unwritable-nogroup', $dir, dirname($dir), basename($dir));
}
}
# Called early on in the installer, later we just want to sanity check
# if it's still writable
if ($create) {
wfSuppressWarnings();
$ok = wfMkdirParents($dir, 0700);
wfRestoreWarnings();
if (!$ok) {
return Status::newFatal('config-sqlite-mkdir-error', $dir);
}
# Put a .htaccess file in in case the user didn't take our advice
file_put_contents("{$dir}/.htaccess", "Deny from all\n");
}
}
if (!is_writable($dir)) {
return Status::newFatal('config-sqlite-dir-unwritable', $dir);
}
# We haven't blown up yet, fall through
return Status::newGood();
}
示例5: run
function run()
{
global $wgExtensionMessagesFiles, $wgMessageCache, $IP;
$nameHash = md5(implode("\n", array_keys($wgExtensionMessagesFiles)));
$dir = "{$IP}/cache/ext-msgs";
wfMkdirParents($dir);
$db = dba_open("{$dir}/{$nameHash}.cdb", 'n', 'cdb');
if (!$db) {
echo "Cannot open DB file\n";
exit(1);
}
# Load extension messages
foreach ($wgExtensionMessagesFiles as $file) {
$messages = $magicWords = array();
require $file;
foreach ($messages as $lang => $unused) {
$wgMessageCache->processMessagesArray($messages, $lang);
}
}
# Write them to the file
foreach ($wgMessageCache->mExtensionMessages as $lang => $messages) {
foreach ($messages as $key => $text) {
dba_insert("{$lang}:{$key}", $text, $db);
}
}
dba_close($db);
}
示例6: execute
function execute() {
global $wgRequest;
if ( !$wgRequest->wasPosted() ) {
echo $this->dtd();
echo <<<EOT
<html>
<head><title>store.php Test Interface</title></head>
<body>
<form method="post" action="store.php" enctype="multipart/form-data" >
<p>File: <input type="file" name="file"/></p>
<p><input type="submit" value="OK"/></p>
</form></body></html>
EOT;
return true;
}
$srcFile = $wgRequest->getFileTempname( 'file' );
if ( !$srcFile ) {
$this->error( 400, 'webstore_no_file' );
return false;
}
// Use an hourly timestamped directory for easy cleanup
$now = time();
$this->cleanupTemp( $now );
$timestamp = gmdate( self::$tempDirFormat, $now );
if ( !wfMkdirParents( "{$this->tmpDir}/$timestamp", null, __METHOD__ ) ) {
$this->error( 500, 'webstore_dest_mkdir' );
return false;
}
// Get the extension of the upload, needs to be preserved for type detection
$name = $wgRequest->getFileName( 'file' );
$n = strrpos( $name, '.' );
if ( $n ) {
$extension = '.' . File::normalizeExtension( substr( $name, $n + 1 ) );
} else {
$extension = '';
}
// Pick a random temporary path
$destRel = $timestamp . '/' . md5( mt_rand() . mt_rand() . mt_rand() ) . $extension;
if ( !@move_uploaded_file( $srcFile, "{$this->tmpDir}/$destRel" ) ) {
$this->error( 400, 'webstore_move_uploaded', $srcFile, "{$this->tmpDir}/$destRel" );
return false;
}
// Succeeded, return temporary location
header( 'Content-Type: text/xml' );
echo <<<EOT
<?xml version="1.0" encoding="utf-8"?>
<response>
<location>$destRel</location>
</response>
EOT;
return true;
}
示例7: execute
public function execute()
{
global $wgCaptchaSecret, $wgCaptchaDirectoryLevels;
$instance = ConfirmEditHooks::getInstance();
if (!$instance instanceof FancyCaptcha) {
$this->error("\$wgCaptchaClass is not FancyCaptcha.\n", 1);
}
$backend = $instance->getBackend();
$countAct = $instance->estimateCaptchaCount();
$this->output("Estimated number of captchas is {$countAct}.\n");
$countGen = (int) $this->getOption('fill') - $countAct;
if ($countGen <= 0) {
$this->output("No need to generate anymore captchas.\n");
return;
}
$tmpDir = wfTempDir() . '/mw-fancycaptcha-' . time() . '-' . wfRandomString(6);
if (!wfMkdirParents($tmpDir)) {
$this->error("Could not create temp directory.\n", 1);
}
$e = null;
// exception
try {
$cmd = sprintf("python %s --key %s --output %s --count %s --dirs %s", wfEscapeShellArg(__DIR__ . '/../captcha.py'), wfEscapeShellArg($wgCaptchaSecret), wfEscapeShellArg($tmpDir), wfEscapeShellArg($countGen), wfEscapeShellArg($wgCaptchaDirectoryLevels));
foreach (array('wordlist', 'font', 'font-size', 'blacklist', 'verbose') as $par) {
if ($this->hasOption($par)) {
$cmd .= " --{$par} " . wfEscapeShellArg($this->getOption($par));
}
}
$this->output("Generating {$countGen} new captchas...\n");
$retVal = 1;
wfShellExec($cmd, $retVal, array(), array('time' => 0));
if ($retVal != 0) {
wfRecursiveRemoveDir($tmpDir);
$this->error("Could not run generation script.\n", 1);
}
$flags = FilesystemIterator::SKIP_DOTS;
$iter = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($tmpDir, $flags), RecursiveIteratorIterator::CHILD_FIRST);
$this->output("Copying the new captchas to storage...\n");
foreach ($iter as $fileInfo) {
if (!$fileInfo->isFile()) {
continue;
}
list($salt, $hash) = $instance->hashFromImageName($fileInfo->getBasename());
$dest = $instance->imagePath($salt, $hash);
$backend->prepare(array('dir' => dirname($dest)));
$status = $backend->quickStore(array('src' => $fileInfo->getPathname(), 'dst' => $dest));
if (!$status->isOK()) {
$this->error("Could not save file '{$fileInfo->getPathname()}'.\n");
}
}
} catch (Exception $e) {
wfRecursiveRemoveDir($tmpDir);
throw $e;
}
$this->output("Removing temporary files...\n");
wfRecursiveRemoveDir($tmpDir);
$this->output("Done.\n");
}
示例8: inspectDirectory
/**
* Run PHP Storm's Code Inspect for a given directory
*
* Actually, PHP storm will be run for a given directory.
* XML reports will then be parsed to get issues for given file.
*
* @param string $dirName file to run Code Inspect for
* @return string output from Code Inspect
* @throws Exception
*/
protected function inspectDirectory($dirName)
{
global $wgPHPStormPath, $IP;
$start = microtime(true);
$dirName = realpath($dirName);
$isCached = $this->cache['directory'] !== '' && strpos($dirName, $this->cache['directory']) === 0;
if (!$isCached) {
$lintProfile = dirname(__FILE__) . '/php/profiles/phplint.xml';
$projectMetaData = dirname(__FILE__) . '/php/project';
// copy project meta data to trunk root
$copyCmd = "cp -rf {$projectMetaData}/.idea {$IP}";
echo "Copying project meta data <{$copyCmd}>...";
exec($copyCmd);
echo " [done]\n";
// create a temporary directory for Code Inspect results
$resultsDir = wfTempDir() . '/phpstorm/' . uniqid('lint');
echo "Creating temporary directory for results <{$resultsDir}>...";
if (wfMkdirParents($resultsDir)) {
echo " [done]\n";
} else {
echo " [err!]\n";
}
$cmd = sprintf('/bin/sh %s/inspect.sh %s %s %s -d %s -v2', $wgPHPStormPath, realpath($IP . '/includes/..'), $lintProfile, $resultsDir, $dirName);
echo "Running PHP storm <{$cmd}>...";
#echo "Running PhpStorm for <{$dirName}>...";
$retVal = 0;
$output = array();
exec($cmd, $output, $retVal);
if ($retVal !== 0) {
throw new Exception("{$cmd} ended with code #{$retVal}");
}
// get the version of PhpStorm
$tool = '';
foreach ($output as $line) {
if (strpos($line, 'Starting up JetBrains PhpStorm') !== false) {
preg_match('#JetBrains PhpStorm [\\d\\.]+#', $line, $matches);
$tool = $matches[0];
}
}
echo implode("\n", $output);
// debug
echo " [done]\n";
// format results
$output = array('problems' => $this->parseResults($resultsDir), 'tool' => $tool);
// update the cache
$this->cache = array('directory' => $dirName, 'output' => $output);
} else {
//echo "Got results from cache for <{$this->cache['directory']}>\n";
$output = $this->cache['output'];
}
$output['time'] = round(microtime(true) - $start, 4);
return $output;
}
示例9: get
static function get( $options ){
global $wgFFmpegLocation, $wgOggThumbLocation;
// Set up lodal pointer to file
$file = $options['file'];
if( !is_dir( dirname( $options['dstPath'] ) ) ){
wfMkdirParents( dirname( $options['dstPath'] ), null, __METHOD__ );
}
wfDebug( "Creating video thumbnail at" . $options['dstPath'] . "\n" );
// Else try ffmpeg and return result:
return self::tryFfmpegThumb( $options );
}
示例10: generate
private function generate()
{
if (preg_match('/^\\s*(\\w+)\\s*{/', $this->source, $matches)) {
$diagram_type = $matches[1];
} else {
$diagram_type = 'blockdiag';
// blockdiag for default
}
$diagprog_path = $this->path_array[$diagram_type];
if (!is_file($diagprog_path)) {
return $this->error("{$diagram_type} is not found at the specified place.");
}
// temporary directory check
if (!file_exists($this->tmpDir)) {
if (!wfMkdirParents($this->tmpDir)) {
return $this->error('temporary directory is not found.');
}
} elseif (!is_dir($this->tmpDir)) {
return $this->error('temporary directory is not directory');
} elseif (!is_writable($this->tmpDir)) {
return $this->error('temporary directory is not writable');
}
// create temporary file
$dstTmpName = tempnam($this->tmpDir, 'blockdiag');
$srcTmpName = tempnam($this->tmpDir, 'blockdiag');
// write blockdiag source
$fp = fopen($srcTmpName, 'w');
fwrite($fp, $this->source);
fclose($fp);
// generate blockdiag image
$cmd = $diagprog_path . ' -T ' . escapeshellarg($this->imgType) . ' -o ' . escapeshellarg($dstTmpName) . ' ' . escapeshellarg($srcTmpName);
$res = `{$cmd}`;
if (filesize($dstTmpName) == 0) {
return $this->error('unknown error.');
}
// move to image directory
$hashpath = $this->getHashPath();
if (!file_exists($hashpath)) {
if (!@wfMkdirParents($hashpath, 0755)) {
return $this->error('can not make blockdiag image directory', $this->blockdiagDir);
}
} elseif (!is_dir($hashpath)) {
return $this->error('blockdiag image directory is already exists. but not directory');
} elseif (!is_writable($hashpath)) {
return $this->error('blockdiag image directory is not writable');
}
if (!rename("{$dstTmpName}", "{$hashpath}/{$this->hash}.png")) {
return $this->error('can not rename blockdiag image');
}
return $this->mkImageTag();
}
示例11: __construct
/**
* Constructor
*/
function __construct($server = false, $user = false, $password = false, $dbName = false, $failFunction = false, $flags = 0)
{
global $wgOut, $wgSQLiteDataDir, $wgSQLiteDataDirMode;
if ("{$wgSQLiteDataDir}" == '') {
$wgSQLiteDataDir = dirname($_SERVER['DOCUMENT_ROOT']) . '/data';
}
if (!is_dir($wgSQLiteDataDir)) {
wfMkdirParents($wgSQLiteDataDir, $wgSQLiteDataDirMode);
}
$this->mFailFunction = $failFunction;
$this->mFlags = $flags;
$this->mDatabaseFile = "{$wgSQLiteDataDir}/{$dbName}.sqlite";
$this->open($server, $user, $password, $dbName);
}
示例12: startWrite
public function startWrite($code)
{
if (!file_exists($this->directory)) {
if (!wfMkdirParents($this->directory, null, __METHOD__)) {
throw new MWException("Unable to create the localisation store " . "directory \"{$this->directory}\"");
}
}
// Close reader to stop permission errors on write
if (!empty($this->readers[$code])) {
$this->readers[$code]->close();
}
try {
$this->writer = Writer::open($this->getFileName($code));
} catch (Exception $e) {
throw new MWException($e->getMessage());
}
$this->currentLang = $code;
}
示例13: doTransform
function doTransform($image, $dstPath, $dstUrl, $params, $flags = 0)
{
global $wgDjvuRenderer, $wgDjvuPostProcessor;
// Fetch XML and check it, to give a more informative error message than the one which
// normaliseParams will inevitably give.
$xml = $image->getMetadata();
if (!$xml) {
return new MediaTransformError('thumbnail_error', @$params['width'], @$params['height'], wfMsg('djvu_no_xml'));
}
if (!$this->normaliseParams($image, $params)) {
return new TransformParameterError($params);
}
$width = $params['width'];
$height = $params['height'];
$srcPath = $image->getPath();
$page = $params['page'];
if ($page > $this->pageCount($image)) {
return new MediaTransformError('thumbnail_error', $width, $height, wfMsg('djvu_page_error'));
}
if ($flags & self::TRANSFORM_LATER) {
return new ThumbnailImage($image, $dstUrl, $width, $height, $dstPath, $page);
}
if (!wfMkdirParents(dirname($dstPath))) {
return new MediaTransformError('thumbnail_error', $width, $height, wfMsg('thumbnail_dest_directory'));
}
# Use a subshell (brackets) to aggregate stderr from both pipeline commands
# before redirecting it to the overall stdout. This works in both Linux and Windows XP.
$cmd = '(' . wfEscapeShellArg($wgDjvuRenderer) . " -format=ppm -page={$page} -size={$width}x{$height} " . wfEscapeShellArg($srcPath);
if ($wgDjvuPostProcessor) {
$cmd .= " | {$wgDjvuPostProcessor}";
}
$cmd .= ' > ' . wfEscapeShellArg($dstPath) . ') 2>&1';
wfProfileIn('ddjvu');
wfDebug(__METHOD__ . ": {$cmd}\n");
$err = wfShellExec($cmd, $retval);
wfProfileOut('ddjvu');
$removed = $this->removeBadFile($dstPath, $retval);
if ($retval != 0 || $removed) {
wfDebugLog('thumbnail', sprintf('thumbnail failed on %s: error %d "%s" from "%s"', wfHostname(), $retval, trim($err), $cmd));
return new MediaTransformError('thumbnail_error', $width, $height, $err);
} else {
return new ThumbnailImage($image, $dstUrl, $width, $height, $dstPath, $page);
}
}
示例14: doJobLoop
function doJobLoop(){
global $wgJobTypeConfig, $wahJobDelay, $wahRunOnce, $wahStatusOutput;
//look for jobs (sleep for $wahJobDelay if none found)
$job = WahJobManager :: getNewJob(false, 'Internal');
if(!$job && $wahRunOnce == false){
if($wahStatusOutput)
print "no jobs found waiting $wahJobDelay \n";
sleep($wahJobDelay);
return doJobLoop();
}elseif(!$job && $wahRunOnce == true){
if($wahStatusOutput)
print "no job found \n";
return ;
}
$jobSet = WahJobManager ::getJobSetById( $job->job_set_id );
$jobDetails = FormatJson::decode( $job->job_json ) ;
//get the title (so we can access the source file)
$fTitle = Title::newFromText( $job->title, $job->ns );
$file = wfLocalFile( $fTitle );
$thumbPath = $file->getThumbPath( $jobSet->set_encodekey );
//make sure the directory is ready:
wfMkdirParents( $thumbPath, null, __METHOD__ );
$destTarget = $thumbPath . '.ogg';
//issue the encoding command
if($wahStatusOutput) print "Running Encode Command...\n";
wahDoEncode($file->getPath(), $destTarget, $jobDetails->encodeSettings );
//once done with encode update the status:
WahJobManager :: updateJobDone($job);
//update set done (if only one item in the set)
$wjm = WahJobManager::newFromSet( $jobSet );
$percDone = $wjm->getDonePerc();
if( $percDone == 1 ){
WahJobManager :: updateSetDone( $jobSet );
}else{
if($wahStatusOutput)
print "job not complete? (might be mixing chunkDuration types?) ";
}
}
示例15: checkImageDirectory
/**
* checkImageDirectory
*
* check if target directory exists. if not create it. if not possible
* signalize it. We have to have id of target wiki
*
* @access public
* @author eloy@wikia
*
* @return boolean: status of operation
*/
public function checkImageDirectory()
{
$mRetVal = false;
if (empty($this->mTargetID)) {
return $mRetVal;
}
wfProfileIn(__METHOD__);
$UploadDirectory = WikiFactory::getVarValueByName("wgUploadDirectory", $this->mTargetID);
if (file_exists($UploadDirectory)) {
if (is_dir($UploadDirectory)) {
$this->addLog("Target {$UploadDirectory} exists and is directory.");
$mRetVal = true;
} else {
$this->addLog("Target {$UploadDirectory} exists but is not directory");
$mRetVal = false;
}
} else {
$mRetVal = wfMkdirParents($UploadDirectory);
}
wfProfileOut(__METHOD__);
return $mRetVal;
}