mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/RelatedArticles
synced 2024-11-24 00:05:50 +00:00
Merge "Breaking change: Remove Sidebar code from RelatedArticles"
This commit is contained in:
commit
70787d2d70
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "RelatedArticles",
|
||||
"version": "2.1.0",
|
||||
"version": "3.0.0",
|
||||
"author": [
|
||||
"Roland Unger",
|
||||
"Hans Musil",
|
||||
|
@ -14,7 +14,6 @@
|
|||
"AutoloadClasses": {
|
||||
"RelatedArticles\\ResourceLoaderMuHoganModule": "includes/ResourceLoaderMuhoganModule.php",
|
||||
"RelatedArticles\\Hooks": "includes/Hooks.php",
|
||||
"RelatedArticles\\SidebarHooks": "includes/SidebarHooks.php",
|
||||
"RelatedArticles\\FooterHooks": "includes/FooterHooks.php"
|
||||
},
|
||||
"ExtensionMessagesFiles": {
|
||||
|
@ -32,10 +31,6 @@
|
|||
"RelatedArticles\\Hooks::onOutputPageParserOutput"
|
||||
],
|
||||
|
||||
"SidebarBeforeOutput": [
|
||||
"RelatedArticles\\SidebarHooks::onSidebarBeforeOutput"
|
||||
],
|
||||
|
||||
"MakeGlobalVariablesScript": [
|
||||
"RelatedArticles\\FooterHooks::onMakeGlobalVariablesScript"
|
||||
],
|
||||
|
@ -164,8 +159,6 @@
|
|||
"config": {
|
||||
"@RelatedArticlesCardLimit": "Maximum number of articles that should be shown in RelatedArticles widget. This limit is derived from limits in TextExtracts and PageImages extensions. Number should be between 1 and 20.",
|
||||
"RelatedArticlesCardLimit": 3,
|
||||
"RelatedArticlesShowInSidebar": true,
|
||||
"RelatedArticlesShowInFooter": false,
|
||||
"RelatedArticlesUseCirrusSearch": false,
|
||||
"RelatedArticlesOnlyUseCirrusSearch": false,
|
||||
"RelatedArticlesLoggingBucketSize": 0.01,
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
"@metadata": {
|
||||
"authors": []
|
||||
},
|
||||
"relatedarticles-title": "Related pages",
|
||||
"relatedarticles-desc": "Adds a link to related pages on the sidebar or in the footer, if the user enables the beta feature.",
|
||||
"relatedarticles-read-more-heading": "Related pages"
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
"Robby"
|
||||
]
|
||||
},
|
||||
"relatedarticles-title": "Title shown on the sidebar",
|
||||
"relatedarticles-desc": "{{desc|name=Related Articles|url=https://www.mediawiki.org/wiki/Extension:RelatedArticles}}",
|
||||
"relatedarticles-read-more-heading": "The heading of section, added at the end of the page, that lists the related pages"
|
||||
}
|
||||
|
|
|
@ -89,7 +89,6 @@ class FooterHooks {
|
|||
* to the output when:
|
||||
*
|
||||
* <ol>
|
||||
* <li><code>$wgRelatedArticlesShowInFooter</code> is truthy</li>
|
||||
* <li>On mobile, the output is being rendered with
|
||||
* <code>SkinMinervaBeta<code></li>
|
||||
* <li>The page is in mainspace</li>
|
||||
|
@ -105,15 +104,10 @@ class FooterHooks {
|
|||
* @return bool Always <code>true</code>
|
||||
*/
|
||||
public static function onBeforePageDisplay( OutputPage $out, Skin $skin ) {
|
||||
$config = MediaWikiServices::getInstance()->getConfigFactory()
|
||||
->makeConfig( 'RelatedArticles' );
|
||||
$showReadMore = $config->get( 'RelatedArticlesShowInFooter' );
|
||||
|
||||
$title = $out->getContext()->getTitle();
|
||||
$action = $out->getRequest()->getText( 'action', 'view' );
|
||||
|
||||
if (
|
||||
$showReadMore &&
|
||||
$title->inNamespace( NS_MAIN ) &&
|
||||
// T120735
|
||||
$action === 'view' &&
|
||||
|
|
|
@ -1,116 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace RelatedArticles;
|
||||
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use Title;
|
||||
use Skin;
|
||||
use Html;
|
||||
use User;
|
||||
|
||||
class SidebarHooks {
|
||||
|
||||
/**
|
||||
* Handler for the <code>SidebarBeforeOutput</code> hook.
|
||||
*
|
||||
* Retrieves the list of related pages
|
||||
* and adds its HTML representation to the sidebar if the ReadMore feature
|
||||
* is disabled and the beta feature is enabled by the user.
|
||||
*
|
||||
* @param Skin $skin Skin object
|
||||
* @param array &$bar Sidebar contents
|
||||
* @return bool Always <code>true</code>
|
||||
*/
|
||||
public static function onSidebarBeforeOutput( Skin $skin, &$bar ) {
|
||||
$out = $skin->getOutput();
|
||||
$relatedPages = $out->getProperty( 'RelatedArticles' );
|
||||
|
||||
if ( !self::isInSidebar( $relatedPages, $out->getUser() ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$relatedPagesUrls = self::getRelatedPagesUrls( $relatedPages );
|
||||
|
||||
// build relatedarticles <li>'s
|
||||
$relatedPages = [];
|
||||
foreach ( (array)$relatedPagesUrls as $url ) {
|
||||
$relatedPages[] =
|
||||
Html::rawElement( 'li', [ 'class' => htmlspecialchars( $url['class'] ) ],
|
||||
Html::element( 'a', [ 'href' => htmlspecialchars( $url['href'] ) ],
|
||||
$url['text']
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// build complete html
|
||||
$bar[$skin->msg( 'relatedarticles-title' )->text()] =
|
||||
Html::rawElement( 'ul', [],
|
||||
implode( '', $relatedPages )
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates anchor element attributes for each entry in list of pages.
|
||||
*
|
||||
* The attributes that are generated are: <code>href</code>,
|
||||
* <code>text</code>, and <code>class</code>, with the latter always
|
||||
* set to <code>"interwiki-relart"</code>.
|
||||
*
|
||||
* If the the page is of the form <code>"Foo && Bar"</code>, then
|
||||
* the <code>text</code> attribute will be set to "Bar", otherwise the
|
||||
* page's {@see Title::getPrefixedText prefixed text} will be used.
|
||||
*
|
||||
* @param array[string] $relatedPages
|
||||
* @return array An array of maps, each with <code>href</code>,
|
||||
* <code>text</code>, and <code>class</code> entries.
|
||||
*/
|
||||
private static function getRelatedPagesUrls( array $relatedPages ) {
|
||||
$relatedPagesUrls = [];
|
||||
|
||||
foreach ( $relatedPages as $page ) {
|
||||
// Tribute to Evan
|
||||
$page = urldecode( $page );
|
||||
|
||||
$altText = '';
|
||||
if ( preg_match( '/\&\&/', $page ) ) {
|
||||
$parts = array_map( 'trim', explode( '&&', $page, 2 ) );
|
||||
$page = $parts[0];
|
||||
$altText = $parts[1];
|
||||
}
|
||||
|
||||
$title = Title::newFromText( $page );
|
||||
if ( $title ) {
|
||||
$relatedPagesUrls[] = [
|
||||
'href' => $title->getLocalURL(),
|
||||
'text' => $altText ?: $title->getPrefixedText(),
|
||||
'class' => 'interwiki-relart'
|
||||
];
|
||||
}
|
||||
};
|
||||
|
||||
return $relatedPagesUrls;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether there are related articles that can be displayed, or
|
||||
* the ReadMore feature is disabled. The beta feature is used only
|
||||
* for enabling ReadMore, so do not take it into account.
|
||||
*
|
||||
* @param mixed $relatedPages
|
||||
* @param User $user
|
||||
* @return bool
|
||||
* @throws \ConfigException
|
||||
*/
|
||||
private static function isInSidebar( $relatedPages, User $user ) {
|
||||
$config = MediaWikiServices::getInstance()->getConfigFactory()
|
||||
->makeConfig( 'RelatedArticles' );
|
||||
|
||||
if ( !$relatedPages || !$config->get( 'RelatedArticlesShowInSidebar' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
<?php
|
||||
|
||||
$wgRelatedArticlesLoggingBucketSize = 1;
|
||||
$wgRelatedArticlesShowInFooter = true;
|
||||
$wgRelatedArticlesShowInSidebar = true;
|
||||
$wgRelatedArticlesLoggingSamplingRate = 1;
|
||||
$wgRelatedArticlesUseCirrusSearch = true;
|
||||
$wgRelatedArticlesOnlyUseCirrusSearch = false;
|
||||
|
|
Loading…
Reference in a new issue