本文整理汇总了PHP中wfRandomString函数的典型用法代码示例。如果您正苦于以下问题:PHP wfRandomString函数的具体用法?PHP wfRandomString怎么用?PHP wfRandomString使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wfRandomString函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
public function execute()
{
$users = 10;
// For number of translations, limited to [0,20]
$mean = 15;
$stddev = 20;
$stash = new TranslationStashStorage(wfGetDB(DB_MASTER));
$languages = array_keys(Language::fetchLanguageNames());
for ($i = 0; $i < $users; $i++) {
$username = 'Pupu' . wfRandomString(6);
$password = wfRandomString(12);
$email = "{$username}.{$password}@blackhole.io";
$user = TranslateSandbox::addUser($username, $password, $email);
$language = $languages[rand(0, count($languages) - 1)];
$count = wfGaussMs($mean, $stddev);
$count = min(20, $count);
$count = max(0, $count);
for ($j = 0; $j < $count; $j++) {
$title = Title::makeTitle(NS_MEDIAWIKI, wfRandomString(24) . '/' . $language);
$value = array('Pupu söi');
for ($k = rand(0, 20); $k > 0; $k--) {
$value[] = wfRandomString(rand(1, 28));
}
$value = implode("\n", $value);
$translation = new StashedTranslation($user, $title, $value);
$stash->addTranslation($translation);
}
}
}
示例2: factory
/**
* Make a new temporary file on the file system.
* Temporary files may be purged when the file object falls out of scope.
*
* @param $prefix string
* @param $extension string
* @return TempFSFile|null
*/
public static function factory($prefix, $extension = '')
{
wfProfileIn(__METHOD__);
$base = wfTempDir() . '/' . $prefix . wfRandomString(12);
$ext = $extension != '' ? ".{$extension}" : "";
for ($attempt = 1; true; $attempt++) {
$path = "{$base}-{$attempt}{$ext}";
wfSuppressWarnings();
$newFileHandle = fopen($path, 'x');
wfRestoreWarnings();
if ($newFileHandle) {
fclose($newFileHandle);
break;
// got it
}
if ($attempt >= 5) {
wfProfileOut(__METHOD__);
return null;
// give up
}
}
$tmpFile = new self($path);
$tmpFile->canDelete = true;
// safely instantiated
wfProfileOut(__METHOD__);
return $tmpFile;
}
示例3: __construct
/**
* @param array[] $markers Markers generated by another instance of TextInjector,
* for use by inject(); a map of string markers associated with
* parameter arrays.
*/
public function __construct(array $markers = array())
{
$this->markers = $markers;
// idea stolen from Parser class in core
$this->uniqPrefix = "UNIQ" . wfRandomString(16);
$this->markerIndex = 0;
}
示例4: testForAuthentication
public function testForAuthentication(array $reqs)
{
$req = AuthenticationRequest::getRequestByClass($reqs, PasswordAuthenticationRequest::class);
if ($req) {
$user = User::newFromName($req->username);
$password = $req->password;
} else {
$user = null;
foreach ($reqs as $req) {
if ($req->username !== null) {
$user = User::newFromName($req->username);
break;
}
}
if (!$user) {
$this->logger->debug(__METHOD__ . ': No username in $reqs, skipping hooks');
return StatusValue::newGood();
}
// Something random for the 'AbortLogin' hook.
$password = wfRandomString(32);
}
$msg = null;
if (!\Hooks::run('LoginUserMigrated', [$user, &$msg])) {
return $this->makeFailResponse($user, null, LoginForm::USER_MIGRATED, $msg, 'LoginUserMigrated');
}
$abort = LoginForm::ABORTED;
$msg = null;
if (!\Hooks::run('AbortLogin', [$user, $password, &$abort, &$msg])) {
return $this->makeFailResponse($user, null, $abort, $msg, 'AbortLogin');
}
return StatusValue::newGood();
}
示例5: testGetAbsent
/**
* @covers ReplicatedBagOStuff::get
*/
public function testGetAbsent()
{
$key = wfRandomString();
$value = wfRandomString();
$this->writeCache->set($key, $value);
// Don't read from master. No failover if value is absent.
$this->assertEquals($this->cache->get($key), false);
}
示例6: 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");
}
示例7: doGetLocalCopyMulti
protected function doGetLocalCopyMulti(array $params)
{
$tmpFiles = array();
// (path => MockFSFile)
foreach ($params['srcs'] as $src) {
$tmpFiles[$src] = new MockFSFile(wfTempDir() . '/' . wfRandomString(32));
}
return $tmpFiles;
}
示例8: testHas
/**
* @covers GlobalVarConfig::has
*/
public function testHas()
{
$this->maybeStashGlobal('wgGlobalVarConfigTestHas');
$GLOBALS['wgGlobalVarConfigTestHas'] = wfRandomString();
$this->maybeStashGlobal('wgGlobalVarConfigTestNotHas');
$config = new GlobalVarConfig();
$this->assertTrue($config->has('GlobalVarConfigTestHas'));
$this->assertFalse($config->has('GlobalVarConfigTestNotHas'));
}
示例9: testSet
/**
* @dataProvider provideSet
* @covers GlobalVarConfig::set
* @covers GlobalVarConfig::setWithPrefix
*/
public function testSet($name, $prefix, $var)
{
$this->maybeStashGlobal($var);
$config = new GlobalVarConfig($prefix);
$random = wfRandomString();
$config->set($name, $random);
$this->assertArrayHasKey($var, $GLOBALS);
$this->assertEquals($random, $GLOBALS[$var]);
}
示例10: __construct
/**
* Construct a new instance from configuration.
*
* @param array $config Parameters include:
* - lockServers : Associative array of server names to "<IP>:<port>" strings.
* - srvsByBucket : Array of 1-16 consecutive integer keys, starting from 0,
* each having an odd-numbered list of server names (peers) as values.
* - redisConfig : Configuration for RedisConnectionPool::__construct().
* @throws Exception
*/
public function __construct(array $config)
{
parent::__construct($config);
$this->lockServers = $config['lockServers'];
// Sanitize srvsByBucket config to prevent PHP errors
$this->srvsByBucket = array_filter($config['srvsByBucket'], 'is_array');
$this->srvsByBucket = array_values($this->srvsByBucket);
// consecutive
$config['redisConfig']['serializer'] = 'none';
$this->redisPool = RedisConnectionPool::singleton($config['redisConfig']);
$this->session = wfRandomString(32);
}
示例11: testSetDelayed
public function testSetDelayed()
{
$key = wfRandomString();
$value = wfRandomString();
// XXX: DeferredUpdates bound to transactions in CLI mode
$dbw = wfGetDB(DB_MASTER);
$dbw->begin();
$this->cache->set($key, $value);
// Set in tier 1
$this->assertEquals($value, $this->cache1->get($key), 'Written to tier 1');
// Not yet set in tier 2
$this->assertEquals(false, $this->cache2->get($key), 'Not written to tier 2');
$dbw->commit();
// Set in tier 2
$this->assertEquals($value, $this->cache2->get($key), 'Written to tier 2');
}
示例12: __construct
/**
* Construct a new instance from configuration.
*
* $config paramaters include:
* - lockServers : Associative array of server names to configuration.
* Configuration is an associative array that includes:
* - host : IP address/hostname
* - port : TCP port
* - authKey : Secret string the lock server uses
* - srvsByBucket : Array of 1-16 consecutive integer keys, starting from 0,
* each having an odd-numbered list of server names (peers) as values.
* - connTimeout : Lock server connection attempt timeout. [optional]
*
* @param Array $config
*/
public function __construct(array $config)
{
parent::__construct($config);
$this->lockServers = $config['lockServers'];
// Sanitize srvsByBucket config to prevent PHP errors
$this->srvsByBucket = array_filter($config['srvsByBucket'], 'is_array');
$this->srvsByBucket = array_values($this->srvsByBucket);
// consecutive
if (isset($config['connTimeout'])) {
$this->connTimeout = $config['connTimeout'];
} else {
$this->connTimeout = 3;
// use some sane amount
}
$this->session = wfRandomString(32);
// 128 bits
}
示例13: __construct
/**
* Construct a new instance from configuration.
*
* @param array $config Parameters include:
* - lockServers : Associative array of server names to "<IP>:<port>" strings.
* - srvsByBucket : Array of 1-16 consecutive integer keys, starting from 0,
* each having an odd-numbered list of server names (peers) as values.
* - memcConfig : Configuration array for ObjectCache::newFromParams. [optional]
* If set, this must use one of the memcached classes.
* @throws Exception
*/
public function __construct(array $config)
{
parent::__construct($config);
// Sanitize srvsByBucket config to prevent PHP errors
$this->srvsByBucket = array_filter($config['srvsByBucket'], 'is_array');
$this->srvsByBucket = array_values($this->srvsByBucket);
// consecutive
$memcConfig = isset($config['memcConfig']) ? $config['memcConfig'] : ['class' => 'MemcachedPhpBagOStuff'];
foreach ($config['lockServers'] as $name => $address) {
$params = ['servers' => [$address]] + $memcConfig;
$cache = ObjectCache::newFromParams($params);
if ($cache instanceof MemcachedBagOStuff) {
$this->bagOStuffs[$name] = $cache;
} else {
throw new Exception('Only MemcachedBagOStuff classes are supported by MemcLockManager.');
}
}
$this->session = wfRandomString(32);
}
示例14: factory
/**
* Make a new temporary file on the file system.
* Temporary files may be purged when the file object falls out of scope.
*
* @param string $prefix
* @param string $extension
* @return TempFSFile|null
*/
public static function factory($prefix, $extension = '')
{
$ext = $extension != '' ? ".{$extension}" : '';
$attempts = 5;
while ($attempts--) {
$path = wfTempDir() . '/' . $prefix . wfRandomString(12) . $ext;
MediaWiki\suppressWarnings();
$newFileHandle = fopen($path, 'x');
MediaWiki\restoreWarnings();
if ($newFileHandle) {
fclose($newFileHandle);
$tmpFile = new self($path);
$tmpFile->autocollect();
// Safely instantiated, end loop.
return $tmpFile;
}
}
// Give up
return null;
}
示例15: execute
public function execute()
{
$user = User::newFromName($this->getOption('user'));
if (!$user->getId()) {
$this->error("No such user exists.", 1);
}
$count = $this->getOption('count');
$namespace = (int) $this->getOption('namespace', 0);
for ($i = 0; $i < $count; ++$i) {
$title = Title::makeTitleSafe($namespace, "Page " . wfRandomString(2));
$page = WikiPage::factory($title);
$content = ContentHandler::makeContent(wfRandomString(), $title);
$summary = "Change " . wfRandomString(6);
$page->doEditContent($content, $summary, 0, false, $user);
$this->output("Edited {$title}\n");
if ($i && $i % $this->mBatchSize == 0) {
wfWaitForSlaves();
}
}
$this->output("Done\n");
}