MediaWiki:Gadget-eventform.js: Unterschied zwischen den Versionen
Admin (Diskussion | Beiträge) Keine Bearbeitungszusammenfassung |
Admin (Diskussion | Beiträge) Keine Bearbeitungszusammenfassung |
||
| (8 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt) | |||
| Zeile 1: | Zeile 1: | ||
/** | /** | ||
* Eventform-Gadget: Komfortables Anlegen von Veranstaltungsseiten | * Eventform-Gadget: Komfortables Anlegen von Veranstaltungsseiten | ||
* Aktiv auf der Seite " | * Aktiv auf der Seite "Veranstaltungen" | ||
*/ | */ | ||
( function () { | ( function () { | ||
'use strict'; | 'use strict'; | ||
// Konfiguration | // Konfiguration: auf welcher Seite soll der Button erscheinen? | ||
var TRIGGER_PAGE = ' | var TRIGGER_PAGE = 'Veranstaltungen'; | ||
if ( mw.config.get( 'wgPageName' ) !== TRIGGER_PAGE ) { | if ( mw.config.get( 'wgPageName' ) !== TRIGGER_PAGE ) { | ||
return; | return; | ||
} | } | ||
if ( !mw.config.get( 'wgUserName' ) ) { | if ( !mw.config.get( 'wgUserName' ) ) { | ||
return; | return; | ||
} | } | ||
| Zeile 38: | Zeile 24: | ||
var lines = []; | var lines = []; | ||
lines.push( '[[Hauptseite]] > [[Hauptseite#Kultur & Events|Kultur & Events]] > [[Veranstaltungen]]' ); | lines.push( '[[Hauptseite]] > [[Hauptseite#Kultur & Events|Kultur & Events]] > [[Veranstaltungen]]' ); | ||
// Zeit | |||
lines.push( '==Zeit==' ); | lines.push( '==Zeit==' ); | ||
lines.push( '🗓️ ' + | lines.push( '🗓️ ' + f.datum ); | ||
lines.push( '' ); | |||
lines.push( '⏰ ' + f.uhrzeit ); | lines.push( '⏰ ' + f.uhrzeit ); | ||
lines.push( '<br>' ); | lines.push( '<br>' ); | ||
| Zeile 45: | Zeile 34: | ||
lines.push( '<br>' ); | lines.push( '<br>' ); | ||
lines.push( '<br>' ); | lines.push( '<br>' ); | ||
// Event | |||
lines.push( '==Event==' ); | lines.push( '==Event==' ); | ||
if ( f.bild ) { | if ( f.bild ) { | ||
lines.push( '[[file:' + f.bild + '|frameless|upright=3.0]]' ); | lines.push( '[[file:' + f.bild + '|frameless|upright=3.0]]' ); | ||
lines.push( '' ); | |||
} | } | ||
if ( f.websiteUrl ) { | if ( f.websiteUrl ) { | ||
lines.push( '🌐 | lines.push( '🌐 ' + f.websiteUrl ); | ||
} | } | ||
lines.push( '<br>' ); | lines.push( '<br>' ); | ||
| Zeile 56: | Zeile 48: | ||
lines.push( '<br>' ); | lines.push( '<br>' ); | ||
lines.push( '<br>' ); | lines.push( '<br>' ); | ||
// Location - jede Symbol-Zeile in eigenem Absatz (Leerzeile dazwischen) | |||
lines.push( '==Location==' ); | lines.push( '==Location==' ); | ||
if ( | var locFirst = true; | ||
function addLocLine( line ) { | |||
if ( !locFirst ) { | |||
lines.push( '' ); | |||
} | |||
lines.push( line ); | |||
locFirst = false; | |||
} | |||
if ( f.Adresse ) { | |||
addLocLine( '📍 ' + f.Adresse ); | |||
} | } | ||
if ( f.osmUrl ) { | if ( f.osmUrl ) { | ||
addLocLine( '[[file:osm.png|24px|link=]] ' + f.osmUrl ); | |||
} | } | ||
if ( f.koordinaten ) { | if ( f.koordinaten ) { | ||
addLocLine( '🧭 ' + f.koordinaten ); | |||
} | } | ||
if ( f.comapsUrl ) { | if ( f.comapsUrl ) { | ||
addLocLine( '[[file:CoMaps.png|24px|link=]] ' + f.comapsUrl ); | |||
} | } | ||
if ( f.gmapsUrl ) { | if ( f.gmapsUrl ) { | ||
addLocLine( '[[file:GoogleMaps.png|24px|link=]] ' + f.gmapsUrl ); | |||
} | } | ||
lines.push( '<br>' ); | lines.push( '<br>' ); | ||
| Zeile 76: | Zeile 78: | ||
lines.push( '<br>' ); | lines.push( '<br>' ); | ||
lines.push( '<br>' ); | lines.push( '<br>' ); | ||
// Photos & Videos | |||
lines.push( '==Photos & Videos==' ); | lines.push( '==Photos & Videos==' ); | ||
lines.push( 'Bitte hier verlinken.' ); | lines.push( 'Bitte hier verlinken.' ); | ||
return lines.join( '\n' ); | return lines.join( '\n' ); | ||
} | } | ||
| Zeile 114: | Zeile 119: | ||
this.bildInput = new OO.ui.TextInputWidget( { placeholder: 'sommerfest.jpg' } ); | this.bildInput = new OO.ui.TextInputWidget( { placeholder: 'sommerfest.jpg' } ); | ||
this.websiteUrlInput = new OO.ui.TextInputWidget( { placeholder: 'https://...' } ); | this.websiteUrlInput = new OO.ui.TextInputWidget( { placeholder: 'https://...' } ); | ||
this. | this.AdresseInput = new OO.ui.TextInputWidget( { placeholder: 'Nussbaum Straße ' } ); | ||
this.osmUrlInput = new OO.ui.TextInputWidget( { placeholder: 'https://www.openstreetmap.org/way/...' } ); | this.osmUrlInput = new OO.ui.TextInputWidget( { placeholder: 'https://www.openstreetmap.org/way/...' } ); | ||
this.koordinatenInput = new OO.ui.TextInputWidget( { placeholder: '47.7500000,15.6800000' } ); | this.koordinatenInput = new OO.ui.TextInputWidget( { placeholder: '47.7500000,15.6800000' } ); | ||
this.comapsUrlInput = new OO.ui.TextInputWidget( { placeholder: 'https://comaps.at/...' } ); | this.comapsUrlInput = new OO.ui.TextInputWidget( { placeholder: 'https://comaps.at/...' } ); | ||
this.gmapsUrlInput = new OO.ui.TextInputWidget( { placeholder: 'https://maps.app.goo.gl/...' } ); | this.gmapsUrlInput = new OO.ui.TextInputWidget( { placeholder: 'https://maps.app.goo.gl/...' } ); | ||
var fsBasis = new OO.ui.FieldsetLayout( { label: 'Pflichtfelder' } ); | var fsBasis = new OO.ui.FieldsetLayout( { label: 'Pflichtfelder' } ); | ||
| Zeile 140: | Zeile 140: | ||
new OO.ui.FieldLayout( this.bildInput, { | new OO.ui.FieldLayout( this.bildInput, { | ||
label: 'Bild (Dateiname)', align: 'left', | label: 'Bild (Dateiname)', align: 'left', | ||
help: ' | help: 'Wenn man die Dateiendung weiß (z.B. jpg), wähle einen sinnvollen Namen mit der richtigen Datei-Endung (z.B. Sommerfest2026.jpg ) wenn mann dann später auf der fertigen Seite darauf klickt, kann man auch das Bild hochladen. Leer lassen, wenn kein Bild.' | ||
} ), | } ), | ||
new OO.ui.FieldLayout( this.websiteUrlInput, { label: 'Website URL | new OO.ui.FieldLayout( this.websiteUrlInput, { label: 'Website URL', align: 'left' } ) | ||
] ); | ] ); | ||
var fsLoc = new OO.ui.FieldsetLayout( { label: 'Location (alles optional)' } ); | var fsLoc = new OO.ui.FieldsetLayout( { label: 'Location (alles optional)' } ); | ||
fsLoc.addItems( [ | fsLoc.addItems( [ | ||
new OO.ui.FieldLayout( this. | new OO.ui.FieldLayout( this.AdresseInput, { label: 'Adresse', align: 'left' } ), | ||
new OO.ui.FieldLayout( this.osmUrlInput, { label: 'OpenStreetMap URL', align: 'left' } ), | new OO.ui.FieldLayout( this.osmUrlInput, { label: 'OpenStreetMap URL', align: 'left' } ), | ||
new OO.ui.FieldLayout( this.koordinatenInput, { label: 'GPS-Koordinaten', align: 'left' } ), | new OO.ui.FieldLayout( this.koordinatenInput, { label: 'GPS-Koordinaten', align: 'left' } ), | ||
new OO.ui.FieldLayout( this.comapsUrlInput, { label: 'CoMaps URL', align: 'left' } ), | new OO.ui.FieldLayout( this.comapsUrlInput, { label: 'CoMaps URL', align: 'left' } ), | ||
new OO.ui.FieldLayout( this.gmapsUrlInput, { label: 'Google Maps URL', align: 'left' } ) | |||
new OO.ui.FieldLayout( this.gmapsUrlInput, { label: 'Google Maps URL | |||
] ); | ] ); | ||
| Zeile 183: | Zeile 178: | ||
bild: v( dialog.bildInput.getValue() ), | bild: v( dialog.bildInput.getValue() ), | ||
websiteUrl: v( dialog.websiteUrlInput.getValue() ), | websiteUrl: v( dialog.websiteUrlInput.getValue() ), | ||
Adresse: v( dialog.AdresseInput.getValue() ), | |||
osmUrl: v( dialog.osmUrlInput.getValue() ), | osmUrl: v( dialog.osmUrlInput.getValue() ), | ||
koordinaten: v( dialog.koordinatenInput.getValue() ), | koordinaten: v( dialog.koordinatenInput.getValue() ), | ||
comapsUrl: v( dialog.comapsUrlInput.getValue() ), | comapsUrl: v( dialog.comapsUrlInput.getValue() ), | ||
gmapsUrl: v( dialog.gmapsUrlInput.getValue() ) | |||
gmapsUrl: v( dialog.gmapsUrlInput | |||
}; | }; | ||
| Zeile 198: | Zeile 188: | ||
var api = new mw.Api(); | var api = new mw.Api(); | ||
return api.get( { | return api.get( { | ||
action: 'query', | action: 'query', | ||
| Zeile 260: | Zeile 249: | ||
$container.empty().append( button.$element ); | $container.empty().append( button.$element ); | ||
} ); | } ); | ||
}() ); | }() ); | ||
Aktuelle Version vom 30. Mai 2026, 02:45 Uhr
/**
* Eventform-Gadget: Komfortables Anlegen von Veranstaltungsseiten
* Aktiv auf der Seite "Veranstaltungen"
*/
( function () {
'use strict';
// Konfiguration: auf welcher Seite soll der Button erscheinen?
var TRIGGER_PAGE = 'Veranstaltungen';
if ( mw.config.get( 'wgPageName' ) !== TRIGGER_PAGE ) {
return;
}
if ( !mw.config.get( 'wgUserName' ) ) {
return;
}
function v( val ) {
return ( val || '' ).trim();
}
function buildWikitext( f ) {
var lines = [];
lines.push( '[[Hauptseite]] > [[Hauptseite#Kultur & Events|Kultur & Events]] > [[Veranstaltungen]]' );
// Zeit
lines.push( '==Zeit==' );
lines.push( '🗓️ ' + f.datum );
lines.push( '' );
lines.push( '⏰ ' + f.uhrzeit );
lines.push( '<br>' );
lines.push( '<br>' );
lines.push( '<br>' );
lines.push( '<br>' );
// Event
lines.push( '==Event==' );
if ( f.bild ) {
lines.push( '[[file:' + f.bild + '|frameless|upright=3.0]]' );
lines.push( '' );
}
if ( f.websiteUrl ) {
lines.push( '🌐 ' + f.websiteUrl );
}
lines.push( '<br>' );
lines.push( '<br>' );
lines.push( '<br>' );
lines.push( '<br>' );
// Location - jede Symbol-Zeile in eigenem Absatz (Leerzeile dazwischen)
lines.push( '==Location==' );
var locFirst = true;
function addLocLine( line ) {
if ( !locFirst ) {
lines.push( '' );
}
lines.push( line );
locFirst = false;
}
if ( f.Adresse ) {
addLocLine( '📍 ' + f.Adresse );
}
if ( f.osmUrl ) {
addLocLine( '[[file:osm.png|24px|link=]] ' + f.osmUrl );
}
if ( f.koordinaten ) {
addLocLine( '🧭 ' + f.koordinaten );
}
if ( f.comapsUrl ) {
addLocLine( '[[file:CoMaps.png|24px|link=]] ' + f.comapsUrl );
}
if ( f.gmapsUrl ) {
addLocLine( '[[file:GoogleMaps.png|24px|link=]] ' + f.gmapsUrl );
}
lines.push( '<br>' );
lines.push( '<br>' );
lines.push( '<br>' );
lines.push( '<br>' );
// Photos & Videos
lines.push( '==Photos & Videos==' );
lines.push( 'Bitte hier verlinken.' );
return lines.join( '\n' );
}
mw.loader.using( [
'oojs-ui-core',
'oojs-ui-windows',
'oojs-ui.styles.icons-interactions',
'mediawiki.api',
'mediawiki.util'
] ).then( function () {
function EventDialog( config ) {
EventDialog.super.call( this, config );
}
OO.inheritClass( EventDialog, OO.ui.ProcessDialog );
EventDialog.static.name = 'eventDialog';
EventDialog.static.title = 'Neue Veranstaltung anlegen';
EventDialog.static.actions = [
{ action: 'save', label: 'Seite anlegen', flags: [ 'primary', 'progressive' ] },
{ label: 'Abbrechen', flags: 'safe' }
];
EventDialog.prototype.initialize = function () {
EventDialog.super.prototype.initialize.apply( this, arguments );
this.panel = new OO.ui.PanelLayout( { padded: true, expanded: false } );
this.titelInput = new OO.ui.TextInputWidget( {
placeholder: 'z.B. Sommerfest 2026', required: true
} );
this.datumInput = new OO.ui.TextInputWidget( { type: 'date', required: true } );
this.uhrzeitInput = new OO.ui.TextInputWidget( { type: 'time', value: '17:00', required: true } );
this.bildInput = new OO.ui.TextInputWidget( { placeholder: 'sommerfest.jpg' } );
this.websiteUrlInput = new OO.ui.TextInputWidget( { placeholder: 'https://...' } );
this.AdresseInput = new OO.ui.TextInputWidget( { placeholder: 'Nussbaum Straße ' } );
this.osmUrlInput = new OO.ui.TextInputWidget( { placeholder: 'https://www.openstreetmap.org/way/...' } );
this.koordinatenInput = new OO.ui.TextInputWidget( { placeholder: '47.7500000,15.6800000' } );
this.comapsUrlInput = new OO.ui.TextInputWidget( { placeholder: 'https://comaps.at/...' } );
this.gmapsUrlInput = new OO.ui.TextInputWidget( { placeholder: 'https://maps.app.goo.gl/...' } );
var fsBasis = new OO.ui.FieldsetLayout( { label: 'Pflichtfelder' } );
fsBasis.addItems( [
new OO.ui.FieldLayout( this.titelInput, {
label: 'Seitentitel', align: 'left',
help: 'Wird der Name der neuen Wiki-Seite. Muss eindeutig sein.'
} ),
new OO.ui.FieldLayout( this.datumInput, { label: 'Datum', align: 'left' } ),
new OO.ui.FieldLayout( this.uhrzeitInput, { label: 'Uhrzeit', align: 'left' } )
] );
var fsEvent = new OO.ui.FieldsetLayout( { label: 'Event' } );
fsEvent.addItems( [
new OO.ui.FieldLayout( this.bildInput, {
label: 'Bild (Dateiname)', align: 'left',
help: 'Wenn man die Dateiendung weiß (z.B. jpg), wähle einen sinnvollen Namen mit der richtigen Datei-Endung (z.B. Sommerfest2026.jpg ) wenn mann dann später auf der fertigen Seite darauf klickt, kann man auch das Bild hochladen. Leer lassen, wenn kein Bild.'
} ),
new OO.ui.FieldLayout( this.websiteUrlInput, { label: 'Website URL', align: 'left' } )
] );
var fsLoc = new OO.ui.FieldsetLayout( { label: 'Location (alles optional)' } );
fsLoc.addItems( [
new OO.ui.FieldLayout( this.AdresseInput, { label: 'Adresse', align: 'left' } ),
new OO.ui.FieldLayout( this.osmUrlInput, { label: 'OpenStreetMap URL', align: 'left' } ),
new OO.ui.FieldLayout( this.koordinatenInput, { label: 'GPS-Koordinaten', align: 'left' } ),
new OO.ui.FieldLayout( this.comapsUrlInput, { label: 'CoMaps URL', align: 'left' } ),
new OO.ui.FieldLayout( this.gmapsUrlInput, { label: 'Google Maps URL', align: 'left' } )
] );
this.panel.$element.append( fsBasis.$element, fsEvent.$element, fsLoc.$element );
this.$body.append( this.panel.$element );
};
EventDialog.prototype.getActionProcess = function ( action ) {
var dialog = this;
if ( action === 'save' ) {
return new OO.ui.Process( function () {
var titel = v( dialog.titelInput.getValue() );
var datum = v( dialog.datumInput.getValue() );
var uhrzeit = v( dialog.uhrzeitInput.getValue() );
if ( !titel || !datum || !uhrzeit ) {
return $.Deferred().reject( new OO.ui.Error(
'Bitte alle Pflichtfelder ausfüllen.',
{ recoverable: true }
) ).promise();
}
var fields = {
datum: datum,
uhrzeit: uhrzeit,
bild: v( dialog.bildInput.getValue() ),
websiteUrl: v( dialog.websiteUrlInput.getValue() ),
Adresse: v( dialog.AdresseInput.getValue() ),
osmUrl: v( dialog.osmUrlInput.getValue() ),
koordinaten: v( dialog.koordinatenInput.getValue() ),
comapsUrl: v( dialog.comapsUrlInput.getValue() ),
gmapsUrl: v( dialog.gmapsUrlInput.getValue() )
};
var wikitext = buildWikitext( fields );
var api = new mw.Api();
return api.get( {
action: 'query',
titles: titel,
formatversion: 2
} ).then( function ( data ) {
var page = data.query.pages[ 0 ];
if ( !page.missing ) {
return $.Deferred().reject( new OO.ui.Error(
'Eine Seite mit dem Titel „' + titel + '" existiert bereits.',
{ recoverable: true }
) ).promise();
}
return api.postWithToken( 'csrf', {
action: 'edit',
title: titel,
text: wikitext,
createonly: true,
summary: 'Veranstaltung über Eventform-Gadget angelegt'
} );
} ).then( function () {
window.location.href = mw.util.getUrl( titel );
}, function ( err ) {
if ( err instanceof OO.ui.Error ) {
return $.Deferred().reject( err ).promise();
}
return $.Deferred().reject( new OO.ui.Error(
'Fehler beim Anlegen: ' + ( err && err.toString ? err.toString() : 'unbekannt' ),
{ recoverable: true }
) ).promise();
} );
} );
}
return EventDialog.super.prototype.getActionProcess.call( this, action );
};
EventDialog.prototype.getBodyHeight = function () {
return 600;
};
var $container = $( '#event-form-container' );
if ( !$container.length ) {
$container = $( '<div id="event-form-container"></div>' )
.appendTo( '#mw-content-text .mw-parser-output' );
}
var button = new OO.ui.ButtonWidget( {
label: 'Neue Veranstaltung anlegen',
flags: [ 'primary', 'progressive' ],
icon: 'add'
} );
var windowManager = new OO.ui.WindowManager();
$( document.body ).append( windowManager.$element );
var dialog = new EventDialog( { size: 'large' } );
windowManager.addWindows( [ dialog ] );
button.on( 'click', function () {
windowManager.openWindow( dialog );
} );
$container.empty().append( button.$element );
} );
}() );