User:Zanaq/browse.js

/* Browse through the articles alphabetically. (c) Zanaq 2013, GPL inspired by Trewal, http://nl.wikipedia.org/w/index.php?title=Wikipedia:De_kroeg&diff=36578376&oldid=36577552

if (wgNamespaceNumber != -1) {

if (typeof(browseShowRedirects) == "undefined") browseShowRedirects = true; if (typeof(browseShowNavigationBelowTitle) == "undefined") browseShowNavigationBelowTitle = true;

if (typeof(browseNumberOfPagesToShowInNavigation) == "undefined") browseNumberOfPagesToShowInNavigation= 3; browseNumberOfPagesToShowInNavigation = browseNumberOfPagesToShowInNavigation + 1; if (browseNumberOfPagesToShowInNavigation < 2) browseNumberOfPagesToShowInNavigation = 2; if (browseNumberOfPagesToShowInNavigation > 100) browseNumberOfPagesToShowInNavigation = 100;

var nextpage = null; var nextpagedata = null; var previouspage = null; var nextredirect = false; var previousredirect = false; var navigation = ''; var encodedTitle = encodeURIComponent(wgTitle);

var thispagename = wgPageName.replace(/_/g," ");

var redirectfilter = (browseShowRedirects) ? '' : '&gapfilterredir=nonredirects';

if (mw.user.options.values.skin == 'vector') { appendCSS('.browse-navigation-top {font-size:70%;}'); } else { appendCSS('.browse-navigation-top {font-size:85%;}'); }

if (document.getElementById('coordinates') != null) { appendCSS('.browse-navigation-top {width:75%;}'); }

appendCSS('#siteSub {display:none;}');

appendCSS('.browse-navigation-top {position:relative;top:-4px;padding-top:0;padding-bottom:0}'); appendCSS('#firstHeading {border-bottom:none}'); appendCSS('.browse-navigation-bottom {margin-top:.5em;}');

if (browseShowNavigationBelowTitle) { navigationtop = ' &nbsp '; $(navigationtop).insertAfter('#firstHeading'); }

$(' ', {   id: 'linknextpage',    text: '>',    style:'margin-left:.25em;' }).appendTo('#firstHeading');

dontredirect = (previousredirect == '') ? '?redirect=no' : '';

$(' ', {   id: 'linkpreviouspage',    text: '<',    style:'margin-right:.25em;' }).prependTo('#firstHeading');

$.getJSON('/w/api.php?action=query&generator=allpages&format=json&gapfrom=' + encodedTitle + '&gapnamespace=' + wgNamespaceNumber + '&gaplimit=' + browseNumberOfPagesToShowInNavigation + '&gapdir=ascending&prop=info&indexpageids' + redirectfilter ,

function(data) {

nextpage = data.query.pages[data.query.pageids[0]].title; nextpagedata = data;

nextredirect = data.query.pages[data.query.pageids[0]].redirect;

if (nextpage == thispagename) { nextpage = data.query.pages[data.query.pageids[1]].title; nextredirect = data.query.pages[data.query.pageids[1]].redirect; }

$.getJSON('/w/api.php?action=query&generator=allpages&format=json&gapfrom=' + encodedTitle + '&gapnamespace=' + wgNamespaceNumber + '&gaplimit=' + browseNumberOfPagesToShowInNavigation + '&gapdir=descending&prop=info&indexpageids' + redirectfilter,

function(data) {

previouspage = data.query.pages[data.query.pageids[0]].title; previousredirect = data.query.pages[data.query.pageids[0]].redirect;

if (previouspage == thispagename) { previouspage = data.query.pages[data.query.pageids[1]].title; previousredirect = data.query.pages[data.query.pageids[1]].redirect; }

dontredirect = (nextredirect == '') ? '?redirect=no' : '';

$('#linknextpage').html($('', { id: 'linknextpage', href: '/wiki/' + encodeURIComponent(nextpage) + dontredirect , title: nextpage, text: '>', }));

dontredirect = (previousredirect == '') ? '?redirect=no' : '';

$('#linkpreviouspage').html($('', { id: 'linkpreviouspage', href: '/wiki/' + encodeURIComponent(previouspage) + dontredirect, title: previouspage, text: '<', }));

$(data.query.pageids).each(

function(id, pageid) { page = data.query.pages[pageid];

if (page.title != thispagename) {

showntitle = (wgNamespaceNumber == 0) ? page.title : page.title.substr(page.title.indexOf(':') + 1);

classname = (typeof(page.redirect) != 'undefined') ? ' class="mw-redirect" ' : ''; href = '/wiki/' + encodeURIComponent(page.title); redirectclassname = (typeof(page.redirect) != 'undefined') ? ' class="allpagesredirect browse-redirect" ' : '';

navigation = '' + showntitle + ' &middot; ' + navigation; }

}

); showntitle = (wgNamespaceNumber == 0) ? thispagename : thispagename.substr(thispagename.indexOf(':') + 1); navigation += ' ' + showntitle +  ' '

$(nextpagedata.query.pageids).each(

function(id, pageid) { page = nextpagedata.query.pages[pageid];

if (page.title != thispagename) { showntitle = (wgNamespaceNumber == 0) ? page.title : page.title.substr(page.title.indexOf(':') + 1);

href = '/wiki/' + encodeURIComponent(page.title); redirectclassname = (typeof(page.redirect) != 'undefined') ? ' class="allpagesredirect browse-redirect" ' : ''; navigation = navigation + ' &middot; ' + showntitle + ' '; }

}

);

navigationbottom = ' ' + navigation + ' ';

$('#content').append(navigationbottom ); if (browseShowNavigationBelowTitle) { $('#browse-navigation-top').html(navigation); }

});

});

}