mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/RelatedArticles
synced 2024-12-18 11:00:58 +00:00
be3385e6d5
Currently, the extension queries the prop=description api to fetch the description, but this api is only available if Wikibaseclient is installed. Let's support other sources to fetch the page description from, too, or disable it (by default) to sabe 85 bytes from each response by avoiding the warning returned from the api when prop=description is not recognized. A new configuration setting has been added: RelatedArticlesDescriptionSource. It defaults to false (no description is fetched), but can be set to one of those string values: - wikidata: What's being used right now on WMF wikis - textextracts: Extension:TextExtracts provides the prop=extracts api. - pagedescription: Extension:Description2 provides a description page property, that can be queried by prop=pageprops&ppprop=description Bug: T230947 Change-Id: I34410334ba9d6db1f686c7efb5722e2a51957145
51 lines
1.4 KiB
JavaScript
51 lines
1.4 KiB
JavaScript
( function () {
|
|
// Make sure 'ext.relatedArticles.cards' is loaded. It may not be because of the race
|
|
// condition in the bootstrap file.
|
|
mw.loader.using( 'ext.relatedArticles.cards' ).done( function () {
|
|
var CardModel = mw.cards.CardModel,
|
|
CardView = mw.cards.CardView,
|
|
CardListView = mw.cards.CardListView;
|
|
|
|
/**
|
|
* Generates `mw.cards.CardView`s from pages
|
|
*
|
|
* @param {Object[]} pages
|
|
* @return {mw.cards.CardView[]}
|
|
*/
|
|
function getCards( pages ) {
|
|
return pages.map( function ( page ) {
|
|
var result = {
|
|
title: page.title,
|
|
url: mw.util.getUrl( page.title ),
|
|
hasThumbnail: false,
|
|
extract: ( page.description || page.extract ||
|
|
( page.pageprops ? page.pageprops.description : '' ) )
|
|
};
|
|
|
|
if ( page.thumbnail ) {
|
|
result.hasThumbnail = true;
|
|
result.thumbnailUrl = page.thumbnail.source;
|
|
result.isThumbnailPortrait = page.thumbnail.height >= page.thumbnail.width;
|
|
}
|
|
|
|
return new CardView( new CardModel( result ) );
|
|
} );
|
|
}
|
|
|
|
mw.trackSubscribe( 'ext.relatedArticles.init', function ( _, pages ) {
|
|
var $readMore,
|
|
cards;
|
|
|
|
cards = new CardListView( getCards( pages ) );
|
|
|
|
$readMore = $( '<aside>' ).addClass( 'ra-read-more noprint' )
|
|
.append( $( '<h2></h2>' ).text( mw.msg( 'relatedarticles-read-more-heading' ) ) )
|
|
.append( cards.$el );
|
|
|
|
// eslint-disable-next-line no-jquery/no-global-selector
|
|
$( '.read-more-container' ).append( $readMore );
|
|
} );
|
|
} );
|
|
|
|
}() );
|