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
|
2010-02-26 13:18:56 +00:00
|
|
|
/**
|
|
|
|
|
* 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.,
|
2010-06-21 13:13:32 +00:00
|
|
|
* 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
|
2010-08-07 19:59:42 +00:00
|
|
|
*
|
|
|
|
|
* @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
|
|
|
*/
|
|
|
|
|
|
2021-07-04 12:47:21 +00:00
|
|
|
use MediaWiki\User\UserOptionsLookup;
|
|
|
|
|
use MediaWiki\Watchlist\WatchlistManager;
|
|
|
|
|
|
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 {
|
2020-06-04 20:16:23 +00:00
|
|
|
|
|
|
|
|
use ApiWatchlistTrait;
|
|
|
|
|
|
2014-07-08 21:40:06 +00:00
|
|
|
/** @var UploadBase|UploadFromChunks */
|
2009-08-26 19:38:38 +00:00
|
|
|
protected $mUpload = null;
|
2011-02-19 00:30:18 +00:00
|
|
|
|
2009-08-26 19:38:38 +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
|
|
|
|
2021-07-02 12:47:52 +00:00
|
|
|
/** @var JobQueueGroup */
|
|
|
|
|
private $jobQueueGroup;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param ApiMain $mainModule
|
|
|
|
|
* @param string $moduleName
|
|
|
|
|
* @param JobQueueGroup $jobQueueGroup
|
2021-07-04 12:47:21 +00:00
|
|
|
* @param WatchlistManager $watchlistManager
|
|
|
|
|
* @param UserOptionsLookup $userOptionsLookup
|
2021-07-02 12:47:52 +00:00
|
|
|
*/
|
|
|
|
|
public function __construct(
|
|
|
|
|
ApiMain $mainModule,
|
|
|
|
|
$moduleName,
|
2021-07-04 12:47:21 +00:00
|
|
|
JobQueueGroup $jobQueueGroup,
|
|
|
|
|
WatchlistManager $watchlistManager,
|
|
|
|
|
UserOptionsLookup $userOptionsLookup
|
2021-07-02 12:47:52 +00:00
|
|
|
) {
|
|
|
|
|
parent::__construct( $mainModule, $moduleName );
|
2021-07-04 12:47:21 +00:00
|
|
|
$this->jobQueueGroup = $jobQueueGroup;
|
2020-06-04 20:16:23 +00:00
|
|
|
|
2021-07-04 12:47:21 +00:00
|
|
|
// Variables needed in ApiWatchlistTrait trait
|
2020-06-04 20:16:23 +00:00
|
|
|
$this->watchlistExpiryEnabled = $this->getConfig()->get( 'WatchlistExpiry' );
|
|
|
|
|
$this->watchlistMaxDuration = $this->getConfig()->get( 'WatchlistExpiryMaxDuration' );
|
2021-07-04 12:47:21 +00:00
|
|
|
$this->watchlistManager = $watchlistManager;
|
|
|
|
|
$this->userOptionsLookup = $userOptionsLookup;
|
2020-06-04 20:16:23 +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
|
|
|
public function execute() {
|
2010-02-10 10:36:11 +00:00
|
|
|
// Check whether upload is enabled
|
2010-02-26 13:18:56 +00:00
|
|
|
if ( !UploadBase::isEnabled() ) {
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->dieWithError( 'uploaddisabled' );
|
2010-02-26 13:18:56 +00:00
|
|
|
}
|
2010-02-10 10:36:11 +00:00
|
|
|
|
2011-10-26 23:27:01 +00:00
|
|
|
$user = $this->getUser();
|
|
|
|
|
|
2010-07-28 17:31:32 +00:00
|
|
|
// 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();
|
2013-02-13 21:25:37 +00:00
|
|
|
// Check if async mode is actually supported (jobs done in cli mode)
|
2015-09-28 11:15:17 +00:00
|
|
|
$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' );
|
2011-08-02 10:13:56 +00:00
|
|
|
$this->mParams['chunk'] = $request->getFileName( 'chunk' );
|
2011-07-17 16:38:24 +00:00
|
|
|
|
2011-07-12 21:11:43 +00:00
|
|
|
// Copy the session key to the file key, for backward compatibility.
|
2013-04-19 18:03:05 +00:00
|
|
|
if ( !$this->mParams['filekey'] && $this->mParams['sessionkey'] ) {
|
2011-07-12 21:11:43 +00:00
|
|
|
$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
|
|
|
|
2010-07-28 17:31:32 +00:00
|
|
|
// Select an upload module
|
2013-06-19 20:52:33 +00:00
|
|
|
try {
|
|
|
|
|
if ( !$this->selectUploadModule() ) {
|
|
|
|
|
return; // not a true upload, but a status request or similar
|
|
|
|
|
} elseif ( !isset( $this->mUpload ) ) {
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->dieDebug( __METHOD__, 'No upload module set' );
|
2013-06-19 20:52:33 +00:00
|
|
|
}
|
|
|
|
|
} catch ( UploadStashException $e ) { // XXX: don't spam exception log
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->dieStatus( $this->handleStashException( $e ) );
|
2010-07-28 17:31:32 +00:00
|
|
|
}
|
2010-08-05 07:02:09 +00:00
|
|
|
|
2010-07-28 17:31:32 +00:00
|
|
|
// First check permission to upload
|
2011-10-26 23:27:01 +00:00
|
|
|
$this->checkPermissions( $user );
|
2010-08-05 07:02:09 +00:00
|
|
|
|
2012-12-04 02:18:48 +00:00
|
|
|
// Fetch the file (usually a no-op)
|
2017-09-04 18:05:26 +00:00
|
|
|
/** @var Status $status */
|
2010-07-28 17:31:32 +00:00
|
|
|
$status = $this->mUpload->fetchFile();
|
|
|
|
|
if ( !$status->isGood() ) {
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->dieStatus( $status );
|
2010-07-28 17:31:32 +00:00
|
|
|
}
|
|
|
|
|
|
2021-11-22 13:35:17 +00:00
|
|
|
// Check the uploaded file
|
2019-05-20 11:47:45 +00:00
|
|
|
$this->verifyUpload();
|
2012-10-10 23:15:29 +00:00
|
|
|
|
2011-03-25 20:42:05 +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)
|
2012-12-04 02:18:48 +00:00
|
|
|
if ( !$this->mParams['stash'] ) {
|
2011-10-26 23:27:01 +00:00
|
|
|
$permErrors = $this->mUpload->verifyTitlePermissions( $user );
|
2011-03-25 20:42:05 +00:00
|
|
|
if ( $permErrors !== true ) {
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->dieRecoverableError( $permErrors, 'filename' );
|
2011-03-25 20:42:05 +00:00
|
|
|
}
|
2010-07-29 13:53:51 +00:00
|
|
|
}
|
2012-12-04 02:18:48 +00:00
|
|
|
|
2012-10-10 23:15:29 +00:00
|
|
|
// Get the result based on the current upload context:
|
2013-06-19 20:52:33 +00:00
|
|
|
try {
|
|
|
|
|
$result = $this->getContextResult();
|
|
|
|
|
} catch ( UploadStashException $e ) { // XXX: don't spam exception log
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->dieStatus( $this->handleStashException( $e ) );
|
2011-11-30 14:56:40 +00:00
|
|
|
}
|
|
|
|
|
$this->getResult()->addValue( null, $this->getModuleName(), $result );
|
2010-12-30 17:06:09 +00:00
|
|
|
|
2016-08-26 13:22:09 +00:00
|
|
|
// 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).
|
2019-10-12 12:30:37 +00:00
|
|
|
// @phan-suppress-next-line PhanTypeArraySuspiciousNullable False positive
|
2016-08-26 13:22:09 +00:00
|
|
|
if ( $result['result'] === 'Success' ) {
|
|
|
|
|
$imageinfo = $this->mUpload->getImageInfo( $this->getResult() );
|
|
|
|
|
$this->getResult()->addValue( $this->getModuleName(), 'imageinfo', $imageinfo );
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-30 14:56:40 +00:00
|
|
|
// Cleanup any temporary mess
|
|
|
|
|
$this->mUpload->cleanupTempFile();
|
|
|
|
|
}
|
2012-11-19 08:07:50 +00:00
|
|
|
|
2011-11-30 14:56:40 +00:00
|
|
|
/**
|
2013-03-11 03:45:51 +00:00
|
|
|
* Get an upload result based on upload context
|
2012-02-09 21:33:27 +00:00
|
|
|
* @return array
|
2011-11-30 14:56:40 +00:00
|
|
|
*/
|
2013-01-26 21:11:09 +00:00
|
|
|
private function getContextResult() {
|
2010-11-03 04:32:41 +00:00
|
|
|
$warnings = $this->getApiWarnings();
|
2012-05-26 00:05:04 +00:00
|
|
|
if ( $warnings && !$this->mParams['ignorewarnings'] ) {
|
2013-03-11 03:45:51 +00:00
|
|
|
// Get warnings formatted in result array format
|
2011-11-30 14:56:40 +00:00
|
|
|
return $this->getWarningsResult( $warnings );
|
2011-11-30 13:54:35 +00:00
|
|
|
} elseif ( $this->mParams['chunk'] ) {
|
2011-11-30 14:56:40 +00:00
|
|
|
// Add chunk, and get result
|
2012-05-26 00:05:04 +00:00
|
|
|
return $this->getChunkResult( $warnings );
|
2011-11-30 14:56:40 +00:00
|
|
|
} elseif ( $this->mParams['stash'] ) {
|
|
|
|
|
// Stash the file and get stash result
|
2012-05-26 00:05:04 +00:00
|
|
|
return $this->getStashResult( $warnings );
|
2011-11-30 14:56:40 +00:00
|
|
|
}
|
2013-11-14 13:01:41 +00:00
|
|
|
|
2015-03-12 01:44:44 +00:00
|
|
|
// Check throttle after we've handled warnings
|
|
|
|
|
if ( UploadBase::isThrottled( $this->getUser() )
|
|
|
|
|
) {
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->dieWithError( 'apierror-ratelimited' );
|
2015-03-12 01:44:44 +00:00
|
|
|
}
|
|
|
|
|
|
2011-11-30 14:56:40 +00:00
|
|
|
// This is the most common case -- a normal upload with no warnings
|
|
|
|
|
// performUpload will return a formatted properly for the API with status
|
2012-05-26 00:05:04 +00:00
|
|
|
return $this->performUpload( $warnings );
|
2011-11-30 14:56:40 +00:00
|
|
|
}
|
2012-12-04 02:18:48 +00:00
|
|
|
|
2011-11-30 14:56:40 +00:00
|
|
|
/**
|
2013-03-11 03:45:51 +00:00
|
|
|
* Get Stash Result, throws an exception if the file could not be stashed.
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param array $warnings Array of Api upload warnings
|
2012-02-09 21:33:27 +00:00
|
|
|
* @return array
|
2011-11-30 14:56:40 +00:00
|
|
|
*/
|
2013-01-26 21:11:09 +00:00
|
|
|
private function getStashResult( $warnings ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$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;
|
|
|
|
|
}
|
2011-11-30 14:56:40 +00:00
|
|
|
// 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 );
|
2013-11-14 13:01:41 +00:00
|
|
|
|
2011-11-30 14:56:40 +00:00
|
|
|
return $result;
|
|
|
|
|
}
|
2012-12-04 02:18:48 +00:00
|
|
|
|
2011-11-30 14:56:40 +00:00
|
|
|
/**
|
|
|
|
|
* Get Warnings Result
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param array $warnings Array of Api upload warnings
|
2012-02-09 21:33:27 +00:00
|
|
|
* @return array
|
2011-11-30 14:56:40 +00:00
|
|
|
*/
|
2013-01-26 21:11:09 +00:00
|
|
|
private function getWarningsResult( $warnings ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$result = [];
|
2011-11-30 14:56:40 +00:00
|
|
|
$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 );
|
2013-11-14 13:01:41 +00:00
|
|
|
|
2011-11-30 14:56:40 +00:00
|
|
|
return $result;
|
|
|
|
|
}
|
2012-12-04 02:18:48 +00:00
|
|
|
|
2020-04-30 02:33:31 +00:00
|
|
|
/**
|
|
|
|
|
* @since 1.35
|
|
|
|
|
* @see $wgMinUploadChunkSize
|
|
|
|
|
* @param Config $config Site configuration for MinUploadChunkSize
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public static function getMinUploadChunkSize( Config $config ) {
|
|
|
|
|
$configured = $config->get( 'MinUploadChunkSize' );
|
|
|
|
|
|
|
|
|
|
// Leave some room for other POST parameters
|
|
|
|
|
$postMax = (
|
|
|
|
|
wfShorthandToInteger(
|
|
|
|
|
ini_get( 'post_max_size' ),
|
|
|
|
|
PHP_INT_MAX
|
|
|
|
|
) ?: PHP_INT_MAX
|
|
|
|
|
) - 1024;
|
|
|
|
|
|
|
|
|
|
// Ensure the minimum chunk size is less than PHP upload limits
|
|
|
|
|
// or the maximum upload size.
|
|
|
|
|
return min(
|
|
|
|
|
$configured,
|
|
|
|
|
UploadBase::getMaxUploadSize( 'file' ),
|
|
|
|
|
UploadBase::getMaxPhpUploadSize(),
|
|
|
|
|
$postMax
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-30 14:56:40 +00:00
|
|
|
/**
|
2012-02-09 21:33:27 +00:00
|
|
|
* Get the result of a chunk upload.
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param array $warnings Array of Api upload warnings
|
2012-02-09 21:33:27 +00:00
|
|
|
* @return array
|
2011-11-30 14:56:40 +00:00
|
|
|
*/
|
2012-11-19 08:07:50 +00:00
|
|
|
private function getChunkResult( $warnings ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$result = [];
|
2012-04-27 15:40:14 +00:00
|
|
|
|
2012-05-26 00:05:04 +00:00
|
|
|
if ( $warnings && count( $warnings ) > 0 ) {
|
|
|
|
|
$result['warnings'] = $warnings;
|
|
|
|
|
}
|
2015-09-08 17:59:44 +00:00
|
|
|
|
2011-11-30 14:56:40 +00:00
|
|
|
$request = $this->getMain()->getRequest();
|
|
|
|
|
$chunkPath = $request->getFileTempname( 'chunk' );
|
|
|
|
|
$chunkSize = $request->getUpload( 'chunk' )->getSize();
|
2015-09-08 17:59:44 +00:00
|
|
|
$totalSoFar = $this->mParams['offset'] + $chunkSize;
|
2020-04-30 02:33:31 +00:00
|
|
|
$minChunkSize = self::getMinUploadChunkSize( $this->getConfig() );
|
2015-09-08 17:59:44 +00:00
|
|
|
|
2021-11-19 23:19:42 +00:00
|
|
|
// Double check sizing
|
2015-09-08 17:59:44 +00:00
|
|
|
if ( $totalSoFar > $this->mParams['filesize'] ) {
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->dieWithError( 'apierror-invalid-chunk' );
|
2015-09-08 17:59:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Enforce minimum chunk size
|
|
|
|
|
if ( $totalSoFar != $this->mParams['filesize'] && $chunkSize < $minChunkSize ) {
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->dieWithError( [ 'apierror-chunk-too-small', Message::numParam( $minChunkSize ) ] );
|
2015-09-08 17:59:44 +00:00
|
|
|
}
|
|
|
|
|
|
2013-02-03 18:47:42 +00:00
|
|
|
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' );
|
2011-11-30 14:56:40 +00:00
|
|
|
} else {
|
2013-02-26 23:19:52 +00:00
|
|
|
$filekey = $this->mParams['filekey'];
|
2015-09-08 17:59:44 +00:00
|
|
|
|
|
|
|
|
// 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
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->dieWithError( 'apierror-stashfailed-nosession', 'stashfailed' );
|
2015-09-08 17:59:44 +00:00
|
|
|
} elseif ( $progress['result'] !== 'Continue' || $progress['stage'] !== 'uploading' ) {
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->dieWithError( 'apierror-stashfailed-complete', 'stashfailed' );
|
2015-09-08 17:59:44 +00:00
|
|
|
}
|
|
|
|
|
|
2012-11-19 08:07:50 +00:00
|
|
|
$status = $this->mUpload->addChunk(
|
|
|
|
|
$chunkPath, $chunkSize, $this->mParams['offset'] );
|
2011-11-30 14:56:40 +00:00
|
|
|
if ( !$status->isGood() ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$extradata = [
|
2015-02-12 15:59:09 +00:00
|
|
|
'offset' => $this->mUpload->getOffset(),
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2015-02-12 15:59:09 +00:00
|
|
|
|
2016-08-17 13:31:22 +00:00
|
|
|
$this->dieStatusWithCode( $status, 'stashfailed', $extradata );
|
2011-11-30 14:56:40 +00:00
|
|
|
}
|
2013-02-26 23:19:52 +00:00
|
|
|
}
|
2012-04-08 11:27:32 +00:00
|
|
|
|
2013-02-26 23:19:52 +00:00
|
|
|
// Check we added the last chunk:
|
2015-09-08 17:59:44 +00:00
|
|
|
if ( $totalSoFar == $this->mParams['filesize'] ) {
|
2013-02-26 23:19:52 +00:00
|
|
|
if ( $this->mParams['async'] ) {
|
|
|
|
|
UploadBase::setSessionStatus(
|
2014-09-29 23:20:57 +00:00
|
|
|
$this->getUser(),
|
2013-05-09 22:09:20 +00:00
|
|
|
$filekey,
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'result' => 'Poll',
|
|
|
|
|
'stage' => 'queued', 'status' => Status::newGood() ]
|
2013-02-26 23:19:52 +00:00
|
|
|
);
|
2021-07-02 12:47:52 +00:00
|
|
|
$this->jobQueueGroup->push( new AssembleUploadChunksJob(
|
2013-05-09 22:09:20 +00:00
|
|
|
Title::makeTitle( NS_FILE, $filekey ),
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
2013-04-14 19:57:46 +00:00
|
|
|
'filename' => $this->mParams['filename'],
|
2013-05-09 22:09:20 +00:00
|
|
|
'filekey' => $filekey,
|
2013-04-14 19:57:46 +00:00
|
|
|
'session' => $this->getContext()->exportSession()
|
2016-02-17 09:09:32 +00:00
|
|
|
]
|
2013-02-26 23:19:52 +00:00
|
|
|
) );
|
2014-04-16 18:07:26 +00:00
|
|
|
$result['result'] = 'Poll';
|
2014-09-05 07:31:00 +00:00
|
|
|
$result['stage'] = 'queued';
|
2012-04-08 11:27:32 +00:00
|
|
|
} else {
|
2013-02-26 23:19:52 +00:00
|
|
|
$status = $this->mUpload->concatenateChunks();
|
|
|
|
|
if ( !$status->isGood() ) {
|
2015-09-08 17:59:44 +00:00
|
|
|
UploadBase::setSessionStatus(
|
|
|
|
|
$this->getUser(),
|
|
|
|
|
$filekey,
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'result' => 'Failure', 'stage' => 'assembling', 'status' => $status ]
|
2015-09-08 17:59:44 +00:00
|
|
|
);
|
2016-08-17 13:31:22 +00:00
|
|
|
$this->dieStatusWithCode( $status, 'stashfailed' );
|
2013-02-26 23:19:52 +00:00
|
|
|
}
|
|
|
|
|
|
2016-08-17 15:57:47 +00:00
|
|
|
// We can only get warnings like 'duplicate' after concatenating the chunks
|
|
|
|
|
$warnings = $this->getApiWarnings();
|
|
|
|
|
if ( $warnings ) {
|
|
|
|
|
$result['warnings'] = $warnings;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-26 23:19:52 +00:00
|
|
|
// The fully concatenated file has a new filekey. So remove
|
|
|
|
|
// the old filekey and fetch the new one.
|
2015-09-08 17:59:44 +00:00
|
|
|
UploadBase::setSessionStatus( $this->getUser(), $filekey, false );
|
2013-02-26 23:19:52 +00:00
|
|
|
$this->mUpload->stash->removeFile( $filekey );
|
2016-08-17 18:43:55 +00:00
|
|
|
$filekey = $this->mUpload->getStashFile()->getFileKey();
|
2013-02-26 23:19:52 +00:00
|
|
|
|
|
|
|
|
$result['result'] = 'Success';
|
2010-11-03 04:32:41 +00:00
|
|
|
}
|
2015-09-08 17:59:44 +00:00
|
|
|
} else {
|
|
|
|
|
UploadBase::setSessionStatus(
|
|
|
|
|
$this->getUser(),
|
|
|
|
|
$filekey,
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
2015-09-08 17:59:44 +00:00
|
|
|
'result' => 'Continue',
|
|
|
|
|
'stage' => 'uploading',
|
|
|
|
|
'offset' => $totalSoFar,
|
|
|
|
|
'status' => Status::newGood(),
|
2016-02-17 09:09:32 +00:00
|
|
|
]
|
2015-09-08 17:59:44 +00:00
|
|
|
);
|
|
|
|
|
$result['result'] = 'Continue';
|
|
|
|
|
$result['offset'] = $totalSoFar;
|
2010-11-03 04:32:41 +00:00
|
|
|
}
|
2015-09-08 17:59:44 +00:00
|
|
|
|
2013-02-26 23:19:52 +00:00
|
|
|
$result['filekey'] = $filekey;
|
2013-11-14 13:01:41 +00:00
|
|
|
|
2011-11-30 14:56:40 +00:00
|
|
|
return $result;
|
2010-07-28 17:31:32 +00:00
|
|
|
}
|
2012-10-10 23:15:29 +00:00
|
|
|
|
2010-11-03 04:32:41 +00:00
|
|
|
/**
|
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.
|
2019-11-23 22:28:57 +00:00
|
|
|
* @param array|null &$data API result to which to add the information
|
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 string|null File key
|
2010-11-03 04:32:41 +00:00
|
|
|
*/
|
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 ) {
|
2016-08-16 23:34:52 +00:00
|
|
|
$isPartial = (bool)$this->mParams['chunk'];
|
2010-11-03 04:32:41 +00:00
|
|
|
try {
|
2016-08-16 23:34:52 +00:00
|
|
|
$status = $this->mUpload->tryStashFile( $this->getUser(), $isPartial );
|
2011-10-05 13:47:02 +00:00
|
|
|
|
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...
|
2016-12-08 18:38:45 +00:00
|
|
|
$status->fatal( new ApiMessage( 'apierror-stashinvalidfile', 'stashfailed' ) );
|
2011-10-05 13:47:02 +00:00
|
|
|
}
|
2015-01-09 23:44:47 +00:00
|
|
|
} 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();
|
2020-06-01 05:00:39 +00:00
|
|
|
wfDebug( __METHOD__ . ' ' . $debugMessage );
|
2016-12-08 18:38:45 +00:00
|
|
|
$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;
|
2020-06-01 05:00:39 +00:00
|
|
|
wfDebug( __METHOD__ . ' ' . $debugMessage );
|
2010-11-03 04:32:41 +00:00
|
|
|
}
|
2013-11-14 13:01:41 +00:00
|
|
|
|
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 {
|
2016-10-19 16:54:25 +00:00
|
|
|
$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;
|
|
|
|
|
}
|
2010-11-03 04:32:41 +00:00
|
|
|
}
|
2011-06-29 23:46:39 +00:00
|
|
|
|
2011-03-25 21:22:02 +00:00
|
|
|
/**
|
2011-06-29 23:46:39 +00:00
|
|
|
* Throw an error that the user can recover from by providing a better
|
2011-03-25 21:22:02 +00:00
|
|
|
* value for $parameter
|
2011-06-29 23:46:39 +00:00
|
|
|
*
|
2016-10-19 16:54:25 +00:00
|
|
|
* @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
|
2021-09-08 19:12:49 +00:00
|
|
|
* @return never
|
2011-03-25 21:22:02 +00:00
|
|
|
*/
|
2016-10-19 16:54:25 +00:00
|
|
|
private function dieRecoverableError( $errors, $parameter = null ) {
|
2021-09-08 19:12:49 +00:00
|
|
|
// @phan-suppress-previous-line PhanTypeMissingReturn
|
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 );
|
2011-06-29 23:46:39 +00:00
|
|
|
|
2016-10-19 16:54:25 +00:00
|
|
|
if ( $parameter ) {
|
|
|
|
|
$data['invalidparameter'] = $parameter;
|
2016-06-17 15:20:11 +00:00
|
|
|
}
|
2015-10-19 12:30:40 +00:00
|
|
|
|
2016-10-19 16:54:25 +00:00
|
|
|
$sv = StatusValue::newGood();
|
|
|
|
|
foreach ( $errors as $error ) {
|
|
|
|
|
$msg = ApiMessage::create( $error );
|
|
|
|
|
$msg->setApiData( $msg->getApiData() + $data );
|
|
|
|
|
$sv->fatal( $msg );
|
|
|
|
|
}
|
|
|
|
|
$this->dieStatus( $sv );
|
2011-03-25 21:22:02 +00:00
|
|
|
}
|
2010-11-03 04:32:41 +00:00
|
|
|
|
2016-08-17 13:31:22 +00:00
|
|
|
/**
|
|
|
|
|
* 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
|
2016-10-19 16:54:25 +00:00
|
|
|
* @throws ApiUsageException
|
2021-09-08 19:12:49 +00:00
|
|
|
* @return never
|
2016-08-17 13:31:22 +00:00
|
|
|
*/
|
|
|
|
|
public function dieStatusWithCode( $status, $overrideCode, $moreExtraData = null ) {
|
2021-09-08 19:12:49 +00:00
|
|
|
// @phan-suppress-previous-line PhanTypeMissingReturn
|
2016-10-19 16:54:25 +00:00
|
|
|
$sv = StatusValue::newGood();
|
|
|
|
|
foreach ( $status->getErrors() as $error ) {
|
|
|
|
|
$msg = ApiMessage::create( $error, $overrideCode );
|
|
|
|
|
if ( $moreExtraData ) {
|
|
|
|
|
$msg->setApiData( $msg->getApiData() + $moreExtraData );
|
|
|
|
|
}
|
|
|
|
|
$sv->fatal( $msg );
|
2016-08-17 13:31:22 +00:00
|
|
|
}
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->dieStatus( $sv );
|
2016-08-17 13:31:22 +00:00
|
|
|
}
|
|
|
|
|
|
2010-07-28 17:31:32 +00:00
|
|
|
/**
|
2010-09-06 10:18:53 +00:00
|
|
|
* Select an upload module and set it to mUpload. Dies on failure. If the
|
2010-12-30 17:06:09 +00:00
|
|
|
* request was a status request and not a true upload, returns false;
|
2010-09-06 10:18:53 +00:00
|
|
|
* otherwise true
|
2010-12-30 17:06:09 +00:00
|
|
|
*
|
2010-09-06 10:18:53 +00:00
|
|
|
* @return bool
|
2019-10-12 12:30:37 +00:00
|
|
|
* @suppress PhanTypeArraySuspiciousNullable False positives
|
2010-07-28 17:31:32 +00:00
|
|
|
*/
|
|
|
|
|
protected function selectUploadModule() {
|
|
|
|
|
$request = $this->getMain()->getRequest();
|
2010-08-05 07:02:09 +00:00
|
|
|
|
2011-08-02 10:13:56 +00:00
|
|
|
// chunk or one and only one of the following parameters is needed
|
2012-11-19 08:07:50 +00:00
|
|
|
if ( !$this->mParams['chunk'] ) {
|
2011-08-02 10:13:56 +00:00
|
|
|
$this->requireOnlyOneParameter( $this->mParams,
|
2016-01-21 22:45:10 +00:00
|
|
|
'filekey', 'file', 'url' );
|
2011-11-10 20:50:21 +00:00
|
|
|
}
|
2010-07-27 21:53:52 +00:00
|
|
|
|
2012-12-04 02:18:48 +00:00
|
|
|
// Status report for "upload to stash"/"upload from stash"
|
2012-11-19 08:07:50 +00:00
|
|
|
if ( $this->mParams['filekey'] && $this->mParams['checkstatus'] ) {
|
2014-09-29 23:20:57 +00:00
|
|
|
$progress = UploadBase::getSessionStatus( $this->getUser(), $this->mParams['filekey'] );
|
2012-11-19 08:07:50 +00:00
|
|
|
if ( !$progress ) {
|
2019-03-26 21:44:05 +00:00
|
|
|
$this->dieWithError( 'apierror-upload-missingresult', 'missingresult' );
|
2012-11-19 08:07:50 +00:00
|
|
|
} elseif ( !$progress['status']->isGood() ) {
|
2016-08-17 13:31:22 +00:00
|
|
|
$this->dieStatusWithCode( $progress['status'], 'stashfailed' );
|
2012-11-19 08:07:50 +00:00
|
|
|
}
|
2012-12-04 02:18:48 +00:00
|
|
|
if ( isset( $progress['status']->value['verification'] ) ) {
|
|
|
|
|
$this->checkVerification( $progress['status']->value['verification'] );
|
|
|
|
|
}
|
2016-08-17 15:57:47 +00:00
|
|
|
if ( isset( $progress['status']->value['warnings'] ) ) {
|
|
|
|
|
$warnings = $this->transformWarnings( $progress['status']->value['warnings'] );
|
|
|
|
|
if ( $warnings ) {
|
|
|
|
|
$progress['warnings'] = $warnings;
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-11-19 08:07:50 +00:00
|
|
|
unset( $progress['status'] ); // remove Status object
|
2016-08-26 13:22:09 +00:00
|
|
|
$imageinfo = null;
|
|
|
|
|
if ( isset( $progress['imageinfo'] ) ) {
|
|
|
|
|
$imageinfo = $progress['imageinfo'];
|
|
|
|
|
unset( $progress['imageinfo'] );
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-19 08:07:50 +00:00
|
|
|
$this->getResult()->addValue( null, $this->getModuleName(), $progress );
|
2016-08-26 13:22:09 +00:00
|
|
|
// 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 );
|
|
|
|
|
}
|
2013-11-14 13:01:41 +00:00
|
|
|
|
2012-11-19 08:07:50 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-06 10:18:53 +00:00
|
|
|
// The following modules all require the filename parameter to be set
|
2020-01-09 23:48:34 +00:00
|
|
|
if ( $this->mParams['filename'] === null ) {
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->dieWithError( [ 'apierror-missingparam', 'filename' ] );
|
2010-09-06 10:18:53 +00:00
|
|
|
}
|
2010-12-30 17:06:09 +00:00
|
|
|
|
2011-11-30 14:56:40 +00:00
|
|
|
if ( $this->mParams['chunk'] ) {
|
|
|
|
|
// Chunk upload
|
2016-08-17 13:31:22 +00:00
|
|
|
$this->mUpload = new UploadFromChunks( $this->getUser() );
|
2013-04-19 18:03:05 +00:00
|
|
|
if ( isset( $this->mParams['filekey'] ) ) {
|
2015-09-08 17:59:44 +00:00
|
|
|
if ( $this->mParams['offset'] === 0 ) {
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->dieWithError( 'apierror-upload-filekeynotallowed', 'filekeynotallowed' );
|
2015-09-08 17:59:44 +00:00
|
|
|
}
|
|
|
|
|
|
2011-11-30 14:56:40 +00:00
|
|
|
// handle new chunk
|
|
|
|
|
$this->mUpload->continueChunks(
|
|
|
|
|
$this->mParams['filename'],
|
|
|
|
|
$this->mParams['filekey'],
|
|
|
|
|
$request->getUpload( 'chunk' )
|
|
|
|
|
);
|
|
|
|
|
} else {
|
2015-09-08 17:59:44 +00:00
|
|
|
if ( $this->mParams['offset'] !== 0 ) {
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->dieWithError( 'apierror-upload-filekeyneeded', 'filekeyneeded' );
|
2015-09-08 17:59:44 +00:00
|
|
|
}
|
|
|
|
|
|
2011-11-30 14:56:40 +00:00
|
|
|
// handle first chunk
|
|
|
|
|
$this->mUpload->initialize(
|
|
|
|
|
$this->mParams['filename'],
|
|
|
|
|
$request->getUpload( 'chunk' )
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
} elseif ( isset( $this->mParams['filekey'] ) ) {
|
2010-07-27 21:53:52 +00:00
|
|
|
// Upload stashed in a previous request
|
2011-07-12 21:11:43 +00:00
|
|
|
if ( !UploadFromStash::isValidKey( $this->mParams['filekey'] ) ) {
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->dieWithError( 'apierror-invalid-file-key' );
|
2010-02-26 13:18:56 +00:00
|
|
|
}
|
2010-01-22 04:37:23 +00:00
|
|
|
|
2011-10-26 23:27:01 +00:00
|
|
|
$this->mUpload = new UploadFromStash( $this->getUser() );
|
2012-12-04 02:18:48 +00:00
|
|
|
// 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']
|
|
|
|
|
);
|
2010-07-27 21:53:52 +00:00
|
|
|
} elseif ( isset( $this->mParams['file'] ) ) {
|
2017-01-26 17:26:38 +00:00
|
|
|
// Can't async upload directly from a POSTed file, we'd have to
|
|
|
|
|
// stash the file and then queue the publish job. The user should
|
|
|
|
|
// just submit the two API queries to perform those two steps.
|
|
|
|
|
if ( $this->mParams['async'] ) {
|
|
|
|
|
$this->dieWithError( 'apierror-cannot-async-upload-file' );
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-27 21:53:52 +00:00
|
|
|
$this->mUpload = new UploadFromFile();
|
|
|
|
|
$this->mUpload->initialize(
|
|
|
|
|
$this->mParams['filename'],
|
|
|
|
|
$request->getUpload( 'file' )
|
2010-08-05 07:02:09 +00:00
|
|
|
);
|
2010-07-27 21:53:52 +00:00
|
|
|
} elseif ( isset( $this->mParams['url'] ) ) {
|
|
|
|
|
// Make sure upload by URL is enabled:
|
2010-07-28 17:14:51 +00:00
|
|
|
if ( !UploadFromUrl::isEnabled() ) {
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->dieWithError( 'copyuploaddisabled' );
|
2010-07-27 21:53:52 +00:00
|
|
|
}
|
2010-08-05 07:02:09 +00:00
|
|
|
|
2012-02-09 23:22:38 +00:00
|
|
|
if ( !UploadFromUrl::isAllowedHost( $this->mParams['url'] ) ) {
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->dieWithError( 'apierror-copyuploadbaddomain' );
|
2012-02-09 23:22:38 +00:00
|
|
|
}
|
|
|
|
|
|
2013-05-23 10:16:38 +00:00
|
|
|
if ( !UploadFromUrl::isAllowedUrl( $this->mParams['url'] ) ) {
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->dieWithError( 'apierror-copyuploadbadurl' );
|
2013-05-23 10:16:38 +00:00
|
|
|
}
|
|
|
|
|
|
2010-07-28 17:14:51 +00:00
|
|
|
$this->mUpload = new UploadFromUrl;
|
|
|
|
|
$this->mUpload->initialize( $this->mParams['filename'],
|
2016-01-21 22:45:10 +00:00
|
|
|
$this->mParams['url'] );
|
2010-02-26 13:18:56 +00:00
|
|
|
}
|
2010-12-30 17:06:09 +00:00
|
|
|
|
2010-09-06 10:18:53 +00:00
|
|
|
return true;
|
2010-06-12 03:58:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Checks that the user has permissions to perform this upload.
|
|
|
|
|
* Dies with usage message on inadequate permissions.
|
2014-04-15 18:12:09 +00:00
|
|
|
* @param User $user The user to check.
|
2010-06-12 03:58:31 +00:00
|
|
|
*/
|
|
|
|
|
protected function checkPermissions( $user ) {
|
2009-07-15 00:55:58 +00:00
|
|
|
// Check whether the user has the appropriate permissions to upload anyway
|
2010-06-12 03:58:31 +00:00
|
|
|
$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
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( $permission !== true ) {
|
2020-12-17 23:10:11 +00:00
|
|
|
if ( !$user->isRegistered() ) {
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->dieWithError( [ 'apierror-mustbeloggedin', $this->msg( 'action-upload' ) ] );
|
2010-02-26 13:18:56 +00:00
|
|
|
}
|
2013-11-17 19:54:11 +00:00
|
|
|
|
2016-10-19 16:54:25 +00:00
|
|
|
$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
|
|
|
}
|
2016-04-29 14:21:13 +00:00
|
|
|
|
|
|
|
|
// Check blocks
|
2019-03-20 22:11:33 +00:00
|
|
|
if ( $user->isBlockedFromUpload() ) {
|
2016-04-29 14:21:13 +00:00
|
|
|
$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
|
|
|
}
|
2009-07-15 00:55:58 +00:00
|
|
|
|
2010-03-30 19:10:10 +00:00
|
|
|
/**
|
|
|
|
|
* Performs file verification, dies on error.
|
|
|
|
|
*/
|
2013-03-17 15:13:22 +00:00
|
|
|
protected function verifyUpload() {
|
2019-05-20 11:47:45 +00:00
|
|
|
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' );
|
|
|
|
|
}
|
|
|
|
|
// file will be assembled after having uploaded the last chunk,
|
|
|
|
|
// so we can only validate the name at this point
|
|
|
|
|
$verification = $this->mUpload->validateName();
|
|
|
|
|
if ( $verification === true ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
} elseif ( $this->mParams['async'] && $this->mParams['filekey'] ) {
|
|
|
|
|
// file will be assembled in a background process, so we
|
|
|
|
|
// can only validate the name at this point
|
|
|
|
|
// file verification will happen in background process
|
|
|
|
|
$verification = $this->mUpload->validateName();
|
|
|
|
|
if ( $verification === true ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
wfDebug( __METHOD__ . " about to verify" );
|
|
|
|
|
|
|
|
|
|
$verification = $this->mUpload->verifyUpload();
|
|
|
|
|
if ( $verification['status'] === UploadBase::OK ) {
|
|
|
|
|
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
|
|
|
}
|
2013-04-01 17:18:15 +00:00
|
|
|
|
|
|
|
|
$this->checkVerification( $verification );
|
2012-12-04 02:18:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Performs file verification, dies on error.
|
2014-08-14 18:22:52 +00:00
|
|
|
* @param array $verification
|
2021-09-08 19:12:49 +00:00
|
|
|
* @return never
|
2012-12-04 02:18:48 +00:00
|
|
|
*/
|
|
|
|
|
protected function checkVerification( array $verification ) {
|
2021-09-08 19:12:49 +00:00
|
|
|
// @phan-suppress-previous-line PhanTypeMissingReturn
|
2013-04-26 14:42:31 +00:00
|
|
|
switch ( $verification['status'] ) {
|
2011-03-25 21:22:02 +00:00
|
|
|
// Recoverable errors
|
|
|
|
|
case UploadBase::MIN_LENGTH_PARTNAME:
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->dieRecoverableError( [ 'filename-tooshort' ], 'filename' );
|
2021-09-03 22:25:13 +00:00
|
|
|
// dieRecoverableError prevents continuation
|
2011-03-25 21:22:02 +00:00
|
|
|
case UploadBase::ILLEGAL_FILENAME:
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->dieRecoverableError(
|
|
|
|
|
[ ApiMessage::create(
|
|
|
|
|
'illegal-filename', null, [ 'filename' => $verification['filtered'] ]
|
|
|
|
|
) ], 'filename'
|
|
|
|
|
);
|
2021-09-03 22:25:13 +00:00
|
|
|
// dieRecoverableError prevents continuation
|
2011-10-07 18:20:55 +00:00
|
|
|
case UploadBase::FILENAME_TOO_LONG:
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->dieRecoverableError( [ 'filename-toolong' ], 'filename' );
|
2021-09-03 22:25:13 +00:00
|
|
|
// dieRecoverableError prevents continuation
|
2011-03-25 21:22:02 +00:00
|
|
|
case UploadBase::FILETYPE_MISSING:
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->dieRecoverableError( [ 'filetype-missing' ], 'filename' );
|
2021-09-03 22:25:13 +00:00
|
|
|
// dieRecoverableError prevents continuation
|
2011-05-15 12:35:50 +00:00
|
|
|
case UploadBase::WINDOWS_NONASCII_FILENAME:
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->dieRecoverableError( [ 'windows-nonascii-filename' ], 'filename' );
|
2011-06-29 23:46:39 +00:00
|
|
|
|
2011-03-25 21:22:02 +00:00
|
|
|
// Unrecoverable errors
|
2010-03-30 19:10:10 +00:00
|
|
|
case UploadBase::EMPTY_FILE:
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->dieWithError( 'empty-file' );
|
2021-09-03 22:25:13 +00:00
|
|
|
// dieWithError prevents continuation
|
2010-04-15 09:28:33 +00:00
|
|
|
case UploadBase::FILE_TOO_LARGE:
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->dieWithError( 'file-too-large' );
|
2021-09-03 22:25:13 +00:00
|
|
|
// dieWithError prevents continuation
|
2011-03-25 21:22:02 +00:00
|
|
|
|
2010-03-30 19:10:10 +00:00
|
|
|
case UploadBase::FILETYPE_BADTYPE:
|
2016-02-17 09:09:32 +00:00
|
|
|
$extradata = [
|
2012-07-19 16:54:05 +00:00
|
|
|
'filetype' => $verification['finalExt'],
|
2014-01-24 02:51:11 +00:00
|
|
|
'allowed' => array_values( array_unique( $this->getConfig()->get( 'FileExtensions' ) ) )
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2016-10-19 16:54:25 +00:00
|
|
|
$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' );
|
2012-07-19 16:54:05 +00:00
|
|
|
|
|
|
|
|
if ( isset( $verification['blacklistedExt'] ) ) {
|
2016-10-19 16:54:25 +00:00
|
|
|
$msg[1] = Message::listParam( $verification['blacklistedExt'], 'comma' );
|
|
|
|
|
$msg[4] = count( $verification['blacklistedExt'] );
|
2012-07-19 16:54:05 +00:00
|
|
|
$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' );
|
2012-07-19 16:54:05 +00:00
|
|
|
} else {
|
2016-10-19 16:54:25 +00:00
|
|
|
$msg[1] = $verification['finalExt'];
|
|
|
|
|
$msg[4] = 1;
|
2012-07-19 16:54:05 +00:00
|
|
|
}
|
2016-10-19 16:54:25 +00:00
|
|
|
|
|
|
|
|
$this->dieWithError( $msg, 'filetype-banned', $extradata );
|
2021-09-03 22:25:13 +00:00
|
|
|
// dieWithError prevents continuation
|
2016-10-19 16:54:25 +00:00
|
|
|
|
2010-03-30 19:10:10 +00:00
|
|
|
case UploadBase::VERIFICATION_ERROR:
|
2016-10-19 16:54:25 +00:00
|
|
|
$msg = ApiMessage::create( $verification['details'], 'verification-error' );
|
|
|
|
|
if ( $verification['details'][0] instanceof MessageSpecifier ) {
|
2016-06-20 21:55:43 +00:00
|
|
|
$details = array_merge( [ $msg->getKey() ], $msg->getParams() );
|
|
|
|
|
} else {
|
|
|
|
|
$details = $verification['details'];
|
|
|
|
|
}
|
|
|
|
|
ApiResult::setIndexedTagName( $details, 'detail' );
|
2016-10-19 16:54:25 +00:00
|
|
|
$msg->setApiData( $msg->getApiData() + [ 'details' => $details ] );
|
2019-06-18 20:26:00 +00:00
|
|
|
// @phan-suppress-next-line PhanTypeMismatchArgument
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->dieWithError( $msg );
|
2021-09-03 22:25:13 +00:00
|
|
|
// dieWithError prevents continuation
|
2016-10-19 16:54:25 +00:00
|
|
|
|
2010-03-30 19:10:10 +00:00
|
|
|
case UploadBase::HOOK_ABORTED:
|
2017-01-18 00:48:59 +00:00
|
|
|
$msg = $verification['error'] === '' ? 'hookaborted' : $verification['error'];
|
|
|
|
|
$this->dieWithError( $msg, 'hookaborted', [ 'details' => $verification['error'] ] );
|
2021-09-03 22:25:13 +00:00
|
|
|
// dieWithError prevents continuation
|
2010-03-30 19:10:10 +00:00
|
|
|
default:
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->dieWithError( 'apierror-unknownerror-nocode', 'unknown-error',
|
|
|
|
|
[ 'details' => [ 'code' => $verification['status'] ] ] );
|
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
|
|
|
}
|
2010-03-30 19:10:10 +00:00
|
|
|
}
|
|
|
|
|
|
2010-07-28 17:31:32 +00:00
|
|
|
/**
|
2012-05-26 00:05:04 +00:00
|
|
|
* Check warnings.
|
2010-11-03 04:32:41 +00:00
|
|
|
* Returns a suitable array for inclusion into API results if there were warnings
|
|
|
|
|
* Returns the empty array if there were no warnings
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
2010-07-28 17:31:32 +00:00
|
|
|
*/
|
2010-11-03 04:32:41 +00:00
|
|
|
protected function getApiWarnings() {
|
2020-04-28 23:41:39 +00:00
|
|
|
$warnings = UploadBase::makeWarningsSerializable(
|
|
|
|
|
$this->mUpload->checkWarnings( $this->getUser() )
|
|
|
|
|
);
|
2012-05-26 00:05:04 +00:00
|
|
|
|
2011-05-15 14:46:13 +00:00
|
|
|
return $this->transformWarnings( $warnings );
|
|
|
|
|
}
|
2011-06-29 23:46:39 +00:00
|
|
|
|
2011-05-15 14:46:13 +00:00
|
|
|
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' );
|
2009-10-15 00:14:05 +00:00
|
|
|
|
2011-05-15 14:46:13 +00:00
|
|
|
if ( isset( $warnings['duplicate'] ) ) {
|
2020-10-27 17:31:39 +00:00
|
|
|
$dupes = array_column( $warnings['duplicate'], 'fileName' );
|
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' );
|
2011-05-15 14:46:13 +00:00
|
|
|
$warnings['duplicate'] = $dupes;
|
2010-09-06 10:18:53 +00:00
|
|
|
}
|
|
|
|
|
|
2011-05-15 14:46:13 +00:00
|
|
|
if ( isset( $warnings['exists'] ) ) {
|
|
|
|
|
$warning = $warnings['exists'];
|
|
|
|
|
unset( $warnings['exists'] );
|
2017-10-06 22:17:58 +00:00
|
|
|
$localFile = $warning['normalizedFile'] ?? $warning['file'];
|
2019-07-26 05:07:41 +00:00
|
|
|
$warnings[$warning['warning']] = $localFile['fileName'];
|
2011-05-15 14:46:13 +00:00
|
|
|
}
|
2016-08-24 07:29:24 +00:00
|
|
|
|
|
|
|
|
if ( isset( $warnings['no-change'] ) ) {
|
|
|
|
|
$file = $warnings['no-change'];
|
|
|
|
|
unset( $warnings['no-change'] );
|
|
|
|
|
|
|
|
|
|
$warnings['nochange'] = [
|
2019-07-26 05:07:41 +00:00
|
|
|
'timestamp' => wfTimestamp( TS_ISO_8601, $file['timestamp'] )
|
2016-08-24 07:29:24 +00:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( isset( $warnings['duplicate-version'] ) ) {
|
|
|
|
|
$dupes = [];
|
|
|
|
|
foreach ( $warnings['duplicate-version'] as $dupe ) {
|
|
|
|
|
$dupes[] = [
|
2019-07-26 05:07:41 +00:00
|
|
|
'timestamp' => wfTimestamp( TS_ISO_8601, $dupe['timestamp'] )
|
2016-08-24 07:29:24 +00:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
unset( $warnings['duplicate-version'] );
|
|
|
|
|
|
|
|
|
|
ApiResult::setIndexedTagName( $dupes, 'ver' );
|
|
|
|
|
$warnings['duplicateversions'] = $dupes;
|
|
|
|
|
}
|
2011-05-15 14:46:13 +00:00
|
|
|
}
|
2013-11-14 13:01:41 +00:00
|
|
|
|
2010-11-03 04:32:41 +00:00
|
|
|
return $warnings;
|
2010-09-06 10:18:53 +00:00
|
|
|
}
|
2010-03-30 19:10:10 +00:00
|
|
|
|
2014-10-24 19:33:05 +00:00
|
|
|
/**
|
|
|
|
|
* Handles a stash exception, giving a useful error to the user.
|
2016-12-08 18:38:45 +00:00
|
|
|
* @todo Internationalize the exceptions then get rid of this
|
2016-10-19 16:54:25 +00:00
|
|
|
* @param Exception $e
|
|
|
|
|
* @return StatusValue
|
2014-10-24 19:33:05 +00:00
|
|
|
*/
|
2016-10-19 16:54:25 +00:00
|
|
|
protected function handleStashException( $e ) {
|
2017-01-04 11:54:45 +00:00
|
|
|
switch ( get_class( $e ) ) {
|
2018-01-13 00:02:09 +00:00
|
|
|
case UploadStashFileNotFoundException::class:
|
2016-12-08 18:38:45 +00:00
|
|
|
$wrap = 'apierror-stashedfilenotfound';
|
|
|
|
|
break;
|
2018-01-13 00:02:09 +00:00
|
|
|
case UploadStashBadPathException::class:
|
2016-12-08 18:38:45 +00:00
|
|
|
$wrap = 'apierror-stashpathinvalid';
|
|
|
|
|
break;
|
2018-01-13 00:02:09 +00:00
|
|
|
case UploadStashFileException::class:
|
2016-12-08 18:38:45 +00:00
|
|
|
$wrap = 'apierror-stashfilestorage';
|
|
|
|
|
break;
|
2018-01-13 00:02:09 +00:00
|
|
|
case UploadStashZeroLengthFileException::class:
|
2016-12-08 18:38:45 +00:00
|
|
|
$wrap = 'apierror-stashzerolength';
|
|
|
|
|
break;
|
2018-01-13 00:02:09 +00:00
|
|
|
case UploadStashNotLoggedInException::class:
|
2016-10-19 16:54:25 +00:00
|
|
|
return StatusValue::newFatal( ApiMessage::create(
|
|
|
|
|
[ 'apierror-mustbeloggedin', $this->msg( 'action-upload' ) ], 'stashnotloggedin'
|
|
|
|
|
) );
|
2018-01-13 00:02:09 +00:00
|
|
|
case UploadStashWrongOwnerException::class:
|
2016-12-08 18:38:45 +00:00
|
|
|
$wrap = 'apierror-stashwrongowner';
|
|
|
|
|
break;
|
2018-01-13 00:02:09 +00:00
|
|
|
case UploadStashNoSuchKeyException::class:
|
2016-12-08 18:38:45 +00:00
|
|
|
$wrap = 'apierror-stashnosuchfilekey';
|
|
|
|
|
break;
|
2014-10-24 19:33:05 +00:00
|
|
|
default:
|
2016-12-08 18:38:45 +00:00
|
|
|
$wrap = [ 'uploadstash-exception', get_class( $e ) ];
|
|
|
|
|
break;
|
2014-10-24 19:33:05 +00:00
|
|
|
}
|
2016-12-08 18:38:45 +00:00
|
|
|
return StatusValue::newFatal(
|
|
|
|
|
$this->getErrorFormatter()->getMessageFromException( $e, [ 'wrap' => $wrap ] )
|
|
|
|
|
);
|
2014-10-24 19:33:05 +00:00
|
|
|
}
|
|
|
|
|
|
2010-07-28 17:31:32 +00:00
|
|
|
/**
|
|
|
|
|
* Perform the actual upload. Returns a suitable result array on success;
|
|
|
|
|
* dies on failure.
|
2011-09-21 16:36:43 +00:00
|
|
|
*
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param array $warnings Array of Api upload warnings
|
2011-09-21 16:36:43 +00:00
|
|
|
* @return array
|
2010-07-28 17:31:32 +00:00
|
|
|
*/
|
2012-05-26 00:05:04 +00:00
|
|
|
protected function performUpload( $warnings ) {
|
2009-11-22 15:14:19 +00:00
|
|
|
// Use comment as initial page text by default
|
2020-01-09 23:48:34 +00:00
|
|
|
if ( $this->mParams['text'] === null ) {
|
2009-11-22 15:14:19 +00:00
|
|
|
$this->mParams['text'] = $this->mParams['comment'];
|
2010-02-26 13:18:56 +00:00
|
|
|
}
|
2010-03-30 19:10:10 +00:00
|
|
|
|
2017-09-04 18:05:26 +00:00
|
|
|
/** @var LocalFile $file */
|
2010-03-30 19:10:10 +00:00
|
|
|
$file = $this->mUpload->getLocalFile();
|
2020-09-04 12:31:40 +00:00
|
|
|
$user = $this->getUser();
|
|
|
|
|
$title = $file->getTitle();
|
2013-11-08 18:01:28 +00:00
|
|
|
|
2020-09-04 12:31:40 +00:00
|
|
|
// for preferences mode, we want to watch if 'watchdefault' is set,
|
2013-11-07 02:50:01 +00:00
|
|
|
// 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.
|
2013-11-08 18:01:28 +00:00
|
|
|
$watch = $this->getWatchlistValue(
|
2020-09-04 12:31:40 +00:00
|
|
|
$this->mParams['watchlist'], $title, $user, 'watchdefault'
|
2013-11-08 18:01:28 +00:00
|
|
|
);
|
2013-11-07 02:50:01 +00:00
|
|
|
|
2013-11-08 18:01:28 +00:00
|
|
|
if ( !$watch && $this->mParams['watchlist'] == 'preferences' && !$file->exists() ) {
|
2013-11-07 02:50:01 +00:00
|
|
|
$watch = (
|
2020-09-04 12:31:40 +00:00
|
|
|
$this->getWatchlistValue( 'preferences', $title, $user, 'watchuploads' ) ||
|
|
|
|
|
$this->getWatchlistValue( 'preferences', $title, $user, 'watchcreations' )
|
2013-11-08 18:01:28 +00:00
|
|
|
);
|
|
|
|
|
}
|
2020-06-04 20:16:23 +00:00
|
|
|
$watchlistExpiry = $this->getExpiryFromParams( $this->mParams );
|
2010-03-30 19:10:10 +00:00
|
|
|
|
2010-03-25 22:15:08 +00:00
|
|
|
// Deprecated parameters
|
|
|
|
|
if ( $this->mParams['watch'] ) {
|
|
|
|
|
$watch = true;
|
|
|
|
|
}
|
2010-03-30 19:10:10 +00:00
|
|
|
|
2016-01-21 18:20:53 +00:00
|
|
|
if ( $this->mParams['tags'] ) {
|
2021-02-23 20:45:00 +00:00
|
|
|
$status = ChangeTags::canAddTagsAccompanyingChange( $this->mParams['tags'], $this->getAuthority() );
|
2016-01-21 18:20:53 +00:00
|
|
|
if ( !$status->isOK() ) {
|
|
|
|
|
$this->dieStatus( $status );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-26 19:38:38 +00:00
|
|
|
// No errors, no warnings: do the upload
|
2019-09-03 17:38:57 +00:00
|
|
|
$result = [];
|
2012-12-04 02:18:48 +00:00
|
|
|
if ( $this->mParams['async'] ) {
|
2014-09-29 23:20:57 +00:00
|
|
|
$progress = UploadBase::getSessionStatus( $this->getUser(), $this->mParams['filekey'] );
|
2012-12-04 02:18:48 +00:00
|
|
|
if ( $progress && $progress['result'] === 'Poll' ) {
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->dieWithError( 'apierror-upload-inprogress', 'publishfailed' );
|
2012-12-04 02:18:48 +00:00
|
|
|
}
|
|
|
|
|
UploadBase::setSessionStatus(
|
2014-09-29 23:20:57 +00:00
|
|
|
$this->getUser(),
|
2012-12-04 02:18:48 +00:00
|
|
|
$this->mParams['filekey'],
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'result' => 'Poll', 'stage' => 'queued', 'status' => Status::newGood() ]
|
2012-12-04 02:18:48 +00:00
|
|
|
);
|
2021-07-02 12:47:52 +00:00
|
|
|
$this->jobQueueGroup->push( new PublishStashedFileJob(
|
2013-02-13 21:25:37 +00:00
|
|
|
Title::makeTitle( NS_FILE, $this->mParams['filename'] ),
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
2013-04-14 19:57:46 +00:00
|
|
|
'filename' => $this->mParams['filename'],
|
|
|
|
|
'filekey' => $this->mParams['filekey'],
|
|
|
|
|
'comment' => $this->mParams['comment'],
|
2022-03-03 11:28:37 +00:00
|
|
|
'tags' => $this->mParams['tags'] ?? [],
|
2013-04-14 19:57:46 +00:00
|
|
|
'text' => $this->mParams['text'],
|
|
|
|
|
'watch' => $watch,
|
2020-06-04 20:16:23 +00:00
|
|
|
'watchlistexpiry' => $watchlistExpiry,
|
2013-04-14 19:57:46 +00:00
|
|
|
'session' => $this->getContext()->exportSession()
|
2016-02-17 09:09:32 +00:00
|
|
|
]
|
2013-02-13 21:25:37 +00:00
|
|
|
) );
|
2014-04-16 18:07:26 +00:00
|
|
|
$result['result'] = 'Poll';
|
2014-09-05 07:31:00 +00:00
|
|
|
$result['stage'] = 'queued';
|
2012-12-04 02:18:48 +00:00
|
|
|
} else {
|
2017-09-04 18:05:26 +00:00
|
|
|
/** @var Status $status */
|
2020-06-04 20:16:23 +00:00
|
|
|
$status = $this->mUpload->performUpload(
|
|
|
|
|
$this->mParams['comment'],
|
|
|
|
|
$this->mParams['text'],
|
|
|
|
|
$watch,
|
|
|
|
|
$this->getUser(),
|
2022-03-03 11:28:37 +00:00
|
|
|
$this->mParams['tags'] ?? [],
|
2020-06-04 20:16:23 +00:00
|
|
|
$watchlistExpiry
|
|
|
|
|
);
|
2012-12-04 02:18:48 +00:00
|
|
|
|
|
|
|
|
if ( !$status->isGood() ) {
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->dieRecoverableError( $status->getErrors() );
|
2010-07-29 13:53:51 +00:00
|
|
|
}
|
2012-12-04 02:18:48 +00:00
|
|
|
$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
|
|
|
}
|
2010-03-30 19:10:10 +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();
|
2012-05-26 00:05:04 +00:00
|
|
|
if ( $warnings && count( $warnings ) > 0 ) {
|
|
|
|
|
$result['warnings'] = $warnings;
|
|
|
|
|
}
|
2010-11-03 04:32:41 +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
|
|
|
return $result;
|
|
|
|
|
}
|
2011-06-29 23:46:39 +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
|
|
|
public function mustBePosted() {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-25 00:07:35 +00:00
|
|
|
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() {
|
2016-02-17 09:09:32 +00:00
|
|
|
$params = [
|
|
|
|
|
'filename' => [
|
2010-08-04 14:15:33 +00:00
|
|
|
ApiBase::PARAM_TYPE => 'string',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'comment' => [
|
2009-07-15 00:55:58 +00:00
|
|
|
ApiBase::PARAM_DFLT => ''
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'tags' => [
|
2016-01-21 18:20:53 +00:00
|
|
|
ApiBase::PARAM_TYPE => 'tags',
|
|
|
|
|
ApiBase::PARAM_ISMULTI => true,
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'text' => [
|
2015-05-07 16:39:55 +00:00
|
|
|
ApiBase::PARAM_TYPE => 'text',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'watch' => [
|
2010-03-25 22:15:08 +00:00
|
|
|
ApiBase::PARAM_DFLT => false,
|
|
|
|
|
ApiBase::PARAM_DEPRECATED => true,
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2020-06-04 20:16:23 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// Params appear in the docs in the order they are defined,
|
|
|
|
|
// which is why this is here and not at the bottom.
|
|
|
|
|
$params += $this->getWatchlistParams( [
|
|
|
|
|
'watch',
|
|
|
|
|
'preferences',
|
|
|
|
|
'nochange',
|
|
|
|
|
] );
|
|
|
|
|
|
|
|
|
|
$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
|
|
|
'ignorewarnings' => false,
|
2016-02-17 09:09:32 +00:00
|
|
|
'file' => [
|
2013-02-26 21:45:37 +00:00
|
|
|
ApiBase::PARAM_TYPE => 'upload',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2009-07-28 17:52:09 +00:00
|
|
|
'url' => null,
|
2011-07-12 21:11:43 +00:00
|
|
|
'filekey' => null,
|
2016-02-17 09:09:32 +00:00
|
|
|
'sessionkey' => [
|
2011-07-12 21:11:43 +00:00
|
|
|
ApiBase::PARAM_DEPRECATED => true,
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2010-11-03 04:32:41 +00:00
|
|
|
'stash' => false,
|
2011-02-10 18:24:19 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
'filesize' => [
|
2015-09-08 17:59:44 +00:00
|
|
|
ApiBase::PARAM_TYPE => 'integer',
|
|
|
|
|
ApiBase::PARAM_MIN => 0,
|
|
|
|
|
ApiBase::PARAM_MAX => UploadBase::getMaxUploadSize(),
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'offset' => [
|
2015-09-08 17:59:44 +00:00
|
|
|
ApiBase::PARAM_TYPE => 'integer',
|
|
|
|
|
ApiBase::PARAM_MIN => 0,
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'chunk' => [
|
2013-02-26 21:45:37 +00:00
|
|
|
ApiBase::PARAM_TYPE => 'upload',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2011-08-02 10:13:56 +00:00
|
|
|
|
2012-11-19 08:07:50 +00:00
|
|
|
'async' => false,
|
|
|
|
|
'checkstatus' => false,
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2010-08-05 07:02:09 +00:00
|
|
|
|
2009-08-27 14:46:54 +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
|
|
|
}
|
|
|
|
|
|
2010-10-01 20:12:50 +00:00
|
|
|
public function needsToken() {
|
2014-08-08 16:56:07 +00:00
|
|
|
return 'csrf';
|
2010-02-14 22:20:27 +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
|
|
|
|
2014-10-28 17:17:02 +00:00
|
|
|
protected function getExamplesMessages() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
2014-09-18 17:38:23 +00:00
|
|
|
'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',
|
2016-02-17 09:09:32 +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
|
|
|
}
|
|
|
|
|
|
2011-07-17 16:38:24 +00:00
|
|
|
public function getHelpUrls() {
|
2017-04-04 22:52:57 +00:00
|
|
|
return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Upload';
|
2011-07-17 16:38:24 +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
|
|
|
}
|