Diferencia entre revisiones de «MediaWiki:Gadget-show-quality-on-cats.js»
Ir a la navegación
Ir a la búsqueda
m (tweak) |
m (fix keeper handling) |
||
Línea 21: | Línea 21: | ||
// not on quality cats (pointless) |
// not on quality cats (pointless) |
||
if (Object.values(cats).includes(mw.config.get('wgTitle'))) return |
if (Object.values(cats).includes(mw.config.get('wgTitle'))) return |
||
// add specials for keepers |
|||
⚫ | |||
⚫ | |||
⚫ | |||
console.warn('gadget:', 'show-quality-markers') |
console.warn('gadget:', 'show-quality-markers') |
||
Línea 77: | Línea 82: | ||
}) // end of MW hook |
}) // end of MW hook |
||
⚫ | |||
⚫ | |||
⚫ |
Revisión del 19:28 14 ago 2019
mw.hook('wikipage.content').add(function hook_handler() { const cats = { // quality stub: 'Stubs', part: 'Partially complete articles', good: 'Articles nearing completion', done: 'Complete articles', // other lookers gold: 'Exemplary articles', look: 'Articles in need of attention', list: 'List articles', note: 'Notable articles', } // 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 // add specials for keepers if (mw.config.get('wgUserGroups').includes('keeper')) { 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).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) // TODO: this doesn't work 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') const cat = all[title][0] if (!cat) return const li = el.parentElement li.classList.add('quality') li.classList.add(css_class[cat]) }) mw.hook('quality-on-cats').fire() }) // end of API query }) // end of MW hook