Diferencia entre revisiones de «MediaWiki:Gadget-show-quality-on-cats.js»
Ir a la navegación
Ir a la búsqueda
m (try) |
m |
||
(No se muestran 32 ediciones intermedias de otro usuario) | |||
Línea 1: | Línea 1: | ||
mw.hook('wikipage.content').add(function () { |
mw.hook('wikipage.content').add(function hook_handler() { |
||
const |
const cats = { |
||
'Stubs' |
stub: 'Stubs', |
||
'Partially complete articles' |
part: 'Partially complete articles', |
||
'Articles nearing completion' |
good: 'Articles nearing completion', |
||
'Complete articles' |
done: 'Complete articles', |
||
best: 'Exemplary articles', |
|||
warn: 'Articles in need of attention', |
|||
meta: 'Meta', |
|||
} |
} |
||
// SEE: [[MediaWiki:Gadget-quality.css]] for icons and colors |
|||
const css_class = Object.fromEntries(Object.entries(cats).map(function map_cats_to_classes(kv) { return [kv[1],'quality-' + kv[0]]; })) |
|||
// only on categories |
// only on categories |
||
if (mw.config.get('wgCanonicalNamespace') != 'Category') return |
if (mw.config.get('wgCanonicalNamespace') != 'Category') return |
||
// not on quality cats (pointless) |
|||
//if (Object.values(cats).includes(mw.config.get('wgTitle'))) return |
|||
// TODO: only ignore |
|||
// add specials for keepers |
|||
if (mw.config.get('wgUserGroups').includes('sysop')) { |
|||
document.querySelector('#mw-pages').classList.add('keeper-highlight-good') |
|||
⚫ | |||
console.warn('gadget:', 'show-quality-markers') |
console.warn('gadget:', 'show-quality-markers') |
||
const query = { |
|||
;(new mw.Api).get({ |
|||
action: "query", |
|||
format: "json", |
|||
prop: "categories", |
prop: "categories", |
||
indexpageids: true, |
indexpageids: true, |
||
cllimit: "max", |
cllimit: "max", |
||
clcategories: Object.values(cats).filter(function (cat) { return cat != mw.config.get('wgTitle') }).map(function(cat) { return 'Category:'+ cat }), |
|||
generator: "categorymembers", |
generator: "categorymembers", |
||
gcmtitle: mw.config.get('wgPageName'), |
gcmtitle: mw.config.get('wgPageName'), |
||
gcmlimit: "max", |
gcmlimit: "max", |
||
gcmtype: "page", |
gcmtype: "page", |
||
} |
|||
}).then(function (response) { |
|||
const |
const api = new mw.Api({ parameters: query, }) |
||
⚫ | |||
⚫ | |||
⚫ | |||
all[page.title] = page.categories.map(function(o){ return o.title.replace('Category:','') }); |
|||
⚫ | |||
// page => [cat,...] |
|||
⚫ | |||
const categories = {} |
|||
⚫ | |||
function paginate(resp) { |
|||
⚫ | |||
⚫ | |||
if (!categories[page.title]) |
|||
categories[page.title] = [] |
|||
⚫ | |||
⚫ | |||
const cat = row.title.replace('Category:','') |
|||
categories[page.title].push(cat) |
|||
}) |
|||
}) |
|||
if (!resp.continue) { |
|||
return categories |
|||
} |
|||
console.debug('continuing:', resp.continue) |
|||
return api.get(resp.continue).then(paginate) |
|||
} |
|||
api.get().then(paginate).then(function all_results(all) { |
|||
console.debug('article-qualities:', all) |
|||
⚫ | |||
const title = el.getAttribute('title') |
const title = el.getAttribute('title') |
||
all[title].forEach(function each_quality_cat(cat) { |
|||
const data = all[title] |
|||
⚫ | |||
if (! |
if (!css_class[cat]) return |
||
const icon = String.fromCodePoint.apply(icons[cat]) |
|||
li.classList.add('quality') |
|||
⚫ | |||
li.classList.add(css_class[cat]) |
|||
}) |
|||
}) |
}) |
||
document.querySelectorAll('.quality-meta').forEach(function clean_meta(el) { |
|||
el.classList.remove('quality') |
|||
}) |
}) |
||
mw.hook('quality-on-cats').fire() |
|||
}) // end of API query |
}) // end of API query |
||
}) // end of MW hook |
}) // end of MW hook |
Revisión actual - 23:39 10 jun 2024
mw.hook('wikipage.content').add(function hook_handler() { const cats = { stub: 'Stubs', part: 'Partially complete articles', good: 'Articles nearing completion', done: 'Complete articles', best: 'Exemplary articles', warn: 'Articles in need of attention', meta: 'Meta', } // SEE: [[MediaWiki:Gadget-quality.css]] for icons and colors const css_class = Object.fromEntries(Object.entries(cats).map(function map_cats_to_classes(kv) { return [kv[1],'quality-' + kv[0]]; })) // only on categories if (mw.config.get('wgCanonicalNamespace') != 'Category') return // not on quality cats (pointless) //if (Object.values(cats).includes(mw.config.get('wgTitle'))) return // TODO: only ignore // add specials for keepers if (mw.config.get('wgUserGroups').includes('sysop')) { document.querySelector('#mw-pages').classList.add('keeper-highlight-good') } console.warn('gadget:', 'show-quality-markers') const query = { prop: "categories", indexpageids: true, cllimit: "max", clcategories: Object.values(cats).filter(function (cat) { return cat != mw.config.get('wgTitle') }).map(function(cat) { return 'Category:'+ cat }), generator: "categorymembers", gcmtitle: mw.config.get('wgPageName'), gcmlimit: "max", gcmtype: "page", } const api = new mw.Api({ parameters: query, }) // page => [cat,...] const categories = {} function paginate(resp) { resp.query.pageids.forEach(function each_pageid(id) { const page = resp.query.pages[id] if (!categories[page.title]) categories[page.title] = [] if (!page.categories) return page.categories.forEach(function each_cat(row) { const cat = row.title.replace('Category:','') categories[page.title].push(cat) }) }) if (!resp.continue) { return categories } console.debug('continuing:', resp.continue) return api.get(resp.continue).then(paginate) } api.get().then(paginate).then(function all_results(all) { console.debug('article-qualities:', all) document.querySelectorAll('#mw-pages a').forEach(function each_link(el) { const title = el.getAttribute('title') all[title].forEach(function each_quality_cat(cat) { const li = el.parentElement if (!css_class[cat]) return li.classList.add('quality') li.classList.add(css_class[cat]) }) }) document.querySelectorAll('.quality-meta').forEach(function clean_meta(el) { el.classList.remove('quality') }) mw.hook('quality-on-cats').fire() }) // end of API query }) // end of MW hook