MediaWiki  1.23.14
UploadFromUrlJob.php
Go to the documentation of this file.
1 <?php
33 class UploadFromUrlJob extends Job {
34  const SESSION_KEYNAME = 'wsUploadFromUrlJobData';
35 
37  public $upload;
38 
40  protected $user;
41 
42  public function __construct( $title, $params ) {
43  parent::__construct( 'uploadFromUrl', $title, $params );
44  }
45 
46  public function run() {
47  global $wgCopyUploadAsyncTimeout;
48  # Initialize this object and the upload object
49  $this->upload = new UploadFromUrl();
50  $this->upload->initialize(
51  $this->title->getText(),
52  $this->params['url'],
53  false
54  );
55  $this->user = User::newFromName( $this->params['userName'] );
56 
57  # Fetch the file
58  $opts = array();
59  if ( $wgCopyUploadAsyncTimeout ) {
60  $opts['timeout'] = $wgCopyUploadAsyncTimeout;
61  }
62  $status = $this->upload->fetchFile( $opts );
63  if ( !$status->isOk() ) {
64  $this->leaveMessage( $status );
65 
66  return true;
67  }
68 
69  # Verify upload
70  $result = $this->upload->verifyUpload();
71  if ( $result['status'] != UploadBase::OK ) {
72  $status = $this->upload->convertVerifyErrorToStatus( $result );
73  $this->leaveMessage( $status );
74 
75  return true;
76  }
77 
78  # Check warnings
79  if ( !$this->params['ignoreWarnings'] ) {
80  $warnings = $this->upload->checkWarnings();
81  if ( $warnings ) {
82 
83  # Stash the upload
84  $key = $this->upload->stashFile();
85 
86  // @todo FIXME: This has been broken for a while.
87  // User::leaveUserMessage() does not exist.
88  if ( $this->params['leaveMessage'] ) {
89  $this->user->leaveUserMessage(
90  wfMessage( 'upload-warning-subj' )->text(),
91  wfMessage( 'upload-warning-msg',
92  $key,
93  $this->params['url'] )->text()
94  );
95  } else {
96  wfSetupSession( $this->params['sessionId'] );
97  $this->storeResultInSession( 'Warning',
98  'warnings', $warnings );
99  session_write_close();
100  }
101 
102  return true;
103  }
104  }
105 
106  # Perform the upload
107  $status = $this->upload->performUpload(
108  $this->params['comment'],
109  $this->params['pageText'],
110  $this->params['watch'],
111  $this->user
112  );
113  $this->leaveMessage( $status );
114 
115  return true;
116  }
117 
124  protected function leaveMessage( $status ) {
125  if ( $this->params['leaveMessage'] ) {
126  if ( $status->isGood() ) {
127  // @todo FIXME: user->leaveUserMessage does not exist.
128  $this->user->leaveUserMessage( wfMessage( 'upload-success-subj' )->text(),
129  wfMessage( 'upload-success-msg',
130  $this->upload->getTitle()->getText(),
131  $this->params['url']
132  )->text() );
133  } else {
134  // @todo FIXME: user->leaveUserMessage does not exist.
135  $this->user->leaveUserMessage( wfMessage( 'upload-failure-subj' )->text(),
136  wfMessage( 'upload-failure-msg',
137  $status->getWikiText(),
138  $this->params['url']
139  )->text() );
140  }
141  } else {
142  wfSetupSession( $this->params['sessionId'] );
143  if ( $status->isOk() ) {
144  $this->storeResultInSession( 'Success',
145  'filename', $this->upload->getLocalFile()->getName() );
146  } else {
147  $this->storeResultInSession( 'Failure',
148  'errors', $status->getErrorsArray() );
149  }
150  session_write_close();
151  }
152  }
153 
162  protected function storeResultInSession( $result, $dataKey, $dataValue ) {
163  $session =& self::getSessionData( $this->params['sessionKey'] );
164  $session['result'] = $result;
165  $session[$dataKey] = $dataValue;
166  }
167 
171  public function initializeSessionData() {
172  $session =& self::getSessionData( $this->params['sessionKey'] );
173  $$session['result'] = 'Queued';
174  }
175 
180  public static function &getSessionData( $key ) {
181  if ( !isset( $_SESSION[self::SESSION_KEYNAME][$key] ) ) {
182  $_SESSION[self::SESSION_KEYNAME][$key] = array();
183  }
184 
185  return $_SESSION[self::SESSION_KEYNAME][$key];
186  }
187 }
UploadFromUrlJob\initializeSessionData
initializeSessionData()
Initialize the session data.
Definition: UploadFromUrlJob.php:169
$result
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message. Please note the header message cannot receive/use parameters. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item. $reader:XMLReader object $logInfo:Array of information Return false to stop further processing of the tag 'ImportHandlePageXMLTag':When parsing a XML tag in a page. $reader:XMLReader object $pageInfo:Array of information Return false to stop further processing of the tag 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision. $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information Return false to stop further processing of the tag 'ImportHandleToplevelXMLTag':When parsing a top level XML tag. $reader:XMLReader object Return false to stop further processing of the tag 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload. $reader:XMLReader object $revisionInfo:Array of information Return false to stop further processing of the tag 'InfoAction':When building information to display on the action=info page. $context:IContextSource object & $pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect. $title:Title object for the current page $request:WebRequest $ignoreRedirect:boolean to skip redirect check $target:Title/string of redirect target $article:Article object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not. Return true without providing an interwiki to continue interwiki search. $prefix:interwiki prefix we are looking for. & $iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InternalParseBeforeSanitize':during Parser 's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings. Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InternalParseBeforeLinks':during Parser 's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InvalidateEmailComplete':Called after a user 's email has been invalidated successfully. $user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification. Callee may modify $url and $query, URL will be constructed as $url . $query & $url:URL to index.php & $query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) $article:article(object) being checked 'IsTrustedProxy':Override the result of wfIsTrustedProxy() $ip:IP being check $result:Change this value to override the result of wfIsTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from & $allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of User::isValidEmailAddr(), for instance to return false if the domain name doesn 't match your organization. $addr:The e-mail address entered by the user & $result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user & $result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we 're looking for a messages file for & $file:The messages file path, you can override this to change the location. 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces. Do not use this hook to add namespaces. Use CanonicalNamespaces for that. & $namespaces:Array of namespaces indexed by their numbers 'LanguageGetMagic':DEPRECATED, use $magicWords in a file listed in $wgExtensionMessagesFiles instead. Use this to define synonyms of magic words depending of the language $magicExtensions:associative array of magic words synonyms $lang:language code(string) 'LanguageGetSpecialPageAliases':DEPRECATED, use $specialPageAliases in a file listed in $wgExtensionMessagesFiles instead. Use to define aliases of special pages names depending of the language $specialPageAliases:associative array of magic words synonyms $lang:language code(string) 'LanguageGetTranslatedLanguageNames':Provide translated language names. & $names:array of language code=> language name $code language of the preferred translations 'LanguageLinks':Manipulate a page 's language links. This is called in various places to allow extensions to define the effective language links for a page. $title:The page 's Title. & $links:Associative array mapping language codes to prefixed links of the form "language:title". & $linkFlags:Associative array mapping prefixed links to arrays of flags. Currently unused, but planned to provide support for marking individual language links in the UI, e.g. for featured articles. 'LinkBegin':Used when generating internal and interwiki links in Linker::link(), before processing starts. Return false to skip default processing and return $ret. See documentation for Linker::link() for details on the expected meanings of parameters. $skin:the Skin object $target:the Title that the link is pointing to & $html:the contents that the< a > tag should have(raw HTML) $result
Definition: hooks.txt:1528
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
wfSetupSession
wfSetupSession( $sessionId=false)
Initialise php session.
Definition: GlobalFunctions.php:3587
text
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add text
Definition: design.txt:12
Job\$title
Title $title
Definition: Job.php:38
User\newFromName
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:389
UploadFromUrlJob\getSessionData
static & getSessionData( $key)
Definition: UploadFromUrlJob.php:178
title
to move a page</td >< td > &*You are moving the page across *A non empty talk page already exists under the new or *You uncheck the box below In those you will have to move or merge the page manually if desired</td >< td > be sure to &You are responsible for making sure that links continue to point where they are supposed to go Note that the page will &a page at the new title
Definition: All_system_messages.txt:2703
Job
Class to both describe a background job and handle jobs.
Definition: Job.php:31
UploadFromUrlJob\$user
User $user
Definition: UploadFromUrlJob.php:38
UploadFromUrl
Implements uploading from a HTTP resource.
Definition: UploadFromUrl.php:31
UploadFromUrlJob\SESSION_KEYNAME
const SESSION_KEYNAME
Definition: UploadFromUrlJob.php:34
UploadFromUrlJob\leaveMessage
leaveMessage( $status)
Leave a message on the user talk page or in the session according to $params['leaveMessage'].
Definition: UploadFromUrlJob.php:122
wfMessage
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing after in associative array form externallinks including delete and has completed for all link tables default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock() - offset Set to overwrite offset parameter in $wgRequest set to '' to unset offset - wrap String Wrap the message in html(usually something like "&lt
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
false
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:188
UploadFromUrlJob\run
run()
Run the job.
Definition: UploadFromUrlJob.php:44
user
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such and we might be restricted by PHP settings such as safe mode or open_basedir We cannot assume that the software even has read access anywhere useful Many shared hosts run all users web applications under the same user
Definition: distributors.txt:9
Job\$params
array bool $params
Array of job parameters or false if none *.
Definition: Job.php:34
UploadFromUrlJob
Job for asynchronous upload-by-url.
Definition: UploadFromUrlJob.php:33
UploadFromUrlJob\storeResultInSession
storeResultInSession( $result, $dataKey, $dataValue)
Store a result in the session data.
Definition: UploadFromUrlJob.php:160
UploadFromUrlJob\__construct
__construct( $title, $params)
Definition: UploadFromUrlJob.php:40
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:59
UploadFromUrlJob\$upload
UploadFromUrl $upload
Definition: UploadFromUrlJob.php:36