$wgUseInstantCommons = false;
/**
- * Array of foreign file repos (set in $wgForeignFileRepos above) that
+ * Array of foreign file repo names (set in $wgForeignFileRepos above) that
* are allowable upload targets. These wikis must have some method of
* authentication (i.e. CentralAuth), and be CORS-enabled for this wiki.
+ *
+ * Example:
+ * $wgForeignUploadTargets = array( 'shared' );
*/
$wgForeignUploadTargets = array();
'wgResourceLoaderStorageEnabled' => $conf->get( 'ResourceLoaderStorageEnabled' ),
'wgResourceLoaderLegacyModules' => self::getLegacyModules(),
'wgForeignUploadTargets' => $conf->get( 'ForeignUploadTargets' ),
+ 'wgEnableUploads' => $conf->get( 'EnableUploads' ),
);
Hooks::run( 'ResourceLoaderGetConfigVars', array( &$vars ) );
* var uploadDialog = new mw.Upload.Dialog( {
* bookletClass: mw.ForeignStructuredUpload.BookletLayout,
* booklet: {
- * targetHost: 'localhost:8080'
+ * target: 'local'
* }
* } );
* var windowManager = new OO.ui.WindowManager();
* @class mw.ForeignStructuredUpload.BookletLayout
* @uses mw.ForeignStructuredUpload
* @extends mw.Upload.BookletLayout
- * @cfg {string} [targetHost] Used to set up the target wiki.
+ * @cfg {string} [target] Used to choose the target repository.
* If nothing is passed, the {@link mw.ForeignUpload#property-target default} is used.
*/
mw.ForeignStructuredUpload.BookletLayout = function ( config ) {
// Parent constructor
mw.ForeignStructuredUpload.BookletLayout.parent.call( this, config );
- this.targetHost = config.targetHost;
+ this.target = config.target;
};
/* Setup */
/**
* Returns a {@link mw.ForeignStructuredUpload mw.ForeignStructuredUpload}
- * with the {@link #cfg-targetHost targetHost} specified in config.
+ * with the {@link #cfg-target target} specified in config.
*
* @protected
* @return {mw.Upload}
*/
mw.ForeignStructuredUpload.BookletLayout.prototype.createUpload = function () {
- return new mw.ForeignStructuredUpload( this.targetHost );
+ return new mw.ForeignStructuredUpload( this.target );
};
/* Form renderers */
* @inheritdoc
*/
mw.ForeignStructuredUpload.BookletLayout.prototype.renderUploadForm = function () {
- var fieldset,
- targets = mw.config.get( 'wgForeignUploadTargets' ),
- // Default to using local, but try to use a configured target.
- // TODO allow finer configuration of this somehow?
- target = ( targets && targets.length ) ? targets[ 0 ] : 'local',
- $ownWorkMessage = $( '<p>' ).html(
- mw.message( 'foreign-structured-upload-form-label-own-work-message-' + target ).parse()
- ),
- $notOwnWorkMessage = $( '<div>' ).append(
- $( '<p>' ).html(
- mw.message( 'foreign-structured-upload-form-label-not-own-work-message-' + target ).parse()
- ),
- $( '<p>' ).html(
- mw.message( 'foreign-structured-upload-form-label-not-own-work-local-' + target ).parse()
- )
- ),
+ var fieldset, $ownWorkMessage, $notOwnWorkMessage,
+ ownWorkMessage, notOwnWorkMessage, notOwnWorkLocal,
+ validTargets = mw.config.get( 'wgForeignUploadTargets' ),
+ target = this.target || validTargets[ 0 ] || 'local',
layout = this;
+ // foreign-structured-upload-form-label-own-work-message-local
+ // foreign-structured-upload-form-label-own-work-message-shared
+ ownWorkMessage = mw.message( 'foreign-structured-upload-form-label-own-work-message-' + target );
+ // foreign-structured-upload-form-label-not-own-work-message-local
+ // foreign-structured-upload-form-label-not-own-work-message-shared
+ notOwnWorkMessage = mw.message( 'foreign-structured-upload-form-label-not-own-work-message-' + target );
+ // foreign-structured-upload-form-label-not-own-work-local-local
+ // foreign-structured-upload-form-label-not-own-work-local-shared
+ notOwnWorkLocal = mw.message( 'foreign-structured-upload-form-label-not-own-work-local-' + target );
+
+ if ( !ownWorkMessage.exists() ) {
+ ownWorkMessage = mw.message( 'foreign-structured-upload-form-label-own-work-message-default' );
+ }
+ if ( !notOwnWorkMessage.exists() ) {
+ notOwnWorkMessage = mw.message( 'foreign-structured-upload-form-label-not-own-work-message-default' );
+ }
+ if ( !notOwnWorkLocal.exists() ) {
+ notOwnWorkLocal = mw.message( 'foreign-structured-upload-form-label-not-own-work-local-default' );
+ }
+
+ $ownWorkMessage = $( '<p>' ).html( ownWorkMessage.parse() );
+ $notOwnWorkMessage = $( '<div>' ).append(
+ $( '<p>' ).html( notOwnWorkMessage.parse() ),
+ $( '<p>' ).html( notOwnWorkLocal.parse() )
+ );
+ $ownWorkMessage.add( $notOwnWorkMessage ).find( 'a' ).attr( 'target', '_blank' );
+
this.selectFileWidget = new OO.ui.SelectFileWidget();
this.messageLabel = new OO.ui.LabelWidget( {
label: $notOwnWorkMessage
*
* @inheritdoc
*/
- function ForeignStructuredUpload( targetHost, apiconfig ) {
+ function ForeignStructuredUpload( target, apiconfig ) {
this.date = undefined;
this.descriptions = [];
this.categories = [];
- mw.ForeignUpload.call( this, targetHost, apiconfig );
+ mw.ForeignUpload.call( this, target, apiconfig );
}
OO.inheritClass( ForeignStructuredUpload, mw.ForeignUpload );
* @param {string} [target] Used to set up the target
* wiki. If not remote, this class behaves identically to mw.Upload (unless further subclassed)
* Use the same names as set in $wgForeignFileRepos for this. Also,
- * make sure there is an entry in the $wgForeignUploadTargets array
- * set to "true" for this name.
+ * make sure there is an entry in the $wgForeignUploadTargets array for this name.
* @param {Object} [apiconfig] Passed to the constructor of mw.ForeignApi or mw.Api, as needed.
*/
function ForeignUpload( target, apiconfig ) {
- var api, upload = this;
+ var api,
+ validTargets = mw.config.get( 'wgForeignUploadTargets' ),
+ upload = this;
if ( typeof target === 'object' ) {
// target probably wasn't passed in, it must
target = undefined;
}
- this.target = target;
+ // * Use the given `target` first;
+ // * If not given, fall back to default (first) ForeignUploadTarget;
+ // * If none is configured, fall back to local uploads.
+ this.target = target || validTargets[ 0 ] || 'local';
// Now we have several different options.
// If the local wiki is the target, then we can skip a bunch of steps
// to confirm that the target is one that this site is configured to
// support.
if ( this.target === 'local' ) {
+ // If local uploads were requested, but they are disabled, fail.
+ if ( !mw.config.get( 'wgEnableUploads' ) ) {
+ throw new Error( 'Local uploads are disabled' );
+ }
// We'll ignore the CORS and centralauth stuff if the target is
// the local wiki.
this.apiPromise = $.Deferred().resolve( new mw.Api( apiconfig ) );
// Skip repos that are not our target, or if they
// are the target, cannot be uploaded to.
- if ( repo.name === upload.target && repo.canUpload ) {
+ if ( repo.name === upload.target && repo.canUpload === '' ) {
return new mw.ForeignApi(
repo.scriptDirUrl + '/api.php',
apiconfig
}
}
- // Second pass - none of the configured repos were our
- // passed-in target, just look for the first one that would
- // work.
- for ( i in repos ) {
- repo = repos[ i ];
-
- if ( repo.canUpload ) {
- return new mw.ForeignApi(
- repo.scriptDirUrl + '/api.php',
- apiconfig
- );
- }
- }
-
- // No luck finding the correct foreign repo, default to local.
- return $.Deferred().resolve( new mw.Api( apiconfig ) );
+ throw new Error( 'Can not upload to requested foreign repo' );
} );
}
*
* Most wikis use "shared" to refer to Wikimedia Commons, we assume that
* in this class and in the messages linked to it.
+ *
+ * Defaults to the first available foreign upload target,
+ * or to local uploads if no foreign target is configured.
*/
/**