LLWiki正在建设中,欢迎加入我们

“MediaWiki:Gadget-MobileCategories.js”的版本间差异

来自LLWiki
跳转到导航 跳转到搜索
标签移动版网页编辑 移动版编辑
第42行: 第42行:
.addClass('mw-normal-catlinks')
.addClass('mw-normal-catlinks')
.append( $( '<ul>' ).append( categories ) )
.append( $( '<ul>' ).append( categories ) )
.prepend( mw.message( 'pagecategories' ).escaped() + mw.message( 'colon-separator' ).escaped() );
.prepend( '<a href="/zh/Special:Categories" title="Special:页面分类">' + mw.message( 'pagecategories' ).escaped() + '</a>' + mw.message( 'colon-separator' ).escaped() );
$('.printfooter')
$('.printfooter')
.after( $( '<div>' )
.after( $( '<div>' )

2020年8月13日 (四) 11:06的版本

// 引自[[wikipedia:mediawiki:gadget-MobileCategories.js]]
mw.hook( 'wikipage.content' ).add( function() {
    if(mw.config.get('skin') == 'vector') { return; }

    var api = new mw.Api(),
        apiRequest = api.get( {
        'action':'query',
        'titles': mw.config.get('wgPageName'),
        'prop': 'categories',
        'clprop': 'sortkey|hidden',
        'cllimit': 50,
        'indexpageids': true,
        'formatversion': 2
    } ),
        apiRequest2 = api.loadMessagesIfMissing( [ 'pagecategories', 'colon-separator' ] );

    $.when( apiRequest, apiRequest2 ).done( function( data ) {
        var categories = [],
            response1Data = data[0],
            response2Data = data[1];
        
        if( !response1Data.query.pages[0].categories ) { return; }
        
        function categoryHtmlGenerator(element, index, array) {
            var title = new mw.Title( element.title, mw.config.get( 'wgNamespaceIds' ).file );
            if( !element.hidden ) {
                categories.push( $('<li>').append(
                    $( '<a>' ).attr( 'href', mw.util.getUrl( element.title ) )
                        .attr( 'title', title )
                        .append( document.createTextNode( title.getMainText() ) )
                    ).get( 0 )
                );
            }
        }
        
        response1Data.query.pages[0].categories.forEach( categoryHtmlGenerator );

        if( categories.length === 0 ) { return; }
        
        var catlinks = $( '<div>' )
            .attr( 'id', 'mw-normal-catlinks' )
            .addClass('mw-normal-catlinks')
            .append( $( '<ul>' ).append( categories ) )
            .prepend( '<a href="/zh/Special:Categories" title="Special:页面分类">' + mw.message( 'pagecategories' ).escaped() + '</a>' + mw.message( 'colon-separator' ).escaped() );
        $('.printfooter')
            .after( $( '<div>' )
                .addClass( 'catlinks' )
                .attr( 'id', 'catlinks' )
                .data( 'mw', 'interface' )
                .append( catlinks )
            );
    } );
} );