本文整理汇总了PHP中RepoGroup::singleton方法的典型用法代码示例。如果您正苦于以下问题:PHP RepoGroup::singleton方法的具体用法?PHP RepoGroup::singleton怎么用?PHP RepoGroup::singleton使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RepoGroup
的用法示例。
在下文中一共展示了RepoGroup::singleton方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
public function execute()
{
$params = $this->extractRequestParams();
$modulePrefix = $this->getModulePrefix();
$prop = array_flip($params['prop']);
$scale = $this->getScale($params);
$result = $this->getResult();
if (!$params['filekey'] && !$params['sessionkey']) {
$this->dieUsage("One of filekey or sessionkey must be supplied", 'nofilekey');
}
// Alias sessionkey to filekey, but give an existing filekey precedence.
if (!$params['filekey'] && $params['sessionkey']) {
$params['filekey'] = $params['sessionkey'];
}
try {
$stash = RepoGroup::singleton()->getLocalRepo()->getUploadStash($this->getUser());
foreach ($params['filekey'] as $filekey) {
$file = $stash->getFile($filekey);
$finalThumbParam = $this->mergeThumbParams($file, $scale, $params['urlparam']);
$imageInfo = ApiQueryImageInfo::getInfo($file, $prop, $result, $finalThumbParam);
$result->addValue(array('query', $this->getModuleName()), null, $imageInfo);
$result->addIndexedTagName(array('query', $this->getModuleName()), $modulePrefix);
}
// @todo Update exception handling here to understand current getFile exceptions
} catch (UploadStashFileNotFoundException $e) {
$this->dieUsage("File not found: " . $e->getMessage(), "invalidsessiondata");
} catch (UploadStashBadPathException $e) {
$this->dieUsage("Bad path: " . $e->getMessage(), "invalidsessiondata");
}
}
示例2: parserFunction
public static function parserFunction($parser, $vid = null, $img = null)
{
global $wgTitle, $wgContLang;
wfLoadExtensionMessages('WHVid');
if ($vid === null || $img === null) {
return '<div class="errorbox">' . wfMsg('missing-params') . '</div>';
}
$vid = htmlspecialchars($vid);
$divId = "whvid-" . md5($vid . mt_rand(1, 1000));
$vidUrl = self::getVidUrl($vid);
$imgTitle = Title::newFromURL($img, NS_IMAGE);
$imgUrl = null;
if ($imgTitle) {
$imgFile = RepoGroup::singleton()->findFile($imgTitle);
$smallImgUrl = '';
$largeImgUrl = '';
if ($imgFile) {
$width = 550;
$height = 309;
$thumb = $imgFile->getThumbnail($width, $height);
$largeImgUrl = wfGetPad($thumb->getUrl());
$width = 240;
//$height = 135;
$thumb = $imgFile->getThumbnail($width);
$smallImgUrl = wfGetPad($thumb->getUrl());
}
}
return $parser->insertStripItem(wfMsgForContent('embed-html', $divId, $vidUrl, $largeImgUrl, $smallImgUrl));
}
示例3: execute
public function execute()
{
$pageIds = $this->getPageSet()->getAllTitlesByNamespace();
// Make sure we have files in the title set:
if (!empty($pageIds[NS_FILE])) {
$titles = array_keys($pageIds[NS_FILE]);
asort($titles);
// Ensure the order is always the same
$result = $this->getResult();
$images = RepoGroup::singleton()->findFiles($titles);
foreach ($images as $img) {
// if its a "transcode" add the transcode status table output
if (TimedMediaHandlerHooks::isTranscodableTitle($img->getTitle())) {
$transcodeStatus = WebVideoTranscode::getTranscodeState($img->getTitle()->getDBKey());
// remove useless properties
foreach ($transcodeStatus as $key => &$val) {
unset($val['id']);
unset($val['image_name']);
unset($val['key']);
}
$result->addValue(array('query', 'pages', $img->getTitle()->getArticleID()), 'transcodestatus', $transcodeStatus);
}
}
}
}
示例4: execute
public function execute()
{
$repo = RepoGroup::singleton()->getLocalRepo();
$dbr = $repo->getSlaveDb();
$this->output("Getting list of files to clean up...\n");
$res = $dbr->select('uploadstash', 'us_key', 'us_timestamp < ' . $dbr->timestamp(time() - UploadStash::REPO_AGE * 3600), __METHOD__);
if (!is_object($res) || $res->numRows() == 0) {
// nothing to do.
return false;
}
// finish the read before starting writes.
$keys = array();
foreach ($res as $row) {
array_push($keys, $row->us_key);
}
$this->output('Removing ' . count($keys) . " file(s)...\n");
// this could be done some other, more direct/efficient way, but using
// UploadStash's own methods means it's less likely to fall accidentally
// out-of-date someday
$stash = new UploadStash($repo);
foreach ($keys as $key) {
$stash->getFile($key, true);
$stash->removeFileNoAuth($key);
}
}
示例5: getLocalFile
public function getLocalFile()
{
if (is_null($this->mLocalFile)) {
$this->mLocalFile = new FakeLocalFile(Title::newFromText('Temp_file_' . time() . '.jpg', NS_FILE), RepoGroup::singleton()->getLocalRepo());
}
return $this->mLocalFile;
}
示例6: execute
public function execute()
{
global $wgCityId;
$db = wfGetDB(DB_MASTER);
(new WikiaSQL())->SELECT('*')->FROM('page')->WHERE('page_is_redirect')->EQUAL_TO(1)->runLoop($db, function ($a, $row) use($db) {
$title = Title::newFromID($row->page_id);
if (!$title->isDeleted()) {
$rev = Revision::newFromTitle($title);
$text = $rev->getText();
$rt = Title::newFromRedirectRecurse($text);
if (!$rt) {
// page is marked as redirect but $text is not valid redirect
$this->output('Fixed ID: ' . $title->getArticleID() . ' Title: ' . $title->getText() . "\n");
// Fix page table
(new WikiaSQL())->UPDATE('page')->SET('page_is_redirect', 0)->WHERE('page_id')->EQUAL_TO($row->page_id)->RUN($db);
// remove redirect from redirect table
(new WikiaSQL())->DELETE('redirect')->WHERE('rd_from')->EQUAL_TO($row->page_id)->RUN($db);
// clear cache
LinkCache::singleton()->addGoodLinkObj($row->page_id, $title, strlen($text), 0, $rev->getId());
if ($title->getNamespace() == NS_FILE) {
RepoGroup::singleton()->getLocalRepo()->invalidateImageRedirect($title);
}
}
}
});
}
示例7: execute
function execute()
{
$subdir = $this->getOption('subdir', '');
$verbose = $this->hasOption('verbose');
$repo = RepoGroup::singleton()->getLocalRepo();
if ($repo->hasSha1Storage()) {
$this->error("Local repo uses SHA-1 file storage names; aborting.", 1);
}
$directory = $repo->getZonePath('public');
if ($subdir != '') {
$directory .= "/{$subdir}/";
}
if ($verbose) {
$this->output("Scanning files under {$directory}:\n");
}
$list = $repo->getBackend()->getFileList(['dir' => $directory]);
if ($list === null) {
$this->error("Could not get file listing.", 1);
}
$pathBatch = [];
foreach ($list as $path) {
if (preg_match('#^(thumb|deleted)/#', $path)) {
continue;
// handle ugly nested containers on stock installs
}
$pathBatch[] = $path;
if (count($pathBatch) >= $this->mBatchSize) {
$this->checkFiles($repo, $pathBatch, $verbose);
$pathBatch = [];
}
}
$this->checkFiles($repo, $pathBatch, $verbose);
}
示例8: uploadImageFromUrl
/**
* @desc Uploads an image on a wki
*
* @static
* @param string $imageUrl url address to original file
* @param Object $oImageData an object with obligatory field "name" and optional fields: "comment", "description"
* @param User | null $user optional User's class instance (the file will be "uploaded" by this user)
*
* @return array
*/
public static function uploadImageFromUrl($imageUrl, $oImageData, $user = null)
{
// disable recentchange hooks
global $wgHooks;
$wgHooks['RecentChange_save'] = array();
$wgHooks['RecentChange_beforeSave'] = array();
/* prepare temporary file */
$data = array('wpUpload' => 1, 'wpSourceType' => 'web', 'wpUploadFileURL' => $imageUrl);
//validate of optional image data
foreach (array(self::FILE_DATA_COMMENT_OPION_NAME, self::FILE_DATA_DESC_OPION_NAME) as $option) {
if (!isset($oImageData->{$option})) {
$oImageData->{$option} = $oImageData->name;
}
}
$upload = F::build('UploadFromUrl');
/* @var $upload UploadFromUrl */
$upload->initializeFromRequest(F::build('FauxRequest', array($data, true)));
$upload->fetchFile();
$upload->verifyUpload();
// create destination file
$title = Title::newFromText($oImageData->name, NS_FILE);
$file = F::build('WikiaLocalFile', array($title, RepoGroup::singleton()->getLocalRepo()));
/* @var $file WikiaLocalFile */
/* real upload */
$result = $file->upload($upload->getTempPath(), $oImageData->comment, $oImageData->description, File::DELETE_SOURCE, false, false, $user);
return array('status' => $result->ok, 'page_id' => $title->getArticleID(), 'errors' => $result->errors);
}
示例9: filePath
function filePath($name)
{
if (!isset($this->repo)) {
$this->repo = RepoGroup::singleton()->getLocalRepo();
}
return $this->repo->getRootDirectory() . '/' . $this->repo->getHashPath($name) . $name;
}
示例10: execute
public function execute()
{
$repo = RepoGroup::singleton()->getLocalRepo();
$dbr = $repo->getSlaveDb();
// how far back should this look for files to delete?
global $wgUploadStashMaxAge;
$this->output("Getting list of files to clean up...\n");
$res = $dbr->select('uploadstash', 'us_key', 'us_timestamp < ' . $dbr->addQuotes($dbr->timestamp(time() - $wgUploadStashMaxAge)), __METHOD__);
if (!is_object($res) || $res->numRows() == 0) {
$this->output("No files to cleanup!\n");
// nothing to do.
return;
}
// finish the read before starting writes.
$keys = array();
foreach ($res as $row) {
array_push($keys, $row->us_key);
}
$this->output('Removing ' . count($keys) . " file(s)...\n");
// this could be done some other, more direct/efficient way, but using
// UploadStash's own methods means it's less likely to fall accidentally
// out-of-date someday
$stash = new UploadStash($repo);
foreach ($keys as $key) {
try {
$stash->getFile($key, true);
$stash->removeFileNoAuth($key);
} catch (UploadStashBadPathException $ex) {
$this->output("Failed removing stashed upload with key: {$key}\n");
}
}
}
示例11: getRepo
/**
* @return FileRepo
*/
function getRepo()
{
if (!isset($this->repo)) {
$this->repo = RepoGroup::singleton()->getLocalRepo();
}
return $this->repo;
}
示例12: execute
function execute()
{
$lastName = $this->getOption('start', '');
$repo = RepoGroup::singleton()->getLocalRepo();
$dbr = $repo->getSlaveDB();
$be = $repo->getBackend();
$mtime1 = $dbr->timestampOrNull($this->getOption('mtimeafter', null));
$mtime2 = $dbr->timestampOrNull($this->getOption('mtimebefore', null));
$joinTables = array('image');
$joinConds = array('image' => array('INNER JOIN', 'img_name = page_title'));
if ($mtime1 || $mtime2) {
$joinTables[] = 'logging';
$on = array('log_page = page_id', 'log_type' => array('upload', 'move', 'delete'));
if ($mtime1) {
$on[] = "log_timestamp > {$dbr->addQuotes($mtime1)}";
}
if ($mtime2) {
$on[] = "log_timestamp < {$dbr->addQuotes($mtime2)}";
}
$joinConds['logging'] = array('INNER JOIN', $on);
}
do {
$res = $dbr->select(array_merge(array('page'), $joinTables), array('img_name' => 'DISTINCT(page_title)'), array('page_namespace' => NS_FILE, "page_title >= " . $dbr->addQuotes($lastName)), __METHOD__, array('ORDER BY' => 'page_title', 'LIMIT' => $this->mBatchSize), $joinConds);
// Check if any of these files are missing...
$pathsByName = array();
foreach ($res as $row) {
$file = $repo->newFile($row->img_name);
$pathsByName[$row->img_name] = $file->getPath();
$lastName = $row->img_name;
}
$be->preloadFileStat(array('srcs' => $pathsByName));
foreach ($pathsByName as $path) {
if ($be->fileExists(array('src' => $path)) === false) {
$this->output("{$path}\n");
}
}
// Find all missing old versions of any of the files in this batch...
if (count($pathsByName)) {
$ores = $dbr->select('oldimage', array('oi_name', 'oi_archive_name'), array('oi_name' => array_keys($pathsByName)), __METHOD__);
$checkPaths = array();
foreach ($ores as $row) {
if (!strlen($row->oi_archive_name)) {
continue;
// broken row
}
$file = $repo->newFromArchiveName($row->oi_name, $row->oi_archive_name);
$checkPaths[] = $file->getPath();
}
foreach (array_chunk($checkPaths, $this->mBatchSize) as $paths) {
$be->preloadFileStat(array('srcs' => $paths));
foreach ($paths as $path) {
if ($be->fileExists(array('src' => $path)) === false) {
$this->output("{$path}\n");
}
}
}
}
} while ($res->numRows() >= $this->mBatchSize);
}
示例13: singleton
/**
* Get a FileCache instance. Typically, only one instance of FileCache
* is needed in a MediaWiki invocation.
*/
static function singleton()
{
if (self::$instance) {
return self::$instance;
}
self::$instance = new FileCache(RepoGroup::singleton());
return self::$instance;
}
示例14: getLocalFile
public function getLocalFile()
{
if (is_null($this->mLocalFile)) {
//TODO: find out what namespace constant 6 is
$this->mLocalFile = new FakeLocalFile(Title::newFromText('Temp_file_' . time(), 6), RepoGroup::singleton()->getLocalRepo());
}
return $this->mLocalFile;
}
示例15: getFileDuplicate
protected function getFileDuplicate($filepath)
{
$duplicates = RepoGroup::singleton()->findBySha1(FSFile::getSha1Base36FromPath($filepath));
if (count($duplicates) > 0) {
return $duplicates[0];
}
return null;
}