Index: branches/ApiEdit_Vodafone/includes/api/ApiUploadFile.php |
— | — | @@ -0,0 +1,306 @@ |
| 2 | +<?php
|
| 3 | +
|
| 4 | +/*
|
| 5 | + * Created on Aug 29, 2007
|
| 6 | + *
|
| 7 | + * API for MediaWiki 1.8+
|
| 8 | + *
|
| 9 | + * Copyright (C) 2007 Alberto Bernal
|
| 10 | + *
|
| 11 | + * This program is free software; you can redistribute it and/or modify
|
| 12 | + * it under the terms of the GNU General Public License as published by
|
| 13 | + * the Free Software Foundation; either version 2 of the License, or
|
| 14 | + * (at your option) any later version.
|
| 15 | + *
|
| 16 | + * This program is distributed in the hope that it will be useful,
|
| 17 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 18 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 19 | + * GNU General Public License for more details.
|
| 20 | + *
|
| 21 | + * You should have received a copy of the GNU General Public License along
|
| 22 | + * with this program; if not, write to the Free Software Foundation, Inc.,
|
| 23 | + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
| 24 | + * http://www.gnu.org/copyleft/gpl.html
|
| 25 | + */
|
| 26 | +
|
| 27 | +if (!defined('MEDIAWIKI')) {
|
| 28 | + // Eclipse helper - will be ignored in production
|
| 29 | + require_once ("ApiBase.php");
|
| 30 | +}
|
| 31 | +
|
| 32 | +/**
|
| 33 | + * A module to upload given files
|
| 34 | + *
|
| 35 | + * @addtogroup API
|
| 36 | + */
|
| 37 | +class ApiUploadFile extends ApiBase {
|
| 38 | + const UPLOAD_INVALID = -1;
|
| 39 | + const UPLOAD_ENABLED_UPLOADS = -2;
|
| 40 | + const UPLOAD_NOT_LOGGED = -3;
|
| 41 | + const UPLOAD_NOT_ALLOWED = -4;
|
| 42 | + const UPLOAD_BLOCKED_PAGE = -5;
|
| 43 | + const UPLOAD_READ_ONLY = -6;
|
| 44 | + const UPLOAD_BAD_TOKEN = -7;
|
| 45 | +
|
| 46 | +
|
| 47 | + public function __construct($query, $moduleName) {
|
| 48 | + parent :: __construct($query, $moduleName, 'up');
|
| 49 | + }
|
| 50 | +
|
| 51 | + public function execute() {
|
| 52 | + global $wgRequest, $wgOut, $wgEnableUploads, $wgUser;
|
| 53 | +
|
| 54 | + if( session_id() == '' ) {
|
| 55 | + wfSetupSession();
|
| 56 | + }
|
| 57 | +
|
| 58 | + if (sizeof($_POST) > 0) {
|
| 59 | + extract($this->extractRequestParams());
|
| 60 | +
|
| 61 | + /*** VODAFONE DEBUG COMMENTS ***/
|
| 62 | + print "\nPARAMETERS POST:\n <br>";
|
| 63 | + print_r($this->extractRequestParams());
|
| 64 | + print "<br><br>";
|
| 65 | + print "\n_FILES:\n <br>";
|
| 66 | + print_r($_FILES);
|
| 67 | + print "<br><br>";
|
| 68 | + /*******************************/
|
| 69 | +
|
| 70 | + $data = array(//'wpUploadFile' => $file,
|
| 71 | + 'wpSourceType' => "file",
|
| 72 | + 'wpDestFile' => $destfile,
|
| 73 | + 'wpUploadDescription' => $summary,
|
| 74 | + 'wpWatchthis' => $watch,
|
| 75 | + 'wpIgnoreWarning' => $ignore,
|
| 76 | + 'wpLicense' => $license);
|
| 77 | + $request = new FauxRequest($data);
|
| 78 | +
|
| 79 | + $form = new UploadForm( $request );
|
| 80 | +
|
| 81 | + $form->mTempPath = $wgRequest->getFileTempName( 'upfile' );
|
| 82 | + $form->mSrcName = $wgRequest->getFileName( 'upfile' );
|
| 83 | + $form->mCurlError = $wgRequest->getUploadError( 'upfile' );
|
| 84 | + $form->mFileSize = $wgRequest->getFileSize( 'upfile' );
|
| 85 | +
|
| 86 | + # If the application client is not web mode, the user must be given.
|
| 87 | + if( $userid!="" && $usertoken!="" ){
|
| 88 | + $MyUser = new User();
|
| 89 | + $MyUser->setID( $userid );
|
| 90 | +
|
| 91 | + if( $MyUser->loadFromId() ){
|
| 92 | + print "\n<br>entro x 1 - user cargado\n<br>";
|
| 93 | +
|
| 94 | + if( $usertoken == $MyUser->mToken ){
|
| 95 | + print "\n<br>entro x 2 - tokens coinciden\n<br>";
|
| 96 | + $MyUser->setCookies();
|
| 97 | + $wgUser = $MyUser;
|
| 98 | + }else{
|
| 99 | + print "\n<br>entro x 3 - mal token\n<br>";
|
| 100 | + $this->process( self::UPLOAD_BAD_TOKEN );
|
| 101 | + return;
|
| 102 | + }
|
| 103 | + }
|
| 104 | + }
|
| 105 | +
|
| 106 | + /*** VODAFONE DEBUG COMMENTS ***/
|
| 107 | + print "\n<br>USER: <br>";
|
| 108 | + print_r($wgUser);
|
| 109 | + print "<br><br>";
|
| 110 | + print "_SESSION: <br>";
|
| 111 | + print_r($_SESSION);
|
| 112 | + print "<br><br>";
|
| 113 | + /*******************************/
|
| 114 | +
|
| 115 | + # Check uploading enabled
|
| 116 | + if( !$wgEnableUploads ) {
|
| 117 | + //$wgOut->showErrorPage( 'uploaddisabled', 'uploaddisabledtext', array( $this->mDesiredDestName ) );
|
| 118 | + $this->process( self::UPLOAD_ENABLED_UPLOADS );
|
| 119 | + return;
|
| 120 | + }
|
| 121 | +
|
| 122 | + # Check permissions
|
| 123 | + if( !$wgUser->isAllowed( 'upload' ) ) {
|
| 124 | + if( !$wgUser->isLoggedIn() ) {
|
| 125 | + //$wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' );
|
| 126 | + $this->process( self::UPLOAD_NOT_LOGGED );
|
| 127 | + } else {
|
| 128 | + //$wgOut->permissionRequired( 'upload' );
|
| 129 | + $this->process( self::UPLOAD_NOT_ALLOWED );
|
| 130 | + }
|
| 131 | + return;
|
| 132 | + }
|
| 133 | +
|
| 134 | + # Check blocks
|
| 135 | + if( $wgUser->isBlocked() ) {
|
| 136 | + //$wgOut->blockedPage();
|
| 137 | + $this->process( self::UPLOAD_BLOCKED_PAGE );
|
| 138 | + return;
|
| 139 | + }
|
| 140 | +
|
| 141 | + if( wfReadOnly() ) {
|
| 142 | + //$wgOut->readOnlyPage();
|
| 143 | + $this->process( self::UPLOAD_READ_ONLY );
|
| 144 | + return;
|
| 145 | + }
|
| 146 | +
|
| 147 | + $this->process($form->processUpload());
|
| 148 | +// $this->cleanupTempFile();
|
| 149 | +
|
| 150 | + } else {
|
| 151 | + $this->process( self::UPLOAD_INVALID );
|
| 152 | + }
|
| 153 | + }
|
| 154 | +
|
| 155 | + public function process($value) {
|
| 156 | + global $wgRequest;
|
| 157 | +
|
| 158 | + switch ($value) {
|
| 159 | + case ApiUploadFile::UPLOAD_INVALID :
|
| 160 | + $result['result'] = 'Upload_Invalid';
|
| 161 | + break;
|
| 162 | +
|
| 163 | + case ApiUploadFile::UPLOAD_ENABLED_UPLOADS :
|
| 164 | + $result['result'] = 'Upload_Enabled_Uploads';
|
| 165 | + break;
|
| 166 | +
|
| 167 | + case ApiUploadFile::UPLOAD_NOT_LOGGED :
|
| 168 | + $result['result'] = 'Upload_Not_Logged';
|
| 169 | + break;
|
| 170 | +
|
| 171 | + case ApiUploadFile::UPLOAD_NOT_ALLOWED :
|
| 172 | + $result['result'] = 'Upload_Not_Allowed';
|
| 173 | + break;
|
| 174 | +
|
| 175 | + case ApiUploadFile::UPLOAD_BLOCKED_PAGE :
|
| 176 | + $result['result'] = 'Upload_Blocked_Page';
|
| 177 | + break;
|
| 178 | +
|
| 179 | + case ApiUploadFile::UPLOAD_READ_ONLY :
|
| 180 | + $result['result'] = 'Upload_Read_Only';
|
| 181 | + break;
|
| 182 | +
|
| 183 | + case ApiUploadFile::UPLOAD_BAD_TOKEN :
|
| 184 | + $result['result'] = 'UPLOAD_BAD_TOKEN';
|
| 185 | + break;
|
| 186 | +
|
| 187 | + case UploadForm::SUCCESS :
|
| 188 | + $result['result'] = 'Success';
|
| 189 | + $result['title'] = $wgRequest->getText( 'updestfile' );
|
| 190 | + $result['ns'] = "6";
|
| 191 | + break;
|
| 192 | +
|
| 193 | + case UploadForm::BEFORE_PROCESSING:
|
| 194 | + $result['result'] = 'Upload_BeforeProcessing';
|
| 195 | + break;
|
| 196 | +
|
| 197 | + case UploadForm::LARGE_FILE_SERVER:
|
| 198 | + $result['result'] = 'Upload_LargeFileServer';
|
| 199 | + break;
|
| 200 | +
|
| 201 | + case UploadForm::EMPTY_FILE:
|
| 202 | + $result['result'] = 'Upload_EmptyFile';
|
| 203 | + break;
|
| 204 | +
|
| 205 | + case UploadForm::MIN_LENGHT_PARTNAME:
|
| 206 | + $result['result'] = 'Upload_MinLenghtPartName';
|
| 207 | + break;
|
| 208 | +
|
| 209 | + case UploadForm::ILLEGAL_FILENAME:
|
| 210 | + $result['result'] = 'Upload_IllegalFilename';
|
| 211 | + break;
|
| 212 | +
|
| 213 | + case UploadForm::PROTECTED_PAGE:
|
| 214 | + $result['result'] = 'Upload_ProtectedPage';
|
| 215 | + break;
|
| 216 | +
|
| 217 | + case UploadForm::OVERWRITE_EXISTING_FILE:
|
| 218 | + $result['result'] = 'Upload_OverwriteExistingFile';
|
| 219 | + break;
|
| 220 | +
|
| 221 | + case UploadForm::FILETYPE_MISSING:
|
| 222 | + $result['result'] = 'Upload_FiletypeMissing';
|
| 223 | + break;
|
| 224 | +
|
| 225 | + case UploadForm::FILETYPE_BADTYPE:
|
| 226 | + $result['result'] = 'Upload_FiletypeBadType';
|
| 227 | + break;
|
| 228 | +
|
| 229 | + case UploadForm::VERIFICATION_ERROR:
|
| 230 | + $result['result'] = 'Upload_VerificationError';
|
| 231 | + break;
|
| 232 | +
|
| 233 | + case UploadForm::UPLOAD_VERIFICATION_ERROR:
|
| 234 | + $result['result'] = 'Upload_UploadVerificationError';
|
| 235 | + break;
|
| 236 | +
|
| 237 | + case UploadForm::UPLOAD_WARNING:
|
| 238 | + $result['result'] = 'Upload_Warning';
|
| 239 | + break;
|
| 240 | +
|
| 241 | + default :
|
| 242 | + $result['result'] = 'Upload_Invalid';
|
| 243 | + }
|
| 244 | +
|
| 245 | + $this->getResult()->addValue(null, 'upload', $result);
|
| 246 | + }
|
| 247 | +
|
| 248 | + protected function getAllowedParams() {
|
| 249 | + return array (
|
| 250 | + 'file' => array(
|
| 251 | + ApiBase :: PARAM_TYPE => 'string'
|
| 252 | + ),
|
| 253 | + 'destfile' => array(
|
| 254 | + ApiBase :: PARAM_TYPE => 'string'
|
| 255 | + ),
|
| 256 | + 'summary' => array(
|
| 257 | + ApiBase :: PARAM_TYPE => 'string'
|
| 258 | + ),
|
| 259 | + 'watch' => array(
|
| 260 | + ApiBase :: PARAM_TYPE => 'string'
|
| 261 | + ),
|
| 262 | + 'ignore' => array(
|
| 263 | + ApiBase :: PARAM_TYPE => 'string'
|
| 264 | + ),
|
| 265 | + 'license' => array(
|
| 266 | + ApiBase :: PARAM_TYPE => 'string'
|
| 267 | + ),
|
| 268 | + 'userid' => array(
|
| 269 | + ApiBase :: PARAM_TYPE => 'string'
|
| 270 | + ),
|
| 271 | + 'usertoken' => array(
|
| 272 | + ApiBase :: PARAM_TYPE => 'string'
|
| 273 | + ),
|
| 274 | +
|
| 275 | +
|
| 276 | + );
|
| 277 | + }
|
| 278 | +
|
| 279 | + protected function getParamDescription() {
|
| 280 | + return array (
|
| 281 | + 'file' => '<file>',
|
| 282 | + 'destfile' => '<file_name.jpg>',
|
| 283 | + 'summary' => 'Description or summary',
|
| 284 | + 'watch' => 'Boolean',
|
| 285 | + 'ignore' => 'Boolean',
|
| 286 | + 'license' => 'License',
|
| 287 | + 'userid' => 'User Id',
|
| 288 | + 'usertoken' => 'User token'
|
| 289 | + );
|
| 290 | + }
|
| 291 | +
|
| 292 | + protected function getDescription() {
|
| 293 | + return 'Upload image selected to path created and insert image to database.';
|
| 294 | + }
|
| 295 | +
|
| 296 | + protected function getExamples() {
|
| 297 | + return array (
|
| 298 | + "For test Upload file selected: ",
|
| 299 | + " http://esdt32606/wikisvn/api_upload_form.php",
|
| 300 | +
|
| 301 | + );
|
| 302 | + }
|
| 303 | +
|
| 304 | + public function getVersion() {
|
| 305 | + return __CLASS__ . ': $Id: ApiUploadFile.php 23819 2007-08-29 14:45:09Z abernala $';
|
| 306 | + }
|
| 307 | +} |
\ No newline at end of file |