本文整理汇总了PHP中LocalFile::getPath方法的典型用法代码示例。如果您正苦于以下问题:PHP LocalFile::getPath方法的具体用法?PHP LocalFile::getPath怎么用?PHP LocalFile::getPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LocalFile
的用法示例。
在下文中一共展示了LocalFile::getPath方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: saveSettings
public function saveSettings($settings, $cityId = null)
{
global $wgCityId, $wgUser;
$cityId = empty($cityId) ? $wgCityId : $cityId;
// Verify wordmark length ( CONN-116 )
if (!empty($settings['wordmark-text'])) {
$settings['wordmark-text'] = trim($settings['wordmark-text']);
}
if (empty($settings['wordmark-text'])) {
// Do not save wordmark if its empty.
unset($settings['wordmark-text']);
} else {
if (mb_strlen($settings['wordmark-text']) > 50) {
$settings['wordmark-text'] = mb_substr($settings['wordmark-text'], 0, 50);
}
}
if (isset($settings['favicon-image-name']) && strpos($settings['favicon-image-name'], 'Temp_file_') === 0) {
$temp_file = new LocalFile(Title::newFromText($settings['favicon-image-name'], 6), RepoGroup::singleton()->getLocalRepo());
$file = new LocalFile(Title::newFromText(self::FaviconImageName, 6), RepoGroup::singleton()->getLocalRepo());
$file->upload($temp_file->getPath(), '', '');
$temp_file->delete('');
Wikia::invalidateFavicon();
$settings['favicon-image-url'] = $file->getURL();
$settings['favicon-image-name'] = $file->getName();
$file->repo->forceMaster();
$history = $file->getHistory(1);
if (count($history) == 1) {
$oldFaviconFile = array('url' => $history[0]->getURL(), 'name' => $history[0]->getArchiveName());
}
}
if (isset($settings['wordmark-image-name']) && strpos($settings['wordmark-image-name'], 'Temp_file_') === 0) {
$temp_file = new LocalFile(Title::newFromText($settings['wordmark-image-name'], 6), RepoGroup::singleton()->getLocalRepo());
$file = new LocalFile(Title::newFromText(self::WordmarkImageName, 6), RepoGroup::singleton()->getLocalRepo());
$file->upload($temp_file->getPath(), '', '');
$temp_file->delete('');
$settings['wordmark-image-url'] = $file->getURL();
$settings['wordmark-image-name'] = $file->getName();
$file->repo->forceMaster();
$history = $file->getHistory(1);
if (count($history) == 1) {
$oldFile = array('url' => $history[0]->getURL(), 'name' => $history[0]->getArchiveName());
}
}
if (isset($settings['background-image-name']) && strpos($settings['background-image-name'], 'Temp_file_') === 0) {
$temp_file = new LocalFile(Title::newFromText($settings['background-image-name'], 6), RepoGroup::singleton()->getLocalRepo());
$file = new LocalFile(Title::newFromText(self::BackgroundImageName, 6), RepoGroup::singleton()->getLocalRepo());
$file->upload($temp_file->getPath(), '', '');
$temp_file->delete('');
$settings['background-image'] = $file->getURL();
$settings['background-image-name'] = $file->getName();
$settings['background-image-width'] = $file->getWidth();
$settings['background-image-height'] = $file->getHeight();
$imageServing = new ImageServing(null, 120, array("w" => "120", "h" => "65"));
$settings['user-background-image'] = $file->getURL();
$settings['user-background-image-thumb'] = wfReplaceImageServer($file->getThumbUrl($imageServing->getCut($file->getWidth(), $file->getHeight(), "origin") . "-" . $file->getName()));
$file->repo->forceMaster();
$history = $file->getHistory(1);
if (count($history) == 1) {
$oldBackgroundFile = array('url' => $history[0]->getURL(), 'name' => $history[0]->getArchiveName());
}
}
$reason = wfMsg('themedesigner-reason', $wgUser->getName());
// update history
if (!empty($GLOBALS[self::WikiFactoryHistory])) {
$history = $GLOBALS[self::WikiFactoryHistory];
$lastItem = end($history);
$revisionId = intval($lastItem['revision']) + 1;
} else {
$history = array();
$revisionId = 1;
}
// #140758 - Jakub
// validation
// default color values
foreach (ThemeDesignerHelper::getColorVars() as $sColorVar => $sDefaultValue) {
if (!isset($settings[$sColorVar]) || !ThemeDesignerHelper::isValidColor($settings[$sColorVar])) {
$settings[$sColorVar] = $sDefaultValue;
}
}
// update WF variable with current theme settings
WikiFactory::setVarByName(self::WikiFactorySettings, $cityId, $settings, $reason);
// add entry
$history[] = array('settings' => $settings, 'author' => $wgUser->getName(), 'timestamp' => wfTimestampNow(), 'revision' => $revisionId);
// limit history size to last 10 changes
$history = array_slice($history, -self::HistoryItemsLimit);
if (count($history) > 1) {
for ($i = 0; $i < count($history) - 1; $i++) {
if (isset($oldFaviconFile) && isset($history[$i]['settings']['favicon-image-name'])) {
if ($history[$i]['settings']['favicon-image-name'] == self::FaviconImageName) {
$history[$i]['settings']['favicon-image-name'] = $oldFaviconFile['name'];
$history[$i]['settings']['favicon-image-url'] = $oldFaviconFile['url'];
}
}
if (isset($oldFile) && isset($history[$i]['settings']['wordmark-image-name'])) {
if ($history[$i]['settings']['wordmark-image-name'] == self::WordmarkImageName) {
$history[$i]['settings']['wordmark-image-name'] = $oldFile['name'];
$history[$i]['settings']['wordmark-image-url'] = $oldFile['url'];
}
}
if (isset($oldBackgroundFile) && isset($history[$i]['settings']['background-image-name'])) {
//.........这里部分代码省略.........
示例2: insertImage
/**
* Insert an image upload into the mediawiki database tables. If the
* image insert was successful, a page showing the wiki text for their
* image is shown. Otherwise, if the image file name already exists in
* the database, a conflict page is returned to the user.
*
* @param $type string with either 'overwrite' or blank -- specifies
* whether to force-overwrite an existing image
* @param $name filename chosen by user for uploaded image
* @param $mwname filename of the file in mediawiki DB
* @param $fromIIA true iff source of call is Special:IntroImageAdder
* @param $image_comment a comment attached to the image upload (only
* used if $fromIIA == true)
* @return outputs either a wikitext results page (if image filename
* didn't exist or force overwrite was selected) or a conflict page.
* Returns an error string or empty string if no error.
*/
private function insertImage($type, $name, $mwname, $fromIIA = false, $image_comment = '')
{
global $wgRequest, $wgUser, $wgOut, $wgFileExtensions;
if (!$fromIIA) {
$license = $wgRequest->getVal('wpLicense', '');
if (!empty($license)) {
$attrib = $wgRequest->getVal('attribution');
$comment = '{{' . $license . (!empty($attrib) ? '|' . $attrib : '') . '}}';
if ($license != '') {
$wgUser->setOption('image_license', $license);
$wgUser->saveSettings();
}
} else {
$comment = $wgRequest->getVal('ImageAttribution', '');
}
} else {
$comment = $image_comment;
}
if (wfReadOnly()) {
return wfMsg('eiu-readonly');
}
if (!empty($mwname) && !empty($name)) {
$name = urldecode($name);
$name = preg_replace('/[^' . Title::legalChars() . ']|[:\\/\\\\]|\\?/', '-', $name);
$name = preg_replace('@&@', '&', $name);
$name = trim($name);
// did they give no extension at all when they changed the name?
list($first, $ext) = self::splitFilenameExt($name);
$ext = strtolower($ext);
$title = Title::makeTitleSafe(NS_IMAGE, $name);
if (is_null($title) || !in_array($ext, $wgFileExtensions)) {
return wfMsg('eiu-filetype-incorrect');
}
$newFile = true;
$titleExists = $title->exists();
if (!$titleExists || $fromIIA) {
//
// DB entry for file doesn't exist. User renamed their
// upload or it never existed.
//
if ($titleExists) {
$suggestedName = self::generateNewFilename($name);
$title = Title::makeTitleSafe(NS_IMAGE, $suggestedName);
}
// is the target protected?
$permErrors = $title->getUserPermissionsErrors('edit', $wgUser);
$permErrorsUpload = $title->getUserPermissionsErrors('upload', $wgUser);
if ($permErrors || $permErrorsUpload) {
return wfMsg('This image is protected');
}
$temp_file = new LocalFile(Title::newFromText($mwname, NS_IMAGE), RepoGroup::singleton()->getLocalRepo());
$file = new LocalFile($title, RepoGroup::singleton()->getLocalRepo());
$file->upload($temp_file->getPath(), $comment, $comment);
$temp_file->delete('');
} elseif ($type == 'overwrite') {
//
// DB entry exists and user selected to overwrite it
//
$title = Title::newFromText($name, NS_IMAGE);
// is the target protected?
$permErrors = $title->getUserPermissionsErrors('edit', $wgUser);
$permErrorsUpload = $title->getUserPermissionsErrors('upload', $wgUser);
$permErrorsCreate = $title->exists() ? array() : $title->getUserPermissionsErrors('create', $wgUser);
if ($permErrors || $permErrorsUpload || $permErrorsCreate) {
return wfMsg('This image is protected');
}
$file_name = new LocalFile($title, RepoGroup::singleton()->getLocalRepo());
$file_mwname = new TempLocalFile(Title::newFromText($mwname, NS_IMAGE), RepoGroup::singleton()->getLocalRepo());
$file_name->upload($file_mwname->getPath(), $comment, $comment);
$file_mwname->delete('');
$newFile = false;
} elseif ($type == 'existing') {
//
// DB entry exists and user doesn't want to overwrite or
// rename, so they use the existing file from the DB.
//
$title = Title::newFromText($name, NS_IMAGE);
} else {
//
// There was a conflict with an existing file in the
// DB. Title exists and overwrite action not taken yet.
//
$data = array('wpUpload' => 1, 'wpSourceType' => 'web', 'wpUploadFileURL' => '');
//.........这里部分代码省略.........
示例3: getDeletedPath
protected function getDeletedPath(LocalRepo $repo, LocalFile $file)
{
$hash = $repo->getFileSha1($file->getPath());
$key = "{$hash}.{$file->getExtension()}";
return $repo->getDeletedHashPath($key) . $key;
}
示例4: insertImage
function insertImage()
{
global $wgRequest, $wgUser, $wgContLang;
$type = $wgRequest->getVal('type');
$name = $wgRequest->getVal('name');
$mwname = $wgRequest->getVal('mwname');
$tempid = $wgRequest->getVal('tempid');
'' != $wgRequest->getVal('gallery') ? $gallery = $wgRequest->getVal('gallery') : ($gallery = '');
'' != $wgRequest->getVal('article') ? $title_main = urldecode($wgRequest->getVal('article')) : ($title_main = '');
'' != $wgRequest->getCheck('fck') ? $fck = $wgRequest->getCheck('ns') : ($fck = false);
'' != $wgRequest->getVal('ns') ? $ns = $wgRequest->getVal('ns') : ($ns = '');
'' != $wgRequest->getVal('link') ? $link = urldecode($wgRequest->getVal('link')) : ($link = '');
$extraId = $wgRequest->getVal('extraId');
$newFile = true;
if ($name !== NULL) {
$name = urldecode($name);
if ($name == '') {
header('X-screen-type: error');
return WfMsg('wmu-warn3');
} else {
$name = preg_replace("/[^" . Title::legalChars() . "]|:/", '-', $name);
// did they give no extension at all when they changed the name?
$ext = explode('.', $name);
array_shift($ext);
if (count($ext)) {
$finalExt = $ext[count($ext) - 1];
} else {
$finalExt = '';
}
if ('' == $finalExt) {
header('X-screen-type: error');
return wfMsg('wmu-filetype-missing');
}
$title = Title::makeTitleSafe(NS_IMAGE, $name);
if (is_null($title)) {
header('X-screen-type: error');
return wfMsg('wmu-filetype-incorrect');
}
if ($title->exists()) {
if ($type == 'overwrite') {
$title = Title::newFromText($name, 6);
// is the target protected?
$permErrors = $title->getUserPermissionsErrors('edit', $wgUser);
$permErrorsUpload = $title->getUserPermissionsErrors('upload', $wgUser);
$permErrorsCreate = $title->exists() ? array() : $title->getUserPermissionsErrors('create', $wgUser);
if ($permErrors || $permErrorsUpload || $permErrorsCreate) {
header('X-screen-type: error');
return wfMsg('wmu-file-protected');
}
$file_name = new LocalFile($title, RepoGroup::singleton()->getLocalRepo());
$file_mwname = new FakeLocalFile(Title::newFromText($mwname, 6), RepoGroup::singleton()->getLocalRepo());
if (!empty($extraId)) {
$flickrResult = $this->getFlickrPhotoInfo($extraId);
$nsid = $flickrResult['owner']['nsid'];
// e.g. 49127042@N00
$username = $flickrResult['owner']['username'];
// e.g. bossa67
$license = $flickrResult['license'];
$caption = '{{MediaWiki:Flickr' . intval($license) . '|1=' . wfEscapeWikiText($extraId) . '|2=' . wfEscapeWikiText($nsid) . '|3=' . wfEscapeWikiText($username) . '}}';
} else {
$caption = '';
}
$file_name->upload($file_mwname->getPath(), '', $caption);
$file_mwname->delete('');
$this->tempFileClearInfo($tempid);
$newFile = false;
} else {
if ($type == 'existing') {
$file = wfFindFile(Title::newFromText($name, 6));
if (!empty($file)) {
header('X-screen-type: existing');
$props = array();
$props['file'] = $file;
$props['mwname'] = $name;
$props['default_caption'] = Wikia::getProps($file->getTitle()->getArticleID(), 'default_caption');
return $this->detailsPage($props);
} else {
header('X-screen-type: error');
return wfMsg('wmu-file-error');
}
} else {
header('X-screen-type: conflict');
$tmpl = new EasyTemplate(dirname(__FILE__) . '/templates/');
// extensions check
list($partname, $ext) = UploadBase::splitExtensions($name);
if (count($ext)) {
$finalExt = $ext[count($ext) - 1];
} else {
$finalExt = '';
}
// for more than one "extension"
if (count($ext) > 1) {
for ($i = 0; $i < count($ext) - 1; $i++) {
$partname .= '.' . $ext[$i];
}
}
$tmpl->set_vars(array('partname' => $partname, 'extension' => strtolower($finalExt), 'mwname' => $mwname, 'extraId' => $extraId));
return $tmpl->render('conflict');
}
}
//.........这里部分代码省略.........