Järjestelmäviesti:Gadget-pendingChangesDiffs.js
Huomautus: Selaimen välimuisti pitää tyhjentää asetusten tallentamisen jälkeen, jotta muutokset tulisivat voimaan.
- Firefox ja Safari: Napsauta Shift-näppäin pohjassa Päivitä, tai paina Ctrl-F5 tai Ctrl-R (⌘-R Macilla)
- Google Chrome: Paina Ctrl-Shift-R (⌘-Shift-R Macilla)
- Internet Explorer ja Edge: Napsauta Ctrl-näppäin pohjassa Päivitä tai paina Ctrl-F5
- Opera: Paina Ctrl-F5.
function showPendingChangesDiffsNew() {
function parseUrlParameters(url) {
let params = {};
let parser = new URL(url, window.location.origin); // Create a URL object
let queryString = parser.search; // Get the query string part of the URL
let urlParams = new URLSearchParams(queryString); // Use URLSearchParams to parse the query string
for (let [key, value] of urlParams.entries()) {
params[key] = value; // Add each key-value pair to the params object
}
return params;
}
// Function to construct the URL for fetching the HTML snippet
function constructSnippetUrl(params) {
return `https://fi.wikipedia.org/w/index.php?title=${params.title}&diff=${params.diff}&oldid=${params.oldid}&action=render&diffonly=1`;
}
function createHeaderLine(params) {
// Create a <h2> element
var h2Element = $('<h2></h2>');
// Create an <a> element with the href attribute and text content
pageTitleLabel = params.title.replace(/_/g, " ");
var aElement = $('<a></a>')
.attr('href', '/wiki/' + params.title)
.text(pageTitleLabel);
// Append the <a> element to the <h2> element
h2Element.append(aElement);
// Create undo-button
undoElement = create_action_button(action_undo, 'Kumoa', params);
h2Element.append(undoElement);
// Create review-button
reviewElement = create_action_button(action_review, 'Arvioi', params);
h2Element.append(reviewElement);
// Create approve-button
approveElement = create_action_button(action_approve, 'Hyväksy', params);
h2Element.append(approveElement);
h2Element.append
// Return the <h2> element
return h2Element;
}
function create_action_button(action_function, label, params) {
var link = $('<input></input>')
.attr('type', 'button')
.attr('value', label)
.attr('data-title', params.title)
.attr('data-oldid', params.oldid)
.attr('data-curid', params.curid)
.attr('data-diff', params.diff)
link.css( 'float', 'right' );
link.css('font-size', '0.6em');
link.css('margin-right', '1em');
link.attr( 'class', 'cdx-button cdx-button--action-progressive');
link.click(action_function);
return link;
}
// https://fi.wikipedia.org/w/index.php?title=Orjakapina&action=edit&undoafter=22088839&undo=22199786
function action_undo() {
$( this ).css( 'color', 'gray' );
var url = '/w/index.php?action=edit'
url += '&title=' + encodeURIComponent( $(this).attr('data-title'));
url += '&undoafter=' + encodeURIComponent($(this).attr('data-oldid'));
url += '&undo=' + encodeURIComponent($(this).attr('data-curid'));
window.open( url );
$( this ).css( 'color', '' );
}
function action_review() {
$( this ).css( 'color', 'gray' );
var url = '/w/index.php?'
url += 'title=' + encodeURIComponent( $(this).attr('data-title'));
url += '&diff=cur&oldid=' + encodeURIComponent($(this).attr('data-oldid'));
window.open( url );
$( this ).css( 'color', '' );
}
function action_approve() {
$( this ).css( 'color', 'gray' );
url = mw.util.wikiScript( 'api' )
url += '?action=query&meta=tokens&type=csrf&format=json';
element=this
$.getJSON( url, function( tokendata ) {
var wpEditToken = tokendata['query']['tokens']['csrftoken'];
var data = {
'action': 'review',
'revid': $(element).attr('data-curid'),
'token': wpEditToken,
'wpaccuracy': 1,
'comment': 'quickreview',
'format': 'xml'
};
if ( $( element ).attr( 'value' ) != 'Hyväksy' ) {
data.unapprove = true;
}
$.ajax( {
type: 'POST',
url: mw.util.wikiScript( 'api' ),
'data': data,
dataType: 'xml'
} ).done( function( xml ) {
if ( $( element ).attr( 'value' ) != 'Hyväksy' ) {
$( element ).attr( 'value', 'Hyväksy' );
} else {
$( element ).attr( 'value', 'Poista hyväksyntä' );
}
$( element ).css( 'color', '' );
} );
});
}
function loadSnipplet(params, pendingchangeslist) {
if (params.title && params.diff && params.oldid) {
let snippetUrl = constructSnippetUrl(params);
$.ajax({
url: snippetUrl,
method: 'GET',
success: function(data) {
data_e=$(`<div>${data}</div>`);
newurl=data_e.find('#mw-diff-ntitle1').find('a').first().attr('href');
newparams=parseUrlParameters(newurl);
params['curid']=newparams.oldid
container_e = $(`<div></div>`);
container_e.attr('data-title', params.title);
container_e.attr('data-diff', params.diff);
container_e.attr('data-oldid', params.oldid);
container_e.attr('data-curid', params.curid);
data_e.find('.mw-revslider-container').css('display', 'none')
data_e.find('.mw-diff-table-prefix').css('display', 'none')
data_e.find('.mw-diff-revision-history-links').css('display', 'none')
data_e.find('.diff-title').css('vertical-align', 'top');
header_e=createHeaderLine(params);
container_e.css('margin-top', '1em');
header_e.css('border-top', '0.2em solid gray');
container_e.append(header_e);
container_e.append(data_e);
pendingchangeslist.append(container_e);
},
error: function(xhr, status, error) {
console.error(`Error fetching HTML snippet: ${error}`);
}
});
}
}
pendingchangeslist = $("#mw-content-text").find("ul").first()
changes = pendingchangeslist.find("li")
changes.each( function() {
change = $( this )
change.css('display', 'none')
change.find('a[href^="/w/index.php?title="][href*="&diff=cur&oldid="][class*=" nonimage needs-review"]').each(function() {
url = $(this).attr('href');
params = parseUrlParameters(url);
loadSnipplet(params, pendingchangeslist);
});
});
}
if ( mw.config.get( 'wgCanonicalSpecialPageName' ) == 'PendingChanges' ) {
mw.loader.load('https://fi.wikipedia.org/w/load.php?modules=mediawiki.diff.styles&only=styles&skin=vector', 'text/css' );
$(document).ready( function() {
if ( ( document.location + '' ).search( 'autodiff=1' ) != -1 ) {
showPendingChangesDiffsNew();
} else {
var button = $( '<input id="showPendingChangesDiffsButton" type="button" value="Näytä diffeinä" />' );
button.click(showPendingChangesDiffsNew);
$( 'fieldset' ).append( button );
}
});
}