本文整理汇总了PHP中wfStripIllegalFilenameChars函数的典型用法代码示例。如果您正苦于以下问题:PHP wfStripIllegalFilenameChars函数的具体用法?PHP wfStripIllegalFilenameChars怎么用?PHP wfStripIllegalFilenameChars使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wfStripIllegalFilenameChars函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: execute3rdPartyVideo
private function execute3rdPartyVideo()
{
if (empty($this->mParams['videoId'])) {
$this->dieUsageMsg('The videoId parameter must be set');
}
$duplicate = $this->getVideoDuplicate($this->mParams['provider'], $this->mParams['videoId']);
if ($duplicate) {
return array('title' => $duplicate->getTitle()->getText());
} else {
$uploader = new VideoFileUploader();
$title = $uploader->getUniqueTitle(wfStripIllegalFilenameChars($this->mParams['title']));
$uploader->setProvider($this->mParams['provider']);
$uploader->setVideoId($this->mParams['videoId']);
$uploader->setTargetTitle($title->getBaseText());
$uploader->upload($title);
return array('title' => $title->getText());
}
}
开发者ID:Tjorriemorrie,项目名称:app,代码行数:18,代码来源:ApiAddMediaPermanent.php
示例2: execute3rdPartyVideo
private function execute3rdPartyVideo()
{
if (empty($this->mParams['videoId'])) {
$this->dieUsageMsg('The videoId parameter must be set');
}
$duplicate = $this->getVideoDuplicate($this->mParams['provider'], $this->mParams['videoId']);
if ($duplicate) {
return array('title' => $duplicate->getTitle()->getText());
} else {
$uploader = new VideoFileUploader();
$title = $uploader->getUniqueTitle(wfStripIllegalFilenameChars($this->mParams['title']));
// https://wikia-inc.atlassian.net/browse/VE-1819
if (!$title) {
WikiaLogger::instance()->debug('ApiAddMediaPermanent', array('title' => $this->mParams['title']));
}
$uploader->setProvider($this->mParams['provider']);
$uploader->setVideoId($this->mParams['videoId']);
$uploader->setTargetTitle($title->getBaseText());
$uploader->upload($title);
return array('title' => $title->getText());
}
}
开发者ID:Tjorriemorrie,项目名称:app,代码行数:22,代码来源:ApiAddMediaPermanent.php
示例3: getTitle
/**
* Returns the title of the file to be uploaded. Sets mTitleError in case
* the name was illegal.
*
* @return Title The title of the file or null in case the name was illegal
*/
public function getTitle()
{
if ($this->mTitle !== false) {
return $this->mTitle;
}
/* Assume that if a user specified File:Something.jpg, this is an error
* and that the namespace prefix needs to be stripped of.
*/
$title = Title::newFromText($this->mDesiredDestName);
if ($title && $title->getNamespace() == NS_FILE) {
$this->mFilteredName = $title->getDBkey();
} else {
$this->mFilteredName = $this->mDesiredDestName;
}
# oi_archive_name is max 255 bytes, which include a timestamp and an
# exclamation mark, so restrict file name to 240 bytes.
if (strlen($this->mFilteredName) > 240) {
$this->mTitleError = self::FILENAME_TOO_LONG;
$this->mTitle = null;
return $this->mTitle;
}
/**
* Chop off any directories in the given filename. Then
* filter out illegal characters, and try to make a legible name
* out of it. We'll strip some silently that Title would die on.
*/
$this->mFilteredName = wfStripIllegalFilenameChars($this->mFilteredName);
/* Normalize to title form before we do any further processing */
$nt = Title::makeTitleSafe(NS_FILE, $this->mFilteredName);
if (is_null($nt)) {
$this->mTitleError = self::ILLEGAL_FILENAME;
$this->mTitle = null;
return $this->mTitle;
}
$this->mFilteredName = $nt->getDBkey();
/**
* We'll want to blacklist against *any* 'extension', and use
* only the final one for the whitelist.
*/
list($partname, $ext) = $this->splitExtensions($this->mFilteredName);
if (count($ext)) {
$this->mFinalExtension = trim($ext[count($ext) - 1]);
} else {
$this->mFinalExtension = '';
# No extension, try guessing one
$magic = MimeMagic::singleton();
$mime = $magic->guessMimeType($this->mTempPath);
if ($mime !== 'unknown/unknown') {
# Get a space separated list of extensions
$extList = $magic->getExtensionsForType($mime);
if ($extList) {
# Set the extension to the canonical extension
$this->mFinalExtension = strtok($extList, ' ');
# Fix up the other variables
$this->mFilteredName .= ".{$this->mFinalExtension}";
$nt = Title::makeTitleSafe(NS_FILE, $this->mFilteredName);
$ext = array($this->mFinalExtension);
}
}
}
/* Don't allow users to override the blacklist (check file extension) */
global $wgCheckFileExtensions, $wgStrictFileExtensions;
global $wgFileExtensions, $wgFileBlacklist;
$blackListedExtensions = $this->checkFileExtensionList($ext, $wgFileBlacklist);
if ($this->mFinalExtension == '') {
$this->mTitleError = self::FILETYPE_MISSING;
$this->mTitle = null;
return $this->mTitle;
} elseif ($blackListedExtensions || $wgCheckFileExtensions && $wgStrictFileExtensions && !$this->checkFileExtension($this->mFinalExtension, $wgFileExtensions)) {
$this->mBlackListedExtensions = $blackListedExtensions;
$this->mTitleError = self::FILETYPE_BADTYPE;
$this->mTitle = null;
return $this->mTitle;
}
// Windows may be broken with special characters, see bug XXX
if (wfIsWindows() && !preg_match('/^[\\x0-\\x7f]*$/', $nt->getText())) {
$this->mTitleError = self::WINDOWS_NONASCII_FILENAME;
$this->mTitle = null;
return $this->mTitle;
}
# 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) {
$this->mTitleError = self::MIN_LENGTH_PARTNAME;
$this->mTitle = null;
return $this->mTitle;
}
$this->mTitle = $nt;
return $this->mTitle;
//.........这里部分代码省略.........
开发者ID:elf-pavlik,项目名称:web-payments.org,代码行数:101,代码来源:UploadBase.php
示例4: validateFileMoveOperation
/**
* Check if the requested move target is a valid file move target
* @param Title $nt Target title
* @return array List of errors
*/
protected function validateFileMoveOperation($nt)
{
global $wgUser;
$errors = array();
// wfFindFile( $nt ) / wfLocalFile( $nt ) is not allowed until below
$file = wfLocalFile($this);
if ($file->exists()) {
if ($nt->getText() != wfStripIllegalFilenameChars($nt->getText())) {
$errors[] = array('imageinvalidfilename');
}
if (!File::checkExtensionCompatibility($file, $nt->getDBkey())) {
$errors[] = array('imagetypemismatch');
}
}
if ($nt->getNamespace() != NS_FILE) {
$errors[] = array('imagenocrossnamespace');
// From here we want to do checks on a file object, so if we can't
// create one, we must return.
return $errors;
}
// wfFindFile( $nt ) / wfLocalFile( $nt ) is allowed below here
$destFile = wfLocalFile($nt);
if (!$wgUser->isAllowed('reupload-shared') && !$destFile->exists() && wfFindFile($nt)) {
$errors[] = array('file-exists-sharedrepo');
}
return $errors;
}
开发者ID:namrenni,项目名称:mediawiki,代码行数:32,代码来源:Title.php
示例5: getTitle
/**
* Returns the title of the file to be uploaded. Sets mTitleError in case
* the name was illegal.
*
* @return Title The title of the file or null in case the name was illegal
*/
public function getTitle()
{
if ($this->mTitle !== false) {
return $this->mTitle;
}
/**
* Chop off any directories in the given filename. Then
* filter out illegal characters, and try to make a legible name
* out of it. We'll strip some silently that Title would die on.
*/
$this->mFilteredName = wfStripIllegalFilenameChars($this->mDesiredDestName);
/* Normalize to title form before we do any further processing */
$nt = Title::makeTitleSafe(NS_FILE, $this->mFilteredName);
if (is_null($nt)) {
$this->mTitleError = self::ILLEGAL_FILENAME;
return $this->mTitle = null;
}
$this->mFilteredName = $nt->getDBkey();
/**
* We'll want to blacklist against *any* 'extension', and use
* only the final one for the whitelist.
*/
list($partname, $ext) = $this->splitExtensions($this->mFilteredName);
if (count($ext)) {
$this->mFinalExtension = trim($ext[count($ext) - 1]);
} else {
$this->mFinalExtension = '';
}
/* Don't allow users to override the blacklist (check file extension) */
global $wgCheckFileExtensions, $wgStrictFileExtensions;
global $wgFileExtensions, $wgFileBlacklist;
if ($this->mFinalExtension == '') {
$this->mTitleError = self::FILETYPE_MISSING;
return $this->mTitle = null;
} elseif ($this->checkFileExtensionList($ext, $wgFileBlacklist) || $wgCheckFileExtensions && $wgStrictFileExtensions && !$this->checkFileExtension($this->mFinalExtension, $wgFileExtensions)) {
$this->mTitleError = self::FILETYPE_BADTYPE;
return $this->mTitle = null;
}
# 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) {
$this->mTitleError = self::MIN_LENGTH_PARTNAME;
return $this->mTitle = null;
}
return $this->mTitle = $nt;
}
开发者ID:GodelDesign,项目名称:Godel,代码行数:57,代码来源:UploadBase.php
示例6: isValidFileMove
/**
* Sanity checks for when a file is being moved
*
* @return Status
*/
protected function isValidFileMove()
{
$status = new Status();
$file = wfLocalFile($this->oldTitle);
$file->load(File::READ_LATEST);
if ($file->exists()) {
if ($this->newTitle->getText() != wfStripIllegalFilenameChars($this->newTitle->getText())) {
$status->fatal('imageinvalidfilename');
}
if (!File::checkExtensionCompatibility($file, $this->newTitle->getDBkey())) {
$status->fatal('imagetypemismatch');
}
}
if (!$this->newTitle->inNamespace(NS_FILE)) {
$status->fatal('imagenocrossnamespace');
}
return $status;
}
开发者ID:MediaWiki-stable,项目名称:1.26.1,代码行数:23,代码来源:MovePage.php
示例7: isValidMoveOperation
/**
* Check whether a given move operation would be valid.
* Returns true if ok, or a getUserPermissionsErrors()-like array otherwise
*
* @param $nt \type{Title} the new title
* @param $auth \type{\bool} indicates whether $wgUser's permissions
* should be checked
* @param $reason \type{\string} is the log summary of the move, used for spam checking
* @return \type{\mixed} True on success, getUserPermissionsErrors()-like array on failure
*/
public function isValidMoveOperation(&$nt, $auth = true, $reason = '')
{
global $wgUser;
$errors = array();
if (!$nt) {
// Normally we'd add this to $errors, but we'll get
// lots of syntax errors if $nt is not an object
return array(array('badtitletext'));
}
if ($this->equals($nt)) {
$errors[] = array('selfmove');
}
if (!$this->isMovable()) {
$errors[] = array('immobile-source-namespace', $this->getNsText());
}
if ($nt->getInterwiki() != '') {
$errors[] = array('immobile-target-namespace-iw');
}
if (!$nt->isMovable()) {
$errors[] = array('immobile-target-namespace', $nt->getNsText());
}
$oldid = $this->getArticleID();
$newid = $nt->getArticleID();
if (strlen($nt->getDBkey()) < 1) {
$errors[] = array('articleexists');
}
if ($this->getDBkey() == '' || !$oldid || $nt->getDBkey() == '') {
$errors[] = array('badarticleerror');
}
// Image-specific checks
if ($this->getNamespace() == NS_FILE) {
if ($nt->getNamespace() != NS_FILE) {
$errors[] = array('imagenocrossnamespace');
}
$file = wfLocalFile($this);
if ($file->exists()) {
if ($nt->getText() != wfStripIllegalFilenameChars($nt->getText())) {
$errors[] = array('imageinvalidfilename');
}
if (!File::checkExtensionCompatibility($file, $nt->getDBkey())) {
$errors[] = array('imagetypemismatch');
}
}
$destfile = wfLocalFile($nt);
if (!$wgUser->isAllowed('reupload-shared') && !$destfile->exists() && wfFindFile($nt)) {
$errors[] = array('file-exists-sharedrepo');
}
}
if ($nt->getNamespace() == NS_FILE && $this->getNamespace() != NS_FILE) {
$errors[] = array('nonfile-cannot-move-to-file');
}
if ($auth) {
$errors = wfMergeErrorArrays($errors, $this->getUserPermissionsErrors('move', $wgUser), $this->getUserPermissionsErrors('edit', $wgUser), $nt->getUserPermissionsErrors('move-target', $wgUser), $nt->getUserPermissionsErrors('edit', $wgUser));
}
$match = EditPage::matchSummarySpamRegex($reason);
if ($match !== false) {
// This is kind of lame, won't display nice
$errors[] = array('spamprotectiontext');
}
$err = null;
if (!wfRunHooks('AbortMove', array($this, $nt, $wgUser, &$err, $reason))) {
$errors[] = array('hookaborted', $err);
}
# The move is allowed only if (1) the target doesn't exist, or
# (2) the target is a redirect to the source, and has no history
# (so we can undo bad moves right after they're done).
if (0 != $newid) {
# Target exists; check for validity
if (!$this->isValidMoveTarget($nt)) {
$errors[] = array('articleexists');
}
} else {
$tp = $nt->getTitleProtection();
$right = $tp['pt_create_perm'] == 'sysop' ? 'protect' : $tp['pt_create_perm'];
if ($tp and !$wgUser->isAllowed($right)) {
$errors[] = array('cantmove-titleprotected');
}
}
if (empty($errors)) {
return true;
}
return $errors;
}
开发者ID:GodelDesign,项目名称:Godel,代码行数:93,代码来源:Title.php
示例8: createCardPage
private function createCardPage($gatherer)
{
$title = Title::newFromText($this->name);
$info = array();
$i = 0;
foreach ($gatherer->sets as $set => $stuff) {
$image = wfStripIllegalFilenameChars(str_replace(':', '', $this->name)) . ' ' . $gatherer->rels[$set]['abbr'] . '.jpg';
if (isset($gatherer->borders[$set]) && $gatherer->borders[$set]) {
$border = $gatherer->rels[$set]['border'];
$info['image' . ++$i] = "{{Border|[[Image:{$image}]]|{$border}}}";
} else {
$info['image' . ++$i] = "[[Image:{$image}]]";
}
foreach ($stuff as $rarity => $meh) {
switch ($rarity) {
case 'R':
$rarity = 'Rare';
break;
case 'U':
$rarity = 'Uncommon';
break;
case 'C':
$rarity = 'Common';
break;
case 'S':
if ($set == 'Time Spiral "Timeshifted"') {
$rarity = 'Timeshifted';
$set = 'Time Spiral';
} else {
$rarity = 'Special';
}
break;
case 'M':
$rarity = 'Mythic Rare';
break;
case 'L':
$rarity = 'Land';
break;
}
$set = wfStripIllegalFilenameChars(str_replace(':', '', $set));
$info['p/r' . $i] = "{{Rarity|{$set}|{$rarity}}}";
}
}
for ($i = 1; $i <= 15; $i++) {
if (!isset($info['image' . $i])) {
$info['image' . $i] = '';
}
if (!isset($info['p/r' . $i])) {
$info['p/r' . $i] = '';
}
}
$article = new WikiPage($title);
$article->doEdit(wfMsgForContentNoTrans('gatherer-cardpage', array($gatherer->info['name'], $gatherer->info['type'], $gatherer->info['cost'], $gatherer->info['cmc'], $gatherer->info['rules'], $gatherer->info['flavor'], $gatherer->info['p/t'], $gatherer->info['planeswalker'], $info['image1'], $info['p/r1'], $info['image2'], $info['p/r2'], $info['image3'], $info['p/r3'], $info['image4'], $info['p/r4'], $info['image5'], $info['p/r5'], $info['image6'], $info['p/r6'], $info['image7'], $info['p/r7'], $info['image8'], $info['p/r8'], $info['image9'], $info['p/r9'], $info['image10'], $info['p/r10'], $info['image11'], $info['p/r11'], $info['image12'], $info['p/r12'], $info['image13'], $info['p/r13'], $info['image14'], $info['p/r14'], $info['image15'], $info['p/r15'])), wfMsg('gatherer-cardpage-com'));
}
开发者ID:Tjorriemorrie,项目名称:app,代码行数:54,代码来源:Gatherer_body.php
示例9: internalProcessUpload
/**
* Really do the upload
* Checks are made in SpecialUpload::execute()
*
* @param array $resultDetails contains result-specific dict of additional values
*
* @access private
*/
function internalProcessUpload(&$resultDetails)
{
global $wgUser;
if (!wfRunHooks('UploadForm:BeforeProcessing', array(&$this))) {
wfDebug("Hook 'UploadForm:BeforeProcessing' broke processing the file.\n");
return self::BEFORE_PROCESSING;
}
/**
* If there was no filename or a zero size given, give up quick.
*/
if (trim($this->mSrcName) == '' || empty($this->mFileSize)) {
return self::EMPTY_FILE;
}
/* Check for curl error */
if ($this->mCurlError) {
return self::BEFORE_PROCESSING;
}
/**
* Chop off any directories in the given filename. Then
* filter out illegal characters, and try to make a legible name
* out of it. We'll strip some silently that Title would die on.
*/
if ($this->mDesiredDestName) {
$basename = $this->mDesiredDestName;
} else {
$basename = $this->mSrcName;
}
$filtered = wfStripIllegalFilenameChars($basename);
/* Normalize to title form before we do any further processing */
$nt = Title::makeTitleSafe(NS_FILE, $filtered);
if (is_null($nt)) {
$resultDetails = array('filtered' => $filtered);
return self::ILLEGAL_FILENAME;
}
$filtered = $nt->getDBkey();
/**
* 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;
}
$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.
*/
$permErrors = $nt->getUserPermissionsErrors('edit', $wgUser);
$permErrorsUpload = $nt->getUserPermissionsErrors('upload', $wgUser);
$permErrorsCreate = $nt->exists() ? array() : $nt->getUserPermissionsErrors('create', $wgUser);
if ($permErrors || $permErrorsUpload || $permErrorsCreate) {
// merge all the problems into one list, avoiding duplicates
$permErrors = array_merge($permErrors, wfArrayDiff2($permErrorsUpload, $permErrors));
$permErrors = array_merge($permErrors, wfArrayDiff2($permErrorsCreate, $permErrors));
$resultDetails = array('permissionserrors' => $permErrors);
return self::PROTECTED_PAGE;
}
/**
* In some cases we may forbid overwriting of existing files.
*/
$overwrite = $this->checkOverwrite($this->mDestName);
if ($overwrite !== true) {
$resultDetails = array('overwrite' => $overwrite);
return self::OVERWRITE_EXISTING_FILE;
}
/* Don't allow users to override the blacklist (check file extension) */
global $wgCheckFileExtensions, $wgStrictFileExtensions;
global $wgFileExtensions, $wgFileBlacklist;
if ($finalExt == '') {
return self::FILETYPE_MISSING;
} elseif ($this->checkFileExtensionList($ext, $wgFileBlacklist) || $wgCheckFileExtensions && $wgStrictFileExtensions && !$this->checkFileExtension($finalExt, $wgFileExtensions)) {
$resultDetails = array('finalExt' => $finalExt);
return self::FILETYPE_BADTYPE;
}
/**
* Look at the contents of the file; if we can recognize the
* type but it's corrupt or data of the wrong type, we should
* probably not accept it.
//.........这里部分代码省略.........
开发者ID:josephdye,项目名称:wikireader,代码行数:101,代码来源:SpecialUpload.php
注:本文中的wfStripIllegalFilenameChars函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论