Add Related Articles section to Minerva
If the page has related articles, is in mainspace, isn't the main page,
and the output is being rendered with the MinervaBeta skin then a
"Related Articles" section is added to the page just before the footer.
Separate loading the information necessary to render the pages, choosing
the renderer, and rendering the data so that multiple skins - currently
Minerva and Vector per the mocks - not just multiple resolutions can all
be handled the same way:
* The bootstrap script (ext.relatedArticles.readMore.bootstrap/index.js)
for fetches the page image and Wikidata description; loading the
renderer module; and, finally, notifying the renderer module that it
should render the data, which it does by emitting
"ext.relatedArticles.readMore.init" event using mw#track
* The Minerva renderer subscribes to the event and, when it's fired,
renders the data by passing it to the WatchstarPageList view
Bug: T113635
Change-Id: I651342bdf9796938fa7051828dd13bc6fe774783
2015-10-07 13:12:42 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace RelatedArticles;
|
|
|
|
|
2015-11-19 03:49:46 +00:00
|
|
|
use BetaFeatures;
|
Add Related Articles section to Minerva
If the page has related articles, is in mainspace, isn't the main page,
and the output is being rendered with the MinervaBeta skin then a
"Related Articles" section is added to the page just before the footer.
Separate loading the information necessary to render the pages, choosing
the renderer, and rendering the data so that multiple skins - currently
Minerva and Vector per the mocks - not just multiple resolutions can all
be handled the same way:
* The bootstrap script (ext.relatedArticles.readMore.bootstrap/index.js)
for fetches the page image and Wikidata description; loading the
renderer module; and, finally, notifying the renderer module that it
should render the data, which it does by emitting
"ext.relatedArticles.readMore.init" event using mw#track
* The Minerva renderer subscribes to the event and, when it's fired,
renders the data by passing it to the WatchstarPageList view
Bug: T113635
Change-Id: I651342bdf9796938fa7051828dd13bc6fe774783
2015-10-07 13:12:42 +00:00
|
|
|
use OutputPage;
|
2015-10-29 17:58:30 +00:00
|
|
|
use ResourceLoader;
|
Add Related Articles section to Minerva
If the page has related articles, is in mainspace, isn't the main page,
and the output is being rendered with the MinervaBeta skin then a
"Related Articles" section is added to the page just before the footer.
Separate loading the information necessary to render the pages, choosing
the renderer, and rendering the data so that multiple skins - currently
Minerva and Vector per the mocks - not just multiple resolutions can all
be handled the same way:
* The bootstrap script (ext.relatedArticles.readMore.bootstrap/index.js)
for fetches the page image and Wikidata description; loading the
renderer module; and, finally, notifying the renderer module that it
should render the data, which it does by emitting
"ext.relatedArticles.readMore.init" event using mw#track
* The Minerva renderer subscribes to the event and, when it's fired,
renders the data by passing it to the WatchstarPageList view
Bug: T113635
Change-Id: I651342bdf9796938fa7051828dd13bc6fe774783
2015-10-07 13:12:42 +00:00
|
|
|
use Skin;
|
2015-11-03 23:39:48 +00:00
|
|
|
use ConfigFactory;
|
2015-12-01 03:45:26 +00:00
|
|
|
use User;
|
Add Related Articles section to Minerva
If the page has related articles, is in mainspace, isn't the main page,
and the output is being rendered with the MinervaBeta skin then a
"Related Articles" section is added to the page just before the footer.
Separate loading the information necessary to render the pages, choosing
the renderer, and rendering the data so that multiple skins - currently
Minerva and Vector per the mocks - not just multiple resolutions can all
be handled the same way:
* The bootstrap script (ext.relatedArticles.readMore.bootstrap/index.js)
for fetches the page image and Wikidata description; loading the
renderer module; and, finally, notifying the renderer module that it
should render the data, which it does by emitting
"ext.relatedArticles.readMore.init" event using mw#track
* The Minerva renderer subscribes to the event and, when it's fired,
renders the data by passing it to the WatchstarPageList view
Bug: T113635
Change-Id: I651342bdf9796938fa7051828dd13bc6fe774783
2015-10-07 13:12:42 +00:00
|
|
|
|
2015-12-02 11:10:04 +00:00
|
|
|
class FooterHooks {
|
Add Related Articles section to Minerva
If the page has related articles, is in mainspace, isn't the main page,
and the output is being rendered with the MinervaBeta skin then a
"Related Articles" section is added to the page just before the footer.
Separate loading the information necessary to render the pages, choosing
the renderer, and rendering the data so that multiple skins - currently
Minerva and Vector per the mocks - not just multiple resolutions can all
be handled the same way:
* The bootstrap script (ext.relatedArticles.readMore.bootstrap/index.js)
for fetches the page image and Wikidata description; loading the
renderer module; and, finally, notifying the renderer module that it
should render the data, which it does by emitting
"ext.relatedArticles.readMore.init" event using mw#track
* The Minerva renderer subscribes to the event and, when it's fired,
renders the data by passing it to the WatchstarPageList view
Bug: T113635
Change-Id: I651342bdf9796938fa7051828dd13bc6fe774783
2015-10-07 13:12:42 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handler for the <code>MakeGlobalVariablesScript</code> hook.
|
|
|
|
*
|
|
|
|
* Sets the value of the <code>wgRelatedArticles</code> global variable
|
|
|
|
* to the list of related articles in the cached parser output.
|
|
|
|
*
|
|
|
|
* @param array $vars
|
|
|
|
* @param OutputPage $out
|
|
|
|
* @return boolean Always <code>true</code>
|
|
|
|
*/
|
|
|
|
public static function onMakeGlobalVariablesScript( &$vars, OutputPage $out ) {
|
2015-10-29 17:58:30 +00:00
|
|
|
$config = ConfigFactory::getDefaultInstance()->makeConfig( 'RelatedArticles' );
|
2015-11-03 23:39:48 +00:00
|
|
|
|
Add Related Articles section to Minerva
If the page has related articles, is in mainspace, isn't the main page,
and the output is being rendered with the MinervaBeta skin then a
"Related Articles" section is added to the page just before the footer.
Separate loading the information necessary to render the pages, choosing
the renderer, and rendering the data so that multiple skins - currently
Minerva and Vector per the mocks - not just multiple resolutions can all
be handled the same way:
* The bootstrap script (ext.relatedArticles.readMore.bootstrap/index.js)
for fetches the page image and Wikidata description; loading the
renderer module; and, finally, notifying the renderer module that it
should render the data, which it does by emitting
"ext.relatedArticles.readMore.init" event using mw#track
* The Minerva renderer subscribes to the event and, when it's fired,
renders the data by passing it to the WatchstarPageList view
Bug: T113635
Change-Id: I651342bdf9796938fa7051828dd13bc6fe774783
2015-10-07 13:12:42 +00:00
|
|
|
$vars['wgRelatedArticles'] = $out->getProperty( 'RelatedArticles' );
|
2015-11-11 15:30:19 +00:00
|
|
|
|
2015-11-03 23:39:48 +00:00
|
|
|
$vars['wgRelatedArticlesUseCirrusSearch'] = $config->get( 'RelatedArticlesUseCirrusSearch' );
|
2015-11-11 15:30:19 +00:00
|
|
|
$vars['wgRelatedArticlesOnlyUseCirrusSearch'] =
|
|
|
|
$config->get( 'RelatedArticlesOnlyUseCirrusSearch' );
|
Add Related Articles section to Minerva
If the page has related articles, is in mainspace, isn't the main page,
and the output is being rendered with the MinervaBeta skin then a
"Related Articles" section is added to the page just before the footer.
Separate loading the information necessary to render the pages, choosing
the renderer, and rendering the data so that multiple skins - currently
Minerva and Vector per the mocks - not just multiple resolutions can all
be handled the same way:
* The bootstrap script (ext.relatedArticles.readMore.bootstrap/index.js)
for fetches the page image and Wikidata description; loading the
renderer module; and, finally, notifying the renderer module that it
should render the data, which it does by emitting
"ext.relatedArticles.readMore.init" event using mw#track
* The Minerva renderer subscribes to the event and, when it's fired,
renders the data by passing it to the WatchstarPageList view
Bug: T113635
Change-Id: I651342bdf9796938fa7051828dd13bc6fe774783
2015-10-07 13:12:42 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handler for the <code>BeforePageDisplay</code> hook.
|
|
|
|
*
|
|
|
|
* Adds the <code>ext.relatedArticles.readMore.bootstrap</code> module
|
|
|
|
* to the output when:
|
|
|
|
*
|
|
|
|
* <ol>
|
2015-12-02 11:17:00 +00:00
|
|
|
* <li><code>$wgRelatedArticlesShowInFooter</code> is truthy</li>
|
2015-11-19 03:49:46 +00:00
|
|
|
* <li>On mobile, the output is being rendered with
|
|
|
|
* <code>SkinMinervaBeta<code></li>
|
2015-12-02 11:17:00 +00:00
|
|
|
* <li>On desktop, the beta feature has been enabled</li>
|
Add Related Articles section to Minerva
If the page has related articles, is in mainspace, isn't the main page,
and the output is being rendered with the MinervaBeta skin then a
"Related Articles" section is added to the page just before the footer.
Separate loading the information necessary to render the pages, choosing
the renderer, and rendering the data so that multiple skins - currently
Minerva and Vector per the mocks - not just multiple resolutions can all
be handled the same way:
* The bootstrap script (ext.relatedArticles.readMore.bootstrap/index.js)
for fetches the page image and Wikidata description; loading the
renderer module; and, finally, notifying the renderer module that it
should render the data, which it does by emitting
"ext.relatedArticles.readMore.init" event using mw#track
* The Minerva renderer subscribes to the event and, when it's fired,
renders the data by passing it to the WatchstarPageList view
Bug: T113635
Change-Id: I651342bdf9796938fa7051828dd13bc6fe774783
2015-10-07 13:12:42 +00:00
|
|
|
* <li>The page is in mainspace</li>
|
|
|
|
* </ol>
|
|
|
|
*
|
|
|
|
* @param OutputPage $out
|
|
|
|
* @param Skin $skin
|
|
|
|
* @return boolean Always <code>true</code>
|
|
|
|
*/
|
|
|
|
public static function onBeforePageDisplay( OutputPage $out, Skin $skin ) {
|
2015-10-29 17:58:30 +00:00
|
|
|
$config = ConfigFactory::getDefaultInstance()->makeConfig( 'RelatedArticles' );
|
2015-12-02 11:17:00 +00:00
|
|
|
$showReadMore = $config->get( 'RelatedArticlesShowInFooter' );
|
2015-11-06 20:10:08 +00:00
|
|
|
|
Add Related Articles section to Minerva
If the page has related articles, is in mainspace, isn't the main page,
and the output is being rendered with the MinervaBeta skin then a
"Related Articles" section is added to the page just before the footer.
Separate loading the information necessary to render the pages, choosing
the renderer, and rendering the data so that multiple skins - currently
Minerva and Vector per the mocks - not just multiple resolutions can all
be handled the same way:
* The bootstrap script (ext.relatedArticles.readMore.bootstrap/index.js)
for fetches the page image and Wikidata description; loading the
renderer module; and, finally, notifying the renderer module that it
should render the data, which it does by emitting
"ext.relatedArticles.readMore.init" event using mw#track
* The Minerva renderer subscribes to the event and, when it's fired,
renders the data by passing it to the WatchstarPageList view
Bug: T113635
Change-Id: I651342bdf9796938fa7051828dd13bc6fe774783
2015-10-07 13:12:42 +00:00
|
|
|
$title = $out->getContext()->getTitle();
|
|
|
|
|
|
|
|
if (
|
2015-11-06 20:10:08 +00:00
|
|
|
$showReadMore &&
|
Add Related Articles section to Minerva
If the page has related articles, is in mainspace, isn't the main page,
and the output is being rendered with the MinervaBeta skin then a
"Related Articles" section is added to the page just before the footer.
Separate loading the information necessary to render the pages, choosing
the renderer, and rendering the data so that multiple skins - currently
Minerva and Vector per the mocks - not just multiple resolutions can all
be handled the same way:
* The bootstrap script (ext.relatedArticles.readMore.bootstrap/index.js)
for fetches the page image and Wikidata description; loading the
renderer module; and, finally, notifying the renderer module that it
should render the data, which it does by emitting
"ext.relatedArticles.readMore.init" event using mw#track
* The Minerva renderer subscribes to the event and, when it's fired,
renders the data by passing it to the WatchstarPageList view
Bug: T113635
Change-Id: I651342bdf9796938fa7051828dd13bc6fe774783
2015-10-07 13:12:42 +00:00
|
|
|
$title->inNamespace( NS_MAIN ) &&
|
|
|
|
!$title->isMainPage()
|
|
|
|
) {
|
2015-11-19 03:49:46 +00:00
|
|
|
if (
|
|
|
|
get_class( $skin ) === 'SkinMinervaBeta' ||
|
|
|
|
(
|
|
|
|
class_exists( 'BetaFeatures' ) &&
|
|
|
|
BetaFeatures::isFeatureEnabled( $out->getUser(), 'read-more' )
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
$out->addModules( array( 'ext.relatedArticles.readMore.bootstrap' ) );
|
|
|
|
}
|
Add Related Articles section to Minerva
If the page has related articles, is in mainspace, isn't the main page,
and the output is being rendered with the MinervaBeta skin then a
"Related Articles" section is added to the page just before the footer.
Separate loading the information necessary to render the pages, choosing
the renderer, and rendering the data so that multiple skins - currently
Minerva and Vector per the mocks - not just multiple resolutions can all
be handled the same way:
* The bootstrap script (ext.relatedArticles.readMore.bootstrap/index.js)
for fetches the page image and Wikidata description; loading the
renderer module; and, finally, notifying the renderer module that it
should render the data, which it does by emitting
"ext.relatedArticles.readMore.init" event using mw#track
* The Minerva renderer subscribes to the event and, when it's fired,
renders the data by passing it to the WatchstarPageList view
Bug: T113635
Change-Id: I651342bdf9796938fa7051828dd13bc6fe774783
2015-10-07 13:12:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2015-10-29 17:58:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* EventLoggingRegisterSchemas hook handler.
|
|
|
|
*
|
|
|
|
* Registers our EventLogging schemas so that they can be converted to
|
|
|
|
* ResourceLoaderSchemaModules by the EventLogging extension.
|
|
|
|
*
|
|
|
|
* If the module has already been registered in
|
|
|
|
* onResourceLoaderRegisterModules, then it is overwritten.
|
|
|
|
*
|
|
|
|
* @param array $schemas The schemas currently registered with the EventLogging
|
|
|
|
* extension
|
|
|
|
* @return bool Always true
|
|
|
|
*/
|
|
|
|
public static function onEventLoggingRegisterSchemas( &$schemas ) {
|
|
|
|
// @see https://meta.wikimedia.org/wiki/Schema:RelatedArticles
|
|
|
|
$schemas['RelatedArticles'] = 14496900;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ResourceLoaderGetConfigVars hook handler for setting a config variable
|
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/ResourceLoaderGetConfigVars
|
|
|
|
*
|
|
|
|
* @param array $vars
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public static function onResourceLoaderGetConfigVars( &$vars ) {
|
|
|
|
$config = ConfigFactory::getDefaultInstance()->makeConfig( 'RelatedArticles' );
|
|
|
|
$vars['wgRelatedArticlesLoggingSamplingRate'] =
|
|
|
|
$config->get( 'RelatedArticlesLoggingSamplingRate' );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-11-16 10:40:03 +00:00
|
|
|
* Register the "ext.relatedArticles.readMore" module.
|
2015-10-29 17:58:30 +00:00
|
|
|
* Optionally update the dependencies and scripts if EventLogging is installed.
|
|
|
|
*
|
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/ResourceLoaderRegisterModules
|
|
|
|
*
|
|
|
|
* @param ResourceLoader &$resourceLoader The ResourceLoader object
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public static function onResourceLoaderRegisterModules( ResourceLoader &$resourceLoader ) {
|
|
|
|
$dependencies = array(
|
2015-11-16 10:40:03 +00:00
|
|
|
"mediawiki.user",
|
|
|
|
"mediawiki.util"
|
2015-10-29 17:58:30 +00:00
|
|
|
);
|
|
|
|
$scripts = array(
|
2015-11-16 10:40:03 +00:00
|
|
|
"resources/ext.relatedArticles.readMore/index.js"
|
2015-10-29 17:58:30 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
if ( class_exists( 'EventLogging' ) ) {
|
2016-04-07 16:23:38 +00:00
|
|
|
$dependencies[] = "mediawiki.viewport";
|
2015-10-29 17:58:30 +00:00
|
|
|
$dependencies[] = "ext.eventLogging.Schema";
|
2015-11-16 10:40:03 +00:00
|
|
|
$scripts[] = "resources/ext.relatedArticles.readMore/eventLogging.js";
|
2015-10-29 17:58:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$resourceLoader->register(
|
2015-11-16 10:40:03 +00:00
|
|
|
"ext.relatedArticles.readMore",
|
2015-10-29 17:58:30 +00:00
|
|
|
array(
|
|
|
|
"dependencies" => $dependencies,
|
|
|
|
"scripts" => $scripts,
|
|
|
|
"styles" => array(
|
2015-11-16 10:40:03 +00:00
|
|
|
"resources/ext.relatedArticles.readMore/readMore.less"
|
2015-10-29 17:58:30 +00:00
|
|
|
),
|
2016-02-19 20:55:59 +00:00
|
|
|
"skinStyles" => array(
|
|
|
|
"default" => "resources/ext.relatedArticles.readMore/readMore.default.less",
|
|
|
|
"monobook" => array(
|
|
|
|
"resources/ext.relatedArticles.readMore/readMore.default.less",
|
|
|
|
"resources/ext.relatedArticles.readMore/readMore.monobook.less"
|
|
|
|
),
|
|
|
|
"minerva" => "resources/ext.relatedArticles.readMore/readMore.minerva.less"
|
|
|
|
),
|
2015-10-29 17:58:30 +00:00
|
|
|
"messages" => array(
|
|
|
|
"relatedarticles-read-more-heading"
|
|
|
|
),
|
|
|
|
"targets" => array(
|
2015-11-19 03:49:46 +00:00
|
|
|
"desktop",
|
2015-10-29 17:58:30 +00:00
|
|
|
"mobile"
|
|
|
|
),
|
|
|
|
"localBasePath" => __DIR__ . "/..",
|
|
|
|
"remoteExtPath" => "RelatedArticles"
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2015-11-19 03:49:46 +00:00
|
|
|
|
2015-12-01 03:45:26 +00:00
|
|
|
/**
|
|
|
|
* GetBetaFeaturePreferences hook handler
|
|
|
|
* The beta feature is for showing ReadMore, not for showing related
|
|
|
|
* articles in the sidebar.
|
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/GetBetaFeaturePreferences
|
|
|
|
*
|
|
|
|
* @param User $user
|
|
|
|
* @param array $preferences
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public static function onGetBetaFeaturePreferences( User $user, array &$preferences ) {
|
|
|
|
$config = ConfigFactory::getDefaultInstance()->makeConfig( 'RelatedArticles' );
|
2015-12-02 11:17:00 +00:00
|
|
|
$showReadMore = $config->get( 'RelatedArticlesShowInFooter' );
|
2015-12-01 03:45:26 +00:00
|
|
|
|
|
|
|
if ( $showReadMore ) {
|
|
|
|
$wgExtensionAssetsPath = $config->get( 'ExtensionAssetsPath' );
|
|
|
|
|
|
|
|
$preferences['read-more'] = array(
|
|
|
|
'label-message' => 'relatedarticles-read-more-beta-feature-title',
|
|
|
|
'desc-message' => 'relatedarticles-read-more-beta-feature-description',
|
|
|
|
'screenshot' => array(
|
|
|
|
'ltr' => "$wgExtensionAssetsPath/RelatedArticles/images/BetaFeatures/wb-readmore-beta-ltr.svg",
|
|
|
|
'rtl' => "$wgExtensionAssetsPath/RelatedArticles/images/BetaFeatures/wb-readmore-beta-rtl.svg",
|
|
|
|
),
|
|
|
|
'info-link' => 'https://www.mediawiki.org/wiki/Reading/Web/Projects/Read_more',
|
|
|
|
'discussion-link' => 'https://www.mediawiki.org/wiki/Talk:Reading/Web/Projects/Read_more',
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
Add Related Articles section to Minerva
If the page has related articles, is in mainspace, isn't the main page,
and the output is being rendered with the MinervaBeta skin then a
"Related Articles" section is added to the page just before the footer.
Separate loading the information necessary to render the pages, choosing
the renderer, and rendering the data so that multiple skins - currently
Minerva and Vector per the mocks - not just multiple resolutions can all
be handled the same way:
* The bootstrap script (ext.relatedArticles.readMore.bootstrap/index.js)
for fetches the page image and Wikidata description; loading the
renderer module; and, finally, notifying the renderer module that it
should render the data, which it does by emitting
"ext.relatedArticles.readMore.init" event using mw#track
* The Minerva renderer subscribes to the event and, when it's fired,
renders the data by passing it to the WatchstarPageList view
Bug: T113635
Change-Id: I651342bdf9796938fa7051828dd13bc6fe774783
2015-10-07 13:12:42 +00:00
|
|
|
}
|