Järjestelmäviesti:Gadget-PendingChangesDiff.js
Siirry navigaatioon
Siirry hakuun
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.
/* PendingChangesDiff() alkaa */
function showPendingChangesDiffs() {
var oldreviewedpages_cache = null;
var pendingchanges_loaded = null;
var do_second_pass = true;
var articles = Array();
// Mikäli käytössä on pienoisohjelmia joilla valitaan tarkistettavia aihepiirejä
// niin tämä piilottaa muut kuin valitut aihepiirit.
function do_hide_by_group() {
if (
( typeof window.use_alternativecheck != 'undefined' ) &&
( window.use_alternativecheck == 1 ) &&
( mw.config.get( 'wgCanonicalSpecialPageName' ) == 'PendingChanges' ) &&
( mw.user.options.get( 'gadget-PendingChangesDiff' ) == 1 )
)
{
var url = '//zache.kapsi.fi/flaggedrevs/flaggedrevs.php?group=' + window.fr_check_groups + '&titles=';
$( '#bodyContent' ).find( 'li' ).addClass( 'grouphided' );
$( '#bodyContent' ).find( 'li' ).each( function() {
url = url + encodeURIComponent( ( $( this ).find( 'a:first' ).attr( 'title' ) + '' ).replace( ' ', '_' ) ) + '|';
} );
$( '.grouphided' ).hide();
$.getJSON( url, function( data ) {
$.each( data, function( n, p ) {
$( '#bodyContent' ).find( 'li' ).each( function() {
if ( $( this ).find( 'a:first' ).attr( 'title' ) == p ) {
$( this ).removeClass( 'grouphided' );
$( this ).show();
}
} );
} );
} );
}
} // do_hide_by_group loppuu
function do_disable_stabilize_buttons() {
$.ajax( {
type: 'GET',
url: '//fi.wikipedia.org/w/index.php?title=Toiminnot%3APendingChanges&namespace=&level=-1&stable=1&category=&size=',
dataType: 'xml'
} ).done( function( xml ) {
$( xml ).find( '#bodyContent' ).find( 'li' ).each( function() {
$( this ).find( 'a' ).each( function() {
if ( $( this ).text() == 'arvioi' ) {
var url = $( this ).attr( 'href' );
var oldid = 0;
var re = new RegExp( 'oldid=([0-9]+)' );
var n = url.match( re );
if ( n ) {
oldid = n[1];
$( '#stabilize_' + oldid ).attr( 'disabled', 'disabled' );
$( '#stabilize_' + oldid ).attr( 'value', 'vakautettu' );
}
}
} );
} );
} );
}
function do_categoryinfo() {
var titles = '';
for ( var title in articles ) {
titles += encodeURIComponent( title ) + '|';
}
var url = '//fi.wikipedia.org/w/api.php?action=query&titles=' + titles + '&prop=categories&format=json&cllimit=500';
$.getJSON( url, function( data ) {
$.each( data.query.pages, function( n, page ) {
var div = $( '<div/>' );
div.css( 'font-size', '90%' );
var pageid = page.pageid;
var delim = '';
if ( typeof page.categories != 'undefined' ) {
$.each( page.categories, function( m, cat ) {
var url = '';
switch ( cat.title ) {
case 'Luokka:Lupaavat artikkelit':
url = '//upload.wikimedia.org/wikipedia/commons/thumb/c/c4/Art%C3%ADculo_bueno-blue.svg/19px-Art%C3%ADculo_bueno-blue.svg.png';
break;
case 'Luokka:Hyvät artikkelit':
url = '//upload.wikimedia.org/wikipedia/commons/thumb/9/94/Symbol_support_vote.svg/19px-Symbol_support_vote.svg.png';
break;
case 'Luokka:Suositellut luettelot':
case 'Luokka:Suositellut artikkelit':
url = '//upload.wikimedia.org/wikipedia/commons/thumb/e/e7/Cscr-featured.svg/20px-Cscr-featured.svg.png';
break;
default:
url = '';
break;
}
if ( url !== '' ) {
var img = $( '<img />' );
img.attr( 'src', url );
img.attr( 'alt', '' );
img.css( 'width', '20px' );
img.css( 'position', 'relative' );
img.css( 'left', '-25px' );
img.css( 'margin-right', '-20px' );
$( '#pageid_' + pageid ).prepend( img );
}
div.append( delim + ' <a href="//fi.wikipedia.org/wiki/' + cat.title + '">' + cat.title.replace( 'Luokka:', '' ) + '</a>' );
delim = ', ';
} );
}
div.insertBefore( $( '#pageid_' + pageid ).find( 'div:first' ) );
} );
} );
}
function do_abusefilterHighlight() {
$.getJSON( '//fi.wikipedia.org/w/api.php?action=query&list=abuselog&aflprop=ids|user&afllimit=50&format=json', function( data ) {
var users = [];
$.each( data.query.abuselog, function( i, item ) {
if ( ( item.filter_id != 26 ) && (item.filter_id != 27 ) && ( item.filter_id != 67 ) ) {
if ( typeof item.user != 'undefined' ) {
users[item.user] = 1;
}
}
} );
$( '#bodyContent' ).find( 'a' ).each( function() {
if ( users[$( this ).html()] == 1 ) {
$( this ).css( 'background-color', 'LightPink' );
var link = '//fi.wikipedia.org/w/index.php?title=Toiminnot:V%C3%A4%C3%A4rink%C3%A4ytt%C3%B6loki&wpSearchUser=' + encodeURIComponent( $( this ).html() );
var abuseFilterLink = $( '<span> | <a href="' + link + '">väärinkäyttöloki</a></span>' );
$( this ).parent().find( '.usertoollinks' ).first().append( abuseFilterLink );
}
} );
} );
}
function print_userlinks( username ) {
var outstr = '<p class="usertools" style="white-space:nowrap">';
var käyttäjä_url = '//fi.wikipedia.org/wiki/K%C3%A4ytt%C3%A4j%C3%A4:' + encodeURIComponent( username );
var keskustelu_url = '//fi.wikipedia.org/wiki/Keskustelu_k%C3%A4ytt%C3%A4j%C3%A4st%C3%A4:' + encodeURIComponent( username );
var muokkaukset_url = '//fi.wikipedia.org/wiki/Toiminnot:Muokkaukset/' + encodeURIComponent( username );
var esto_url = '//fi.wikipedia.org/wiki/Toiminnot:Est%C3%A4/' + encodeURIComponent( username );
var re = new RegExp( "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}" );
if ( username.match( re ) ) {
outstr += '<a href="' + muokkaukset_url + '">' + username + '</a> ';
} else {
outstr += '<a href="' + käyttäjä_url + '">' + username + '</a> ';
}
outstr += ' ( <span class="usertoollinks"><a href="' + keskustelu_url + '">keskustelu</a> ';
if ( username.match( re ) === null ) {
outstr += ' | <a href="' + muokkaukset_url + '">muokkaukset</a> ';
}
if ( ( mw.config.get( 'wgUserGroups' ) + '' ).search( 'sysop' ) != -1 ) {
outstr += ' | <a href="' + esto_url + '">estä</a> ';
}
outstr += '</span> )</p>';
return outstr;
}
function do_revisioninfo( element, title, revision ) {
$.getJSON(
'//fi.wikipedia.org/w/api.php?action=query&prop=revisions|info&format=json&inprop=&rvprop=ids|flags|timestamp|user|size|comment|content&titles=' + encodeURIComponent( title ) + '&rvdir=newer&rvstartid=' + encodeURIComponent( revision ) + 'rvlimit=1&format=json',
function( data ) {
$.each( data.query.pages, function( i, item ) {
var usertext = print_userlinks( item.revisions[0].user );
var d = new Date( Date.parse( item.revisions[0].timestamp ) );
var months = ['tammikuu', 'helmikuu', 'maaliskuu', 'huhtikuu', 'toukokuu', 'kesäkuu', 'heinäkuu', 'elokuu', 'syyskuu', 'lokakuu', 'marraskuu', 'joulukuu'];
var datetext = d.getDate() + '. ' + months[d.getMonth()] + 'ta ' + d.getFullYear() + ' kello ' + ( d.getHours() < 10 ? '0' : '' ) + d.getHours() + ':' + ( d.getMinutes() < 10 ? '0' : '' ) + d.getMinutes();
// Muutetaan kommentista wikilinkit HTML-linkeiksi
var comment = item.revisions[0].comment;
comment = comment.replace( /\[\[(.*?)(\|(.*?))\]\]/g, "<a href='//fi.wikipedia.org/wiki/$1'>$3</a>" );
comment = comment.replace( /\[\[(.*?)\]\]/g, "<a href='//fi.wikipedia.org/wiki/$1'>$1</a>" );
comment = comment.replace( /(versio ([0-9]+))/g, "versio <a href='//fi.wikipedia.org/w/index.php?title=" + encodeURIComponent( title ) + "&oldid=$2'>$2</a>" );
comment = comment.replace( /\/\*(.*?)\*\//g, "<span class='autocomment'>$1</span>" );
var datetime = $( element ).find( 'a:first' );
datetime.html( datetime.html() + ' ' + datetext );
element.append( $( usertext ) );
element.append( $( '<p>' + comment + '</p>' ) );
} );
}
);
}
function second_pass() {
if ( oldreviewedpages_cache && pendingchanges_loaded && do_second_pass ) {
do_second_pass = false;
do_abusefilterHighlight();
if ( ( mw.config.get( 'wgUserGroups' ) + '' ).search( 'sysop' ) != -1 ) {
do_disable_stabilize_buttons();
}
$( '#bodyContent' ).find( 'li' ).each( function() {
var title = $( this ).find( 'a:first' ).attr( 'title' );
var node = null;
$( oldreviewedpages_cache ).find( 'p' ).each( function () {
if ( $( this ).attr( 'title' ) == title ) {
node = $( this );
}
} );
if ( node ) {
articles[title] = $( node ).attr( 'pageid' );
$( this ).attr( 'id', 'pageid_' + $( node ).attr( 'pageid' ) );
var flagged_level_text = ['Vakaa versio', 'Laadukas versio'];
var oldid = $( node ).attr( 'stable_revid' );
var revid = $( node ).attr( 'revid' );
var flagged_level = $( node ).attr( 'flagged_level' );
var url = '//fi.wikipedia.org/w/index.php?title=' + encodeURIComponent( title ) + '&oldid=' + oldid;
var muokkaa_url = '//fi.wikipedia.org/w/index.php?title=' + encodeURIComponent( title ) + '&oldid=' + oldid + '&action=edit';
var ero_url = '//fi.wikipedia.org/w/index.php?title=' + encodeURIComponent( title ) + '&oldid=' + oldid + '&diff=prev';
var col = $( this ).find( 'td:first' );
col.html( '<b><a href="' + url + '">' + flagged_level_text[flagged_level] + '</a> (<a href="' + muokkaa_url + '">muokkaa</a>)</b><div class="revisionuserinfo" /><a href="' + ero_url + '">← Vanhempi muutos</a>' );
do_revisioninfo( col.find( '.revisionuserinfo' ), title, oldid );
url = '//fi.wikipedia.org/w/index.php?title=' + encodeURIComponent( title ) + '&oldid=' + revid;
muokkaa_url = '//fi.wikipedia.org/w/index.php?title=' + encodeURIComponent( title ) + '&oldid=' + revid + '&action=edit';
var kumoa_url = '//fi.wikipedia.org/w/index.php?title=' + encodeURIComponent( title ) + '&action=edit&undoafter=' + oldid + '&undo=' + revid;
col = col.next().find( '.datetime' );
col.html( '<b><a href="' + url + '">' + col.html() + '</a> (<a href="' + muokkaa_url + '">muokkaa</a>) (<a href="' + kumoa_url + '">kumoa</a>)</b>' );
}
} );
do_categoryinfo();
}
}
// Vanha CSS-sääntö joka on poistunut
// mw.loader.load( 'https://fi.wikipedia.org/w/load.php?modules=mediawiki.action.history.diff&only=styles&skin=vector', 'text/css' );
// CSS-säännöt paikallisesti kopioituna
mw.loader.load( '/w/index.php?title=Mediawiki:Gadget-historydiff.css&action=raw&ctype=text/css', 'text/css' );
mw.loader.load( '/w/index.php?title=Mediawiki:Gadget-wikEdDiff.css&action=raw&ctype=text/css', 'text/css' );
if ( ( document.location + '' ).search( 'autodiff=1' ) != -1 ) {
do_hide_by_group();
}
$.ajax( {
type: 'GET',
url: '//fi.wikipedia.org/w/index.php?title=Toiminnot:PendingChanges&feed=atom',
dataType: 'xml'
} ).done( function( xml ) {
$( xml ).find( 'entry' ).each( function() {
var title = $( this ).find( 'title' ).text();
var author = $( this ).find( 'author' ).text();
var summary = $( this ).find( 'summary' ).text();
// var pending_since = $( this ).find( 'pending_since' ).text();
var div = $( '<div/>' ).html( summary );
div.css( 'border-top', '0.2em solid black' );
div.css( 'margin-top', '0.5em' );
div.css( 'background-color', 'white' );
div.find( 'table' ).css( 'width', '100%' );
div.find( 'tr:first' ).css( 'text-align', 'center' );
div.find( 'td.diff-marker' ).each( function() {
var td = $( this ).next();
switch ( $( this ).text() ) {
case '−':
td.attr( 'style', '' );
td.attr( 'class', 'diff-deletedline' );
break;
case '+':
td.attr( 'style', '' );
td.attr( 'class', 'diff-addedline' );
break;
default:
td.attr( 'style', '' );
td.attr( 'class', 'diff-context' );
break;
}
} );
div.find( 'td' ).each( function () {
if ( $( this ).attr( 'class' ) != 'diff-marker' ) {
$( this ).css( 'width', '50%' );
}
} );
$( '#bodyContent' ).find( 'li' ).each( function () {
if ( $( this ).children( 'a:first' ).attr( 'title' ) == title ) {
$( this ).append( div );
var author_str = '<p class="usertools" style="white-space:nowrap">';
var käyttäjä_url = '//fi.wikipedia.org/wiki/K%C3%A4ytt%C3%A4j%C3%A4:' + encodeURIComponent( author );
var keskustelu_url = '//fi.wikipedia.org/wiki/Keskustelu_k%C3%A4ytt%C3%A4j%C3%A4st%C3%A4:' + encodeURIComponent( author );
var muokkaukset_url = '//fi.wikipedia.org/wiki/Toiminnot:Muokkaukset/' + encodeURIComponent( author );
var esto_url = '//fi.wikipedia.org/wiki/Toiminnot:Est%C3%A4/' + encodeURIComponent( author );
var re = new RegExp( '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' );
if ( author.match( re ) ) {
author_str += '<a href="' + muokkaukset_url + '">' + author + '</a> ';
} else {
author_str += '<a href="' + käyttäjä_url + '">' + author + '</a> ';
}
author_str += ' ( <span class="usertoollinks"><a href="' + keskustelu_url + '">keskustelu</a> ';
if ( author.match( re ) === null ) {
author_str += ' | <a href="' + muokkaukset_url + '">muokkaukset</a> ';
}
if ( ( mw.config.get( 'wgUserGroups' ) + '' ).search( 'sysop' ) != -1 ) {
author_str += ' | <a href="' + esto_url + '">estä</a> ';
}
author_str += '</span> )</p>';
var col = $( this ).find( 'td:first' ).next();
col.html( '<div class="datetime">' + col.html() + '</div>' );
col.append( $( author_str ) );
$( this ).find( 'p:first' ).appendTo( col );
$( this ).css( 'margin-bottom', '4em' );
$( this ).css( 'padding-top', '1em' );
$( this ).css( 'border-top', '0.2em solid black' );
$( this ).parent().css( 'list-style', 'none' );
$( this ).children( ':first' ).css( 'font-size', '150%' );
$( this ).find( '.diff-multi' ).each( function( i ) {
var diff_multi = $( this );
$.get( '//fi.wikipedia.org/w/index.php?title=' + encodeURIComponent( title ) + '&action=history', function( data ) {
var parts = data.split( "<ul id=\"pagehistory\">" );
if ( !parts || !parts[1] ) return;
parts = parts[1].split( '</ul>' )[0];
var tmplist = $( '<ul>' ).html( parts );
var list = $( '<ul>' );
list.css( 'text-align', 'left' );
tmplist.find( '.flaggedrevs-pending' ).each( function () {
var oldid = $( this ).find( 'input[name=oldid]' ).attr( 'value' );
$( this ).css( 'background-color', 'white' );
var row = $( '<li><a href="//fi.wikipedia.org/w/index.php?title=' + encodeURIComponent( title ) + '&diff=prev&oldid=' + oldid + '">(ero)</a> </li>' ).append( this );
row.find( '.mw-history-histlinks' ).css( 'display', 'none' );
row.find( 'input' ).css( 'display', 'none' );
row.appendTo( list );
} );
list.appendTo( diff_multi );
} );
} );
$( this ).find( 'a' ).each( function() {
if ( $( this ).html() == 'arvioi' ) {
function do_action( action, url, oldid, element ) {
$( element ).css( 'color', 'gray' );
var node, revid, title;
if ( action == 'kumoa' ) {
node = $( oldreviewedpages_cache ).find( 'p[stable_revid=' + oldid + ']' );
if ( node !== undefined ) {
revid = node.attr( 'revid' );
title = node.attr( 'title' );
url = '//fi.wikipedia.org/w/index.php?title=' + encodeURIComponent( title ) + '&action=edit&undoafter=' + oldid + '&undo=' + revid;
window.open( url );
$( element ).css( 'color', '' );
}
} else if ( action == 'arvioi' ) {
node = $( oldreviewedpages_cache ).find( 'p[stable_revid=' + oldid + ']' );
if ( node !== undefined ) {
revid = node.attr( 'revid' );
title = node.attr( 'title' );
// https://fi.wikipedia.org/w/index.php?title=Super_Smash_Bros._(pelisarja)&diff=cur&oldid=14294562
url = '//fi.wikipedia.org/w/index.php?title=' + encodeURIComponent( title ) + '&diff=cur&oldid=' + oldid;
window.open( url );
$( element ).css( 'color', '' );
}
} else if ( action == 'vakauta' ) {
$( element ).attr( 'disabled', 'disabled' );
node = $( oldreviewedpages_cache ).find( 'p[stable_revid=' + oldid + ']' );
if ( node !== undefined ) {
title = node.attr( 'title' );
}
$.getJSON( '//fi.wikipedia.org/w/api.php?action=tokens&type=edit&format=json', function( data ) {
var wpEditToken = data.tokens.edittoken;
data = {
'wpStableconfig-override': 1,
'mwProtect-level-autoreview': '',
'wpExpirySelection': '1 week',
'mwStabilize-expiry': '',
'wpReasonSelection': 'other',
'wpReason': 'Vakautettu quickreviewin pikavakautusnapilla.',
'wpReviewthis': 0,
'wpWatchthis': 1,
'title': 'Toiminnot:Vakaaksi_versioksi',
'page': title,
'wpEditToken': wpEditToken
};
$.ajax( {
type: 'POST',
url: '/w/index.php?title=Toiminnot:Vakaaksi_versioksi&page=' + encodeURIComponent( title ),
'data': data,
dataType: 'html'
} ).done( function( xml ) {
$( element ).attr( 'value', 'Vakautettu' );
} );
} );
} else if ( action == 'hyväksy' ) {
$.ajax( {
type: 'GET',
url: url,
dataType: 'html'
} ).done( function( xml ) {
if ( ( $( xml ).find( '#mw-diff-otitle1' ).html() + '' ).search( oldid ) == -1 ) {
alert( 'wrong oldid id (page has been changed?)' );
return false;
} else {
var revid = $( xml ).find( '#mw-fr-input-oldid' ).val();
var wpEditToken = $( xml ).find( 'input[name=wpEditToken]' ).val();
var wpaccuracy = $( xml ).find( 'input:radio[name=wpaccuracy]:checked' ).val();
var data = {
'action': 'review',
'revid': revid,
'token': wpEditToken,
'wpaccuracy': wpaccuracy,
'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', '' );
} );
}
} );
} else {
alert( action );
}
}
var url = $( this ).attr( 'href' );
var oldid = 0;
var re = new RegExp( 'oldid=([0-9]+)' );
var n = url.match( re );
if ( n ) {
oldid = n[1];
}
var link = $( '<input type="button" value="Arvioi">' );
link.css( 'float', 'right' );
link.css( 'padding-right', '1em' );
link.css( 'padding-left', '1em' );
link.css( 'margin-top', '-0.25em' );
link.css( 'margin-right', '0.5em' );
link.css( 'cursor', 'pointer' );
link.css( 'text-align', 'center' );
link.click( function() { do_action( 'arvioi', url, oldid, this ); } );
$( this ).parent().prepend( link );
link = $( '<input type="button" value="Hyväksy">' );
link.css( 'float', 'right' );
link.css( 'padding-right', '1em' );
link.css( 'padding-left', '1em' );
link.css( 'margin-top', '-0.25em' );
link.css( 'margin-right', '0.5em' );
link.css( 'cursor', 'pointer' );
link.css( 'text-align', 'center' );
link.click( function() { do_action( 'hyväksy', url, oldid, this ); } );
$( this ).parent().prepend( link );
if ( ( mw.config.get( 'wgUserGroups' ) + '' ).search( 'sysop' ) != - 1 ) {
link = $( '<input type="button" value="Vakauta">' );
link.attr( 'id', 'stabilize_' + oldid );
link.css( 'float', 'right' );
link.css( 'margin-top', '-0.25em' );
link.css( 'padding-right', '1em' );
link.css( 'padding-left', '1em' );
link.css( 'cursor', 'pointer' );
link.css( 'text-align', 'center' );
link.click( function() { do_action( 'vakauta', url, oldid, this ); return false; } );
$( this ).parent().prepend( link );
}
}
} );
}
} );
} );
pendingchanges_loaded = true;
second_pass();
} );
$.ajax( {
type: 'GET',
url: '//fi.wikipedia.org/w/api.php?action=query&list=oldreviewedpages&ornamespace=0&format=xml&orlimit=100',
dataType: 'xml'
} ).done( function( xml ) {
oldreviewedpages_cache = xml;
second_pass();
} );
}
/* PendingChangesDiff() Loppuu */
if ( mw.user.options.get( 'gadget-PendingChangesDiff' ) == 1 ) {
if ( $.cookie( 'flaggedRevsCheck' ) == 2 ) {
$( '<li id="n-pendingchanges"><a href="//fi.wikipedia.org/wiki/Toiminnot:PendingChanges?autodiff=1">Näytä odottavat muutokset</a></li>' ).insertAfter( '#n-recentchanges' );
}
if ( mw.config.get( 'wgCanonicalSpecialPageName' ) == 'PendingChanges' ) {
if ( ( document.location + '' ).search( 'autodiff=1' ) != -1 ) {
showPendingChangesDiffs();
} else {
var button = $( '<input id="showPendingChangesDiffsButton" type="button" onclick="showPendingChangesDiffs()" value="Näytä diffeinä" />' );
$( 'fieldset' ).append( button );
}
}
}