Diferencia entre revisiones de «Usuario:Leoncastro/Taller/MediaWiki:Gadget-newpages.js»

De Wikipedia, la enciclopedia libre
Contenido eliminado Contenido añadido
Nueva herramienta para señalar en rosa las páginas con plantillas de mantenimiento crítico entre las páginas nuevas sin verificar
 
Agrego soporte para Especial:LoQueEnlazaAquí
Línea 2: Línea 2:
( function ( $, mw ) {
( function ( $, mw ) {


// system structure
const not_patrolled = 'not-patrolled';
const pageStructure = {
'Newpages' : { list: '.mw-special-Newpages li.not-patrolled', anchor: 'a.mw-newpages-pagename' },
'Whatlinkshere' : { list: '.mw-special-Whatlinkshere #mw-whatlinkshere-list li', anchor: 'a' },
};
// internal className strings
const with_problems = 'with-problems';
const with_problems = 'with-problems';
// message strings
const strAPIReadError = 'Error en la recuperación de datos de la API';


var pageName = mw.config.get( 'wgCanonicalSpecialPageName' );
var strAPIReadError = 'Error en la recuperación de datos de la API';

var categories = [
var categories = [
'Categoría:Wikipedia:Borrar (definitivo)',
'Categoría:Wikipedia:Borrar (definitivo)',
Línea 29: Línea 36:
function getTitlesFromPage ()
function getTitlesFromPage ()
{
{
return $( 'li.' + not_patrolled ).map( function ( index, item ) {
return $( pageStructure[pageName].list ).map( function ( index, item ) {
var anchor = $( item ).find( 'a.mw-newpages-pagename' );
var anchor = $( item ).find( pageStructure[pageName].anchor );
var title = getTitleFromLink( anchor.attr( 'href' ) );
var title = getTitleFromLink( anchor.attr( 'href' ) );
return title;
return title;
Línea 101: Línea 108:
{
{
apiBuildList( getTitlesFromPage() ).done( function ( list ) {
apiBuildList( getTitlesFromPage() ).done( function ( list ) {
$( 'li.' + not_patrolled ).each( function ( index, item ) {
$( pageStructure[pageName].list ).each( function ( index, item ) {
var anchor = $( item ).find( 'a.mw-newpages-pagename' );
var anchor = $( item ).find( pageStructure[pageName].anchor );
var title = getTitleFromLink( anchor.attr( 'href' ) );
var title = getTitleFromLink( anchor.attr( 'href' ) );
if ( $.inArray( title, list ) >= 0 )
if ( $.inArray( title, list ) >= 0 )
Línea 114: Línea 121:
function init ()
function init ()
{
{
var css = '.' + not_patrolled + '.' + with_problems + ' { background-color: pink; }\n';
var css = '.' + with_problems + ' { background-color: pink; }\n';
mw.util.addCSS( css );
mw.util.addCSS( css );
exec();
exec();
Línea 120: Línea 127:


if ( 'Special' === mw.config.get( 'wgCanonicalNamespace' ) &&
if ( 'Special' === mw.config.get( 'wgCanonicalNamespace' ) &&
'Newpages' === mw.config.get( 'wgCanonicalSpecialPageName' ) )
( 'Newpages' === pageName || 'Whatlinkshere' === pageName ) )
{
{
mw.loader.using( [ 'mediawiki.util', 'mediawiki.api' ] ).then( init );
mw.loader.using( [ 'mediawiki.util', 'mediawiki.api' ] ).then( init );

Revisión del 04:00 19 abr 2019

//<nowiki>
( function ( $, mw ) {

	// system structure
	const pageStructure = {
		'Newpages' : { list: '.mw-special-Newpages li.not-patrolled', anchor: 'a.mw-newpages-pagename' },
		'Whatlinkshere' : { list: '.mw-special-Whatlinkshere #mw-whatlinkshere-list li', anchor: 'a' },
	};
	// internal className strings
	const with_problems = 'with-problems';
	// message strings
	const strAPIReadError = 'Error en la recuperación de datos de la API';

	var pageName = mw.config.get( 'wgCanonicalSpecialPageName' );
 
	var categories = [
		'Categoría:Wikipedia:Borrar (definitivo)',
		'Categoría:Wikipedia:Artículos propuestos para borrado',
		'Categoría:Wikipedia:Traducción automática',
		'Categoría:Wikipedia:Artículos sin contextualizar',
		'Categoría:Wikipedia:Artículos sospechosos de fuente primaria',
		'Categoría:Wikipedia:Infraesbozos',
		'Categoría:Wikipedia:Plantillas para borrar',
		'Categoría:Wikipedia:Plagios obvios',
		'Categoría:Wikipedia:Artículos sospechosos de violar los derechos de autor',
		'Categoría:Wikipedia:Posible promoción o publicidad',
		'Categoría:Wikipedia:Sin relevancia aparente'
	];

	function getTitleFromLink ( href )
	{
		const uriRegexp = /^\/w(?:iki)?\/(?:index.php\?title\=)?|\&redirect\=no/g;
		return decodeURIComponent( href.replace( uriRegexp, '' ).replace( /_/g, ' ' ) );
	}

	function getTitlesFromPage ()
	{
		return $( pageStructure[pageName].list ).map( function ( index, item ) {
			var anchor = $( item ).find( pageStructure[pageName].anchor );
			var title = getTitleFromLink( anchor.attr( 'href' ) );
			return title;
		} ).toArray();
	}

	var longquery = {};

	function apiQueryCats ( query, result, queryContinue )
	{
		if ( !queryContinue )
		{
			queryContinue = { 'continue': '' };
		}
		$.get( mw.util.wikiScript('api'), $.extend( {}, query, queryContinue ) )
		.done( function ( json ) {
			if ( json )
			{
				if ( json.query && json.query.pages )
				{
					$.extend( longquery, json.query.pages );
				}
				if ( json['continue'] )
				{
					apiQueryCats( query, result, json['continue'] );
				}
				else
				{
					result.resolve( longquery );
				}
			}
		} )
		.fail( function (e) {
			mw.notify( strAPIReadError );
		} );
	}

	function apiBuildList ( titles )
	{
		var looping = $.Deferred();
		var listing = $.Deferred();
		var query = {
			action: 'query',
			format: 'json',
			prop: 'categories',
			clcategories: categories.join( '|' ),
			cllimit: 'max'
		};
		while ( titles.length > 0 )
		{
			apiQueryCats( $.extend( {}, query, { titles: titles.splice( 0, 50 ).join( '|' ) } ), looping );
		}
		$.when( looping ).done( function ( pages ) {
			var list = [];
			for ( var pageid in pages )
			{
				var item = pages[ pageid ];
				if ( item.categories )
				{
					list.push( item.title );
				}
			}
			listing.resolve( list );
			longquery = {};
		} );
		return $.when( listing );
	}

	function exec ()
	{
		apiBuildList( getTitlesFromPage() ).done( function ( list ) {
			$( pageStructure[pageName].list ).each( function ( index, item ) {
				var anchor = $( item ).find( pageStructure[pageName].anchor );
				var title = getTitleFromLink( anchor.attr( 'href' ) );
				if ( $.inArray( title, list ) >= 0 )
				{
					$( item ).addClass( with_problems );
				}
			} );
		} );
	}

	function init ()
	{
		var css = '.' + with_problems + ' { background-color: pink; }\n';
		mw.util.addCSS( css );
		exec();
	}

	if ( 'Special' === mw.config.get( 'wgCanonicalNamespace' ) &&
		( 'Newpages' === pageName || 'Whatlinkshere' === pageName ) )
	{
		mw.loader.using( [ 'mediawiki.util', 'mediawiki.api' ] ).then( init );
	}
} ( jQuery, mediaWiki ) );
//</nowiki>