wiki.techinc.nl/includes/api/ApiUpload.php

926 lines
29 KiB
PHP
Raw Normal View History

here it is ... the upload-api, script-server, js2 (javascript phase2) branch merge 1st attempt. Here is a short overview of changes and associated default configuration variables (most everything is off by default) also see ~soon to be updated~: http://www.mediawiki.org/wiki/Media_Projects_Overview = Upload Improvements = ==Upload API == * Based on the early work of Bryan Tong and others it adds the upload option to the api. * We rewrite Special:Upload page to include use the new refactoring * Added in token checks in both the SpecialUpload.php page so avoids DOS / xss copy-by-url JavaScript based cross site POST file submissions == Copy by URL== $wgAllowCopyUploads = false; * http class rewrite includes a new http background download see: includes/HttpFunctions.php * spins off a php process that calls: maintenance/http_session_download.php * pushes updates to the session and gives the user a progress bar on http copy uploads from other server progress (using js2 upload interface) (if not using the js2 upload interface it does the request in-place but the download is limited to the php ini timeout time) == Firefogg == * Firefogg enables resumable upload by chunks * progress indicators and conditional invokation (js2 system) * and of-course client side transcoding. = Script Server = $wgEnableScriptLoader = false; * off by default if $wgEnableScriptLoader is turned on script files are grouped, gziped, cached etc. for more info see: http://www.mediawiki.org/wiki/Extension:ScriptLoader * Includes some early skin js include fixes (skin/script system still lots of love) * Includes a "javascript class autoloader" this is packaged into mwEmbed so that the mwEmbed library can work in stand alone mode (while retaining localization and script serving) (one such application is the make page for firefogg.org : http://www.firefogg.org/make/index.html ) * The file that contains the autojavascript loading classes is: js2/php/jsAutoloadLocalClasses.php * One can use this auto class loading dependency system with extensions and add-ons but I need to better document that. = js2 system / mwEmbed= $wgEnableJS2system = false * includes initial rewrite towards more jquery based javascript code * especially for the Special:Upload page. * Also the edit page include support for the "add-media-wizard" * includes dependency loader for javascript that optionally takes advantage of the script-loader * remote embedding of javascript interfaces (like embedding video, or commons media searching) * $wgDebugJavaScript = false; .. .this variable lets you always get "always fresh javascript". When used with the script-loader it does not minify the script-loader output. = mwEmbed = * Will commit a separate patch to oggHandler that conditionally outputs <video tag> to use the new javascript video player. ** mv_embed player includes: play-head, volume control, remote embedding, oggz-chop support across plugins. * add-media-wizard adds easy inserts of media to pages (with import) == jQuery== * we include a base install of jQuery, jQuery ui and some plugins. * all the javascript classes are in the scriptloader so its easy to load any set of jquery ui components that you may need using the script-server. You get a callback so you can then execute js with dependencies loaded. == other stuff == there is a bit more code in js2 that pertains to sequence editing, timed text display and basic image editing. We include a base import of pixastic-lib & pixastic-editor... will work with the pixastic developer to try and ensure upstream compatibility on our usage of the library for in-browser photo and sequence manipulation.
2009-07-14 23:52:14 +00:00
<?php
/**
*
here it is ... the upload-api, script-server, js2 (javascript phase2) branch merge 1st attempt. Here is a short overview of changes and associated default configuration variables (most everything is off by default) also see ~soon to be updated~: http://www.mediawiki.org/wiki/Media_Projects_Overview = Upload Improvements = ==Upload API == * Based on the early work of Bryan Tong and others it adds the upload option to the api. * We rewrite Special:Upload page to include use the new refactoring * Added in token checks in both the SpecialUpload.php page so avoids DOS / xss copy-by-url JavaScript based cross site POST file submissions == Copy by URL== $wgAllowCopyUploads = false; * http class rewrite includes a new http background download see: includes/HttpFunctions.php * spins off a php process that calls: maintenance/http_session_download.php * pushes updates to the session and gives the user a progress bar on http copy uploads from other server progress (using js2 upload interface) (if not using the js2 upload interface it does the request in-place but the download is limited to the php ini timeout time) == Firefogg == * Firefogg enables resumable upload by chunks * progress indicators and conditional invokation (js2 system) * and of-course client side transcoding. = Script Server = $wgEnableScriptLoader = false; * off by default if $wgEnableScriptLoader is turned on script files are grouped, gziped, cached etc. for more info see: http://www.mediawiki.org/wiki/Extension:ScriptLoader * Includes some early skin js include fixes (skin/script system still lots of love) * Includes a "javascript class autoloader" this is packaged into mwEmbed so that the mwEmbed library can work in stand alone mode (while retaining localization and script serving) (one such application is the make page for firefogg.org : http://www.firefogg.org/make/index.html ) * The file that contains the autojavascript loading classes is: js2/php/jsAutoloadLocalClasses.php * One can use this auto class loading dependency system with extensions and add-ons but I need to better document that. = js2 system / mwEmbed= $wgEnableJS2system = false * includes initial rewrite towards more jquery based javascript code * especially for the Special:Upload page. * Also the edit page include support for the "add-media-wizard" * includes dependency loader for javascript that optionally takes advantage of the script-loader * remote embedding of javascript interfaces (like embedding video, or commons media searching) * $wgDebugJavaScript = false; .. .this variable lets you always get "always fresh javascript". When used with the script-loader it does not minify the script-loader output. = mwEmbed = * Will commit a separate patch to oggHandler that conditionally outputs <video tag> to use the new javascript video player. ** mv_embed player includes: play-head, volume control, remote embedding, oggz-chop support across plugins. * add-media-wizard adds easy inserts of media to pages (with import) == jQuery== * we include a base install of jQuery, jQuery ui and some plugins. * all the javascript classes are in the scriptloader so its easy to load any set of jquery ui components that you may need using the script-server. You get a callback so you can then execute js with dependencies loaded. == other stuff == there is a bit more code in js2 that pertains to sequence editing, timed text display and basic image editing. We include a base import of pixastic-lib & pixastic-editor... will work with the pixastic developer to try and ensure upstream compatibility on our usage of the library for in-browser photo and sequence manipulation.
2009-07-14 23:52:14 +00:00
*
* Created on Aug 21, 2008
*
* Copyright © 2008 - 2010 Bryan Tong Minh <Bryan.TongMinh@Gmail.com>
here it is ... the upload-api, script-server, js2 (javascript phase2) branch merge 1st attempt. Here is a short overview of changes and associated default configuration variables (most everything is off by default) also see ~soon to be updated~: http://www.mediawiki.org/wiki/Media_Projects_Overview = Upload Improvements = ==Upload API == * Based on the early work of Bryan Tong and others it adds the upload option to the api. * We rewrite Special:Upload page to include use the new refactoring * Added in token checks in both the SpecialUpload.php page so avoids DOS / xss copy-by-url JavaScript based cross site POST file submissions == Copy by URL== $wgAllowCopyUploads = false; * http class rewrite includes a new http background download see: includes/HttpFunctions.php * spins off a php process that calls: maintenance/http_session_download.php * pushes updates to the session and gives the user a progress bar on http copy uploads from other server progress (using js2 upload interface) (if not using the js2 upload interface it does the request in-place but the download is limited to the php ini timeout time) == Firefogg == * Firefogg enables resumable upload by chunks * progress indicators and conditional invokation (js2 system) * and of-course client side transcoding. = Script Server = $wgEnableScriptLoader = false; * off by default if $wgEnableScriptLoader is turned on script files are grouped, gziped, cached etc. for more info see: http://www.mediawiki.org/wiki/Extension:ScriptLoader * Includes some early skin js include fixes (skin/script system still lots of love) * Includes a "javascript class autoloader" this is packaged into mwEmbed so that the mwEmbed library can work in stand alone mode (while retaining localization and script serving) (one such application is the make page for firefogg.org : http://www.firefogg.org/make/index.html ) * The file that contains the autojavascript loading classes is: js2/php/jsAutoloadLocalClasses.php * One can use this auto class loading dependency system with extensions and add-ons but I need to better document that. = js2 system / mwEmbed= $wgEnableJS2system = false * includes initial rewrite towards more jquery based javascript code * especially for the Special:Upload page. * Also the edit page include support for the "add-media-wizard" * includes dependency loader for javascript that optionally takes advantage of the script-loader * remote embedding of javascript interfaces (like embedding video, or commons media searching) * $wgDebugJavaScript = false; .. .this variable lets you always get "always fresh javascript". When used with the script-loader it does not minify the script-loader output. = mwEmbed = * Will commit a separate patch to oggHandler that conditionally outputs <video tag> to use the new javascript video player. ** mv_embed player includes: play-head, volume control, remote embedding, oggz-chop support across plugins. * add-media-wizard adds easy inserts of media to pages (with import) == jQuery== * we include a base install of jQuery, jQuery ui and some plugins. * all the javascript classes are in the scriptloader so its easy to load any set of jquery ui components that you may need using the script-server. You get a callback so you can then execute js with dependencies loaded. == other stuff == there is a bit more code in js2 that pertains to sequence editing, timed text display and basic image editing. We include a base import of pixastic-lib & pixastic-editor... will work with the pixastic developer to try and ensure upstream compatibility on our usage of the library for in-browser photo and sequence manipulation.
2009-07-14 23:52:14 +00:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
here it is ... the upload-api, script-server, js2 (javascript phase2) branch merge 1st attempt. Here is a short overview of changes and associated default configuration variables (most everything is off by default) also see ~soon to be updated~: http://www.mediawiki.org/wiki/Media_Projects_Overview = Upload Improvements = ==Upload API == * Based on the early work of Bryan Tong and others it adds the upload option to the api. * We rewrite Special:Upload page to include use the new refactoring * Added in token checks in both the SpecialUpload.php page so avoids DOS / xss copy-by-url JavaScript based cross site POST file submissions == Copy by URL== $wgAllowCopyUploads = false; * http class rewrite includes a new http background download see: includes/HttpFunctions.php * spins off a php process that calls: maintenance/http_session_download.php * pushes updates to the session and gives the user a progress bar on http copy uploads from other server progress (using js2 upload interface) (if not using the js2 upload interface it does the request in-place but the download is limited to the php ini timeout time) == Firefogg == * Firefogg enables resumable upload by chunks * progress indicators and conditional invokation (js2 system) * and of-course client side transcoding. = Script Server = $wgEnableScriptLoader = false; * off by default if $wgEnableScriptLoader is turned on script files are grouped, gziped, cached etc. for more info see: http://www.mediawiki.org/wiki/Extension:ScriptLoader * Includes some early skin js include fixes (skin/script system still lots of love) * Includes a "javascript class autoloader" this is packaged into mwEmbed so that the mwEmbed library can work in stand alone mode (while retaining localization and script serving) (one such application is the make page for firefogg.org : http://www.firefogg.org/make/index.html ) * The file that contains the autojavascript loading classes is: js2/php/jsAutoloadLocalClasses.php * One can use this auto class loading dependency system with extensions and add-ons but I need to better document that. = js2 system / mwEmbed= $wgEnableJS2system = false * includes initial rewrite towards more jquery based javascript code * especially for the Special:Upload page. * Also the edit page include support for the "add-media-wizard" * includes dependency loader for javascript that optionally takes advantage of the script-loader * remote embedding of javascript interfaces (like embedding video, or commons media searching) * $wgDebugJavaScript = false; .. .this variable lets you always get "always fresh javascript". When used with the script-loader it does not minify the script-loader output. = mwEmbed = * Will commit a separate patch to oggHandler that conditionally outputs <video tag> to use the new javascript video player. ** mv_embed player includes: play-head, volume control, remote embedding, oggz-chop support across plugins. * add-media-wizard adds easy inserts of media to pages (with import) == jQuery== * we include a base install of jQuery, jQuery ui and some plugins. * all the javascript classes are in the scriptloader so its easy to load any set of jquery ui components that you may need using the script-server. You get a callback so you can then execute js with dependencies loaded. == other stuff == there is a bit more code in js2 that pertains to sequence editing, timed text display and basic image editing. We include a base import of pixastic-lib & pixastic-editor... will work with the pixastic developer to try and ensure upstream compatibility on our usage of the library for in-browser photo and sequence manipulation.
2009-07-14 23:52:14 +00:00
* http://www.gnu.org/copyleft/gpl.html
*
* @file
here it is ... the upload-api, script-server, js2 (javascript phase2) branch merge 1st attempt. Here is a short overview of changes and associated default configuration variables (most everything is off by default) also see ~soon to be updated~: http://www.mediawiki.org/wiki/Media_Projects_Overview = Upload Improvements = ==Upload API == * Based on the early work of Bryan Tong and others it adds the upload option to the api. * We rewrite Special:Upload page to include use the new refactoring * Added in token checks in both the SpecialUpload.php page so avoids DOS / xss copy-by-url JavaScript based cross site POST file submissions == Copy by URL== $wgAllowCopyUploads = false; * http class rewrite includes a new http background download see: includes/HttpFunctions.php * spins off a php process that calls: maintenance/http_session_download.php * pushes updates to the session and gives the user a progress bar on http copy uploads from other server progress (using js2 upload interface) (if not using the js2 upload interface it does the request in-place but the download is limited to the php ini timeout time) == Firefogg == * Firefogg enables resumable upload by chunks * progress indicators and conditional invokation (js2 system) * and of-course client side transcoding. = Script Server = $wgEnableScriptLoader = false; * off by default if $wgEnableScriptLoader is turned on script files are grouped, gziped, cached etc. for more info see: http://www.mediawiki.org/wiki/Extension:ScriptLoader * Includes some early skin js include fixes (skin/script system still lots of love) * Includes a "javascript class autoloader" this is packaged into mwEmbed so that the mwEmbed library can work in stand alone mode (while retaining localization and script serving) (one such application is the make page for firefogg.org : http://www.firefogg.org/make/index.html ) * The file that contains the autojavascript loading classes is: js2/php/jsAutoloadLocalClasses.php * One can use this auto class loading dependency system with extensions and add-ons but I need to better document that. = js2 system / mwEmbed= $wgEnableJS2system = false * includes initial rewrite towards more jquery based javascript code * especially for the Special:Upload page. * Also the edit page include support for the "add-media-wizard" * includes dependency loader for javascript that optionally takes advantage of the script-loader * remote embedding of javascript interfaces (like embedding video, or commons media searching) * $wgDebugJavaScript = false; .. .this variable lets you always get "always fresh javascript". When used with the script-loader it does not minify the script-loader output. = mwEmbed = * Will commit a separate patch to oggHandler that conditionally outputs <video tag> to use the new javascript video player. ** mv_embed player includes: play-head, volume control, remote embedding, oggz-chop support across plugins. * add-media-wizard adds easy inserts of media to pages (with import) == jQuery== * we include a base install of jQuery, jQuery ui and some plugins. * all the javascript classes are in the scriptloader so its easy to load any set of jquery ui components that you may need using the script-server. You get a callback so you can then execute js with dependencies loaded. == other stuff == there is a bit more code in js2 that pertains to sequence editing, timed text display and basic image editing. We include a base import of pixastic-lib & pixastic-editor... will work with the pixastic developer to try and ensure upstream compatibility on our usage of the library for in-browser photo and sequence manipulation.
2009-07-14 23:52:14 +00:00
*/
/**
* @ingroup API
*/
class ApiUpload extends ApiBase {
/** @var UploadBase|UploadFromChunks */
protected $mUpload = null;
2011-02-19 00:30:18 +00:00
protected $mParams;
here it is ... the upload-api, script-server, js2 (javascript phase2) branch merge 1st attempt. Here is a short overview of changes and associated default configuration variables (most everything is off by default) also see ~soon to be updated~: http://www.mediawiki.org/wiki/Media_Projects_Overview = Upload Improvements = ==Upload API == * Based on the early work of Bryan Tong and others it adds the upload option to the api. * We rewrite Special:Upload page to include use the new refactoring * Added in token checks in both the SpecialUpload.php page so avoids DOS / xss copy-by-url JavaScript based cross site POST file submissions == Copy by URL== $wgAllowCopyUploads = false; * http class rewrite includes a new http background download see: includes/HttpFunctions.php * spins off a php process that calls: maintenance/http_session_download.php * pushes updates to the session and gives the user a progress bar on http copy uploads from other server progress (using js2 upload interface) (if not using the js2 upload interface it does the request in-place but the download is limited to the php ini timeout time) == Firefogg == * Firefogg enables resumable upload by chunks * progress indicators and conditional invokation (js2 system) * and of-course client side transcoding. = Script Server = $wgEnableScriptLoader = false; * off by default if $wgEnableScriptLoader is turned on script files are grouped, gziped, cached etc. for more info see: http://www.mediawiki.org/wiki/Extension:ScriptLoader * Includes some early skin js include fixes (skin/script system still lots of love) * Includes a "javascript class autoloader" this is packaged into mwEmbed so that the mwEmbed library can work in stand alone mode (while retaining localization and script serving) (one such application is the make page for firefogg.org : http://www.firefogg.org/make/index.html ) * The file that contains the autojavascript loading classes is: js2/php/jsAutoloadLocalClasses.php * One can use this auto class loading dependency system with extensions and add-ons but I need to better document that. = js2 system / mwEmbed= $wgEnableJS2system = false * includes initial rewrite towards more jquery based javascript code * especially for the Special:Upload page. * Also the edit page include support for the "add-media-wizard" * includes dependency loader for javascript that optionally takes advantage of the script-loader * remote embedding of javascript interfaces (like embedding video, or commons media searching) * $wgDebugJavaScript = false; .. .this variable lets you always get "always fresh javascript". When used with the script-loader it does not minify the script-loader output. = mwEmbed = * Will commit a separate patch to oggHandler that conditionally outputs <video tag> to use the new javascript video player. ** mv_embed player includes: play-head, volume control, remote embedding, oggz-chop support across plugins. * add-media-wizard adds easy inserts of media to pages (with import) == jQuery== * we include a base install of jQuery, jQuery ui and some plugins. * all the javascript classes are in the scriptloader so its easy to load any set of jquery ui components that you may need using the script-server. You get a callback so you can then execute js with dependencies loaded. == other stuff == there is a bit more code in js2 that pertains to sequence editing, timed text display and basic image editing. We include a base import of pixastic-lib & pixastic-editor... will work with the pixastic developer to try and ensure upstream compatibility on our usage of the library for in-browser photo and sequence manipulation.
2009-07-14 23:52:14 +00:00
public function execute() {
// Check whether upload is enabled
if ( !UploadBase::isEnabled() ) {
$this->dieWithError( 'uploaddisabled' );
}
$user = $this->getUser();
// Parameter handling
here it is ... the upload-api, script-server, js2 (javascript phase2) branch merge 1st attempt. Here is a short overview of changes and associated default configuration variables (most everything is off by default) also see ~soon to be updated~: http://www.mediawiki.org/wiki/Media_Projects_Overview = Upload Improvements = ==Upload API == * Based on the early work of Bryan Tong and others it adds the upload option to the api. * We rewrite Special:Upload page to include use the new refactoring * Added in token checks in both the SpecialUpload.php page so avoids DOS / xss copy-by-url JavaScript based cross site POST file submissions == Copy by URL== $wgAllowCopyUploads = false; * http class rewrite includes a new http background download see: includes/HttpFunctions.php * spins off a php process that calls: maintenance/http_session_download.php * pushes updates to the session and gives the user a progress bar on http copy uploads from other server progress (using js2 upload interface) (if not using the js2 upload interface it does the request in-place but the download is limited to the php ini timeout time) == Firefogg == * Firefogg enables resumable upload by chunks * progress indicators and conditional invokation (js2 system) * and of-course client side transcoding. = Script Server = $wgEnableScriptLoader = false; * off by default if $wgEnableScriptLoader is turned on script files are grouped, gziped, cached etc. for more info see: http://www.mediawiki.org/wiki/Extension:ScriptLoader * Includes some early skin js include fixes (skin/script system still lots of love) * Includes a "javascript class autoloader" this is packaged into mwEmbed so that the mwEmbed library can work in stand alone mode (while retaining localization and script serving) (one such application is the make page for firefogg.org : http://www.firefogg.org/make/index.html ) * The file that contains the autojavascript loading classes is: js2/php/jsAutoloadLocalClasses.php * One can use this auto class loading dependency system with extensions and add-ons but I need to better document that. = js2 system / mwEmbed= $wgEnableJS2system = false * includes initial rewrite towards more jquery based javascript code * especially for the Special:Upload page. * Also the edit page include support for the "add-media-wizard" * includes dependency loader for javascript that optionally takes advantage of the script-loader * remote embedding of javascript interfaces (like embedding video, or commons media searching) * $wgDebugJavaScript = false; .. .this variable lets you always get "always fresh javascript". When used with the script-loader it does not minify the script-loader output. = mwEmbed = * Will commit a separate patch to oggHandler that conditionally outputs <video tag> to use the new javascript video player. ** mv_embed player includes: play-head, volume control, remote embedding, oggz-chop support across plugins. * add-media-wizard adds easy inserts of media to pages (with import) == jQuery== * we include a base install of jQuery, jQuery ui and some plugins. * all the javascript classes are in the scriptloader so its easy to load any set of jquery ui components that you may need using the script-server. You get a callback so you can then execute js with dependencies loaded. == other stuff == there is a bit more code in js2 that pertains to sequence editing, timed text display and basic image editing. We include a base import of pixastic-lib & pixastic-editor... will work with the pixastic developer to try and ensure upstream compatibility on our usage of the library for in-browser photo and sequence manipulation.
2009-07-14 23:52:14 +00:00
$this->mParams = $this->extractRequestParams();
$request = $this->getMain()->getRequest();
// Check if async mode is actually supported (jobs done in cli mode)
$this->mParams['async'] = ( $this->mParams['async'] &&
$this->getConfig()->get( 'EnableAsyncUploads' ) );
here it is ... the upload-api, script-server, js2 (javascript phase2) branch merge 1st attempt. Here is a short overview of changes and associated default configuration variables (most everything is off by default) also see ~soon to be updated~: http://www.mediawiki.org/wiki/Media_Projects_Overview = Upload Improvements = ==Upload API == * Based on the early work of Bryan Tong and others it adds the upload option to the api. * We rewrite Special:Upload page to include use the new refactoring * Added in token checks in both the SpecialUpload.php page so avoids DOS / xss copy-by-url JavaScript based cross site POST file submissions == Copy by URL== $wgAllowCopyUploads = false; * http class rewrite includes a new http background download see: includes/HttpFunctions.php * spins off a php process that calls: maintenance/http_session_download.php * pushes updates to the session and gives the user a progress bar on http copy uploads from other server progress (using js2 upload interface) (if not using the js2 upload interface it does the request in-place but the download is limited to the php ini timeout time) == Firefogg == * Firefogg enables resumable upload by chunks * progress indicators and conditional invokation (js2 system) * and of-course client side transcoding. = Script Server = $wgEnableScriptLoader = false; * off by default if $wgEnableScriptLoader is turned on script files are grouped, gziped, cached etc. for more info see: http://www.mediawiki.org/wiki/Extension:ScriptLoader * Includes some early skin js include fixes (skin/script system still lots of love) * Includes a "javascript class autoloader" this is packaged into mwEmbed so that the mwEmbed library can work in stand alone mode (while retaining localization and script serving) (one such application is the make page for firefogg.org : http://www.firefogg.org/make/index.html ) * The file that contains the autojavascript loading classes is: js2/php/jsAutoloadLocalClasses.php * One can use this auto class loading dependency system with extensions and add-ons but I need to better document that. = js2 system / mwEmbed= $wgEnableJS2system = false * includes initial rewrite towards more jquery based javascript code * especially for the Special:Upload page. * Also the edit page include support for the "add-media-wizard" * includes dependency loader for javascript that optionally takes advantage of the script-loader * remote embedding of javascript interfaces (like embedding video, or commons media searching) * $wgDebugJavaScript = false; .. .this variable lets you always get "always fresh javascript". When used with the script-loader it does not minify the script-loader output. = mwEmbed = * Will commit a separate patch to oggHandler that conditionally outputs <video tag> to use the new javascript video player. ** mv_embed player includes: play-head, volume control, remote embedding, oggz-chop support across plugins. * add-media-wizard adds easy inserts of media to pages (with import) == jQuery== * we include a base install of jQuery, jQuery ui and some plugins. * all the javascript classes are in the scriptloader so its easy to load any set of jquery ui components that you may need using the script-server. You get a callback so you can then execute js with dependencies loaded. == other stuff == there is a bit more code in js2 that pertains to sequence editing, timed text display and basic image editing. We include a base import of pixastic-lib & pixastic-editor... will work with the pixastic developer to try and ensure upstream compatibility on our usage of the library for in-browser photo and sequence manipulation.
2009-07-14 23:52:14 +00:00
// Add the uploaded file to the params array
$this->mParams['file'] = $request->getFileName( 'file' );
$this->mParams['chunk'] = $request->getFileName( 'chunk' );
// Copy the session key to the file key, for backward compatibility.
if ( !$this->mParams['filekey'] && $this->mParams['sessionkey'] ) {
$this->mParams['filekey'] = $this->mParams['sessionkey'];
}
here it is ... the upload-api, script-server, js2 (javascript phase2) branch merge 1st attempt. Here is a short overview of changes and associated default configuration variables (most everything is off by default) also see ~soon to be updated~: http://www.mediawiki.org/wiki/Media_Projects_Overview = Upload Improvements = ==Upload API == * Based on the early work of Bryan Tong and others it adds the upload option to the api. * We rewrite Special:Upload page to include use the new refactoring * Added in token checks in both the SpecialUpload.php page so avoids DOS / xss copy-by-url JavaScript based cross site POST file submissions == Copy by URL== $wgAllowCopyUploads = false; * http class rewrite includes a new http background download see: includes/HttpFunctions.php * spins off a php process that calls: maintenance/http_session_download.php * pushes updates to the session and gives the user a progress bar on http copy uploads from other server progress (using js2 upload interface) (if not using the js2 upload interface it does the request in-place but the download is limited to the php ini timeout time) == Firefogg == * Firefogg enables resumable upload by chunks * progress indicators and conditional invokation (js2 system) * and of-course client side transcoding. = Script Server = $wgEnableScriptLoader = false; * off by default if $wgEnableScriptLoader is turned on script files are grouped, gziped, cached etc. for more info see: http://www.mediawiki.org/wiki/Extension:ScriptLoader * Includes some early skin js include fixes (skin/script system still lots of love) * Includes a "javascript class autoloader" this is packaged into mwEmbed so that the mwEmbed library can work in stand alone mode (while retaining localization and script serving) (one such application is the make page for firefogg.org : http://www.firefogg.org/make/index.html ) * The file that contains the autojavascript loading classes is: js2/php/jsAutoloadLocalClasses.php * One can use this auto class loading dependency system with extensions and add-ons but I need to better document that. = js2 system / mwEmbed= $wgEnableJS2system = false * includes initial rewrite towards more jquery based javascript code * especially for the Special:Upload page. * Also the edit page include support for the "add-media-wizard" * includes dependency loader for javascript that optionally takes advantage of the script-loader * remote embedding of javascript interfaces (like embedding video, or commons media searching) * $wgDebugJavaScript = false; .. .this variable lets you always get "always fresh javascript". When used with the script-loader it does not minify the script-loader output. = mwEmbed = * Will commit a separate patch to oggHandler that conditionally outputs <video tag> to use the new javascript video player. ** mv_embed player includes: play-head, volume control, remote embedding, oggz-chop support across plugins. * add-media-wizard adds easy inserts of media to pages (with import) == jQuery== * we include a base install of jQuery, jQuery ui and some plugins. * all the javascript classes are in the scriptloader so its easy to load any set of jquery ui components that you may need using the script-server. You get a callback so you can then execute js with dependencies loaded. == other stuff == there is a bit more code in js2 that pertains to sequence editing, timed text display and basic image editing. We include a base import of pixastic-lib & pixastic-editor... will work with the pixastic developer to try and ensure upstream compatibility on our usage of the library for in-browser photo and sequence manipulation.
2009-07-14 23:52:14 +00:00
// Select an upload module
try {
if ( !$this->selectUploadModule() ) {
return; // not a true upload, but a status request or similar
} elseif ( !isset( $this->mUpload ) ) {
$this->dieDebug( __METHOD__, 'No upload module set' );
}
} catch ( UploadStashException $e ) { // XXX: don't spam exception log
$this->dieStatus( $this->handleStashException( $e ) );
}
2010-08-05 07:02:09 +00:00
// First check permission to upload
$this->checkPermissions( $user );
2010-08-05 07:02:09 +00:00
// Fetch the file (usually a no-op)
/** @var $status Status */
$status = $this->mUpload->fetchFile();
if ( !$status->isGood() ) {
$this->dieStatus( $status );
}
// Check if the uploaded file is sane
if ( $this->mParams['chunk'] ) {
$maxSize = UploadBase::getMaxUploadSize();
if ( $this->mParams['filesize'] > $maxSize ) {
$this->dieWithError( 'file-too-large' );
}
if ( !$this->mUpload->getTitle() ) {
$this->dieWithError( 'illegal-filename' );
}
} elseif ( $this->mParams['async'] && $this->mParams['filekey'] ) {
// defer verification to background process
2011-08-02 11:01:01 +00:00
} else {
wfDebug( __METHOD__ . " about to verify\n" );
$this->verifyUpload();
2011-08-02 11:01:01 +00:00
}
// Check if the user has the rights to modify or overwrite the requested title
// (This check is irrelevant if stashing is already requested, since the errors
// can always be fixed by changing the title)
if ( !$this->mParams['stash'] ) {
$permErrors = $this->mUpload->verifyTitlePermissions( $user );
if ( $permErrors !== true ) {
$this->dieRecoverableError( $permErrors, 'filename' );
}
}
// Get the result based on the current upload context:
try {
$result = $this->getContextResult();
} catch ( UploadStashException $e ) { // XXX: don't spam exception log
$this->dieStatus( $this->handleStashException( $e ) );
}
$this->getResult()->addValue( null, $this->getModuleName(), $result );
// Add 'imageinfo' in a separate addValue() call. File metadata can be unreasonably large,
// so otherwise when it exceeded $wgAPIMaxResultSize, no result would be returned (T143993).
if ( $result['result'] === 'Success' ) {
$imageinfo = $this->mUpload->getImageInfo( $this->getResult() );
$this->getResult()->addValue( $this->getModuleName(), 'imageinfo', $imageinfo );
}
// Cleanup any temporary mess
$this->mUpload->cleanupTempFile();
}
/**
* Get an upload result based on upload context
2012-02-09 21:33:27 +00:00
* @return array
*/
private function getContextResult() {
$warnings = $this->getApiWarnings();
if ( $warnings && !$this->mParams['ignorewarnings'] ) {
// Get warnings formatted in result array format
return $this->getWarningsResult( $warnings );
} elseif ( $this->mParams['chunk'] ) {
// Add chunk, and get result
return $this->getChunkResult( $warnings );
} elseif ( $this->mParams['stash'] ) {
// Stash the file and get stash result
return $this->getStashResult( $warnings );
}
// Check throttle after we've handled warnings
if ( UploadBase::isThrottled( $this->getUser() )
) {
$this->dieWithError( 'apierror-ratelimited' );
}
// This is the most common case -- a normal upload with no warnings
// performUpload will return a formatted properly for the API with status
return $this->performUpload( $warnings );
}
/**
* Get Stash Result, throws an exception if the file could not be stashed.
* @param array $warnings Array of Api upload warnings
2012-02-09 21:33:27 +00:00
* @return array
*/
private function getStashResult( $warnings ) {
$result = [];
Introduce UploadStashFile hook, improve API handling of stash errors UploadBase: * Introduce a new method, tryStashFile(), as a replacement for the now-soft-deprecated stashFile(). The method runs the new hook and returns a Status object, with an error (if the hook returned an error) or a value (if it didn't). * Introduce a new hook, UploadStashFile, allowing extensions to prevent a file from being stashed. Note that code in extensions which has not been updated for MediaWiki 1.28 may still call stashFile() directly, and therefore not call this hook. For important checks (not just for UI), extension authors should use UploadVerifyFile or UploadVerifyUpload hooks. * Extract common code of tryStashFile() and stashFile() to a new protected method doStashFile(). SpecialUpload: * Use tryStashFile() when stashing a file after a warning or "recoverable error" was encountered. ApiUpload: * Refactor stashing code so that error handling only happens in one place, not four different ones. Use Status objects rather than exception throwing/catching for control flow. * Simplify the error messages slightly (error codes are unchanged). Produce better ones by always using handleStashException(). 'stashfailed' is now always at root (not nested inside 'warnings'), behaving the same as 'filekey' does on success. * Use tryStashFile() when stashing. Handle errors so as to allow custom API results passed via ApiMessage to be preserved. Some API result changes for different requests are shown below. api.php?action=upload&format=json&filename=good.png&file=...&stash=1 Before: { "error": { "code": "stashfilestorage", "info": "Could not store upload in the stash: Stashing temporary file failed: UploadStashFileException Error storing file in '/tmp/phpB32SRT': Could not create directory \"mwstore://local-backend/local-temp/3/3a\".", "*": "See http://localhost:3080/w/api.php for API usage" } } After: { "error": { "code": "stashfilestorage", "info": "Could not store upload in the stash: Error storing file in '/tmp/phpB32SRT': Could not create directory \"mwstore://local-backend/local-temp/3/3a\".", "*": "See http://localhost:3080/w/api.php for API usage" } } api.php?action=upload&format=json&filename=[bad].png&file=... Before: { "upload": { "result": "Warning", "warnings": { "badfilename": "-bad-.png", "stashfailed": "Stashing temporary file failed: UploadStashFileException Error storing file in '/tmp/phpB32SRT': Could not create directory \"mwstore://local-backend/local-temp/3/3a\"." } } } After: { "upload": { "result": "Warning", "stashfailed": "Could not store upload in the stash: Error storing file in '/tmp/phpB32SRT': Could not create directory \"mwstore://local-backend/local-temp/3/3a\"." "warnings": { "badfilename": "-bad-.png", } } } Bug: T140521 Change-Id: I2f574b355cd33b2e9fa7ff8e1793503b257cce65
2016-08-03 00:13:01 +00:00
$result['result'] = 'Success';
if ( $warnings && count( $warnings ) > 0 ) {
$result['warnings'] = $warnings;
}
// Some uploads can request they be stashed, so as not to publish them immediately.
// In this case, a failure to stash ought to be fatal
Introduce UploadStashFile hook, improve API handling of stash errors UploadBase: * Introduce a new method, tryStashFile(), as a replacement for the now-soft-deprecated stashFile(). The method runs the new hook and returns a Status object, with an error (if the hook returned an error) or a value (if it didn't). * Introduce a new hook, UploadStashFile, allowing extensions to prevent a file from being stashed. Note that code in extensions which has not been updated for MediaWiki 1.28 may still call stashFile() directly, and therefore not call this hook. For important checks (not just for UI), extension authors should use UploadVerifyFile or UploadVerifyUpload hooks. * Extract common code of tryStashFile() and stashFile() to a new protected method doStashFile(). SpecialUpload: * Use tryStashFile() when stashing a file after a warning or "recoverable error" was encountered. ApiUpload: * Refactor stashing code so that error handling only happens in one place, not four different ones. Use Status objects rather than exception throwing/catching for control flow. * Simplify the error messages slightly (error codes are unchanged). Produce better ones by always using handleStashException(). 'stashfailed' is now always at root (not nested inside 'warnings'), behaving the same as 'filekey' does on success. * Use tryStashFile() when stashing. Handle errors so as to allow custom API results passed via ApiMessage to be preserved. Some API result changes for different requests are shown below. api.php?action=upload&format=json&filename=good.png&file=...&stash=1 Before: { "error": { "code": "stashfilestorage", "info": "Could not store upload in the stash: Stashing temporary file failed: UploadStashFileException Error storing file in '/tmp/phpB32SRT': Could not create directory \"mwstore://local-backend/local-temp/3/3a\".", "*": "See http://localhost:3080/w/api.php for API usage" } } After: { "error": { "code": "stashfilestorage", "info": "Could not store upload in the stash: Error storing file in '/tmp/phpB32SRT': Could not create directory \"mwstore://local-backend/local-temp/3/3a\".", "*": "See http://localhost:3080/w/api.php for API usage" } } api.php?action=upload&format=json&filename=[bad].png&file=... Before: { "upload": { "result": "Warning", "warnings": { "badfilename": "-bad-.png", "stashfailed": "Stashing temporary file failed: UploadStashFileException Error storing file in '/tmp/phpB32SRT': Could not create directory \"mwstore://local-backend/local-temp/3/3a\"." } } } After: { "upload": { "result": "Warning", "stashfailed": "Could not store upload in the stash: Error storing file in '/tmp/phpB32SRT': Could not create directory \"mwstore://local-backend/local-temp/3/3a\"." "warnings": { "badfilename": "-bad-.png", } } } Bug: T140521 Change-Id: I2f574b355cd33b2e9fa7ff8e1793503b257cce65
2016-08-03 00:13:01 +00:00
$this->performStash( 'critical', $result );
return $result;
}
/**
* Get Warnings Result
* @param array $warnings Array of Api upload warnings
2012-02-09 21:33:27 +00:00
* @return array
*/
private function getWarningsResult( $warnings ) {
$result = [];
$result['result'] = 'Warning';
$result['warnings'] = $warnings;
// in case the warnings can be fixed with some further user action, let's stash this upload
// and return a key they can use to restart it
Introduce UploadStashFile hook, improve API handling of stash errors UploadBase: * Introduce a new method, tryStashFile(), as a replacement for the now-soft-deprecated stashFile(). The method runs the new hook and returns a Status object, with an error (if the hook returned an error) or a value (if it didn't). * Introduce a new hook, UploadStashFile, allowing extensions to prevent a file from being stashed. Note that code in extensions which has not been updated for MediaWiki 1.28 may still call stashFile() directly, and therefore not call this hook. For important checks (not just for UI), extension authors should use UploadVerifyFile or UploadVerifyUpload hooks. * Extract common code of tryStashFile() and stashFile() to a new protected method doStashFile(). SpecialUpload: * Use tryStashFile() when stashing a file after a warning or "recoverable error" was encountered. ApiUpload: * Refactor stashing code so that error handling only happens in one place, not four different ones. Use Status objects rather than exception throwing/catching for control flow. * Simplify the error messages slightly (error codes are unchanged). Produce better ones by always using handleStashException(). 'stashfailed' is now always at root (not nested inside 'warnings'), behaving the same as 'filekey' does on success. * Use tryStashFile() when stashing. Handle errors so as to allow custom API results passed via ApiMessage to be preserved. Some API result changes for different requests are shown below. api.php?action=upload&format=json&filename=good.png&file=...&stash=1 Before: { "error": { "code": "stashfilestorage", "info": "Could not store upload in the stash: Stashing temporary file failed: UploadStashFileException Error storing file in '/tmp/phpB32SRT': Could not create directory \"mwstore://local-backend/local-temp/3/3a\".", "*": "See http://localhost:3080/w/api.php for API usage" } } After: { "error": { "code": "stashfilestorage", "info": "Could not store upload in the stash: Error storing file in '/tmp/phpB32SRT': Could not create directory \"mwstore://local-backend/local-temp/3/3a\".", "*": "See http://localhost:3080/w/api.php for API usage" } } api.php?action=upload&format=json&filename=[bad].png&file=... Before: { "upload": { "result": "Warning", "warnings": { "badfilename": "-bad-.png", "stashfailed": "Stashing temporary file failed: UploadStashFileException Error storing file in '/tmp/phpB32SRT': Could not create directory \"mwstore://local-backend/local-temp/3/3a\"." } } } After: { "upload": { "result": "Warning", "stashfailed": "Could not store upload in the stash: Error storing file in '/tmp/phpB32SRT': Could not create directory \"mwstore://local-backend/local-temp/3/3a\"." "warnings": { "badfilename": "-bad-.png", } } } Bug: T140521 Change-Id: I2f574b355cd33b2e9fa7ff8e1793503b257cce65
2016-08-03 00:13:01 +00:00
$this->performStash( 'optional', $result );
return $result;
}
/**
2012-02-09 21:33:27 +00:00
* Get the result of a chunk upload.
* @param array $warnings Array of Api upload warnings
2012-02-09 21:33:27 +00:00
* @return array
*/
private function getChunkResult( $warnings ) {
$result = [];
if ( $warnings && count( $warnings ) > 0 ) {
$result['warnings'] = $warnings;
}
$request = $this->getMain()->getRequest();
$chunkPath = $request->getFileTempname( 'chunk' );
$chunkSize = $request->getUpload( 'chunk' )->getSize();
$totalSoFar = $this->mParams['offset'] + $chunkSize;
$minChunkSize = $this->getConfig()->get( 'MinUploadChunkSize' );
// Sanity check sizing
if ( $totalSoFar > $this->mParams['filesize'] ) {
$this->dieWithError( 'apierror-invalid-chunk' );
}
// Enforce minimum chunk size
if ( $totalSoFar != $this->mParams['filesize'] && $chunkSize < $minChunkSize ) {
$this->dieWithError( [ 'apierror-chunk-too-small', Message::numParam( $minChunkSize ) ] );
}
if ( $this->mParams['offset'] == 0 ) {
Introduce UploadStashFile hook, improve API handling of stash errors UploadBase: * Introduce a new method, tryStashFile(), as a replacement for the now-soft-deprecated stashFile(). The method runs the new hook and returns a Status object, with an error (if the hook returned an error) or a value (if it didn't). * Introduce a new hook, UploadStashFile, allowing extensions to prevent a file from being stashed. Note that code in extensions which has not been updated for MediaWiki 1.28 may still call stashFile() directly, and therefore not call this hook. For important checks (not just for UI), extension authors should use UploadVerifyFile or UploadVerifyUpload hooks. * Extract common code of tryStashFile() and stashFile() to a new protected method doStashFile(). SpecialUpload: * Use tryStashFile() when stashing a file after a warning or "recoverable error" was encountered. ApiUpload: * Refactor stashing code so that error handling only happens in one place, not four different ones. Use Status objects rather than exception throwing/catching for control flow. * Simplify the error messages slightly (error codes are unchanged). Produce better ones by always using handleStashException(). 'stashfailed' is now always at root (not nested inside 'warnings'), behaving the same as 'filekey' does on success. * Use tryStashFile() when stashing. Handle errors so as to allow custom API results passed via ApiMessage to be preserved. Some API result changes for different requests are shown below. api.php?action=upload&format=json&filename=good.png&file=...&stash=1 Before: { "error": { "code": "stashfilestorage", "info": "Could not store upload in the stash: Stashing temporary file failed: UploadStashFileException Error storing file in '/tmp/phpB32SRT': Could not create directory \"mwstore://local-backend/local-temp/3/3a\".", "*": "See http://localhost:3080/w/api.php for API usage" } } After: { "error": { "code": "stashfilestorage", "info": "Could not store upload in the stash: Error storing file in '/tmp/phpB32SRT': Could not create directory \"mwstore://local-backend/local-temp/3/3a\".", "*": "See http://localhost:3080/w/api.php for API usage" } } api.php?action=upload&format=json&filename=[bad].png&file=... Before: { "upload": { "result": "Warning", "warnings": { "badfilename": "-bad-.png", "stashfailed": "Stashing temporary file failed: UploadStashFileException Error storing file in '/tmp/phpB32SRT': Could not create directory \"mwstore://local-backend/local-temp/3/3a\"." } } } After: { "upload": { "result": "Warning", "stashfailed": "Could not store upload in the stash: Error storing file in '/tmp/phpB32SRT': Could not create directory \"mwstore://local-backend/local-temp/3/3a\"." "warnings": { "badfilename": "-bad-.png", } } } Bug: T140521 Change-Id: I2f574b355cd33b2e9fa7ff8e1793503b257cce65
2016-08-03 00:13:01 +00:00
$filekey = $this->performStash( 'critical' );
} else {
$filekey = $this->mParams['filekey'];
// Don't allow further uploads to an already-completed session
$progress = UploadBase::getSessionStatus( $this->getUser(), $filekey );
if ( !$progress ) {
// Probably can't get here, but check anyway just in case
$this->dieWithError( 'apierror-stashfailed-nosession', 'stashfailed' );
} elseif ( $progress['result'] !== 'Continue' || $progress['stage'] !== 'uploading' ) {
$this->dieWithError( 'apierror-stashfailed-complete', 'stashfailed' );
}
$status = $this->mUpload->addChunk(
$chunkPath, $chunkSize, $this->mParams['offset'] );
if ( !$status->isGood() ) {
$extradata = [
'offset' => $this->mUpload->getOffset(),
];
$this->dieStatusWithCode( $status, 'stashfailed', $extradata );
}
}
// Check we added the last chunk:
if ( $totalSoFar == $this->mParams['filesize'] ) {
if ( $this->mParams['async'] ) {
UploadBase::setSessionStatus(
$this->getUser(),
$filekey,
[ 'result' => 'Poll',
'stage' => 'queued', 'status' => Status::newGood() ]
);
JobQueueGroup::singleton()->push( new AssembleUploadChunksJob(
Title::makeTitle( NS_FILE, $filekey ),
[
'filename' => $this->mParams['filename'],
'filekey' => $filekey,
'session' => $this->getContext()->exportSession()
]
) );
$result['result'] = 'Poll';
$result['stage'] = 'queued';
} else {
$status = $this->mUpload->concatenateChunks();
if ( !$status->isGood() ) {
UploadBase::setSessionStatus(
$this->getUser(),
$filekey,
[ 'result' => 'Failure', 'stage' => 'assembling', 'status' => $status ]
);
$this->dieStatusWithCode( $status, 'stashfailed' );
}
// We can only get warnings like 'duplicate' after concatenating the chunks
$warnings = $this->getApiWarnings();
if ( $warnings ) {
$result['warnings'] = $warnings;
}
// The fully concatenated file has a new filekey. So remove
// the old filekey and fetch the new one.
UploadBase::setSessionStatus( $this->getUser(), $filekey, false );
$this->mUpload->stash->removeFile( $filekey );
$filekey = $this->mUpload->getStashFile()->getFileKey();
$result['result'] = 'Success';
}
} else {
UploadBase::setSessionStatus(
$this->getUser(),
$filekey,
[
'result' => 'Continue',
'stage' => 'uploading',
'offset' => $totalSoFar,
'status' => Status::newGood(),
]
);
$result['result'] = 'Continue';
$result['offset'] = $totalSoFar;
}
$result['filekey'] = $filekey;
return $result;
}
/**
Introduce UploadStashFile hook, improve API handling of stash errors UploadBase: * Introduce a new method, tryStashFile(), as a replacement for the now-soft-deprecated stashFile(). The method runs the new hook and returns a Status object, with an error (if the hook returned an error) or a value (if it didn't). * Introduce a new hook, UploadStashFile, allowing extensions to prevent a file from being stashed. Note that code in extensions which has not been updated for MediaWiki 1.28 may still call stashFile() directly, and therefore not call this hook. For important checks (not just for UI), extension authors should use UploadVerifyFile or UploadVerifyUpload hooks. * Extract common code of tryStashFile() and stashFile() to a new protected method doStashFile(). SpecialUpload: * Use tryStashFile() when stashing a file after a warning or "recoverable error" was encountered. ApiUpload: * Refactor stashing code so that error handling only happens in one place, not four different ones. Use Status objects rather than exception throwing/catching for control flow. * Simplify the error messages slightly (error codes are unchanged). Produce better ones by always using handleStashException(). 'stashfailed' is now always at root (not nested inside 'warnings'), behaving the same as 'filekey' does on success. * Use tryStashFile() when stashing. Handle errors so as to allow custom API results passed via ApiMessage to be preserved. Some API result changes for different requests are shown below. api.php?action=upload&format=json&filename=good.png&file=...&stash=1 Before: { "error": { "code": "stashfilestorage", "info": "Could not store upload in the stash: Stashing temporary file failed: UploadStashFileException Error storing file in '/tmp/phpB32SRT': Could not create directory \"mwstore://local-backend/local-temp/3/3a\".", "*": "See http://localhost:3080/w/api.php for API usage" } } After: { "error": { "code": "stashfilestorage", "info": "Could not store upload in the stash: Error storing file in '/tmp/phpB32SRT': Could not create directory \"mwstore://local-backend/local-temp/3/3a\".", "*": "See http://localhost:3080/w/api.php for API usage" } } api.php?action=upload&format=json&filename=[bad].png&file=... Before: { "upload": { "result": "Warning", "warnings": { "badfilename": "-bad-.png", "stashfailed": "Stashing temporary file failed: UploadStashFileException Error storing file in '/tmp/phpB32SRT': Could not create directory \"mwstore://local-backend/local-temp/3/3a\"." } } } After: { "upload": { "result": "Warning", "stashfailed": "Could not store upload in the stash: Error storing file in '/tmp/phpB32SRT': Could not create directory \"mwstore://local-backend/local-temp/3/3a\"." "warnings": { "badfilename": "-bad-.png", } } } Bug: T140521 Change-Id: I2f574b355cd33b2e9fa7ff8e1793503b257cce65
2016-08-03 00:13:01 +00:00
* Stash the file and add the file key, or error information if it fails, to the data.
*
* @param string $failureMode What to do on failure to stash:
* - When 'critical', use dieStatus() to produce an error response and throw an exception.
* Use this when stashing the file was the primary purpose of the API request.
* - When 'optional', only add a 'stashfailed' key to the data and return null.
* Use this when some error happened for a non-stash upload and we're stashing the file
* only to save the client the trouble of re-uploading it.
* @param array &$data API result to which to add the information
* @return string|null File key
*/
Introduce UploadStashFile hook, improve API handling of stash errors UploadBase: * Introduce a new method, tryStashFile(), as a replacement for the now-soft-deprecated stashFile(). The method runs the new hook and returns a Status object, with an error (if the hook returned an error) or a value (if it didn't). * Introduce a new hook, UploadStashFile, allowing extensions to prevent a file from being stashed. Note that code in extensions which has not been updated for MediaWiki 1.28 may still call stashFile() directly, and therefore not call this hook. For important checks (not just for UI), extension authors should use UploadVerifyFile or UploadVerifyUpload hooks. * Extract common code of tryStashFile() and stashFile() to a new protected method doStashFile(). SpecialUpload: * Use tryStashFile() when stashing a file after a warning or "recoverable error" was encountered. ApiUpload: * Refactor stashing code so that error handling only happens in one place, not four different ones. Use Status objects rather than exception throwing/catching for control flow. * Simplify the error messages slightly (error codes are unchanged). Produce better ones by always using handleStashException(). 'stashfailed' is now always at root (not nested inside 'warnings'), behaving the same as 'filekey' does on success. * Use tryStashFile() when stashing. Handle errors so as to allow custom API results passed via ApiMessage to be preserved. Some API result changes for different requests are shown below. api.php?action=upload&format=json&filename=good.png&file=...&stash=1 Before: { "error": { "code": "stashfilestorage", "info": "Could not store upload in the stash: Stashing temporary file failed: UploadStashFileException Error storing file in '/tmp/phpB32SRT': Could not create directory \"mwstore://local-backend/local-temp/3/3a\".", "*": "See http://localhost:3080/w/api.php for API usage" } } After: { "error": { "code": "stashfilestorage", "info": "Could not store upload in the stash: Error storing file in '/tmp/phpB32SRT': Could not create directory \"mwstore://local-backend/local-temp/3/3a\".", "*": "See http://localhost:3080/w/api.php for API usage" } } api.php?action=upload&format=json&filename=[bad].png&file=... Before: { "upload": { "result": "Warning", "warnings": { "badfilename": "-bad-.png", "stashfailed": "Stashing temporary file failed: UploadStashFileException Error storing file in '/tmp/phpB32SRT': Could not create directory \"mwstore://local-backend/local-temp/3/3a\"." } } } After: { "upload": { "result": "Warning", "stashfailed": "Could not store upload in the stash: Error storing file in '/tmp/phpB32SRT': Could not create directory \"mwstore://local-backend/local-temp/3/3a\"." "warnings": { "badfilename": "-bad-.png", } } } Bug: T140521 Change-Id: I2f574b355cd33b2e9fa7ff8e1793503b257cce65
2016-08-03 00:13:01 +00:00
private function performStash( $failureMode, &$data = null ) {
$isPartial = (bool)$this->mParams['chunk'];
try {
$status = $this->mUpload->tryStashFile( $this->getUser(), $isPartial );
Introduce UploadStashFile hook, improve API handling of stash errors UploadBase: * Introduce a new method, tryStashFile(), as a replacement for the now-soft-deprecated stashFile(). The method runs the new hook and returns a Status object, with an error (if the hook returned an error) or a value (if it didn't). * Introduce a new hook, UploadStashFile, allowing extensions to prevent a file from being stashed. Note that code in extensions which has not been updated for MediaWiki 1.28 may still call stashFile() directly, and therefore not call this hook. For important checks (not just for UI), extension authors should use UploadVerifyFile or UploadVerifyUpload hooks. * Extract common code of tryStashFile() and stashFile() to a new protected method doStashFile(). SpecialUpload: * Use tryStashFile() when stashing a file after a warning or "recoverable error" was encountered. ApiUpload: * Refactor stashing code so that error handling only happens in one place, not four different ones. Use Status objects rather than exception throwing/catching for control flow. * Simplify the error messages slightly (error codes are unchanged). Produce better ones by always using handleStashException(). 'stashfailed' is now always at root (not nested inside 'warnings'), behaving the same as 'filekey' does on success. * Use tryStashFile() when stashing. Handle errors so as to allow custom API results passed via ApiMessage to be preserved. Some API result changes for different requests are shown below. api.php?action=upload&format=json&filename=good.png&file=...&stash=1 Before: { "error": { "code": "stashfilestorage", "info": "Could not store upload in the stash: Stashing temporary file failed: UploadStashFileException Error storing file in '/tmp/phpB32SRT': Could not create directory \"mwstore://local-backend/local-temp/3/3a\".", "*": "See http://localhost:3080/w/api.php for API usage" } } After: { "error": { "code": "stashfilestorage", "info": "Could not store upload in the stash: Error storing file in '/tmp/phpB32SRT': Could not create directory \"mwstore://local-backend/local-temp/3/3a\".", "*": "See http://localhost:3080/w/api.php for API usage" } } api.php?action=upload&format=json&filename=[bad].png&file=... Before: { "upload": { "result": "Warning", "warnings": { "badfilename": "-bad-.png", "stashfailed": "Stashing temporary file failed: UploadStashFileException Error storing file in '/tmp/phpB32SRT': Could not create directory \"mwstore://local-backend/local-temp/3/3a\"." } } } After: { "upload": { "result": "Warning", "stashfailed": "Could not store upload in the stash: Error storing file in '/tmp/phpB32SRT': Could not create directory \"mwstore://local-backend/local-temp/3/3a\"." "warnings": { "badfilename": "-bad-.png", } } } Bug: T140521 Change-Id: I2f574b355cd33b2e9fa7ff8e1793503b257cce65
2016-08-03 00:13:01 +00:00
if ( $status->isGood() && !$status->getValue() ) {
// Not actually a 'good' status...
$status->fatal( new ApiMessage( 'apierror-stashinvalidfile', 'stashfailed' ) );
}
} catch ( Exception $e ) {
Introduce UploadStashFile hook, improve API handling of stash errors UploadBase: * Introduce a new method, tryStashFile(), as a replacement for the now-soft-deprecated stashFile(). The method runs the new hook and returns a Status object, with an error (if the hook returned an error) or a value (if it didn't). * Introduce a new hook, UploadStashFile, allowing extensions to prevent a file from being stashed. Note that code in extensions which has not been updated for MediaWiki 1.28 may still call stashFile() directly, and therefore not call this hook. For important checks (not just for UI), extension authors should use UploadVerifyFile or UploadVerifyUpload hooks. * Extract common code of tryStashFile() and stashFile() to a new protected method doStashFile(). SpecialUpload: * Use tryStashFile() when stashing a file after a warning or "recoverable error" was encountered. ApiUpload: * Refactor stashing code so that error handling only happens in one place, not four different ones. Use Status objects rather than exception throwing/catching for control flow. * Simplify the error messages slightly (error codes are unchanged). Produce better ones by always using handleStashException(). 'stashfailed' is now always at root (not nested inside 'warnings'), behaving the same as 'filekey' does on success. * Use tryStashFile() when stashing. Handle errors so as to allow custom API results passed via ApiMessage to be preserved. Some API result changes for different requests are shown below. api.php?action=upload&format=json&filename=good.png&file=...&stash=1 Before: { "error": { "code": "stashfilestorage", "info": "Could not store upload in the stash: Stashing temporary file failed: UploadStashFileException Error storing file in '/tmp/phpB32SRT': Could not create directory \"mwstore://local-backend/local-temp/3/3a\".", "*": "See http://localhost:3080/w/api.php for API usage" } } After: { "error": { "code": "stashfilestorage", "info": "Could not store upload in the stash: Error storing file in '/tmp/phpB32SRT': Could not create directory \"mwstore://local-backend/local-temp/3/3a\".", "*": "See http://localhost:3080/w/api.php for API usage" } } api.php?action=upload&format=json&filename=[bad].png&file=... Before: { "upload": { "result": "Warning", "warnings": { "badfilename": "-bad-.png", "stashfailed": "Stashing temporary file failed: UploadStashFileException Error storing file in '/tmp/phpB32SRT': Could not create directory \"mwstore://local-backend/local-temp/3/3a\"." } } } After: { "upload": { "result": "Warning", "stashfailed": "Could not store upload in the stash: Error storing file in '/tmp/phpB32SRT': Could not create directory \"mwstore://local-backend/local-temp/3/3a\"." "warnings": { "badfilename": "-bad-.png", } } } Bug: T140521 Change-Id: I2f574b355cd33b2e9fa7ff8e1793503b257cce65
2016-08-03 00:13:01 +00:00
$debugMessage = 'Stashing temporary file failed: ' . get_class( $e ) . ' ' . $e->getMessage();
wfDebug( __METHOD__ . ' ' . $debugMessage . "\n" );
$status = Status::newFatal( $this->getErrorFormatter()->getMessageFromException(
$e, [ 'wrap' => new ApiMessage( 'apierror-stashexception', 'stashfailed' ) ]
) );
Introduce UploadStashFile hook, improve API handling of stash errors UploadBase: * Introduce a new method, tryStashFile(), as a replacement for the now-soft-deprecated stashFile(). The method runs the new hook and returns a Status object, with an error (if the hook returned an error) or a value (if it didn't). * Introduce a new hook, UploadStashFile, allowing extensions to prevent a file from being stashed. Note that code in extensions which has not been updated for MediaWiki 1.28 may still call stashFile() directly, and therefore not call this hook. For important checks (not just for UI), extension authors should use UploadVerifyFile or UploadVerifyUpload hooks. * Extract common code of tryStashFile() and stashFile() to a new protected method doStashFile(). SpecialUpload: * Use tryStashFile() when stashing a file after a warning or "recoverable error" was encountered. ApiUpload: * Refactor stashing code so that error handling only happens in one place, not four different ones. Use Status objects rather than exception throwing/catching for control flow. * Simplify the error messages slightly (error codes are unchanged). Produce better ones by always using handleStashException(). 'stashfailed' is now always at root (not nested inside 'warnings'), behaving the same as 'filekey' does on success. * Use tryStashFile() when stashing. Handle errors so as to allow custom API results passed via ApiMessage to be preserved. Some API result changes for different requests are shown below. api.php?action=upload&format=json&filename=good.png&file=...&stash=1 Before: { "error": { "code": "stashfilestorage", "info": "Could not store upload in the stash: Stashing temporary file failed: UploadStashFileException Error storing file in '/tmp/phpB32SRT': Could not create directory \"mwstore://local-backend/local-temp/3/3a\".", "*": "See http://localhost:3080/w/api.php for API usage" } } After: { "error": { "code": "stashfilestorage", "info": "Could not store upload in the stash: Error storing file in '/tmp/phpB32SRT': Could not create directory \"mwstore://local-backend/local-temp/3/3a\".", "*": "See http://localhost:3080/w/api.php for API usage" } } api.php?action=upload&format=json&filename=[bad].png&file=... Before: { "upload": { "result": "Warning", "warnings": { "badfilename": "-bad-.png", "stashfailed": "Stashing temporary file failed: UploadStashFileException Error storing file in '/tmp/phpB32SRT': Could not create directory \"mwstore://local-backend/local-temp/3/3a\"." } } } After: { "upload": { "result": "Warning", "stashfailed": "Could not store upload in the stash: Error storing file in '/tmp/phpB32SRT': Could not create directory \"mwstore://local-backend/local-temp/3/3a\"." "warnings": { "badfilename": "-bad-.png", } } } Bug: T140521 Change-Id: I2f574b355cd33b2e9fa7ff8e1793503b257cce65
2016-08-03 00:13:01 +00:00
}
if ( $status->isGood() ) {
$stashFile = $status->getValue();
$data['filekey'] = $stashFile->getFileKey();
// Backwards compatibility
$data['sessionkey'] = $data['filekey'];
return $data['filekey'];
}
if ( $status->getMessage()->getKey() === 'uploadstash-exception' ) {
// The exceptions thrown by upload stash code and pretty silly and UploadBase returns poor
// Statuses for it. Just extract the exception details and parse them ourselves.
list( $exceptionType, $message ) = $status->getMessage()->getParams();
$debugMessage = 'Stashing temporary file failed: ' . $exceptionType . ' ' . $message;
wfDebug( __METHOD__ . ' ' . $debugMessage . "\n" );
}
Introduce UploadStashFile hook, improve API handling of stash errors UploadBase: * Introduce a new method, tryStashFile(), as a replacement for the now-soft-deprecated stashFile(). The method runs the new hook and returns a Status object, with an error (if the hook returned an error) or a value (if it didn't). * Introduce a new hook, UploadStashFile, allowing extensions to prevent a file from being stashed. Note that code in extensions which has not been updated for MediaWiki 1.28 may still call stashFile() directly, and therefore not call this hook. For important checks (not just for UI), extension authors should use UploadVerifyFile or UploadVerifyUpload hooks. * Extract common code of tryStashFile() and stashFile() to a new protected method doStashFile(). SpecialUpload: * Use tryStashFile() when stashing a file after a warning or "recoverable error" was encountered. ApiUpload: * Refactor stashing code so that error handling only happens in one place, not four different ones. Use Status objects rather than exception throwing/catching for control flow. * Simplify the error messages slightly (error codes are unchanged). Produce better ones by always using handleStashException(). 'stashfailed' is now always at root (not nested inside 'warnings'), behaving the same as 'filekey' does on success. * Use tryStashFile() when stashing. Handle errors so as to allow custom API results passed via ApiMessage to be preserved. Some API result changes for different requests are shown below. api.php?action=upload&format=json&filename=good.png&file=...&stash=1 Before: { "error": { "code": "stashfilestorage", "info": "Could not store upload in the stash: Stashing temporary file failed: UploadStashFileException Error storing file in '/tmp/phpB32SRT': Could not create directory \"mwstore://local-backend/local-temp/3/3a\".", "*": "See http://localhost:3080/w/api.php for API usage" } } After: { "error": { "code": "stashfilestorage", "info": "Could not store upload in the stash: Error storing file in '/tmp/phpB32SRT': Could not create directory \"mwstore://local-backend/local-temp/3/3a\".", "*": "See http://localhost:3080/w/api.php for API usage" } } api.php?action=upload&format=json&filename=[bad].png&file=... Before: { "upload": { "result": "Warning", "warnings": { "badfilename": "-bad-.png", "stashfailed": "Stashing temporary file failed: UploadStashFileException Error storing file in '/tmp/phpB32SRT': Could not create directory \"mwstore://local-backend/local-temp/3/3a\"." } } } After: { "upload": { "result": "Warning", "stashfailed": "Could not store upload in the stash: Error storing file in '/tmp/phpB32SRT': Could not create directory \"mwstore://local-backend/local-temp/3/3a\"." "warnings": { "badfilename": "-bad-.png", } } } Bug: T140521 Change-Id: I2f574b355cd33b2e9fa7ff8e1793503b257cce65
2016-08-03 00:13:01 +00:00
// Bad status
if ( $failureMode !== 'optional' ) {
$this->dieStatus( $status );
} else {
$data['stasherrors'] = $this->getErrorFormatter()->arrayFromStatus( $status );
Introduce UploadStashFile hook, improve API handling of stash errors UploadBase: * Introduce a new method, tryStashFile(), as a replacement for the now-soft-deprecated stashFile(). The method runs the new hook and returns a Status object, with an error (if the hook returned an error) or a value (if it didn't). * Introduce a new hook, UploadStashFile, allowing extensions to prevent a file from being stashed. Note that code in extensions which has not been updated for MediaWiki 1.28 may still call stashFile() directly, and therefore not call this hook. For important checks (not just for UI), extension authors should use UploadVerifyFile or UploadVerifyUpload hooks. * Extract common code of tryStashFile() and stashFile() to a new protected method doStashFile(). SpecialUpload: * Use tryStashFile() when stashing a file after a warning or "recoverable error" was encountered. ApiUpload: * Refactor stashing code so that error handling only happens in one place, not four different ones. Use Status objects rather than exception throwing/catching for control flow. * Simplify the error messages slightly (error codes are unchanged). Produce better ones by always using handleStashException(). 'stashfailed' is now always at root (not nested inside 'warnings'), behaving the same as 'filekey' does on success. * Use tryStashFile() when stashing. Handle errors so as to allow custom API results passed via ApiMessage to be preserved. Some API result changes for different requests are shown below. api.php?action=upload&format=json&filename=good.png&file=...&stash=1 Before: { "error": { "code": "stashfilestorage", "info": "Could not store upload in the stash: Stashing temporary file failed: UploadStashFileException Error storing file in '/tmp/phpB32SRT': Could not create directory \"mwstore://local-backend/local-temp/3/3a\".", "*": "See http://localhost:3080/w/api.php for API usage" } } After: { "error": { "code": "stashfilestorage", "info": "Could not store upload in the stash: Error storing file in '/tmp/phpB32SRT': Could not create directory \"mwstore://local-backend/local-temp/3/3a\".", "*": "See http://localhost:3080/w/api.php for API usage" } } api.php?action=upload&format=json&filename=[bad].png&file=... Before: { "upload": { "result": "Warning", "warnings": { "badfilename": "-bad-.png", "stashfailed": "Stashing temporary file failed: UploadStashFileException Error storing file in '/tmp/phpB32SRT': Could not create directory \"mwstore://local-backend/local-temp/3/3a\"." } } } After: { "upload": { "result": "Warning", "stashfailed": "Could not store upload in the stash: Error storing file in '/tmp/phpB32SRT': Could not create directory \"mwstore://local-backend/local-temp/3/3a\"." "warnings": { "badfilename": "-bad-.png", } } } Bug: T140521 Change-Id: I2f574b355cd33b2e9fa7ff8e1793503b257cce65
2016-08-03 00:13:01 +00:00
return null;
}
}
/**
* Throw an error that the user can recover from by providing a better
* value for $parameter
*
* @param array $errors Array of Message objects, message keys, key+param
* arrays, or StatusValue::getErrors()-style arrays
* @param string|null $parameter Parameter that needs revising
* @throws ApiUsageException
*/
private function dieRecoverableError( $errors, $parameter = null ) {
Introduce UploadStashFile hook, improve API handling of stash errors UploadBase: * Introduce a new method, tryStashFile(), as a replacement for the now-soft-deprecated stashFile(). The method runs the new hook and returns a Status object, with an error (if the hook returned an error) or a value (if it didn't). * Introduce a new hook, UploadStashFile, allowing extensions to prevent a file from being stashed. Note that code in extensions which has not been updated for MediaWiki 1.28 may still call stashFile() directly, and therefore not call this hook. For important checks (not just for UI), extension authors should use UploadVerifyFile or UploadVerifyUpload hooks. * Extract common code of tryStashFile() and stashFile() to a new protected method doStashFile(). SpecialUpload: * Use tryStashFile() when stashing a file after a warning or "recoverable error" was encountered. ApiUpload: * Refactor stashing code so that error handling only happens in one place, not four different ones. Use Status objects rather than exception throwing/catching for control flow. * Simplify the error messages slightly (error codes are unchanged). Produce better ones by always using handleStashException(). 'stashfailed' is now always at root (not nested inside 'warnings'), behaving the same as 'filekey' does on success. * Use tryStashFile() when stashing. Handle errors so as to allow custom API results passed via ApiMessage to be preserved. Some API result changes for different requests are shown below. api.php?action=upload&format=json&filename=good.png&file=...&stash=1 Before: { "error": { "code": "stashfilestorage", "info": "Could not store upload in the stash: Stashing temporary file failed: UploadStashFileException Error storing file in '/tmp/phpB32SRT': Could not create directory \"mwstore://local-backend/local-temp/3/3a\".", "*": "See http://localhost:3080/w/api.php for API usage" } } After: { "error": { "code": "stashfilestorage", "info": "Could not store upload in the stash: Error storing file in '/tmp/phpB32SRT': Could not create directory \"mwstore://local-backend/local-temp/3/3a\".", "*": "See http://localhost:3080/w/api.php for API usage" } } api.php?action=upload&format=json&filename=[bad].png&file=... Before: { "upload": { "result": "Warning", "warnings": { "badfilename": "-bad-.png", "stashfailed": "Stashing temporary file failed: UploadStashFileException Error storing file in '/tmp/phpB32SRT': Could not create directory \"mwstore://local-backend/local-temp/3/3a\"." } } } After: { "upload": { "result": "Warning", "stashfailed": "Could not store upload in the stash: Error storing file in '/tmp/phpB32SRT': Could not create directory \"mwstore://local-backend/local-temp/3/3a\"." "warnings": { "badfilename": "-bad-.png", } } } Bug: T140521 Change-Id: I2f574b355cd33b2e9fa7ff8e1793503b257cce65
2016-08-03 00:13:01 +00:00
$this->performStash( 'optional', $data );
if ( $parameter ) {
$data['invalidparameter'] = $parameter;
}
$sv = StatusValue::newGood();
foreach ( $errors as $error ) {
$msg = ApiMessage::create( $error );
$msg->setApiData( $msg->getApiData() + $data );
$sv->fatal( $msg );
}
$this->dieStatus( $sv );
}
/**
* Like dieStatus(), but always uses $overrideCode for the error code, unless the code comes from
* IApiMessage.
*
* @param Status $status
* @param string $overrideCode Error code to use if there isn't one from IApiMessage
* @param array|null $moreExtraData
* @throws ApiUsageException
*/
public function dieStatusWithCode( $status, $overrideCode, $moreExtraData = null ) {
$sv = StatusValue::newGood();
foreach ( $status->getErrors() as $error ) {
$msg = ApiMessage::create( $error, $overrideCode );
if ( $moreExtraData ) {
$msg->setApiData( $msg->getApiData() + $moreExtraData );
}
$sv->fatal( $msg );
}
$this->dieStatus( $sv );
}
/**
* 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();
2010-08-05 07:02:09 +00:00
// chunk or one and only one of the following parameters is needed
if ( !$this->mParams['chunk'] ) {
$this->requireOnlyOneParameter( $this->mParams,
'filekey', 'file', 'url' );
2011-11-10 20:50:21 +00:00
}
// 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->dieWithError( 'api-upload-missingresult', 'missingresult' );
} elseif ( !$progress['status']->isGood() ) {
$this->dieStatusWithCode( $progress['status'], 'stashfailed' );
}
if ( isset( $progress['status']->value['verification'] ) ) {
$this->checkVerification( $progress['status']->value['verification'] );
}
if ( isset( $progress['status']->value['warnings'] ) ) {
$warnings = $this->transformWarnings( $progress['status']->value['warnings'] );
if ( $warnings ) {
$progress['warnings'] = $warnings;
}
}
unset( $progress['status'] ); // remove Status object
$imageinfo = null;
if ( isset( $progress['imageinfo'] ) ) {
$imageinfo = $progress['imageinfo'];
unset( $progress['imageinfo'] );
}
$this->getResult()->addValue( null, $this->getModuleName(), $progress );
// Add 'imageinfo' in a separate addValue() call. File metadata can be unreasonably large,
// so otherwise when it exceeded $wgAPIMaxResultSize, no result would be returned (T143993).
if ( $imageinfo ) {
$this->getResult()->addValue( $this->getModuleName(), 'imageinfo', $imageinfo );
}
return false;
}
// The following modules all require the filename parameter to be set
if ( is_null( $this->mParams['filename'] ) ) {
$this->dieWithError( [ 'apierror-missingparam', 'filename' ] );
}
if ( $this->mParams['chunk'] ) {
// Chunk upload
$this->mUpload = new UploadFromChunks( $this->getUser() );
if ( isset( $this->mParams['filekey'] ) ) {
if ( $this->mParams['offset'] === 0 ) {
$this->dieWithError( 'apierror-upload-filekeynotallowed', 'filekeynotallowed' );
}
// handle new chunk
$this->mUpload->continueChunks(
$this->mParams['filename'],
$this->mParams['filekey'],
$request->getUpload( 'chunk' )
);
} else {
if ( $this->mParams['offset'] !== 0 ) {
$this->dieWithError( 'apierror-upload-filekeyneeded', 'filekeyneeded' );
}
// 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->dieWithError( 'apierror-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' )
2010-08-05 07:02:09 +00:00
);
} elseif ( isset( $this->mParams['url'] ) ) {
// Make sure upload by URL is enabled:
if ( !UploadFromUrl::isEnabled() ) {
$this->dieWithError( 'copyuploaddisabled' );
}
2010-08-05 07:02:09 +00:00
if ( !UploadFromUrl::isAllowedHost( $this->mParams['url'] ) ) {
$this->dieWithError( 'apierror-copyuploadbaddomain' );
}
if ( !UploadFromUrl::isAllowedUrl( $this->mParams['url'] ) ) {
$this->dieWithError( 'apierror-copyuploadbadurl' );
}
$this->mUpload = new UploadFromUrl;
$this->mUpload->initialize( $this->mParams['filename'],
$this->mParams['url'] );
}
return true;
}
/**
* Checks that the user has permissions to perform this upload.
* Dies with usage message on inadequate permissions.
* @param User $user The user to check.
*/
protected function checkPermissions( $user ) {
// Check whether the user has the appropriate permissions to upload anyway
$permission = $this->mUpload->isAllowed( $user );
here it is ... the upload-api, script-server, js2 (javascript phase2) branch merge 1st attempt. Here is a short overview of changes and associated default configuration variables (most everything is off by default) also see ~soon to be updated~: http://www.mediawiki.org/wiki/Media_Projects_Overview = Upload Improvements = ==Upload API == * Based on the early work of Bryan Tong and others it adds the upload option to the api. * We rewrite Special:Upload page to include use the new refactoring * Added in token checks in both the SpecialUpload.php page so avoids DOS / xss copy-by-url JavaScript based cross site POST file submissions == Copy by URL== $wgAllowCopyUploads = false; * http class rewrite includes a new http background download see: includes/HttpFunctions.php * spins off a php process that calls: maintenance/http_session_download.php * pushes updates to the session and gives the user a progress bar on http copy uploads from other server progress (using js2 upload interface) (if not using the js2 upload interface it does the request in-place but the download is limited to the php ini timeout time) == Firefogg == * Firefogg enables resumable upload by chunks * progress indicators and conditional invokation (js2 system) * and of-course client side transcoding. = Script Server = $wgEnableScriptLoader = false; * off by default if $wgEnableScriptLoader is turned on script files are grouped, gziped, cached etc. for more info see: http://www.mediawiki.org/wiki/Extension:ScriptLoader * Includes some early skin js include fixes (skin/script system still lots of love) * Includes a "javascript class autoloader" this is packaged into mwEmbed so that the mwEmbed library can work in stand alone mode (while retaining localization and script serving) (one such application is the make page for firefogg.org : http://www.firefogg.org/make/index.html ) * The file that contains the autojavascript loading classes is: js2/php/jsAutoloadLocalClasses.php * One can use this auto class loading dependency system with extensions and add-ons but I need to better document that. = js2 system / mwEmbed= $wgEnableJS2system = false * includes initial rewrite towards more jquery based javascript code * especially for the Special:Upload page. * Also the edit page include support for the "add-media-wizard" * includes dependency loader for javascript that optionally takes advantage of the script-loader * remote embedding of javascript interfaces (like embedding video, or commons media searching) * $wgDebugJavaScript = false; .. .this variable lets you always get "always fresh javascript". When used with the script-loader it does not minify the script-loader output. = mwEmbed = * Will commit a separate patch to oggHandler that conditionally outputs <video tag> to use the new javascript video player. ** mv_embed player includes: play-head, volume control, remote embedding, oggz-chop support across plugins. * add-media-wizard adds easy inserts of media to pages (with import) == jQuery== * we include a base install of jQuery, jQuery ui and some plugins. * all the javascript classes are in the scriptloader so its easy to load any set of jquery ui components that you may need using the script-server. You get a callback so you can then execute js with dependencies loaded. == other stuff == there is a bit more code in js2 that pertains to sequence editing, timed text display and basic image editing. We include a base import of pixastic-lib & pixastic-editor... will work with the pixastic developer to try and ensure upstream compatibility on our usage of the library for in-browser photo and sequence manipulation.
2009-07-14 23:52:14 +00:00
if ( $permission !== true ) {
if ( !$user->isLoggedIn() ) {
$this->dieWithError( [ 'apierror-mustbeloggedin', $this->msg( 'action-upload' ) ] );
}
$this->dieStatus( User::newFatalPermissionDeniedStatus( $permission ) );
here it is ... the upload-api, script-server, js2 (javascript phase2) branch merge 1st attempt. Here is a short overview of changes and associated default configuration variables (most everything is off by default) also see ~soon to be updated~: http://www.mediawiki.org/wiki/Media_Projects_Overview = Upload Improvements = ==Upload API == * Based on the early work of Bryan Tong and others it adds the upload option to the api. * We rewrite Special:Upload page to include use the new refactoring * Added in token checks in both the SpecialUpload.php page so avoids DOS / xss copy-by-url JavaScript based cross site POST file submissions == Copy by URL== $wgAllowCopyUploads = false; * http class rewrite includes a new http background download see: includes/HttpFunctions.php * spins off a php process that calls: maintenance/http_session_download.php * pushes updates to the session and gives the user a progress bar on http copy uploads from other server progress (using js2 upload interface) (if not using the js2 upload interface it does the request in-place but the download is limited to the php ini timeout time) == Firefogg == * Firefogg enables resumable upload by chunks * progress indicators and conditional invokation (js2 system) * and of-course client side transcoding. = Script Server = $wgEnableScriptLoader = false; * off by default if $wgEnableScriptLoader is turned on script files are grouped, gziped, cached etc. for more info see: http://www.mediawiki.org/wiki/Extension:ScriptLoader * Includes some early skin js include fixes (skin/script system still lots of love) * Includes a "javascript class autoloader" this is packaged into mwEmbed so that the mwEmbed library can work in stand alone mode (while retaining localization and script serving) (one such application is the make page for firefogg.org : http://www.firefogg.org/make/index.html ) * The file that contains the autojavascript loading classes is: js2/php/jsAutoloadLocalClasses.php * One can use this auto class loading dependency system with extensions and add-ons but I need to better document that. = js2 system / mwEmbed= $wgEnableJS2system = false * includes initial rewrite towards more jquery based javascript code * especially for the Special:Upload page. * Also the edit page include support for the "add-media-wizard" * includes dependency loader for javascript that optionally takes advantage of the script-loader * remote embedding of javascript interfaces (like embedding video, or commons media searching) * $wgDebugJavaScript = false; .. .this variable lets you always get "always fresh javascript". When used with the script-loader it does not minify the script-loader output. = mwEmbed = * Will commit a separate patch to oggHandler that conditionally outputs <video tag> to use the new javascript video player. ** mv_embed player includes: play-head, volume control, remote embedding, oggz-chop support across plugins. * add-media-wizard adds easy inserts of media to pages (with import) == jQuery== * we include a base install of jQuery, jQuery ui and some plugins. * all the javascript classes are in the scriptloader so its easy to load any set of jquery ui components that you may need using the script-server. You get a callback so you can then execute js with dependencies loaded. == other stuff == there is a bit more code in js2 that pertains to sequence editing, timed text display and basic image editing. We include a base import of pixastic-lib & pixastic-editor... will work with the pixastic developer to try and ensure upstream compatibility on our usage of the library for in-browser photo and sequence manipulation.
2009-07-14 23:52:14 +00:00
}
// Check blocks
if ( $user->isBlocked() ) {
$this->dieBlocked( $user->getBlock() );
}
// Global blocks
if ( $user->isBlockedGlobally() ) {
$this->dieBlocked( $user->getGlobalBlock() );
}
here it is ... the upload-api, script-server, js2 (javascript phase2) branch merge 1st attempt. Here is a short overview of changes and associated default configuration variables (most everything is off by default) also see ~soon to be updated~: http://www.mediawiki.org/wiki/Media_Projects_Overview = Upload Improvements = ==Upload API == * Based on the early work of Bryan Tong and others it adds the upload option to the api. * We rewrite Special:Upload page to include use the new refactoring * Added in token checks in both the SpecialUpload.php page so avoids DOS / xss copy-by-url JavaScript based cross site POST file submissions == Copy by URL== $wgAllowCopyUploads = false; * http class rewrite includes a new http background download see: includes/HttpFunctions.php * spins off a php process that calls: maintenance/http_session_download.php * pushes updates to the session and gives the user a progress bar on http copy uploads from other server progress (using js2 upload interface) (if not using the js2 upload interface it does the request in-place but the download is limited to the php ini timeout time) == Firefogg == * Firefogg enables resumable upload by chunks * progress indicators and conditional invokation (js2 system) * and of-course client side transcoding. = Script Server = $wgEnableScriptLoader = false; * off by default if $wgEnableScriptLoader is turned on script files are grouped, gziped, cached etc. for more info see: http://www.mediawiki.org/wiki/Extension:ScriptLoader * Includes some early skin js include fixes (skin/script system still lots of love) * Includes a "javascript class autoloader" this is packaged into mwEmbed so that the mwEmbed library can work in stand alone mode (while retaining localization and script serving) (one such application is the make page for firefogg.org : http://www.firefogg.org/make/index.html ) * The file that contains the autojavascript loading classes is: js2/php/jsAutoloadLocalClasses.php * One can use this auto class loading dependency system with extensions and add-ons but I need to better document that. = js2 system / mwEmbed= $wgEnableJS2system = false * includes initial rewrite towards more jquery based javascript code * especially for the Special:Upload page. * Also the edit page include support for the "add-media-wizard" * includes dependency loader for javascript that optionally takes advantage of the script-loader * remote embedding of javascript interfaces (like embedding video, or commons media searching) * $wgDebugJavaScript = false; .. .this variable lets you always get "always fresh javascript". When used with the script-loader it does not minify the script-loader output. = mwEmbed = * Will commit a separate patch to oggHandler that conditionally outputs <video tag> to use the new javascript video player. ** mv_embed player includes: play-head, volume control, remote embedding, oggz-chop support across plugins. * add-media-wizard adds easy inserts of media to pages (with import) == jQuery== * we include a base install of jQuery, jQuery ui and some plugins. * all the javascript classes are in the scriptloader so its easy to load any set of jquery ui components that you may need using the script-server. You get a callback so you can then execute js with dependencies loaded. == other stuff == there is a bit more code in js2 that pertains to sequence editing, timed text display and basic image editing. We include a base import of pixastic-lib & pixastic-editor... will work with the pixastic developer to try and ensure upstream compatibility on our usage of the library for in-browser photo and sequence manipulation.
2009-07-14 23:52:14 +00:00
}
/**
* Performs file verification, dies on error.
*/
protected function verifyUpload() {
$verification = $this->mUpload->verifyUpload();
if ( $verification['status'] === UploadBase::OK ) {
2010-08-05 07:02:09 +00:00
return;
here it is ... the upload-api, script-server, js2 (javascript phase2) branch merge 1st attempt. Here is a short overview of changes and associated default configuration variables (most everything is off by default) also see ~soon to be updated~: http://www.mediawiki.org/wiki/Media_Projects_Overview = Upload Improvements = ==Upload API == * Based on the early work of Bryan Tong and others it adds the upload option to the api. * We rewrite Special:Upload page to include use the new refactoring * Added in token checks in both the SpecialUpload.php page so avoids DOS / xss copy-by-url JavaScript based cross site POST file submissions == Copy by URL== $wgAllowCopyUploads = false; * http class rewrite includes a new http background download see: includes/HttpFunctions.php * spins off a php process that calls: maintenance/http_session_download.php * pushes updates to the session and gives the user a progress bar on http copy uploads from other server progress (using js2 upload interface) (if not using the js2 upload interface it does the request in-place but the download is limited to the php ini timeout time) == Firefogg == * Firefogg enables resumable upload by chunks * progress indicators and conditional invokation (js2 system) * and of-course client side transcoding. = Script Server = $wgEnableScriptLoader = false; * off by default if $wgEnableScriptLoader is turned on script files are grouped, gziped, cached etc. for more info see: http://www.mediawiki.org/wiki/Extension:ScriptLoader * Includes some early skin js include fixes (skin/script system still lots of love) * Includes a "javascript class autoloader" this is packaged into mwEmbed so that the mwEmbed library can work in stand alone mode (while retaining localization and script serving) (one such application is the make page for firefogg.org : http://www.firefogg.org/make/index.html ) * The file that contains the autojavascript loading classes is: js2/php/jsAutoloadLocalClasses.php * One can use this auto class loading dependency system with extensions and add-ons but I need to better document that. = js2 system / mwEmbed= $wgEnableJS2system = false * includes initial rewrite towards more jquery based javascript code * especially for the Special:Upload page. * Also the edit page include support for the "add-media-wizard" * includes dependency loader for javascript that optionally takes advantage of the script-loader * remote embedding of javascript interfaces (like embedding video, or commons media searching) * $wgDebugJavaScript = false; .. .this variable lets you always get "always fresh javascript". When used with the script-loader it does not minify the script-loader output. = mwEmbed = * Will commit a separate patch to oggHandler that conditionally outputs <video tag> to use the new javascript video player. ** mv_embed player includes: play-head, volume control, remote embedding, oggz-chop support across plugins. * add-media-wizard adds easy inserts of media to pages (with import) == jQuery== * we include a base install of jQuery, jQuery ui and some plugins. * all the javascript classes are in the scriptloader so its easy to load any set of jquery ui components that you may need using the script-server. You get a callback so you can then execute js with dependencies loaded. == other stuff == there is a bit more code in js2 that pertains to sequence editing, timed text display and basic image editing. We include a base import of pixastic-lib & pixastic-editor... will work with the pixastic developer to try and ensure upstream compatibility on our usage of the library for in-browser photo and sequence manipulation.
2009-07-14 23:52:14 +00:00
}
$this->checkVerification( $verification );
}
/**
* Performs file verification, dies on error.
* @param array $verification
*/
protected function checkVerification( array $verification ) {
switch ( $verification['status'] ) {
// Recoverable errors
case UploadBase::MIN_LENGTH_PARTNAME:
$this->dieRecoverableError( [ 'filename-tooshort' ], 'filename' );
break;
case UploadBase::ILLEGAL_FILENAME:
$this->dieRecoverableError(
[ ApiMessage::create(
'illegal-filename', null, [ 'filename' => $verification['filtered'] ]
) ], 'filename'
);
break;
case UploadBase::FILENAME_TOO_LONG:
$this->dieRecoverableError( [ 'filename-toolong' ], 'filename' );
break;
case UploadBase::FILETYPE_MISSING:
$this->dieRecoverableError( [ 'filetype-missing' ], 'filename' );
break;
case UploadBase::WINDOWS_NONASCII_FILENAME:
$this->dieRecoverableError( [ 'windows-nonascii-filename' ], 'filename' );
break;
// Unrecoverable errors
case UploadBase::EMPTY_FILE:
$this->dieWithError( 'empty-file' );
break;
case UploadBase::FILE_TOO_LARGE:
$this->dieWithError( 'file-too-large' );
break;
case UploadBase::FILETYPE_BADTYPE:
$extradata = [
'filetype' => $verification['finalExt'],
'allowed' => array_values( array_unique( $this->getConfig()->get( 'FileExtensions' ) ) )
];
$extensions = array_unique( $this->getConfig()->get( 'FileExtensions' ) );
$msg = [
'filetype-banned-type',
null, // filled in below
Message::listParam( $extensions, 'comma' ),
count( $extensions ),
null, // filled in below
];
API: Overhaul ApiResult, make format=xml not throw, and add json formatversion ApiResult was a mess: some methods could only be used with an array reference instead of manipulating the stored data, methods that had both array-ref and internal-data versions had names that didn't at all correspond, some methods that worked on an array reference were annoyingly non-static, and then the whole mess with setIndexedTagName. ApiFormatXml is also entirely annoying to deal with, as it liked to throw exceptions if certain metadata wasn't provided that no other formatter required. Its legacy also means we have this silly convention of using empty-string rather than boolean true, annoying restrictions on keys (leading to things that should be hashes being arrays of key-value object instead), '*' used as a key all over the place, and so on. So, changes here: * ApiResult is no longer an ApiBase or a ContextSource. * Wherever sensible, ApiResult provides a static method working on an arrayref and a non-static method working on internal data. * Metadata is now always added to ApiResult's internal data structure. Formatters are responsible for stripping it if necessary. "raw mode" is deprecated. * New metadata to replace the '*' key, solve the array() => '[]' vs '{}' question, and so on. * New class for formatting warnings and errors using i18n messages, and support for multiple errors and a more machine-readable format for warnings. For the moment, though, the actual output will not be changing yet (see T47843 for future plans). * New formatversion parameter for format=json and format=php, to select between BC mode and the modern output. * In BC mode, booleans will be converted to empty-string presence style; modules currently returning booleans will need to use ApiResult::META_BC_BOOLS to preserve their current output. Actual changes to the API modules' output (e.g. actually returning booleans for the new formatversion) beyond the use of ApiResult::setContentValue() are left for a future change. Bug: T76728 Bug: T57371 Bug: T33629 Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2014-12-03 22:14:22 +00:00
ApiResult::setIndexedTagName( $extradata['allowed'], 'ext' );
if ( isset( $verification['blacklistedExt'] ) ) {
$msg[1] = Message::listParam( $verification['blacklistedExt'], 'comma' );
$msg[4] = count( $verification['blacklistedExt'] );
$extradata['blacklisted'] = array_values( $verification['blacklistedExt'] );
API: Overhaul ApiResult, make format=xml not throw, and add json formatversion ApiResult was a mess: some methods could only be used with an array reference instead of manipulating the stored data, methods that had both array-ref and internal-data versions had names that didn't at all correspond, some methods that worked on an array reference were annoyingly non-static, and then the whole mess with setIndexedTagName. ApiFormatXml is also entirely annoying to deal with, as it liked to throw exceptions if certain metadata wasn't provided that no other formatter required. Its legacy also means we have this silly convention of using empty-string rather than boolean true, annoying restrictions on keys (leading to things that should be hashes being arrays of key-value object instead), '*' used as a key all over the place, and so on. So, changes here: * ApiResult is no longer an ApiBase or a ContextSource. * Wherever sensible, ApiResult provides a static method working on an arrayref and a non-static method working on internal data. * Metadata is now always added to ApiResult's internal data structure. Formatters are responsible for stripping it if necessary. "raw mode" is deprecated. * New metadata to replace the '*' key, solve the array() => '[]' vs '{}' question, and so on. * New class for formatting warnings and errors using i18n messages, and support for multiple errors and a more machine-readable format for warnings. For the moment, though, the actual output will not be changing yet (see T47843 for future plans). * New formatversion parameter for format=json and format=php, to select between BC mode and the modern output. * In BC mode, booleans will be converted to empty-string presence style; modules currently returning booleans will need to use ApiResult::META_BC_BOOLS to preserve their current output. Actual changes to the API modules' output (e.g. actually returning booleans for the new formatversion) beyond the use of ApiResult::setContentValue() are left for a future change. Bug: T76728 Bug: T57371 Bug: T33629 Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2014-12-03 22:14:22 +00:00
ApiResult::setIndexedTagName( $extradata['blacklisted'], 'ext' );
} else {
$msg[1] = $verification['finalExt'];
$msg[4] = 1;
}
$this->dieWithError( $msg, 'filetype-banned', $extradata );
break;
case UploadBase::VERIFICATION_ERROR:
$msg = ApiMessage::create( $verification['details'], 'verification-error' );
if ( $verification['details'][0] instanceof MessageSpecifier ) {
$details = array_merge( [ $msg->getKey() ], $msg->getParams() );
} else {
$details = $verification['details'];
}
ApiResult::setIndexedTagName( $details, 'detail' );
$msg->setApiData( $msg->getApiData() + [ 'details' => $details ] );
$this->dieWithError( $msg );
break;
case UploadBase::HOOK_ABORTED:
$this->dieWithError( $params, 'hookaborted', [ 'details' => $verification['error'] ] );
break;
default:
$this->dieWithError( 'apierror-unknownerror-nocode', 'unknown-error',
[ 'details' => [ 'code' => $verification['status'] ] ] );
break;
here it is ... the upload-api, script-server, js2 (javascript phase2) branch merge 1st attempt. Here is a short overview of changes and associated default configuration variables (most everything is off by default) also see ~soon to be updated~: http://www.mediawiki.org/wiki/Media_Projects_Overview = Upload Improvements = ==Upload API == * Based on the early work of Bryan Tong and others it adds the upload option to the api. * We rewrite Special:Upload page to include use the new refactoring * Added in token checks in both the SpecialUpload.php page so avoids DOS / xss copy-by-url JavaScript based cross site POST file submissions == Copy by URL== $wgAllowCopyUploads = false; * http class rewrite includes a new http background download see: includes/HttpFunctions.php * spins off a php process that calls: maintenance/http_session_download.php * pushes updates to the session and gives the user a progress bar on http copy uploads from other server progress (using js2 upload interface) (if not using the js2 upload interface it does the request in-place but the download is limited to the php ini timeout time) == Firefogg == * Firefogg enables resumable upload by chunks * progress indicators and conditional invokation (js2 system) * and of-course client side transcoding. = Script Server = $wgEnableScriptLoader = false; * off by default if $wgEnableScriptLoader is turned on script files are grouped, gziped, cached etc. for more info see: http://www.mediawiki.org/wiki/Extension:ScriptLoader * Includes some early skin js include fixes (skin/script system still lots of love) * Includes a "javascript class autoloader" this is packaged into mwEmbed so that the mwEmbed library can work in stand alone mode (while retaining localization and script serving) (one such application is the make page for firefogg.org : http://www.firefogg.org/make/index.html ) * The file that contains the autojavascript loading classes is: js2/php/jsAutoloadLocalClasses.php * One can use this auto class loading dependency system with extensions and add-ons but I need to better document that. = js2 system / mwEmbed= $wgEnableJS2system = false * includes initial rewrite towards more jquery based javascript code * especially for the Special:Upload page. * Also the edit page include support for the "add-media-wizard" * includes dependency loader for javascript that optionally takes advantage of the script-loader * remote embedding of javascript interfaces (like embedding video, or commons media searching) * $wgDebugJavaScript = false; .. .this variable lets you always get "always fresh javascript". When used with the script-loader it does not minify the script-loader output. = mwEmbed = * Will commit a separate patch to oggHandler that conditionally outputs <video tag> to use the new javascript video player. ** mv_embed player includes: play-head, volume control, remote embedding, oggz-chop support across plugins. * add-media-wizard adds easy inserts of media to pages (with import) == jQuery== * we include a base install of jQuery, jQuery ui and some plugins. * all the javascript classes are in the scriptloader so its easy to load any set of jquery ui components that you may need using the script-server. You get a callback so you can then execute js with dependencies loaded. == other stuff == there is a bit more code in js2 that pertains to sequence editing, timed text display and basic image editing. We include a base import of pixastic-lib & pixastic-editor... will work with the pixastic developer to try and ensure upstream compatibility on our usage of the library for in-browser photo and sequence manipulation.
2009-07-14 23:52:14 +00:00
}
}
/**
* Check warnings.
* Returns a suitable array for inclusion into API results if there were warnings
* Returns the empty array if there were no warnings
*
* @return array
*/
protected function getApiWarnings() {
$warnings = $this->mUpload->checkWarnings();
return $this->transformWarnings( $warnings );
}
protected function transformWarnings( $warnings ) {
if ( $warnings ) {
// Add indices
API: Overhaul ApiResult, make format=xml not throw, and add json formatversion ApiResult was a mess: some methods could only be used with an array reference instead of manipulating the stored data, methods that had both array-ref and internal-data versions had names that didn't at all correspond, some methods that worked on an array reference were annoyingly non-static, and then the whole mess with setIndexedTagName. ApiFormatXml is also entirely annoying to deal with, as it liked to throw exceptions if certain metadata wasn't provided that no other formatter required. Its legacy also means we have this silly convention of using empty-string rather than boolean true, annoying restrictions on keys (leading to things that should be hashes being arrays of key-value object instead), '*' used as a key all over the place, and so on. So, changes here: * ApiResult is no longer an ApiBase or a ContextSource. * Wherever sensible, ApiResult provides a static method working on an arrayref and a non-static method working on internal data. * Metadata is now always added to ApiResult's internal data structure. Formatters are responsible for stripping it if necessary. "raw mode" is deprecated. * New metadata to replace the '*' key, solve the array() => '[]' vs '{}' question, and so on. * New class for formatting warnings and errors using i18n messages, and support for multiple errors and a more machine-readable format for warnings. For the moment, though, the actual output will not be changing yet (see T47843 for future plans). * New formatversion parameter for format=json and format=php, to select between BC mode and the modern output. * In BC mode, booleans will be converted to empty-string presence style; modules currently returning booleans will need to use ApiResult::META_BC_BOOLS to preserve their current output. Actual changes to the API modules' output (e.g. actually returning booleans for the new formatversion) beyond the use of ApiResult::setContentValue() are left for a future change. Bug: T76728 Bug: T57371 Bug: T33629 Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2014-12-03 22:14:22 +00:00
ApiResult::setIndexedTagName( $warnings, 'warning' );
if ( isset( $warnings['duplicate'] ) ) {
$dupes = [];
/** @var File $dupe */
foreach ( $warnings['duplicate'] as $dupe ) {
$dupes[] = $dupe->getName();
}
API: Overhaul ApiResult, make format=xml not throw, and add json formatversion ApiResult was a mess: some methods could only be used with an array reference instead of manipulating the stored data, methods that had both array-ref and internal-data versions had names that didn't at all correspond, some methods that worked on an array reference were annoyingly non-static, and then the whole mess with setIndexedTagName. ApiFormatXml is also entirely annoying to deal with, as it liked to throw exceptions if certain metadata wasn't provided that no other formatter required. Its legacy also means we have this silly convention of using empty-string rather than boolean true, annoying restrictions on keys (leading to things that should be hashes being arrays of key-value object instead), '*' used as a key all over the place, and so on. So, changes here: * ApiResult is no longer an ApiBase or a ContextSource. * Wherever sensible, ApiResult provides a static method working on an arrayref and a non-static method working on internal data. * Metadata is now always added to ApiResult's internal data structure. Formatters are responsible for stripping it if necessary. "raw mode" is deprecated. * New metadata to replace the '*' key, solve the array() => '[]' vs '{}' question, and so on. * New class for formatting warnings and errors using i18n messages, and support for multiple errors and a more machine-readable format for warnings. For the moment, though, the actual output will not be changing yet (see T47843 for future plans). * New formatversion parameter for format=json and format=php, to select between BC mode and the modern output. * In BC mode, booleans will be converted to empty-string presence style; modules currently returning booleans will need to use ApiResult::META_BC_BOOLS to preserve their current output. Actual changes to the API modules' output (e.g. actually returning booleans for the new formatversion) beyond the use of ApiResult::setContentValue() are left for a future change. Bug: T76728 Bug: T57371 Bug: T33629 Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2014-12-03 22:14:22 +00:00
ApiResult::setIndexedTagName( $dupes, 'duplicate' );
$warnings['duplicate'] = $dupes;
}
if ( isset( $warnings['exists'] ) ) {
$warning = $warnings['exists'];
unset( $warnings['exists'] );
/** @var LocalFile $localFile */
$localFile = isset( $warning['normalizedFile'] )
? $warning['normalizedFile']
: $warning['file'];
$warnings[$warning['warning']] = $localFile->getName();
}
if ( isset( $warnings['no-change'] ) ) {
/** @var File $file */
$file = $warnings['no-change'];
unset( $warnings['no-change'] );
$warnings['nochange'] = [
'timestamp' => wfTimestamp( TS_ISO_8601, $file->getTimestamp() )
];
}
if ( isset( $warnings['duplicate-version'] ) ) {
$dupes = [];
/** @var File $dupe */
foreach ( $warnings['duplicate-version'] as $dupe ) {
$dupes[] = [
'timestamp' => wfTimestamp( TS_ISO_8601, $dupe->getTimestamp() )
];
}
unset( $warnings['duplicate-version'] );
ApiResult::setIndexedTagName( $dupes, 'ver' );
$warnings['duplicateversions'] = $dupes;
}
}
return $warnings;
}
/**
* Handles a stash exception, giving a useful error to the user.
* @todo Internationalize the exceptions then get rid of this
* @param Exception $e
* @return StatusValue
*/
protected function handleStashException( $e ) {
switch ( get_class( $exception ) ) {
case 'UploadStashFileNotFoundException':
$wrap = 'apierror-stashedfilenotfound';
break;
case 'UploadStashBadPathException':
$wrap = 'apierror-stashpathinvalid';
break;
case 'UploadStashFileException':
$wrap = 'apierror-stashfilestorage';
break;
case 'UploadStashZeroLengthFileException':
$wrap = 'apierror-stashzerolength';
break;
case 'UploadStashNotLoggedInException':
return StatusValue::newFatal( ApiMessage::create(
[ 'apierror-mustbeloggedin', $this->msg( 'action-upload' ) ], 'stashnotloggedin'
) );
case 'UploadStashWrongOwnerException':
$wrap = 'apierror-stashwrongowner';
break;
case 'UploadStashNoSuchKeyException':
$wrap = 'apierror-stashnosuchfilekey';
break;
default:
$wrap = [ 'uploadstash-exception', get_class( $e ) ];
break;
}
return StatusValue::newFatal(
$this->getErrorFormatter()->getMessageFromException( $e, [ 'wrap' => $wrap ] )
);
}
/**
* Perform the actual upload. Returns a suitable result array on success;
* dies on failure.
2011-09-21 16:36:43 +00:00
*
* @param array $warnings Array of Api upload warnings
2011-09-21 16:36:43 +00:00
* @return array
*/
protected function performUpload( $warnings ) {
// Use comment as initial page text by default
if ( is_null( $this->mParams['text'] ) ) {
$this->mParams['text'] = $this->mParams['comment'];
}
/** @var $file LocalFile */
$file = $this->mUpload->getLocalFile();
// For preferences mode, we want to watch if 'watchdefault' is set,
// or if the *file* doesn't exist, and either 'watchuploads' or
// 'watchcreations' is set. But getWatchlistValue()'s automatic
// handling checks if the *title* exists or not, so we need to check
// all three preferences manually.
$watch = $this->getWatchlistValue(
$this->mParams['watchlist'], $file->getTitle(), 'watchdefault'
);
if ( !$watch && $this->mParams['watchlist'] == 'preferences' && !$file->exists() ) {
$watch = (
$this->getWatchlistValue( 'preferences', $file->getTitle(), 'watchuploads' ) ||
$this->getWatchlistValue( 'preferences', $file->getTitle(), 'watchcreations' )
);
}
// Deprecated parameters
if ( $this->mParams['watch'] ) {
$watch = true;
}
if ( $this->mParams['tags'] ) {
$status = ChangeTags::canAddTagsAccompanyingChange( $this->mParams['tags'], $this->getUser() );
if ( !$status->isOK() ) {
$this->dieStatus( $status );
}
}
// No errors, no warnings: do the upload
if ( $this->mParams['async'] ) {
$progress = UploadBase::getSessionStatus( $this->getUser(), $this->mParams['filekey'] );
if ( $progress && $progress['result'] === 'Poll' ) {
$this->dieWithError( 'apierror-upload-inprogress', 'publishfailed' );
}
UploadBase::setSessionStatus(
$this->getUser(),
$this->mParams['filekey'],
[ 'result' => 'Poll', 'stage' => 'queued', 'status' => Status::newGood() ]
);
JobQueueGroup::singleton()->push( new PublishStashedFileJob(
Title::makeTitle( NS_FILE, $this->mParams['filename'] ),
[
'filename' => $this->mParams['filename'],
'filekey' => $this->mParams['filekey'],
'comment' => $this->mParams['comment'],
'tags' => $this->mParams['tags'],
'text' => $this->mParams['text'],
'watch' => $watch,
'session' => $this->getContext()->exportSession()
]
) );
$result['result'] = 'Poll';
$result['stage'] = 'queued';
} else {
/** @var $status Status */
$status = $this->mUpload->performUpload( $this->mParams['comment'],
$this->mParams['text'], $watch, $this->getUser(), $this->mParams['tags'] );
if ( !$status->isGood() ) {
$this->dieRecoverableError( $status->getErrors() );
}
$result['result'] = 'Success';
here it is ... the upload-api, script-server, js2 (javascript phase2) branch merge 1st attempt. Here is a short overview of changes and associated default configuration variables (most everything is off by default) also see ~soon to be updated~: http://www.mediawiki.org/wiki/Media_Projects_Overview = Upload Improvements = ==Upload API == * Based on the early work of Bryan Tong and others it adds the upload option to the api. * We rewrite Special:Upload page to include use the new refactoring * Added in token checks in both the SpecialUpload.php page so avoids DOS / xss copy-by-url JavaScript based cross site POST file submissions == Copy by URL== $wgAllowCopyUploads = false; * http class rewrite includes a new http background download see: includes/HttpFunctions.php * spins off a php process that calls: maintenance/http_session_download.php * pushes updates to the session and gives the user a progress bar on http copy uploads from other server progress (using js2 upload interface) (if not using the js2 upload interface it does the request in-place but the download is limited to the php ini timeout time) == Firefogg == * Firefogg enables resumable upload by chunks * progress indicators and conditional invokation (js2 system) * and of-course client side transcoding. = Script Server = $wgEnableScriptLoader = false; * off by default if $wgEnableScriptLoader is turned on script files are grouped, gziped, cached etc. for more info see: http://www.mediawiki.org/wiki/Extension:ScriptLoader * Includes some early skin js include fixes (skin/script system still lots of love) * Includes a "javascript class autoloader" this is packaged into mwEmbed so that the mwEmbed library can work in stand alone mode (while retaining localization and script serving) (one such application is the make page for firefogg.org : http://www.firefogg.org/make/index.html ) * The file that contains the autojavascript loading classes is: js2/php/jsAutoloadLocalClasses.php * One can use this auto class loading dependency system with extensions and add-ons but I need to better document that. = js2 system / mwEmbed= $wgEnableJS2system = false * includes initial rewrite towards more jquery based javascript code * especially for the Special:Upload page. * Also the edit page include support for the "add-media-wizard" * includes dependency loader for javascript that optionally takes advantage of the script-loader * remote embedding of javascript interfaces (like embedding video, or commons media searching) * $wgDebugJavaScript = false; .. .this variable lets you always get "always fresh javascript". When used with the script-loader it does not minify the script-loader output. = mwEmbed = * Will commit a separate patch to oggHandler that conditionally outputs <video tag> to use the new javascript video player. ** mv_embed player includes: play-head, volume control, remote embedding, oggz-chop support across plugins. * add-media-wizard adds easy inserts of media to pages (with import) == jQuery== * we include a base install of jQuery, jQuery ui and some plugins. * all the javascript classes are in the scriptloader so its easy to load any set of jquery ui components that you may need using the script-server. You get a callback so you can then execute js with dependencies loaded. == other stuff == there is a bit more code in js2 that pertains to sequence editing, timed text display and basic image editing. We include a base import of pixastic-lib & pixastic-editor... will work with the pixastic developer to try and ensure upstream compatibility on our usage of the library for in-browser photo and sequence manipulation.
2009-07-14 23:52:14 +00:00
}
here it is ... the upload-api, script-server, js2 (javascript phase2) branch merge 1st attempt. Here is a short overview of changes and associated default configuration variables (most everything is off by default) also see ~soon to be updated~: http://www.mediawiki.org/wiki/Media_Projects_Overview = Upload Improvements = ==Upload API == * Based on the early work of Bryan Tong and others it adds the upload option to the api. * We rewrite Special:Upload page to include use the new refactoring * Added in token checks in both the SpecialUpload.php page so avoids DOS / xss copy-by-url JavaScript based cross site POST file submissions == Copy by URL== $wgAllowCopyUploads = false; * http class rewrite includes a new http background download see: includes/HttpFunctions.php * spins off a php process that calls: maintenance/http_session_download.php * pushes updates to the session and gives the user a progress bar on http copy uploads from other server progress (using js2 upload interface) (if not using the js2 upload interface it does the request in-place but the download is limited to the php ini timeout time) == Firefogg == * Firefogg enables resumable upload by chunks * progress indicators and conditional invokation (js2 system) * and of-course client side transcoding. = Script Server = $wgEnableScriptLoader = false; * off by default if $wgEnableScriptLoader is turned on script files are grouped, gziped, cached etc. for more info see: http://www.mediawiki.org/wiki/Extension:ScriptLoader * Includes some early skin js include fixes (skin/script system still lots of love) * Includes a "javascript class autoloader" this is packaged into mwEmbed so that the mwEmbed library can work in stand alone mode (while retaining localization and script serving) (one such application is the make page for firefogg.org : http://www.firefogg.org/make/index.html ) * The file that contains the autojavascript loading classes is: js2/php/jsAutoloadLocalClasses.php * One can use this auto class loading dependency system with extensions and add-ons but I need to better document that. = js2 system / mwEmbed= $wgEnableJS2system = false * includes initial rewrite towards more jquery based javascript code * especially for the Special:Upload page. * Also the edit page include support for the "add-media-wizard" * includes dependency loader for javascript that optionally takes advantage of the script-loader * remote embedding of javascript interfaces (like embedding video, or commons media searching) * $wgDebugJavaScript = false; .. .this variable lets you always get "always fresh javascript". When used with the script-loader it does not minify the script-loader output. = mwEmbed = * Will commit a separate patch to oggHandler that conditionally outputs <video tag> to use the new javascript video player. ** mv_embed player includes: play-head, volume control, remote embedding, oggz-chop support across plugins. * add-media-wizard adds easy inserts of media to pages (with import) == jQuery== * we include a base install of jQuery, jQuery ui and some plugins. * all the javascript classes are in the scriptloader so its easy to load any set of jquery ui components that you may need using the script-server. You get a callback so you can then execute js with dependencies loaded. == other stuff == there is a bit more code in js2 that pertains to sequence editing, timed text display and basic image editing. We include a base import of pixastic-lib & pixastic-editor... will work with the pixastic developer to try and ensure upstream compatibility on our usage of the library for in-browser photo and sequence manipulation.
2009-07-14 23:52:14 +00:00
$result['filename'] = $file->getName();
if ( $warnings && count( $warnings ) > 0 ) {
$result['warnings'] = $warnings;
}
here it is ... the upload-api, script-server, js2 (javascript phase2) branch merge 1st attempt. Here is a short overview of changes and associated default configuration variables (most everything is off by default) also see ~soon to be updated~: http://www.mediawiki.org/wiki/Media_Projects_Overview = Upload Improvements = ==Upload API == * Based on the early work of Bryan Tong and others it adds the upload option to the api. * We rewrite Special:Upload page to include use the new refactoring * Added in token checks in both the SpecialUpload.php page so avoids DOS / xss copy-by-url JavaScript based cross site POST file submissions == Copy by URL== $wgAllowCopyUploads = false; * http class rewrite includes a new http background download see: includes/HttpFunctions.php * spins off a php process that calls: maintenance/http_session_download.php * pushes updates to the session and gives the user a progress bar on http copy uploads from other server progress (using js2 upload interface) (if not using the js2 upload interface it does the request in-place but the download is limited to the php ini timeout time) == Firefogg == * Firefogg enables resumable upload by chunks * progress indicators and conditional invokation (js2 system) * and of-course client side transcoding. = Script Server = $wgEnableScriptLoader = false; * off by default if $wgEnableScriptLoader is turned on script files are grouped, gziped, cached etc. for more info see: http://www.mediawiki.org/wiki/Extension:ScriptLoader * Includes some early skin js include fixes (skin/script system still lots of love) * Includes a "javascript class autoloader" this is packaged into mwEmbed so that the mwEmbed library can work in stand alone mode (while retaining localization and script serving) (one such application is the make page for firefogg.org : http://www.firefogg.org/make/index.html ) * The file that contains the autojavascript loading classes is: js2/php/jsAutoloadLocalClasses.php * One can use this auto class loading dependency system with extensions and add-ons but I need to better document that. = js2 system / mwEmbed= $wgEnableJS2system = false * includes initial rewrite towards more jquery based javascript code * especially for the Special:Upload page. * Also the edit page include support for the "add-media-wizard" * includes dependency loader for javascript that optionally takes advantage of the script-loader * remote embedding of javascript interfaces (like embedding video, or commons media searching) * $wgDebugJavaScript = false; .. .this variable lets you always get "always fresh javascript". When used with the script-loader it does not minify the script-loader output. = mwEmbed = * Will commit a separate patch to oggHandler that conditionally outputs <video tag> to use the new javascript video player. ** mv_embed player includes: play-head, volume control, remote embedding, oggz-chop support across plugins. * add-media-wizard adds easy inserts of media to pages (with import) == jQuery== * we include a base install of jQuery, jQuery ui and some plugins. * all the javascript classes are in the scriptloader so its easy to load any set of jquery ui components that you may need using the script-server. You get a callback so you can then execute js with dependencies loaded. == other stuff == there is a bit more code in js2 that pertains to sequence editing, timed text display and basic image editing. We include a base import of pixastic-lib & pixastic-editor... will work with the pixastic developer to try and ensure upstream compatibility on our usage of the library for in-browser photo and sequence manipulation.
2009-07-14 23:52:14 +00:00
return $result;
}
here it is ... the upload-api, script-server, js2 (javascript phase2) branch merge 1st attempt. Here is a short overview of changes and associated default configuration variables (most everything is off by default) also see ~soon to be updated~: http://www.mediawiki.org/wiki/Media_Projects_Overview = Upload Improvements = ==Upload API == * Based on the early work of Bryan Tong and others it adds the upload option to the api. * We rewrite Special:Upload page to include use the new refactoring * Added in token checks in both the SpecialUpload.php page so avoids DOS / xss copy-by-url JavaScript based cross site POST file submissions == Copy by URL== $wgAllowCopyUploads = false; * http class rewrite includes a new http background download see: includes/HttpFunctions.php * spins off a php process that calls: maintenance/http_session_download.php * pushes updates to the session and gives the user a progress bar on http copy uploads from other server progress (using js2 upload interface) (if not using the js2 upload interface it does the request in-place but the download is limited to the php ini timeout time) == Firefogg == * Firefogg enables resumable upload by chunks * progress indicators and conditional invokation (js2 system) * and of-course client side transcoding. = Script Server = $wgEnableScriptLoader = false; * off by default if $wgEnableScriptLoader is turned on script files are grouped, gziped, cached etc. for more info see: http://www.mediawiki.org/wiki/Extension:ScriptLoader * Includes some early skin js include fixes (skin/script system still lots of love) * Includes a "javascript class autoloader" this is packaged into mwEmbed so that the mwEmbed library can work in stand alone mode (while retaining localization and script serving) (one such application is the make page for firefogg.org : http://www.firefogg.org/make/index.html ) * The file that contains the autojavascript loading classes is: js2/php/jsAutoloadLocalClasses.php * One can use this auto class loading dependency system with extensions and add-ons but I need to better document that. = js2 system / mwEmbed= $wgEnableJS2system = false * includes initial rewrite towards more jquery based javascript code * especially for the Special:Upload page. * Also the edit page include support for the "add-media-wizard" * includes dependency loader for javascript that optionally takes advantage of the script-loader * remote embedding of javascript interfaces (like embedding video, or commons media searching) * $wgDebugJavaScript = false; .. .this variable lets you always get "always fresh javascript". When used with the script-loader it does not minify the script-loader output. = mwEmbed = * Will commit a separate patch to oggHandler that conditionally outputs <video tag> to use the new javascript video player. ** mv_embed player includes: play-head, volume control, remote embedding, oggz-chop support across plugins. * add-media-wizard adds easy inserts of media to pages (with import) == jQuery== * we include a base install of jQuery, jQuery ui and some plugins. * all the javascript classes are in the scriptloader so its easy to load any set of jquery ui components that you may need using the script-server. You get a callback so you can then execute js with dependencies loaded. == other stuff == there is a bit more code in js2 that pertains to sequence editing, timed text display and basic image editing. We include a base import of pixastic-lib & pixastic-editor... will work with the pixastic developer to try and ensure upstream compatibility on our usage of the library for in-browser photo and sequence manipulation.
2009-07-14 23:52:14 +00:00
public function mustBePosted() {
return true;
}
public function isWriteMode() {
return true;
}
here it is ... the upload-api, script-server, js2 (javascript phase2) branch merge 1st attempt. Here is a short overview of changes and associated default configuration variables (most everything is off by default) also see ~soon to be updated~: http://www.mediawiki.org/wiki/Media_Projects_Overview = Upload Improvements = ==Upload API == * Based on the early work of Bryan Tong and others it adds the upload option to the api. * We rewrite Special:Upload page to include use the new refactoring * Added in token checks in both the SpecialUpload.php page so avoids DOS / xss copy-by-url JavaScript based cross site POST file submissions == Copy by URL== $wgAllowCopyUploads = false; * http class rewrite includes a new http background download see: includes/HttpFunctions.php * spins off a php process that calls: maintenance/http_session_download.php * pushes updates to the session and gives the user a progress bar on http copy uploads from other server progress (using js2 upload interface) (if not using the js2 upload interface it does the request in-place but the download is limited to the php ini timeout time) == Firefogg == * Firefogg enables resumable upload by chunks * progress indicators and conditional invokation (js2 system) * and of-course client side transcoding. = Script Server = $wgEnableScriptLoader = false; * off by default if $wgEnableScriptLoader is turned on script files are grouped, gziped, cached etc. for more info see: http://www.mediawiki.org/wiki/Extension:ScriptLoader * Includes some early skin js include fixes (skin/script system still lots of love) * Includes a "javascript class autoloader" this is packaged into mwEmbed so that the mwEmbed library can work in stand alone mode (while retaining localization and script serving) (one such application is the make page for firefogg.org : http://www.firefogg.org/make/index.html ) * The file that contains the autojavascript loading classes is: js2/php/jsAutoloadLocalClasses.php * One can use this auto class loading dependency system with extensions and add-ons but I need to better document that. = js2 system / mwEmbed= $wgEnableJS2system = false * includes initial rewrite towards more jquery based javascript code * especially for the Special:Upload page. * Also the edit page include support for the "add-media-wizard" * includes dependency loader for javascript that optionally takes advantage of the script-loader * remote embedding of javascript interfaces (like embedding video, or commons media searching) * $wgDebugJavaScript = false; .. .this variable lets you always get "always fresh javascript". When used with the script-loader it does not minify the script-loader output. = mwEmbed = * Will commit a separate patch to oggHandler that conditionally outputs <video tag> to use the new javascript video player. ** mv_embed player includes: play-head, volume control, remote embedding, oggz-chop support across plugins. * add-media-wizard adds easy inserts of media to pages (with import) == jQuery== * we include a base install of jQuery, jQuery ui and some plugins. * all the javascript classes are in the scriptloader so its easy to load any set of jquery ui components that you may need using the script-server. You get a callback so you can then execute js with dependencies loaded. == other stuff == there is a bit more code in js2 that pertains to sequence editing, timed text display and basic image editing. We include a base import of pixastic-lib & pixastic-editor... will work with the pixastic developer to try and ensure upstream compatibility on our usage of the library for in-browser photo and sequence manipulation.
2009-07-14 23:52:14 +00:00
public function getAllowedParams() {
$params = [
'filename' => [
ApiBase::PARAM_TYPE => 'string',
],
'comment' => [
ApiBase::PARAM_DFLT => ''
],
'tags' => [
ApiBase::PARAM_TYPE => 'tags',
ApiBase::PARAM_ISMULTI => true,
],
'text' => [
ApiBase::PARAM_TYPE => 'text',
],
'watch' => [
ApiBase::PARAM_DFLT => false,
ApiBase::PARAM_DEPRECATED => true,
],
'watchlist' => [
ApiBase::PARAM_DFLT => 'preferences',
ApiBase::PARAM_TYPE => [
'watch',
'preferences',
'nochange'
],
],
here it is ... the upload-api, script-server, js2 (javascript phase2) branch merge 1st attempt. Here is a short overview of changes and associated default configuration variables (most everything is off by default) also see ~soon to be updated~: http://www.mediawiki.org/wiki/Media_Projects_Overview = Upload Improvements = ==Upload API == * Based on the early work of Bryan Tong and others it adds the upload option to the api. * We rewrite Special:Upload page to include use the new refactoring * Added in token checks in both the SpecialUpload.php page so avoids DOS / xss copy-by-url JavaScript based cross site POST file submissions == Copy by URL== $wgAllowCopyUploads = false; * http class rewrite includes a new http background download see: includes/HttpFunctions.php * spins off a php process that calls: maintenance/http_session_download.php * pushes updates to the session and gives the user a progress bar on http copy uploads from other server progress (using js2 upload interface) (if not using the js2 upload interface it does the request in-place but the download is limited to the php ini timeout time) == Firefogg == * Firefogg enables resumable upload by chunks * progress indicators and conditional invokation (js2 system) * and of-course client side transcoding. = Script Server = $wgEnableScriptLoader = false; * off by default if $wgEnableScriptLoader is turned on script files are grouped, gziped, cached etc. for more info see: http://www.mediawiki.org/wiki/Extension:ScriptLoader * Includes some early skin js include fixes (skin/script system still lots of love) * Includes a "javascript class autoloader" this is packaged into mwEmbed so that the mwEmbed library can work in stand alone mode (while retaining localization and script serving) (one such application is the make page for firefogg.org : http://www.firefogg.org/make/index.html ) * The file that contains the autojavascript loading classes is: js2/php/jsAutoloadLocalClasses.php * One can use this auto class loading dependency system with extensions and add-ons but I need to better document that. = js2 system / mwEmbed= $wgEnableJS2system = false * includes initial rewrite towards more jquery based javascript code * especially for the Special:Upload page. * Also the edit page include support for the "add-media-wizard" * includes dependency loader for javascript that optionally takes advantage of the script-loader * remote embedding of javascript interfaces (like embedding video, or commons media searching) * $wgDebugJavaScript = false; .. .this variable lets you always get "always fresh javascript". When used with the script-loader it does not minify the script-loader output. = mwEmbed = * Will commit a separate patch to oggHandler that conditionally outputs <video tag> to use the new javascript video player. ** mv_embed player includes: play-head, volume control, remote embedding, oggz-chop support across plugins. * add-media-wizard adds easy inserts of media to pages (with import) == jQuery== * we include a base install of jQuery, jQuery ui and some plugins. * all the javascript classes are in the scriptloader so its easy to load any set of jquery ui components that you may need using the script-server. You get a callback so you can then execute js with dependencies loaded. == other stuff == there is a bit more code in js2 that pertains to sequence editing, timed text display and basic image editing. We include a base import of pixastic-lib & pixastic-editor... will work with the pixastic developer to try and ensure upstream compatibility on our usage of the library for in-browser photo and sequence manipulation.
2009-07-14 23:52:14 +00:00
'ignorewarnings' => false,
'file' => [
ApiBase::PARAM_TYPE => 'upload',
],
2009-07-28 17:52:09 +00:00
'url' => null,
'filekey' => null,
'sessionkey' => [
ApiBase::PARAM_DEPRECATED => true,
],
'stash' => false,
'filesize' => [
ApiBase::PARAM_TYPE => 'integer',
ApiBase::PARAM_MIN => 0,
ApiBase::PARAM_MAX => UploadBase::getMaxUploadSize(),
],
'offset' => [
ApiBase::PARAM_TYPE => 'integer',
ApiBase::PARAM_MIN => 0,
],
'chunk' => [
ApiBase::PARAM_TYPE => 'upload',
],
'async' => false,
'checkstatus' => false,
];
2010-08-05 07:02:09 +00:00
return $params;
here it is ... the upload-api, script-server, js2 (javascript phase2) branch merge 1st attempt. Here is a short overview of changes and associated default configuration variables (most everything is off by default) also see ~soon to be updated~: http://www.mediawiki.org/wiki/Media_Projects_Overview = Upload Improvements = ==Upload API == * Based on the early work of Bryan Tong and others it adds the upload option to the api. * We rewrite Special:Upload page to include use the new refactoring * Added in token checks in both the SpecialUpload.php page so avoids DOS / xss copy-by-url JavaScript based cross site POST file submissions == Copy by URL== $wgAllowCopyUploads = false; * http class rewrite includes a new http background download see: includes/HttpFunctions.php * spins off a php process that calls: maintenance/http_session_download.php * pushes updates to the session and gives the user a progress bar on http copy uploads from other server progress (using js2 upload interface) (if not using the js2 upload interface it does the request in-place but the download is limited to the php ini timeout time) == Firefogg == * Firefogg enables resumable upload by chunks * progress indicators and conditional invokation (js2 system) * and of-course client side transcoding. = Script Server = $wgEnableScriptLoader = false; * off by default if $wgEnableScriptLoader is turned on script files are grouped, gziped, cached etc. for more info see: http://www.mediawiki.org/wiki/Extension:ScriptLoader * Includes some early skin js include fixes (skin/script system still lots of love) * Includes a "javascript class autoloader" this is packaged into mwEmbed so that the mwEmbed library can work in stand alone mode (while retaining localization and script serving) (one such application is the make page for firefogg.org : http://www.firefogg.org/make/index.html ) * The file that contains the autojavascript loading classes is: js2/php/jsAutoloadLocalClasses.php * One can use this auto class loading dependency system with extensions and add-ons but I need to better document that. = js2 system / mwEmbed= $wgEnableJS2system = false * includes initial rewrite towards more jquery based javascript code * especially for the Special:Upload page. * Also the edit page include support for the "add-media-wizard" * includes dependency loader for javascript that optionally takes advantage of the script-loader * remote embedding of javascript interfaces (like embedding video, or commons media searching) * $wgDebugJavaScript = false; .. .this variable lets you always get "always fresh javascript". When used with the script-loader it does not minify the script-loader output. = mwEmbed = * Will commit a separate patch to oggHandler that conditionally outputs <video tag> to use the new javascript video player. ** mv_embed player includes: play-head, volume control, remote embedding, oggz-chop support across plugins. * add-media-wizard adds easy inserts of media to pages (with import) == jQuery== * we include a base install of jQuery, jQuery ui and some plugins. * all the javascript classes are in the scriptloader so its easy to load any set of jquery ui components that you may need using the script-server. You get a callback so you can then execute js with dependencies loaded. == other stuff == there is a bit more code in js2 that pertains to sequence editing, timed text display and basic image editing. We include a base import of pixastic-lib & pixastic-editor... will work with the pixastic developer to try and ensure upstream compatibility on our usage of the library for in-browser photo and sequence manipulation.
2009-07-14 23:52:14 +00:00
}
public function needsToken() {
return 'csrf';
}
here it is ... the upload-api, script-server, js2 (javascript phase2) branch merge 1st attempt. Here is a short overview of changes and associated default configuration variables (most everything is off by default) also see ~soon to be updated~: http://www.mediawiki.org/wiki/Media_Projects_Overview = Upload Improvements = ==Upload API == * Based on the early work of Bryan Tong and others it adds the upload option to the api. * We rewrite Special:Upload page to include use the new refactoring * Added in token checks in both the SpecialUpload.php page so avoids DOS / xss copy-by-url JavaScript based cross site POST file submissions == Copy by URL== $wgAllowCopyUploads = false; * http class rewrite includes a new http background download see: includes/HttpFunctions.php * spins off a php process that calls: maintenance/http_session_download.php * pushes updates to the session and gives the user a progress bar on http copy uploads from other server progress (using js2 upload interface) (if not using the js2 upload interface it does the request in-place but the download is limited to the php ini timeout time) == Firefogg == * Firefogg enables resumable upload by chunks * progress indicators and conditional invokation (js2 system) * and of-course client side transcoding. = Script Server = $wgEnableScriptLoader = false; * off by default if $wgEnableScriptLoader is turned on script files are grouped, gziped, cached etc. for more info see: http://www.mediawiki.org/wiki/Extension:ScriptLoader * Includes some early skin js include fixes (skin/script system still lots of love) * Includes a "javascript class autoloader" this is packaged into mwEmbed so that the mwEmbed library can work in stand alone mode (while retaining localization and script serving) (one such application is the make page for firefogg.org : http://www.firefogg.org/make/index.html ) * The file that contains the autojavascript loading classes is: js2/php/jsAutoloadLocalClasses.php * One can use this auto class loading dependency system with extensions and add-ons but I need to better document that. = js2 system / mwEmbed= $wgEnableJS2system = false * includes initial rewrite towards more jquery based javascript code * especially for the Special:Upload page. * Also the edit page include support for the "add-media-wizard" * includes dependency loader for javascript that optionally takes advantage of the script-loader * remote embedding of javascript interfaces (like embedding video, or commons media searching) * $wgDebugJavaScript = false; .. .this variable lets you always get "always fresh javascript". When used with the script-loader it does not minify the script-loader output. = mwEmbed = * Will commit a separate patch to oggHandler that conditionally outputs <video tag> to use the new javascript video player. ** mv_embed player includes: play-head, volume control, remote embedding, oggz-chop support across plugins. * add-media-wizard adds easy inserts of media to pages (with import) == jQuery== * we include a base install of jQuery, jQuery ui and some plugins. * all the javascript classes are in the scriptloader so its easy to load any set of jquery ui components that you may need using the script-server. You get a callback so you can then execute js with dependencies loaded. == other stuff == there is a bit more code in js2 that pertains to sequence editing, timed text display and basic image editing. We include a base import of pixastic-lib & pixastic-editor... will work with the pixastic developer to try and ensure upstream compatibility on our usage of the library for in-browser photo and sequence manipulation.
2009-07-14 23:52:14 +00:00
protected function getExamplesMessages() {
return [
'action=upload&filename=Wiki.png' .
'&url=http%3A//upload.wikimedia.org/wikipedia/en/b/bc/Wiki.png&token=123ABC'
=> 'apihelp-upload-example-url',
'action=upload&filename=Wiki.png&filekey=filekey&ignorewarnings=1&token=123ABC'
=> 'apihelp-upload-example-filekey',
];
here it is ... the upload-api, script-server, js2 (javascript phase2) branch merge 1st attempt. Here is a short overview of changes and associated default configuration variables (most everything is off by default) also see ~soon to be updated~: http://www.mediawiki.org/wiki/Media_Projects_Overview = Upload Improvements = ==Upload API == * Based on the early work of Bryan Tong and others it adds the upload option to the api. * We rewrite Special:Upload page to include use the new refactoring * Added in token checks in both the SpecialUpload.php page so avoids DOS / xss copy-by-url JavaScript based cross site POST file submissions == Copy by URL== $wgAllowCopyUploads = false; * http class rewrite includes a new http background download see: includes/HttpFunctions.php * spins off a php process that calls: maintenance/http_session_download.php * pushes updates to the session and gives the user a progress bar on http copy uploads from other server progress (using js2 upload interface) (if not using the js2 upload interface it does the request in-place but the download is limited to the php ini timeout time) == Firefogg == * Firefogg enables resumable upload by chunks * progress indicators and conditional invokation (js2 system) * and of-course client side transcoding. = Script Server = $wgEnableScriptLoader = false; * off by default if $wgEnableScriptLoader is turned on script files are grouped, gziped, cached etc. for more info see: http://www.mediawiki.org/wiki/Extension:ScriptLoader * Includes some early skin js include fixes (skin/script system still lots of love) * Includes a "javascript class autoloader" this is packaged into mwEmbed so that the mwEmbed library can work in stand alone mode (while retaining localization and script serving) (one such application is the make page for firefogg.org : http://www.firefogg.org/make/index.html ) * The file that contains the autojavascript loading classes is: js2/php/jsAutoloadLocalClasses.php * One can use this auto class loading dependency system with extensions and add-ons but I need to better document that. = js2 system / mwEmbed= $wgEnableJS2system = false * includes initial rewrite towards more jquery based javascript code * especially for the Special:Upload page. * Also the edit page include support for the "add-media-wizard" * includes dependency loader for javascript that optionally takes advantage of the script-loader * remote embedding of javascript interfaces (like embedding video, or commons media searching) * $wgDebugJavaScript = false; .. .this variable lets you always get "always fresh javascript". When used with the script-loader it does not minify the script-loader output. = mwEmbed = * Will commit a separate patch to oggHandler that conditionally outputs <video tag> to use the new javascript video player. ** mv_embed player includes: play-head, volume control, remote embedding, oggz-chop support across plugins. * add-media-wizard adds easy inserts of media to pages (with import) == jQuery== * we include a base install of jQuery, jQuery ui and some plugins. * all the javascript classes are in the scriptloader so its easy to load any set of jquery ui components that you may need using the script-server. You get a callback so you can then execute js with dependencies loaded. == other stuff == there is a bit more code in js2 that pertains to sequence editing, timed text display and basic image editing. We include a base import of pixastic-lib & pixastic-editor... will work with the pixastic developer to try and ensure upstream compatibility on our usage of the library for in-browser photo and sequence manipulation.
2009-07-14 23:52:14 +00:00
}
public function getHelpUrls() {
2011-11-28 15:43:11 +00:00
return 'https://www.mediawiki.org/wiki/API:Upload';
}
here it is ... the upload-api, script-server, js2 (javascript phase2) branch merge 1st attempt. Here is a short overview of changes and associated default configuration variables (most everything is off by default) also see ~soon to be updated~: http://www.mediawiki.org/wiki/Media_Projects_Overview = Upload Improvements = ==Upload API == * Based on the early work of Bryan Tong and others it adds the upload option to the api. * We rewrite Special:Upload page to include use the new refactoring * Added in token checks in both the SpecialUpload.php page so avoids DOS / xss copy-by-url JavaScript based cross site POST file submissions == Copy by URL== $wgAllowCopyUploads = false; * http class rewrite includes a new http background download see: includes/HttpFunctions.php * spins off a php process that calls: maintenance/http_session_download.php * pushes updates to the session and gives the user a progress bar on http copy uploads from other server progress (using js2 upload interface) (if not using the js2 upload interface it does the request in-place but the download is limited to the php ini timeout time) == Firefogg == * Firefogg enables resumable upload by chunks * progress indicators and conditional invokation (js2 system) * and of-course client side transcoding. = Script Server = $wgEnableScriptLoader = false; * off by default if $wgEnableScriptLoader is turned on script files are grouped, gziped, cached etc. for more info see: http://www.mediawiki.org/wiki/Extension:ScriptLoader * Includes some early skin js include fixes (skin/script system still lots of love) * Includes a "javascript class autoloader" this is packaged into mwEmbed so that the mwEmbed library can work in stand alone mode (while retaining localization and script serving) (one such application is the make page for firefogg.org : http://www.firefogg.org/make/index.html ) * The file that contains the autojavascript loading classes is: js2/php/jsAutoloadLocalClasses.php * One can use this auto class loading dependency system with extensions and add-ons but I need to better document that. = js2 system / mwEmbed= $wgEnableJS2system = false * includes initial rewrite towards more jquery based javascript code * especially for the Special:Upload page. * Also the edit page include support for the "add-media-wizard" * includes dependency loader for javascript that optionally takes advantage of the script-loader * remote embedding of javascript interfaces (like embedding video, or commons media searching) * $wgDebugJavaScript = false; .. .this variable lets you always get "always fresh javascript". When used with the script-loader it does not minify the script-loader output. = mwEmbed = * Will commit a separate patch to oggHandler that conditionally outputs <video tag> to use the new javascript video player. ** mv_embed player includes: play-head, volume control, remote embedding, oggz-chop support across plugins. * add-media-wizard adds easy inserts of media to pages (with import) == jQuery== * we include a base install of jQuery, jQuery ui and some plugins. * all the javascript classes are in the scriptloader so its easy to load any set of jquery ui components that you may need using the script-server. You get a callback so you can then execute js with dependencies loaded. == other stuff == there is a bit more code in js2 that pertains to sequence editing, timed text display and basic image editing. We include a base import of pixastic-lib & pixastic-editor... will work with the pixastic developer to try and ensure upstream compatibility on our usage of the library for in-browser photo and sequence manipulation.
2009-07-14 23:52:14 +00:00
}