MediaWiki:Gadget-MobileCategories.js:修订间差异

无编辑摘要
Mediawiki>TheDJ
无编辑摘要
 
imported>=海豚=
无编辑摘要
 
(未显示同一用户的2个中间版本)
第1行: 第1行:
mw.hook( 'wikipage.content' ).add( function() {
/**
var api = new mw.Api();
* @Source: https://llwiki.org/zh/mediawiki:gadget-MobileCategories.js
* @Author: wikipedia:mediawiki:gadget-MobileCategories.js
var apiRequest = api.get( {
* @License: CC BY-NC-SA 3.0
'action':'query',
*/
'titles': mw.config.get('wgPageName'),
$(function() {
'prop': 'categories',
   if ( mw.config.get('skin') == 'vector' ||
'clprop': 'sortkey|hidden',
   !["view","submit"].includes(mw.config.get('wgAction')) ) {
'cllimit': 50,
     window.MobileCategoriesComplete = true;
'indexpageids': true,
     return;
'formatversion': 2
   }
} );
var apiRequest2 = api.loadMessagesIfMissing( [ 'pagecategories', 'colon-separator' ] );


$.when( apiRequest, apiRequest2 ).done( function( data ) {
   var showhiddencats = mw.user.options.get('showhiddencats'),
var categories = [],
     api = new mw.Api(),
response1Data = data[0],
     apiRequest = api.get( {action:'query', titles: mw.config.get('wgPageName'), prop: 'categories', clprop: 'hidden', cllimit: 50, formatversion: 2 } ),
response2Data = data[1];
     apiRequest2 = api.loadMessagesIfMissing( [ 'pagecategories', 'colon-separator' ] );
if( !response1Data.query.pages[0].categories ) {
return;
}
function categoryHtmlGenerator(element, index, array) {
if( element.hidden ) {
return;
}
var title = new mw.Title( element.title, mw.config.get( 'wgNamespaceIds' ).file );
  categories.push(
  $( '<a>' ).attr( {
  'href': mw.util.getUrl( element.title )
  } ).append(
  document.createTextNode( title.getMainText() )
  ).get( 0 )
  );
categories.push( ', ' );
}
response1Data.query.pages[0].categories.forEach( categoryHtmlGenerator );


if( categories.length === 0 ) {
   $.when( apiRequest, apiRequest2 ).done( function( data ) {
return;
     var categories = [],
}
       hiddenCats = [],
categories.pop(); //remove the last comma
       response1Data = data[0],
categories.unshift( document.createTextNode(
       response2Data = data[1],
mw.message( 'pagecategories' ).escaped() + mw.message( 'colon-separator' ).escaped() + ' '
       allCats = response1Data.query.pages[0].categories || [];
) );
    
     if ( allCats.length === 0 ) {
$('.printfooter')
       window.MobileCategoriesComplete = true;
.after( $( '<div>' )
       return;
.addClass( 'catlinks' )
     }
.attr( 'id', 'catlinks' )
     mw.config.set('wgCategories', allCats.map(function(ele) { return ele.title.slice(9); }));
.data( 'mw', 'interface' )
 
.append( $( '<div>' )
     api.get({ action:'parse', text:JSON.stringify(allCats), contentmodel:'wikitext', variant:mw.config.get('wgUserVariant'), formatversion:2, prop:'text' })
.attr( 'id', 'mw-normal-catlink' )
       .then(function(data2) {
.append( categories )
       const allCatsVar = data2.parse.text.match(/<p>(.*)\n<\/p>/)[1],
)
         contentCats = JSON.parse(allCatsVar);
);
      
} );
       function categoryHtmlGenerator(element, index, array) {
         if ( !element.hidden ) {
           categories.push( $('<li>').append(
             $( '<a>' ).attr( 'href', mw.util.getUrl( element.title ) )
               .attr( 'title', element.title )
               .append( document.createTextNode( contentCats[index].title.substring(9) ) )
             ).get( 0 )
           );
         }
         else if (showhiddencats) {
           hiddenCats.push( $('<li>').append(
             $( '<a>' ).attr( 'href', mw.util.getUrl( element.title ) )
               .attr( 'title', element.title )
               .append( document.createTextNode( contentCats[index].title.substring(9) ) )
             ).get( 0 )
           );
         }
       }
 
       allCats.forEach( categoryHtmlGenerator );
 
       if ( categories.length === 0 && hiddenCats.length === 0 ) {
         window.MobileCategoriesComplete = true;
         return;
       }
    
       var normalCatlinks, hiddenCatlinks;
       if (categories.length) {
         normalCatlinks = $( '<div>' )
           .attr( 'id', 'mw-normal-catlinks' )
           .addClass('mw-normal-catlinks')
           .append( $( '<ul>' ).append( categories ) )
           .prepend( '<a href="/Special:Categories" title="Special:页面分类">' + mw.message( 'pagecategories' ).escaped() + '</a>' + mw.message( 'colon-separator' ).escaped() );
       }
       if (hiddenCats.length) {
         hiddenCatlinks = $( '<div>' )
           .attr( 'id', 'mw-hidden-catlinks' )
           .addClass(['mw-hidden-catlinks', 'mw-hidden-cats-user-shown'])
           .append( $( '<ul>' ).append( hiddenCats ) )
           .prepend( wgULS("隐藏分类", "隱藏分類") + mw.message( 'colon-separator' ).escaped() );
       }
       var catlinks = $( '<div>' )
         .addClass( 'catlinks' )
         .attr( 'id', 'catlinks' )
         .data( 'mw', 'interface' );
       if (normalCatlinks) { catlinks.append(normalCatlinks); }
       if (hiddenCatlinks) { catlinks.append(hiddenCatlinks); }
       $('.printfooter').after(catlinks);
       window.MobileCategoriesComplete = true;
       mw.hook( 'wikipage.categories' ).fire(catlinks);
     });
   } );
} );
} );
匿名用户