Zum Inhalt springen

„MediaWiki:Gadget-uploadtools.js“ – Versionsunterschied

aus Wikipedia, der freien Enzyklopädie
Inhalt gelöscht Inhalt hinzugefügt
K Standardtext für das Hochladeformular nach MediaWiki:Upload-default-description ausgelagert - https://de.wikipedia.org/w/index.php?title=Wikipedia:Projektneuheiten&curid=3180504#26._September
K updateTooltipAccessKeys ist deprecated, ersetzt - Leerzeichen und Zeilumbrüche zur besseren Lesbarkeit gesetzt - https://de.wikipedia.org/?oldid=138553538#updateTooltipAccessKeys_in_MediaWiki:Onlyifuploading.js
Zeile 1: Zeile 1:
/**
/**
* Ermöglicht eine Vorschau der Beschreibung auf [[Spezial:Hochladen]]
* Lädt die Informationsvorlage beim Hochladen direkt im Beschreibungsfeld
* siehe auch [[phab:T4537]]
* und ermöglicht eine Vorschau der Beschreibung auf [[Spezial:Hochladen]]
* wird in [[MediaWiki:Common.js]] eingebunden
* wird in [[MediaWiki:Common.js]] eingebunden
* Code von [[Benutzer:Schnark]]
* Code von [[Benutzer:Schnark]]
* <nowiki>
* <nowiki>
*/
*/
mw.loader.using( [ 'mediawiki.util', 'jquery.accessKeyLabel' ], function() { $( function() {
$(document).ready(function(){
var $editbox = $('#wpUploadDescription');
var $editbox = $( '#wpUploadDescription' );
if ($editbox.length != 1) return; // exits silently if not exactly one #wpUploadDescription is found
if ( $editbox.length !== 1 ) {
return; // exits silently if not exactly one #wpUploadDescription is found
}
var parseAsSummary; // Fallunterscheidung für Vorschaufunktion
var parseAsSummary; // Fallunterscheidung für Vorschaufunktion
if (mw.util.getParamValue('wpForReUpload') != '1') { // Kein Upload von neuer Dateiversion?
if ( mw.util.getParamValue( 'wpForReUpload' ) !== '1' ) { // Kein Upload von neuer Dateiversion?
parseAsSummary = false; // bei Upload der ersten Dateiversion wird eingegebener Text auf der Seite erscheinen
parseAsSummary = false; // bei Upload der ersten Dateiversion wird eingegebener Text auf der Seite erscheinen
} else {
} else {
Zeile 16: Zeile 18:
}
}


if (!mw.config.get('wgEnableAPI')) return;
if ( !mw.config.get( 'wgEnableAPI' ) ) {
return;
}
var previewText = 'Vorschau';
var previewText = 'Vorschau';
if ($('#mw-description-preview').length === 0) {
if ( $( '#mw-description-preview' ).length === 0 ) {
$('#mw-htmlform-description').before($(mw.html.element('div', {id: 'mw-description-preview'})));
$( '#mw-htmlform-description' ).before( $( mw.html.element( 'div', { id: 'mw-description-preview' } ) ) );
}
}
$('input[name="wpUpload"]').after($(mw.html.element('input', {value: previewText, type: 'button', id: 'wpPreview', title: previewText + ' [p]', accesskey: 'p'})).click(function(){
$( 'input[name="wpUpload"]' ).after( $( mw.html.element( 'input', {
value: previewText,
type: 'button',
id: 'wpPreview',
title: previewText,
accesskey: 'p'
})).click( function() {
if (typeof wikEd != 'undefined'&& wikEd.useWikEd) { // if WikEd is active
if ( typeof wikEd !== 'undefined' && wikEd.useWikEd ) { // if WikEd is active
wikEd.UpdateTextarea(); // transfer WikEd to $editbox
wikEd.UpdateTextarea(); // transfer WikEd to $editbox
}
}
var param = {action: 'parse',
var param = {action: 'parse',
title: 'Datei:' + ($('#wpDestFile').val() || 'Beispiel.jpg'), //Titel, Datei:Beispiel.jpg als Standard
title: 'Datei:' + ( $( '#wpDestFile' ).val() || 'Beispiel.jpg' ), //Titel, Datei:Beispiel.jpg als Standard
prop: 'text|categories|langlinks', //categories und langlinks noch nicht verwendet
prop: 'text',
pst: '',
pst: '',
text: '', //text wird benötigt, wenn title angegeben (bug 48319), wird eventuell überschrieben
text: '', //text wird benötigt, wenn title angegeben (bug 48319), wird eventuell überschrieben
format: 'json'};
format: 'json'};
param[ parseAsSummary ? 'summary' : 'text' ] = $editbox.val(); //Inhalt des Eingabefeldes entweder als Kommentar oder als Text parsen
param[ parseAsSummary ? 'summary' : 'text' ] = $editbox.val(); //Inhalt des Eingabefeldes entweder als Kommentar oder als Text parsen
$.getJSON(mw.util.wikiScript('api'), param, function (json) {
$.getJSON( mw.util.wikiScript( 'api' ), param, function ( json ) {
var content = parseAsSummary ? 'parsedsummary' : 'text'; //Geparster Inhalt entweder in parsedsummary oder in text
var content = parseAsSummary ? 'parsedsummary' : 'text'; //Geparster Inhalt entweder in parsedsummary oder in text
if (!json || !json.parse || !json.parse[content] || !json.parse[content]['*']) return;
if ( !json || !json.parse || !json.parse[content] || !json.parse[content]['*'] ) {
var html = '<p><strong>' + previewText + ':</strong><p>' + json.parse[content]['*'];
return;
}
var html = '<p><strong>' + previewText + ':</strong></p><div>' + json.parse[content]['*'] + '</div>';
$('#mw-description-preview').html(html);
$( '#mw-description-preview' ).html( html );
}); //getJSON
}); //getJSON
})); //click
})); //click
mw.util.updateTooltipAccessKeys($('#wpPreview'));
$( '#wpPreview' ).updateTooltipAccessKeys();
}); //ready
});}); //ready
//</nowiki>
//</nowiki>

Version vom 6. Februar 2015, 17:32 Uhr

/**
  * Ermöglicht eine Vorschau der Beschreibung auf [[Spezial:Hochladen]]
  * siehe auch [[phab:T4537]]
  * wird in [[MediaWiki:Common.js]] eingebunden
  * Code von [[Benutzer:Schnark]]
  * <nowiki>
  */
 mw.loader.using( [ 'mediawiki.util', 'jquery.accessKeyLabel' ], function() { $( function() {
  var $editbox = $( '#wpUploadDescription' );
  if ( $editbox.length !== 1 ) {
     return; // exits silently if not exactly one #wpUploadDescription is found
  }
  var parseAsSummary; // Fallunterscheidung für Vorschaufunktion
  if ( mw.util.getParamValue( 'wpForReUpload' ) !== '1' ) { // Kein Upload von neuer Dateiversion?
     parseAsSummary = false; // bei Upload der ersten Dateiversion wird eingegebener Text auf der Seite erscheinen
  } else {
     parseAsSummary = true; // bei Upload von neuer Dateiversion wird eingegebener Text nur im Log erscheinen
  }

  if ( !mw.config.get( 'wgEnableAPI' ) ) {
     return;
  }
  var previewText = 'Vorschau';
  if ( $( '#mw-description-preview' ).length === 0 ) {
     $( '#mw-htmlform-description' ).before( $( mw.html.element( 'div', { id: 'mw-description-preview' } ) ) );
  }
  $( 'input[name="wpUpload"]' ).after( $( mw.html.element( 'input', {
   value: previewText,
   type: 'button',
   id: 'wpPreview',
   title: previewText,
   accesskey: 'p'
  })).click( function() {
    if ( typeof wikEd !== 'undefined' && wikEd.useWikEd ) { // if WikEd is active
       wikEd.UpdateTextarea(); // transfer WikEd to $editbox
    }
    var param = {action: 'parse',
                 title: 'Datei:' + ( $( '#wpDestFile' ).val() || 'Beispiel.jpg' ), //Titel, Datei:Beispiel.jpg als Standard
                 prop: 'text',
                 pst: '',
                 text: '', //text wird benötigt, wenn title angegeben (bug 48319), wird eventuell überschrieben
                 format: 'json'};
    param[ parseAsSummary ? 'summary' : 'text' ] = $editbox.val(); //Inhalt des Eingabefeldes entweder als Kommentar oder als Text parsen
    $.getJSON( mw.util.wikiScript( 'api' ), param, function ( json ) {
       var content = parseAsSummary ? 'parsedsummary' : 'text'; //Geparster Inhalt entweder in parsedsummary oder in text
       if ( !json || !json.parse || !json.parse[content] || !json.parse[content]['*'] ) {
          return;
       }
       var html = '<p><strong>' + previewText + ':</strong></p><div>' + json.parse[content]['*'] + '</div>';
       $( '#mw-description-preview' ).html( html );
    }); //getJSON
  })); //click
  $( '#wpPreview' ).updateTooltipAccessKeys();
 });}); //ready
//</nowiki>