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;
|
|
|
|
|
|
|
|
use OutputPage;
|
|
|
|
use Skin;
|
2015-11-03 23:39:48 +00:00
|
|
|
use ConfigFactory;
|
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
|
|
|
|
|
|
|
class ReadMoreHooks {
|
2015-11-03 23:39:48 +00:00
|
|
|
/**
|
|
|
|
* Register QUnit tests.
|
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/ResourceLoaderTestModules
|
|
|
|
*
|
|
|
|
* @param array $modules
|
|
|
|
* @param ResourceLoader $rl
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public static function onResourceLoaderTestModules( &$modules, &$rl ) {
|
|
|
|
$boilerplate = array(
|
|
|
|
'localBasePath' => __DIR__ . '/../tests/qunit/',
|
|
|
|
'remoteExtPath' => 'RelatedArticles/tests/qunit',
|
|
|
|
'targets' => array( 'desktop', 'mobile' ),
|
|
|
|
);
|
|
|
|
|
|
|
|
$modules['qunit']['ext.relatedArticles.readMore.tests'] = $boilerplate + array(
|
|
|
|
'scripts' => array(
|
|
|
|
'ext.relatedArticles.readMore/test_RelatedPagesGateway.js',
|
|
|
|
),
|
|
|
|
'dependencies' => array(
|
|
|
|
'ext.relatedArticles.readMore',
|
|
|
|
),
|
|
|
|
);
|
|
|
|
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
|
|
|
|
|
|
|
/**
|
|
|
|
* 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-11-03 23:39:48 +00:00
|
|
|
$config = ConfigFactory::getDefaultInstance()->makeConfig( 'relatedarticles' );
|
|
|
|
|
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-03 23:39:48 +00:00
|
|
|
$vars['wgRelatedArticlesUseCirrusSearch'] = $config->get( 'RelatedArticlesUseCirrusSearch' );
|
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>
|
|
|
|
* <li>
|
|
|
|
* The output is being rendered with the
|
|
|
|
* <code>SkinMinervaBeta<code> skin, i.e. the user is currently
|
|
|
|
* viewing the page on the mobile set in beta mode
|
|
|
|
* </li>
|
|
|
|
* <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 ) {
|
|
|
|
$title = $out->getContext()->getTitle();
|
|
|
|
|
|
|
|
if (
|
|
|
|
get_class( $skin ) === 'SkinMinervaBeta' &&
|
|
|
|
$title->inNamespace( NS_MAIN ) &&
|
|
|
|
!$title->isMainPage()
|
|
|
|
) {
|
|
|
|
|
|
|
|
$out->addModules( array( 'ext.relatedArticles.readMore.bootstrap' ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|