Whitelist the <wbr> element.
[mediawiki.git] / includes / job / jobs / PublishStashedFileJob.php
blob5a24f93c3c1caebb2d393eb31201dcf6b675de7e
1 <?php
2 /**
3 * Upload a file from the upload stash into the local file repo.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * @file
21 * @ingroup Upload
24 /**
25 * Upload a file from the upload stash into the local file repo.
27 * @ingroup Upload
29 class PublishStashedFileJob extends Job {
30 public function __construct( $title, $params, $id = 0 ) {
31 parent::__construct( 'PublishStashedFile', $title, $params, $id );
32 $this->removeDuplicates = true;
35 public function run() {
36 $scope = RequestContext::importScopedSession( $this->params['session'] );
37 $context = RequestContext::getMain();
38 try {
39 $user = $context->getUser();
40 if ( !$user->isLoggedIn() ) {
41 $this->setLastError( "Could not load the author user from session." );
42 return false;
45 if ( count( $_SESSION ) === 0 ) {
46 // Empty session probably indicates that we didn't associate
47 // with the session correctly. Note that being able to load
48 // the user does not necessarily mean the session was loaded.
49 // Most likely cause by suhosin.session.encrypt = On.
50 $this->setLastError( "Error associating with user session. Try setting suhosin.session.encrypt = Off" );
51 return false;
55 UploadBase::setSessionStatus(
56 $this->params['filekey'],
57 array( 'result' => 'Poll', 'stage' => 'publish', 'status' => Status::newGood() )
60 $upload = new UploadFromStash( $user );
61 // @todo initialize() causes a GET, ideally we could frontload the antivirus
62 // checks and anything else to the stash stage (which includes concatenation and
63 // the local file is thus already there). That way, instead of GET+PUT, there could
64 // just be a COPY operation from the stash to the public zone.
65 $upload->initialize( $this->params['filekey'], $this->params['filename'] );
67 // Check if the local file checks out (this is generally a no-op)
68 $verification = $upload->verifyUpload();
69 if ( $verification['status'] !== UploadBase::OK ) {
70 $status = Status::newFatal( 'verification-error' );
71 $status->value = array( 'verification' => $verification );
72 UploadBase::setSessionStatus(
73 $this->params['filekey'],
74 array( 'result' => 'Failure', 'stage' => 'publish', 'status' => $status )
76 $this->setLastError( "Could not verify upload." );
77 return false;
80 // Upload the stashed file to a permanent location
81 $status = $upload->performUpload(
82 $this->params['comment'],
83 $this->params['text'],
84 $this->params['watch'],
85 $user
87 if ( !$status->isGood() ) {
88 UploadBase::setSessionStatus(
89 $this->params['filekey'],
90 array( 'result' => 'Failure', 'stage' => 'publish', 'status' => $status )
92 $this->setLastError( $status->getWikiText() );
93 return false;
96 // Build the image info array while we have the local reference handy
97 $apiMain = new ApiMain(); // dummy object (XXX)
98 $imageInfo = $upload->getImageInfo( $apiMain->getResult() );
100 // Cleanup any temporary local file
101 $upload->cleanupTempFile();
103 // Cache the info so the user doesn't have to wait forever to get the final info
104 UploadBase::setSessionStatus(
105 $this->params['filekey'],
106 array(
107 'result' => 'Success',
108 'stage' => 'publish',
109 'filename' => $upload->getLocalFile()->getName(),
110 'imageinfo' => $imageInfo,
111 'status' => Status::newGood()
114 } catch ( MWException $e ) {
115 UploadBase::setSessionStatus(
116 $this->params['filekey'],
117 array(
118 'result' => 'Failure',
119 'stage' => 'publish',
120 'status' => Status::newFatal( 'api-error-publishfailed' )
123 $this->setLastError( get_class( $e ) . ": " . $e->getText() );
124 return false;
126 return true;
129 public function getDeduplicationInfo() {
130 $info = parent::getDeduplicationInfo();
131 if ( is_array( $info['params'] ) ) {
132 $info['params'] = array( 'filekey' => $info['params']['filekey'] );
134 return $info;
137 public function allowRetries() {
138 return false;