|
|
| Zeile 58: |
Zeile 58: |
| /* Empfehlungs-Dings */ | | /* Empfehlungs-Dings */ |
|
| |
|
| var gagaList;
| | importJS('MediaWiki:Empfehlung.js'); |
| var entry;
| |
| var subpath = '/Empfehlung'; // Name bzw. Pfad der Kamelbau-Unterseiten
| |
| var gagaNS = new Array ("", "File", "Kamelionary"); // hierhin die Namensräume, die zur Wahl stehen (Achtung! canonical namespaces!);
| |
|
| |
| // Empfehlungsliste auslesen
| |
| function readGaGA(username) {
| |
| jQuery.ajax({
| |
| url: wgScript,
| |
| data: { title: "Kamel:" + username + subpath, action: "raw" },
| |
| cache: false,
| |
| // Noch keine Empfehlungs-Seite angelegt
| |
| error: function() { gagaList = new Array() },
| |
| // Empfehlungs-Seite auslesen
| |
| success: function(data) { gagaList = data.match(/\[\[.*\]\]/g) }
| |
| });
| |
| }
| |
| | |
| // Seite zur Empfehlungsliste hinzufügen
| |
| function addGaGA() {
| |
| // edit-Token holen
| |
| jQuery.ajax({
| |
| url: '/api.php',
| |
| data: { action: "query", prop: "info", intoken: "edit", titles: "Kamel:" + wgUserName + subpath, format: "xml" },
| |
| cache: false,
| |
| success: function(data) {
| |
| var edittoken = data.getElementsByTagName('page')[0].getAttribute('edittoken');
| |
| gagaList.push(entry); // Aktuelle Seite dazu
| |
| gagaList = sortGaGA(gagaList); // Sortieren
| |
| // Empfehlungsliste bearbeiten
| |
| jQuery.ajax({
| |
| url: '/api.php',
| |
| type: 'POST',
| |
| cache: false,
| |
| data: { action: "edit", title: "Kamel:" + wgUserName + subpath, text: "* " + gagaList.join("\n* "), summary: "+ " + entry, token: edittoken },
| |
| success: function(data) {
| |
| var text = '<p>Die Seite „' + wgPageName.replace(/_/g, ' ') + '“ wurde zu deinen <a href="'
| |
| + wgScript + '/Kamel:' + wgUserName + subpath + '">Empfehlungen</a> hinzugefügt.</p>';
| |
| jQuery('#mw-js-message').html(text);
| |
| jQuery('#mw-js-message').slideDown('fast');
| |
| }
| |
| })
| |
| }
| |
| });
| |
| }
| |
| | |
| function removeGaGA() {
| |
| // edit-Token holen
| |
| jQuery.ajax({
| |
| url: '/api.php',
| |
| data: { action: "query", prop: "info", intoken: "edit", titles: "Kamel:" + wgUserName + subpath, format: "xml" },
| |
| cache: false,
| |
| success: function(data) {
| |
| var edittoken = data.getElementsByTagName('page')[0].getAttribute('edittoken');
| |
| var i = jQuery.inArray(entry, gagaList);
| |
| delete gagaList[i]; // Aktuelle Seite wech
| |
| gagaList = sortGaGA(gagaList); // Sortieren
| |
| // Empfehlungsliste bearbeiten
| |
| jQuery.ajax({
| |
| url: '/api.php',
| |
| type: 'POST',
| |
| cache: false,
| |
| data: { action: "edit", title: "Kamel:" + wgUserName + subpath, text: "* " + gagaList.join("\n* "), summary: "- " + entry, token: edittoken },
| |
| success: function(data) {
| |
| var text = '<p>Die Seite „' + wgPageName.replace(/_/g, ' ') + '“ wurde von deinen <a href="'
| |
| + wgScript + '/Kamel:' + wgUserName + subpath + '">Empfehlungen</a> entfernt.</p>';
| |
| jQuery('#mw-js-message').html(text);
| |
| jQuery('#mw-js-message').slideDown('fast');
| |
| }
| |
| })
| |
| }
| |
| });
| |
| }
| |
| | |
| function showGaGA(username) {
| |
| /* soll später html-Code für Empfehlungslisten ausspucken */
| |
| }
| |
| | |
| // doppelte & leere Einträge entfernen + alphabetisch sortieren
| |
| function sortGaGA(list) {
| |
| var sorted = new Array();
| |
| for(var i=0; i<list.length; i++){
| |
| for(var j=i+1; j<list.length; j++){
| |
| if (list[i] == list[j]) j = ++i;
| |
| }
| |
| if (typeof(list[i]) != 'undefined') sorted.push(list[i]);
| |
| }
| |
| return sorted.sort();
| |
| }
| |
| | |
| // Das ganze starten
| |
| jQuery(document).ready(function() {
| |
| if(typeof(disableGaGA) != 'undefined' && disableGaGA) return;
| |
| if(jQuery.inArray(wgCanonicalNamespace, gagaNS) != -1) {
| |
| entry = (wgCanonicalNamespace == "File") ? "[[:" + wgPageName.replace(/_/g, ' ') + "]]"
| |
| : "[[" + wgPageName.replace(/_/g, ' ') + "]]";
| |
| jQuery('#p-views ul').append('<li class="icon"><span><a href="#"></a></span></li>');
| |
| jQuery('#p-views li:last').ajaxComplete(function() {
| |
| if(jQuery.inArray(entry, gagaList) != -1) {
| |
| jQuery(this).attr('id', 'ca-ungaga');
| |
| jQuery('#ca-ungaga a').html('Entfehlen');
| |
| jQuery('#ca-ungaga a').attr('title', 'Seite nicht mehr empfehlen');
| |
| jQuery('#ca-ungaga a').unbind('click');
| |
| jQuery('#ca-ungaga a').bind('click', function() { removeGaGA() });
| |
| } else {
| |
| jQuery(this).attr('id', 'ca-gaga');
| |
| jQuery('#ca-gaga a').html('Empfehlen');
| |
| jQuery('#ca-gaga a').attr('title', 'Seite empfehlen');
| |
| jQuery('#ca-gaga a').unbind('click');
| |
| jQuery('#ca-gaga a').bind('click', function() { addGaGA() });
| |
| }
| |
| });
| |
| readGaGA(wgUserName);
| |
| }
| |
| })
| |