本文整理汇总了PHP中UploadBase::initialize方法的典型用法代码示例。如果您正苦于以下问题:PHP UploadBase::initialize方法的具体用法?PHP UploadBase::initialize怎么用?PHP UploadBase::initialize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UploadBase
的用法示例。
在下文中一共展示了UploadBase::initialize方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: selectUploadModule
/**
* Select an upload module and set it to mUpload. Dies on failure. If the
* request was a status request and not a true upload, returns false;
* otherwise true
*
* @return bool
*/
protected function selectUploadModule()
{
$request = $this->getMain()->getRequest();
// One and only one of the following parameters is needed
$this->requireOnlyOneParameter($this->mParams, 'filekey', 'file', 'url', 'statuskey');
if ($this->mParams['statuskey']) {
$this->checkAsyncDownloadEnabled();
// Status request for an async upload
$sessionData = UploadFromUrlJob::getSessionData($this->mParams['statuskey']);
if (!isset($sessionData['result'])) {
$this->dieUsage('No result in session data', 'missingresult');
}
if ($sessionData['result'] == 'Warning') {
$sessionData['warnings'] = $this->transformWarnings($sessionData['warnings']);
$sessionData['sessionkey'] = $this->mParams['statuskey'];
}
$this->getResult()->addValue(null, $this->getModuleName(), $sessionData);
return false;
}
// The following modules all require the filename parameter to be set
if (is_null($this->mParams['filename'])) {
$this->dieUsageMsg(array('missingparam', 'filename'));
}
if ($this->mParams['filekey']) {
// Upload stashed in a previous request
if (!UploadFromStash::isValidKey($this->mParams['filekey'])) {
$this->dieUsageMsg('invalid-file-key');
}
// context allows access to the current user without creating new $wgUser references
$context = $this->createContext();
$this->mUpload = new UploadFromStash($context->getUser());
$this->mUpload->initialize($this->mParams['filekey'], $this->mParams['filename']);
} elseif (isset($this->mParams['file'])) {
$this->mUpload = new UploadFromFile();
$this->mUpload->initialize($this->mParams['filename'], $request->getUpload('file'));
} elseif (isset($this->mParams['url'])) {
// Make sure upload by URL is enabled:
if (!UploadFromUrl::isEnabled()) {
$this->dieUsageMsg('copyuploaddisabled');
}
$async = false;
if ($this->mParams['asyncdownload']) {
$this->checkAsyncDownloadEnabled();
if ($this->mParams['leavemessage'] && !$this->mParams['ignorewarnings']) {
$this->dieUsage('Using leavemessage without ignorewarnings is not supported', 'missing-ignorewarnings');
}
if ($this->mParams['leavemessage']) {
$async = 'async-leavemessage';
} else {
$async = 'async';
}
}
$this->mUpload = new UploadFromUrl();
$this->mUpload->initialize($this->mParams['filename'], $this->mParams['url'], $async);
}
return true;
}
示例2: selectUploadModule
/**
* Select an upload module and set it to mUpload. Dies on failure. If the
* request was a status request and not a true upload, returns false;
* otherwise true
*
* @return bool
*/
protected function selectUploadModule()
{
$request = $this->getMain()->getRequest();
// chunk or one and only one of the following parameters is needed
if (!$this->mParams['chunk']) {
$this->requireOnlyOneParameter($this->mParams, 'filekey', 'file', 'url', 'statuskey');
}
// The following modules all require the filename parameter to be set
if (is_null($this->mParams['filename'])) {
$this->dieUsageMsg(array('missingparam', 'filename'));
}
if ($this->mParams['chunk']) {
// Chunk upload
$this->mUpload = new UploadFromChunks();
if (isset($this->mParams['filekey'])) {
// handle new chunk
$this->mUpload->continueChunks($this->mParams['filename'], $this->mParams['filekey'], $request->getUpload('chunk'));
} else {
// handle first chunk
$this->mUpload->initialize($this->mParams['filename'], $request->getUpload('chunk'));
}
} elseif (isset($this->mParams['filekey'])) {
// Upload stashed in a previous request
if (!UploadFromStash::isValidKey($this->mParams['filekey'])) {
$this->dieUsageMsg('invalid-file-key');
}
$this->mUpload = new UploadFromStash($this->getUser());
$this->mUpload->initialize($this->mParams['filekey'], $this->mParams['filename']);
} elseif (isset($this->mParams['file'])) {
$this->mUpload = new UploadFromFile();
$this->mUpload->initialize($this->mParams['filename'], $request->getUpload('file'));
} elseif (isset($this->mParams['url'])) {
// Make sure upload by URL is enabled:
if (!UploadFromUrl::isEnabled()) {
$this->dieUsageMsg('copyuploaddisabled');
}
$this->mUpload = new UploadFromUrl();
$this->mUpload->initialize($this->mParams['filename'], $this->mParams['url']);
}
return true;
}
示例3: selectUploadModule
/**
* Select an upload module and set it to mUpload. Dies on failure. If the
* request was a status request and not a true upload, returns false;
* otherwise true
*
* @return bool
*/
protected function selectUploadModule()
{
$request = $this->getMain()->getRequest();
// chunk or one and only one of the following parameters is needed
if (!$this->mParams['chunk']) {
$this->requireOnlyOneParameter($this->mParams, 'filekey', 'file', 'url');
}
// Status report for "upload to stash"/"upload from stash"
if ($this->mParams['filekey'] && $this->mParams['checkstatus']) {
$progress = UploadBase::getSessionStatus($this->getUser(), $this->mParams['filekey']);
if (!$progress) {
$this->dieUsage('No result in status data', 'missingresult');
} elseif (!$progress['status']->isGood()) {
$this->dieUsage($progress['status']->getWikiText(false, false, 'en'), 'stashfailed');
}
if (isset($progress['status']->value['verification'])) {
$this->checkVerification($progress['status']->value['verification']);
}
unset($progress['status']);
// remove Status object
$this->getResult()->addValue(null, $this->getModuleName(), $progress);
return false;
}
// The following modules all require the filename parameter to be set
if (is_null($this->mParams['filename'])) {
$this->dieUsageMsg(['missingparam', 'filename']);
}
if ($this->mParams['chunk']) {
// Chunk upload
$this->mUpload = new UploadFromChunks();
if (isset($this->mParams['filekey'])) {
if ($this->mParams['offset'] === 0) {
$this->dieUsage('Cannot supply a filekey when offset is 0', 'badparams');
}
// handle new chunk
$this->mUpload->continueChunks($this->mParams['filename'], $this->mParams['filekey'], $request->getUpload('chunk'));
} else {
if ($this->mParams['offset'] !== 0) {
$this->dieUsage('Must supply a filekey when offset is non-zero', 'badparams');
}
// handle first chunk
$this->mUpload->initialize($this->mParams['filename'], $request->getUpload('chunk'));
}
} elseif (isset($this->mParams['filekey'])) {
// Upload stashed in a previous request
if (!UploadFromStash::isValidKey($this->mParams['filekey'])) {
$this->dieUsageMsg('invalid-file-key');
}
$this->mUpload = new UploadFromStash($this->getUser());
// This will not download the temp file in initialize() in async mode.
// We still have enough information to call checkWarnings() and such.
$this->mUpload->initialize($this->mParams['filekey'], $this->mParams['filename'], !$this->mParams['async']);
} elseif (isset($this->mParams['file'])) {
$this->mUpload = new UploadFromFile();
$this->mUpload->initialize($this->mParams['filename'], $request->getUpload('file'));
} elseif (isset($this->mParams['url'])) {
// Make sure upload by URL is enabled:
if (!UploadFromUrl::isEnabled()) {
$this->dieUsageMsg('copyuploaddisabled');
}
if (!UploadFromUrl::isAllowedHost($this->mParams['url'])) {
$this->dieUsageMsg('copyuploadbaddomain');
}
if (!UploadFromUrl::isAllowedUrl($this->mParams['url'])) {
$this->dieUsageMsg('copyuploadbadurl');
}
$this->mUpload = new UploadFromUrl();
$this->mUpload->initialize($this->mParams['filename'], $this->mParams['url']);
}
return true;
}
示例4: selectUploadModule
/**
* Select an upload module and set it to mUpload. Dies on failure. If the
* request was a status request and not a true upload, returns false;
* otherwise true
*
* @return bool
*/
protected function selectUploadModule() {
$request = $this->getMain()->getRequest();
// chunk or one and only one of the following parameters is needed
if ( !$this->mParams['chunk'] ) {
$this->requireOnlyOneParameter( $this->mParams,
'filekey', 'file', 'url', 'statuskey' );
}
// Status report for "upload to stash"/"upload from stash"
if ( $this->mParams['filekey'] && $this->mParams['checkstatus'] ) {
$progress = UploadBase::getSessionStatus( $this->mParams['filekey'] );
if ( !$progress ) {
$this->dieUsage( 'No result in status data', 'missingresult' );
} elseif ( !$progress['status']->isGood() ) {
$this->dieUsage( $progress['status']->getWikiText(), 'stashfailed' );
}
if ( isset( $progress['status']->value['verification'] ) ) {
$this->checkVerification( $progress['status']->value['verification'] );
}
unset( $progress['status'] ); // remove Status object
$this->getResult()->addValue( null, $this->getModuleName(), $progress );
return false;
}
if ( $this->mParams['statuskey'] ) {
$this->checkAsyncDownloadEnabled();
// Status request for an async upload
$sessionData = UploadFromUrlJob::getSessionData( $this->mParams['statuskey'] );
if ( !isset( $sessionData['result'] ) ) {
$this->dieUsage( 'No result in session data', 'missingresult' );
}
if ( $sessionData['result'] == 'Warning' ) {
$sessionData['warnings'] = $this->transformWarnings( $sessionData['warnings'] );
$sessionData['sessionkey'] = $this->mParams['statuskey'];
}
$this->getResult()->addValue( null, $this->getModuleName(), $sessionData );
return false;
}
// The following modules all require the filename parameter to be set
if ( is_null( $this->mParams['filename'] ) ) {
$this->dieUsageMsg( array( 'missingparam', 'filename' ) );
}
if ( $this->mParams['chunk'] ) {
// Chunk upload
$this->mUpload = new UploadFromChunks();
if ( isset( $this->mParams['filekey'] ) ) {
// handle new chunk
$this->mUpload->continueChunks(
$this->mParams['filename'],
$this->mParams['filekey'],
$request->getUpload( 'chunk' )
);
} else {
// handle first chunk
$this->mUpload->initialize(
$this->mParams['filename'],
$request->getUpload( 'chunk' )
);
}
} elseif ( isset( $this->mParams['filekey'] ) ) {
// Upload stashed in a previous request
if ( !UploadFromStash::isValidKey( $this->mParams['filekey'] ) ) {
$this->dieUsageMsg( 'invalid-file-key' );
}
$this->mUpload = new UploadFromStash( $this->getUser() );
// This will not download the temp file in initialize() in async mode.
// We still have enough information to call checkWarnings() and such.
$this->mUpload->initialize(
$this->mParams['filekey'], $this->mParams['filename'], !$this->mParams['async']
);
} elseif ( isset( $this->mParams['file'] ) ) {
$this->mUpload = new UploadFromFile();
$this->mUpload->initialize(
$this->mParams['filename'],
$request->getUpload( 'file' )
);
} elseif ( isset( $this->mParams['url'] ) ) {
// Make sure upload by URL is enabled:
if ( !UploadFromUrl::isEnabled() ) {
$this->dieUsageMsg( 'copyuploaddisabled' );
}
if ( !UploadFromUrl::isAllowedHost( $this->mParams['url'] ) ) {
$this->dieUsageMsg( 'copyuploadbaddomain' );
}
if ( !UploadFromUrl::isAllowedUrl( $this->mParams['url'] ) ) {
$this->dieUsageMsg( 'copyuploadbadurl' );
//.........这里部分代码省略.........