„MediaWiki:Gadget-uploadtools.js“ – Versionsunterschied
Erscheinungsbild
Inhalt gelöscht Inhalt hinzugefügt
Hgzh (Diskussion | Beiträge) leichte Anpassungen |
Hgzh (Diskussion | Beiträge) neue Version; Autor: user:PerfektesChaos |
||
Zeile 1: | Zeile 1: | ||
/// uploadtools.js for [[Special:Upload]] |
|||
/** |
|||
// Preset with raw Template:Information, preview of description |
|||
* Ermöglicht eine Vorschau der Beschreibung auf [[Spezial:Hochladen]] |
|||
// Vorschau der Beschreibung auf [[Spezial:Hochladen]] |
|||
* siehe auch [[phab:T4537]] |
|||
// see also [[phab:T4537]] |
|||
// Code von [[Benutzer:Schnark]] 2011 |
|||
* <nowiki> |
|||
// PerfektesChaos@de.wikipedia 2025-03 |
|||
*/ |
|||
/// <nowiki> |
|||
$( function() { |
|||
/* global window: false */ |
|||
var $editbox = $( '#wpUploadDescription' ); |
|||
/* jshint forin: false, |
|||
if ( $editbox.length !== 1 ) { |
|||
bitwise:true, curly:true, eqeqeq:true, latedef:true, |
|||
return; // exits silently if not exactly one #wpUploadDescription is found |
|||
laxbreak:true, |
|||
} |
|||
nocomma:true, strict:true, undef:true, unused:true */ |
|||
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 |
|||
} |
|||
var previewText = 'Vorschau'; |
|||
if ( $( '#mw-description-preview' ).length === 0 ) { |
|||
( function ( mw, $ ) { |
|||
$( '#mw-htmlform-description' ).before( $( mw.html.element( 'div', { id: 'mw-description-preview' } ) ) ); |
|||
"use strict"; |
|||
} |
|||
var UPLT = { API: { Api: false }, |
|||
$( 'input[name="wpUpload"]' ).after( $( mw.html.element( 'input', { |
|||
I18N: { }, |
|||
value: previewText, |
|||
light: true, // new version of existing file |
|||
type: 'button', |
|||
self: "gadget-uploadtools", |
|||
id: 'wpPreview', |
|||
selDesc: "#wpUploadDescription", |
|||
title: previewText, |
|||
selFormD: "#mw-htmlform-description", |
|||
accesskey: 'p' |
|||
selTitle: "#wpDestFile", |
|||
})).click( function() { |
|||
selTprint: "#t-print a", |
|||
if ( typeof window.wikEd !== 'undefined' && window.wikEd.useWikEd ) { // if WikEd is active |
|||
sequel: "wpForReUpload", |
|||
window.wikEd.UpdateTextarea(); // transfer WikEd to $editbox |
|||
site: false, |
|||
} |
|||
slang: false, |
|||
submit: "wpUpload", |
|||
title: 'Datei:' + ( $( '#wpDestFile' ).val() || 'Beispiel.jpg' ), //Titel, Datei:Beispiel.jpg als Standard |
|||
preload: { }, |
|||
preview: { css: { "border-color": "#808080", |
|||
"border-style": "dotted", |
|||
"border-width": "2px", |
|||
param[ parseAsSummary ? 'summary' : 'text' ] = $editbox.val(); //Inhalt des Eingabefeldes entweder als Kommentar oder als Text parsen |
|||
"margin-bottom": "1.5em", |
|||
$.getJSON( mw.util.wikiScript( 'api' ), param, function ( json ) { |
|||
"margin-top": "0.5em", |
|||
var content = parseAsSummary ? 'parsedsummary' : 'text'; //Geparster Inhalt entweder in parsedsummary oder in text |
|||
"padding-bottom": "0.5em", |
|||
if ( !json || !json.parse || !json.parse[content] || !json.parse[content]['*'] ) { |
|||
"padding-left": "1em", |
|||
return; |
|||
"padding-right": "1em", |
|||
} |
|||
"padding-top": "0.5em" }, |
|||
var html = '<p><strong>' + previewText + ':</strong></p><div>' + json.parse[content]['*'] + '</div>'; |
|||
show: false, |
|||
$( '#mw-description-preview' ).html( html ); |
|||
sign: false, |
|||
}); //getJSON |
|||
$button: false, |
|||
})); //click |
|||
$div: false, |
|||
$( '#t-print a' ).removeAttr( 'accesskey' ); // T58786 |
|||
$headline: false |
|||
$( '#t-print a, #wpPreview' ).updateTooltipAccessKeys(); |
|||
}, |
|||
}); //ready |
|||
wiki: false, |
|||
//</nowiki> |
|||
$editbox: false, |
|||
$filename: false }; |
|||
UPLT.I18N.projects = { |
|||
"dewiki": {"seek": "{{ *[Ii]nformation", |
|||
"source": "{{Information\n" + |
|||
" |Beschreibung = \n" + |
|||
" |Quelle = \n" + |
|||
" |Urheber = \n" + |
|||
" |Datum = \n" + |
|||
" |Genehmigung = \n" + |
|||
" |Andere Versionen = \n" + |
|||
" |Anmerkungen = \n" + |
|||
"}}"}, |
|||
"enwiki": {"seek": "{{ *(?:[Tt]emplate:)? *[Ii]nformation", |
|||
"source": "{{Information\n" + |
|||
" |description = \n" + |
|||
" |date = \n" + |
|||
" |source = \n" + |
|||
" |author = \n" + |
|||
" |permission = \n" + |
|||
" |other_versions = \n" + |
|||
" |additional_information = \n" + |
|||
"}}"} |
|||
}; // .I18N.projects |
|||
UPLT.I18N.texts = { |
|||
"show": {"en": "Preview", |
|||
"bg": "Предварителен преглед", |
|||
"da": "Forhåndsvisning", |
|||
"de": "Vorschau", |
|||
"dsb": "Pśeglěd", |
|||
"ee": "Kpɔe do ŋgɔ", |
|||
"el": "Προεπισκόπηση", |
|||
"es": "Previsualizar", |
|||
"et": "Eelvaade", |
|||
"eu": "Aurrebista erakutsi", |
|||
"fi": "Esikatselu", |
|||
"fr": "Prévisualisation", |
|||
"ga": "Réamhamharc", |
|||
"hi": "पूर्वावलोकन", |
|||
"hr": "Pretpregled", |
|||
"hsb": "Přehlad", |
|||
"hu": "Előnézet", |
|||
"id": "Pratayang", |
|||
"is": "Forskoða", |
|||
"it": "Anteprima", |
|||
"ka": "წინასწარი გადახედვა", |
|||
"kl": "Isikkua", |
|||
"km": "មើលជាមុន", |
|||
"kv": "Водзвыв видзӧдлӧм", |
|||
"lb": "Kucken ouni ofzespäicheren", |
|||
"lt": "Peržiūra", |
|||
"lv": "Pirmskats", |
|||
"mg": "Topi-maso", |
|||
"mo": "Превизуализязэ", |
|||
"mt": "Dehra proviżorja", |
|||
"nb": "Forhåndsvisning", |
|||
"nl": "Voorvertoning", |
|||
"nn": "Førehandsvising", |
|||
"pl": "Podgląd", |
|||
"pt": "Antevisão", |
|||
"rm": "Prevista", |
|||
"ro": "Previzualizare", |
|||
"ru": "Предпросмотр", |
|||
"sq": "Shqyrto", |
|||
"sr-ec": "Претпреглед", |
|||
"sr-el": "Pretpregled", |
|||
"sv": "Förhandsgranskning", |
|||
"tr": "Önizleme", |
|||
"uk": "Попередній перегляд", |
|||
"vi": "Xem trước"} |
|||
}; // .I18N.texts |
|||
function fair( apply ) { |
|||
// Synchronize textarea and overlay |
|||
// Precondition: |
|||
// apply -- true: Update textarea -- else: Update overlay |
|||
UPLT.codeMirror( apply ); |
|||
UPLT.wikEd( apply ); |
|||
} // fair() |
|||
function features() { |
|||
// Equip page |
|||
// Precondition: |
|||
// DOM ready |
|||
var submit = "input[name=\"" + UPLT.submit + "\"]", |
|||
$button = $( submit ), |
|||
$descr = $( UPLT.selFormD ), |
|||
sign, $tbPrint; |
|||
UPLT.$editbox = $( UPLT.selDesc ); |
|||
UPLT.$filename = $( UPLT.selTitle ); |
|||
if ( $button.length === 1 && |
|||
$descr.length === 1 && |
|||
UPLT.$editbox.length === 1 && |
|||
UPLT.$filename.length === 1 ) { |
|||
sign = UPLT.self + "-preview"; |
|||
UPLT.preview.$div = $( "." + sign ); |
|||
if ( ! UPLT.preview.$div.length ) { |
|||
UPLT.preview.$div = $( "<div>" ); |
|||
UPLT.preview.$div.addClass( sign ) |
|||
.css( UPLT.preview.css ) |
|||
.hide(); |
|||
$descr.before( UPLT.preview.$div ); |
|||
$tbPrint = $( UPLT.selTprint ); |
|||
$tbPrint.removeAttr( "accesskey" ) // T58786 |
|||
.updateTooltipAccessKeys(); |
|||
UPLT.preview.factory(); |
|||
$button.after( UPLT.preview.$button ); |
|||
UPLT.preload.fill(); |
|||
} |
|||
} |
|||
} // features() |
|||
function fire() { |
|||
// Resources completed |
|||
// Precondition: |
|||
// mediawiki.util |
|||
if ( mw.util.getParamValue( UPLT.sequel ) !== "1" ) { |
|||
UPLT.light = false; |
|||
} |
|||
$( features ); |
|||
} // fire() |
|||
function first() { |
|||
// Autorun on loading |
|||
var env = mw.config.get( [ "wgCanonicalSpecialPageName", |
|||
"wgDBname", |
|||
"wgUserLanguage" ] ); |
|||
if ( env.wgCanonicalSpecialPageName === "Upload" ) { |
|||
UPLT.site = env.wgDBname; |
|||
UPLT.slang = env.wgUserLanguage.toLowerCase(); |
|||
if ( typeof UPLT.I18N.projects[ UPLT.site ] === "object" ) { |
|||
UPLT.wiki = UPLT.I18N.projects[ UPLT.site ]; |
|||
} |
|||
mw.loader.using( [ "mediawiki.api", |
|||
"mediawiki.util" ], |
|||
fire ); |
|||
} |
|||
} // first() |
|||
UPLT.codeMirror = function ( apply ) { |
|||
// Execute function iff CodeMirror is active |
|||
// Precondition: |
|||
// apply -- true: Update textarea -- else: Update CM.doc |
|||
var doc, story; |
|||
if ( typeof window.CodeMirror !== "undefined" |
|||
&& window.CodeMirror |
|||
&& window.CodeMirror.getDoc() ) { |
|||
doc = window.CodeMirror.getDoc(); |
|||
if ( apply ) { |
|||
story = doc.getValue(); |
|||
UPLT.$editbox.val( story ); |
|||
} else { |
|||
story = UPLT.$editbox.val(); |
|||
doc.setValue( story ); |
|||
} |
|||
} |
|||
}; // .codeMirror() |
|||
UPLT.wikEd = function ( apply ) { |
|||
// Execute function iff wikEd is active |
|||
// Precondition: |
|||
// apply -- true: UpdateTextarea -- else: UpdateFrame |
|||
if ( typeof window.wikEd !== "undefined" |
|||
&& window.wikEd |
|||
&& window.wikEd.useWikEd ) { |
|||
window.wikEd[ ( apply ? "UpdateTextarea" |
|||
: "UpdateFrame" ) ](); |
|||
} |
|||
}; // .wikEd() |
|||
UPLT.preload.fill = function () { |
|||
var less, re, story; |
|||
if ( ! UPLT.light |
|||
&& UPLT.wiki && |
|||
typeof UPLT.wiki.source === "string" ) { |
|||
fair( true ); |
|||
story = UPLT.$editbox.val(); |
|||
if ( story ) { |
|||
if ( typeof UPLT.wiki.seek === "string" ) { |
|||
re = new RegExp( UPLT.wiki.seek ); |
|||
less = ! re.test( story ); |
|||
} |
|||
} else { |
|||
less = true; |
|||
} |
|||
if ( less ) { |
|||
story = UPLT.wiki.source + |
|||
( story ? "\n" + story : "" ); |
|||
UPLT.$editbox.val( story ); |
|||
fair(); |
|||
} |
|||
} |
|||
}; // .preload.fill() |
|||
UPLT.preview.factory = function () { |
|||
// Create preview button |
|||
// Postcondition: |
|||
// Button is defined |
|||
var entry = UPLT.I18N.texts.show, |
|||
slang, sub; |
|||
if ( typeof entry[ UPLT.slang ] === "string" ) { |
|||
UPLT.preview.show = entry[ UPLT.slang ]; |
|||
} else { |
|||
switch ( UPLT.slang ) { |
|||
case "als": |
|||
case "bar": |
|||
case "de": |
|||
case "de-at": |
|||
case "de-ch": |
|||
case "de-formal": |
|||
case "de-x-formal": |
|||
case "dsb": |
|||
case "frr": |
|||
case "gsw": |
|||
case "hsb": |
|||
case "ksh": |
|||
case "lb": |
|||
case "nds": |
|||
case "pdc": |
|||
case "pdt": |
|||
case "pfl": |
|||
case "sli": |
|||
case "stq": |
|||
case "vmf": |
|||
slang = "de"; |
|||
sub = "de"; |
|||
break; |
|||
case "pt-br": |
|||
slang = "pt"; |
|||
sub = "pt"; |
|||
break; |
|||
} // switch UPLT.slang |
|||
if ( typeof entry[ sub ] === "string" ) { |
|||
UPLT.preview.show = entry[ sub ]; |
|||
} else { |
|||
UPLT.preview.show = entry.en; |
|||
slang = "en"; |
|||
} |
|||
} |
|||
UPLT.preview.$button = $( "<input>" ); |
|||
UPLT.preview.$button.addClass( UPLT.self + "-button" ) |
|||
.attr( { "accesskey": "p", |
|||
"title": UPLT.preview.show, |
|||
"type": "button", |
|||
"value": UPLT.preview.show } ) |
|||
.css( { "margin-left": "1em", |
|||
"margin-right": "1em" } ) |
|||
.on( "click", UPLT.preview.fired ) |
|||
.updateTooltipAccessKeys(); |
|||
if ( slang && slang !== UPLT.slang ) { |
|||
UPLT.preview.$button.attr( "lang", slang ); |
|||
} |
|||
}; // .preview.factory() |
|||
UPLT.preview.fill = function ( arrived ) { |
|||
// Show preview |
|||
// Precondition: |
|||
// arrived -- (string) HTML |
|||
var $preview = $( "<div>" ); |
|||
if ( ! UPLT.$headline ) { |
|||
UPLT.preview.$headline = $( "<div>" ); |
|||
UPLT.preview.$headline.attr( { "title": UPLT.preview.show } ) |
|||
.css( { "font-size": "150%", |
|||
"font-weight": "bold", |
|||
"padding-bottom": "1em" } ) |
|||
.text( UPLT.preview.show ); |
|||
} |
|||
$preview.html( arrived ); |
|||
UPLT.preview.$div.append( UPLT.preview.$headline, $preview ) |
|||
.show(); |
|||
}; // .preview.fill() |
|||
UPLT.preview.fired = function () { |
|||
// Preview button has been clicked |
|||
var send = UPLT.$filename.val(), |
|||
story; |
|||
UPLT.preload.fill(); |
|||
fair( true ); |
|||
story = UPLT.$editbox.val(); |
|||
if ( UPLT.preview.$headline ) { |
|||
UPLT.preview.$div.hide(); |
|||
UPLT.preview.$headline.detach(); |
|||
UPLT.preview.$div.empty(); |
|||
} |
|||
UPLT.API.fetch( story, send ); |
|||
}; // .preview.fired() |
|||
UPLT.API.fault = function ( jqXHR, textStatus, errorThrown ) { |
|||
// API failure |
|||
var s; |
|||
if ( textStatus ) { |
|||
switch ( typeof textStatus ) { |
|||
case "object": |
|||
if ( typeof textStatus.textStatus === "string" ) { |
|||
s = textStatus.textStatus; |
|||
} else { |
|||
s = ""; |
|||
} |
|||
if ( typeof textStatus.exception === "string" |
|||
&& textStatus.exception ) { |
|||
s = s + " (" + textStatus.exception + ")"; |
|||
} |
|||
break; |
|||
case "string": |
|||
s = textStatus; |
|||
break; |
|||
} // switch typeof textStatus |
|||
} |
|||
if ( errorThrown ) { |
|||
if ( s ) { |
|||
s = s + " -- Error: "; |
|||
} |
|||
s = s + errorThrown; |
|||
} |
|||
if ( ! s ) { |
|||
s = "???"; |
|||
} |
|||
if ( typeof window.console === "object" && |
|||
typeof window.console.log === "function" ) { |
|||
window.console.log( UPLT.self + " * " + s ); |
|||
if ( typeof textStatus === "object" |
|||
&& textStatus && |
|||
typeof window.console.dir === "function" ) { |
|||
window.console.dir( textStatus ); |
|||
} |
|||
} |
|||
}; // .API.fault() |
|||
UPLT.API.fetch = function ( ask, about ) { |
|||
// Request parsing |
|||
// Precondition: |
|||
// ask -- wikitext |
|||
// about -- file title |
|||
var s = ( UPLT.light ? "summary" : "text" ); |
|||
if ( ! UPLT.API.Api ) { |
|||
UPLT.API.Api = new mw.Api(); |
|||
UPLT.API.params = { action: "parse", |
|||
contentmodel: "wikitext", |
|||
format: "json", |
|||
prop : "text" /*, |
|||
pst: "" */ |
|||
}; |
|||
} |
|||
UPLT.API.params.title = "File:" + ( about ? about |
|||
: "JustAnExample.JPG" ); |
|||
UPLT.API.params[ s ] = ask; |
|||
UPLT.API.Api.get( UPLT.API.params ) |
|||
.done( UPLT.API.fetched ) |
|||
.fail( UPLT.API.fault ); |
|||
}; // .API.fetch() |
|||
UPLT.API.fetched = function ( arrived ) { |
|||
// Answer arrived |
|||
// Precondition: |
|||
// arrived -- JSON result of request |
|||
var p, s; |
|||
if ( typeof arrived === "object" |
|||
&& arrived && |
|||
typeof arrived.parse === "object" |
|||
&& arrived.parse ) { |
|||
p = arrived.parse; |
|||
s = ( UPLT.light ? "parsedsummary" : "text" ); |
|||
if ( typeof p[ s ] === "object" |
|||
&& p[ s ] ) { |
|||
p = p[ s ]; |
|||
if ( typeof p[ "*" ] === "string" |
|||
&& p[ "*" ] ) { |
|||
UPLT.preview.fill( p[ "*" ] ); |
|||
} |
|||
} |
|||
} |
|||
}; // .API.fetched() |
|||
first(); |
|||
}( window.mediaWiki, window.jQuery ) ); |
|||
// Emacs |
|||
// Local Variables: |
|||
// coding: utf-8-dos |
|||
// fill-column: 80 |
|||
// End: |
|||
/// EOF </nowiki> uploadtools.js |
Aktuelle Version vom 19. März 2025, 15:15 Uhr
/// uploadtools.js for [[Special:Upload]]
// Preset with raw Template:Information, preview of description
// Vorschau der Beschreibung auf [[Spezial:Hochladen]]
// see also [[phab:T4537]]
// Code von [[Benutzer:Schnark]] 2011
// PerfektesChaos@de.wikipedia 2025-03
/// <nowiki>
/* global window: false */
/* jshint forin: false,
bitwise:true, curly:true, eqeqeq:true, latedef:true,
laxbreak:true,
nocomma:true, strict:true, undef:true, unused:true */
( function ( mw, $ ) {
"use strict";
var UPLT = { API: { Api: false },
I18N: { },
light: true, // new version of existing file
self: "gadget-uploadtools",
selDesc: "#wpUploadDescription",
selFormD: "#mw-htmlform-description",
selTitle: "#wpDestFile",
selTprint: "#t-print a",
sequel: "wpForReUpload",
site: false,
slang: false,
submit: "wpUpload",
preload: { },
preview: { css: { "border-color": "#808080",
"border-style": "dotted",
"border-width": "2px",
"margin-bottom": "1.5em",
"margin-top": "0.5em",
"padding-bottom": "0.5em",
"padding-left": "1em",
"padding-right": "1em",
"padding-top": "0.5em" },
show: false,
sign: false,
$button: false,
$div: false,
$headline: false
},
wiki: false,
$editbox: false,
$filename: false };
UPLT.I18N.projects = {
"dewiki": {"seek": "{{ *[Ii]nformation",
"source": "{{Information\n" +
" |Beschreibung = \n" +
" |Quelle = \n" +
" |Urheber = \n" +
" |Datum = \n" +
" |Genehmigung = \n" +
" |Andere Versionen = \n" +
" |Anmerkungen = \n" +
"}}"},
"enwiki": {"seek": "{{ *(?:[Tt]emplate:)? *[Ii]nformation",
"source": "{{Information\n" +
" |description = \n" +
" |date = \n" +
" |source = \n" +
" |author = \n" +
" |permission = \n" +
" |other_versions = \n" +
" |additional_information = \n" +
"}}"}
}; // .I18N.projects
UPLT.I18N.texts = {
"show": {"en": "Preview",
"bg": "Предварителен преглед",
"da": "Forhåndsvisning",
"de": "Vorschau",
"dsb": "Pśeglěd",
"ee": "Kpɔe do ŋgɔ",
"el": "Προεπισκόπηση",
"es": "Previsualizar",
"et": "Eelvaade",
"eu": "Aurrebista erakutsi",
"fi": "Esikatselu",
"fr": "Prévisualisation",
"ga": "Réamhamharc",
"hi": "पूर्वावलोकन",
"hr": "Pretpregled",
"hsb": "Přehlad",
"hu": "Előnézet",
"id": "Pratayang",
"is": "Forskoða",
"it": "Anteprima",
"ka": "წინასწარი გადახედვა",
"kl": "Isikkua",
"km": "មើលជាមុន",
"kv": "Водзвыв видзӧдлӧм",
"lb": "Kucken ouni ofzespäicheren",
"lt": "Peržiūra",
"lv": "Pirmskats",
"mg": "Topi-maso",
"mo": "Превизуализязэ",
"mt": "Dehra proviżorja",
"nb": "Forhåndsvisning",
"nl": "Voorvertoning",
"nn": "Førehandsvising",
"pl": "Podgląd",
"pt": "Antevisão",
"rm": "Prevista",
"ro": "Previzualizare",
"ru": "Предпросмотр",
"sq": "Shqyrto",
"sr-ec": "Претпреглед",
"sr-el": "Pretpregled",
"sv": "Förhandsgranskning",
"tr": "Önizleme",
"uk": "Попередній перегляд",
"vi": "Xem trước"}
}; // .I18N.texts
function fair( apply ) {
// Synchronize textarea and overlay
// Precondition:
// apply -- true: Update textarea -- else: Update overlay
UPLT.codeMirror( apply );
UPLT.wikEd( apply );
} // fair()
function features() {
// Equip page
// Precondition:
// DOM ready
var submit = "input[name=\"" + UPLT.submit + "\"]",
$button = $( submit ),
$descr = $( UPLT.selFormD ),
sign, $tbPrint;
UPLT.$editbox = $( UPLT.selDesc );
UPLT.$filename = $( UPLT.selTitle );
if ( $button.length === 1 &&
$descr.length === 1 &&
UPLT.$editbox.length === 1 &&
UPLT.$filename.length === 1 ) {
sign = UPLT.self + "-preview";
UPLT.preview.$div = $( "." + sign );
if ( ! UPLT.preview.$div.length ) {
UPLT.preview.$div = $( "<div>" );
UPLT.preview.$div.addClass( sign )
.css( UPLT.preview.css )
.hide();
$descr.before( UPLT.preview.$div );
$tbPrint = $( UPLT.selTprint );
$tbPrint.removeAttr( "accesskey" ) // T58786
.updateTooltipAccessKeys();
UPLT.preview.factory();
$button.after( UPLT.preview.$button );
UPLT.preload.fill();
}
}
} // features()
function fire() {
// Resources completed
// Precondition:
// mediawiki.util
if ( mw.util.getParamValue( UPLT.sequel ) !== "1" ) {
UPLT.light = false;
}
$( features );
} // fire()
function first() {
// Autorun on loading
var env = mw.config.get( [ "wgCanonicalSpecialPageName",
"wgDBname",
"wgUserLanguage" ] );
if ( env.wgCanonicalSpecialPageName === "Upload" ) {
UPLT.site = env.wgDBname;
UPLT.slang = env.wgUserLanguage.toLowerCase();
if ( typeof UPLT.I18N.projects[ UPLT.site ] === "object" ) {
UPLT.wiki = UPLT.I18N.projects[ UPLT.site ];
}
mw.loader.using( [ "mediawiki.api",
"mediawiki.util" ],
fire );
}
} // first()
UPLT.codeMirror = function ( apply ) {
// Execute function iff CodeMirror is active
// Precondition:
// apply -- true: Update textarea -- else: Update CM.doc
var doc, story;
if ( typeof window.CodeMirror !== "undefined"
&& window.CodeMirror
&& window.CodeMirror.getDoc() ) {
doc = window.CodeMirror.getDoc();
if ( apply ) {
story = doc.getValue();
UPLT.$editbox.val( story );
} else {
story = UPLT.$editbox.val();
doc.setValue( story );
}
}
}; // .codeMirror()
UPLT.wikEd = function ( apply ) {
// Execute function iff wikEd is active
// Precondition:
// apply -- true: UpdateTextarea -- else: UpdateFrame
if ( typeof window.wikEd !== "undefined"
&& window.wikEd
&& window.wikEd.useWikEd ) {
window.wikEd[ ( apply ? "UpdateTextarea"
: "UpdateFrame" ) ]();
}
}; // .wikEd()
UPLT.preload.fill = function () {
var less, re, story;
if ( ! UPLT.light
&& UPLT.wiki &&
typeof UPLT.wiki.source === "string" ) {
fair( true );
story = UPLT.$editbox.val();
if ( story ) {
if ( typeof UPLT.wiki.seek === "string" ) {
re = new RegExp( UPLT.wiki.seek );
less = ! re.test( story );
}
} else {
less = true;
}
if ( less ) {
story = UPLT.wiki.source +
( story ? "\n" + story : "" );
UPLT.$editbox.val( story );
fair();
}
}
}; // .preload.fill()
UPLT.preview.factory = function () {
// Create preview button
// Postcondition:
// Button is defined
var entry = UPLT.I18N.texts.show,
slang, sub;
if ( typeof entry[ UPLT.slang ] === "string" ) {
UPLT.preview.show = entry[ UPLT.slang ];
} else {
switch ( UPLT.slang ) {
case "als":
case "bar":
case "de":
case "de-at":
case "de-ch":
case "de-formal":
case "de-x-formal":
case "dsb":
case "frr":
case "gsw":
case "hsb":
case "ksh":
case "lb":
case "nds":
case "pdc":
case "pdt":
case "pfl":
case "sli":
case "stq":
case "vmf":
slang = "de";
sub = "de";
break;
case "pt-br":
slang = "pt";
sub = "pt";
break;
} // switch UPLT.slang
if ( typeof entry[ sub ] === "string" ) {
UPLT.preview.show = entry[ sub ];
} else {
UPLT.preview.show = entry.en;
slang = "en";
}
}
UPLT.preview.$button = $( "<input>" );
UPLT.preview.$button.addClass( UPLT.self + "-button" )
.attr( { "accesskey": "p",
"title": UPLT.preview.show,
"type": "button",
"value": UPLT.preview.show } )
.css( { "margin-left": "1em",
"margin-right": "1em" } )
.on( "click", UPLT.preview.fired )
.updateTooltipAccessKeys();
if ( slang && slang !== UPLT.slang ) {
UPLT.preview.$button.attr( "lang", slang );
}
}; // .preview.factory()
UPLT.preview.fill = function ( arrived ) {
// Show preview
// Precondition:
// arrived -- (string) HTML
var $preview = $( "<div>" );
if ( ! UPLT.$headline ) {
UPLT.preview.$headline = $( "<div>" );
UPLT.preview.$headline.attr( { "title": UPLT.preview.show } )
.css( { "font-size": "150%",
"font-weight": "bold",
"padding-bottom": "1em" } )
.text( UPLT.preview.show );
}
$preview.html( arrived );
UPLT.preview.$div.append( UPLT.preview.$headline, $preview )
.show();
}; // .preview.fill()
UPLT.preview.fired = function () {
// Preview button has been clicked
var send = UPLT.$filename.val(),
story;
UPLT.preload.fill();
fair( true );
story = UPLT.$editbox.val();
if ( UPLT.preview.$headline ) {
UPLT.preview.$div.hide();
UPLT.preview.$headline.detach();
UPLT.preview.$div.empty();
}
UPLT.API.fetch( story, send );
}; // .preview.fired()
UPLT.API.fault = function ( jqXHR, textStatus, errorThrown ) {
// API failure
var s;
if ( textStatus ) {
switch ( typeof textStatus ) {
case "object":
if ( typeof textStatus.textStatus === "string" ) {
s = textStatus.textStatus;
} else {
s = "";
}
if ( typeof textStatus.exception === "string"
&& textStatus.exception ) {
s = s + " (" + textStatus.exception + ")";
}
break;
case "string":
s = textStatus;
break;
} // switch typeof textStatus
}
if ( errorThrown ) {
if ( s ) {
s = s + " -- Error: ";
}
s = s + errorThrown;
}
if ( ! s ) {
s = "???";
}
if ( typeof window.console === "object" &&
typeof window.console.log === "function" ) {
window.console.log( UPLT.self + " * " + s );
if ( typeof textStatus === "object"
&& textStatus &&
typeof window.console.dir === "function" ) {
window.console.dir( textStatus );
}
}
}; // .API.fault()
UPLT.API.fetch = function ( ask, about ) {
// Request parsing
// Precondition:
// ask -- wikitext
// about -- file title
var s = ( UPLT.light ? "summary" : "text" );
if ( ! UPLT.API.Api ) {
UPLT.API.Api = new mw.Api();
UPLT.API.params = { action: "parse",
contentmodel: "wikitext",
format: "json",
prop : "text" /*,
pst: "" */
};
}
UPLT.API.params.title = "File:" + ( about ? about
: "JustAnExample.JPG" );
UPLT.API.params[ s ] = ask;
UPLT.API.Api.get( UPLT.API.params )
.done( UPLT.API.fetched )
.fail( UPLT.API.fault );
}; // .API.fetch()
UPLT.API.fetched = function ( arrived ) {
// Answer arrived
// Precondition:
// arrived -- JSON result of request
var p, s;
if ( typeof arrived === "object"
&& arrived &&
typeof arrived.parse === "object"
&& arrived.parse ) {
p = arrived.parse;
s = ( UPLT.light ? "parsedsummary" : "text" );
if ( typeof p[ s ] === "object"
&& p[ s ] ) {
p = p[ s ];
if ( typeof p[ "*" ] === "string"
&& p[ "*" ] ) {
UPLT.preview.fill( p[ "*" ] );
}
}
}
}; // .API.fetched()
first();
}( window.mediaWiki, window.jQuery ) );
// Emacs
// Local Variables:
// coding: utf-8-dos
// fill-column: 80
// End:
/// EOF </nowiki> uploadtools.js