Phuedx has uploaded a new change for review.
https://gerrit.wikimedia.org/r/253919
Change subject: [Hygiene] Reorganise hooks to reflect placements
......................................................................
[Hygiene] Reorganise hooks to reflect placements
There are two positions where the list of related articles is rendered:
the sidebar, and the the footer. Move the hook handlers related to
rendering the former to RelatedArticles\SidebarHooks and those related
to rendering the latter to RelatedArticles\FooterHooks.
Change-Id: Idde57905d828e63309bfdc360a3a09e64e291304
---
M extension.json
R includes/FooterHooks.php
M includes/Hooks.php
A includes/SidebarHooks.php
4 files changed, 192 insertions(+), 176 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/RelatedArticles
refs/changes/19/253919/1
diff --git a/extension.json b/extension.json
index ebea57c..c9e0634 100644
--- a/extension.json
+++ b/extension.json
@@ -13,15 +13,13 @@
"type": "other",
"AutoloadClasses": {
"RelatedArticles\\Hooks": "includes/Hooks.php",
- "RelatedArticles\\ReadMoreHooks": "includes/ReadMoreHooks.php"
+ "RelatedArticles\\SidebarHooks": "includes/SidebarHooks.php",
+ "RelatedArticles\\FooterHooks": "includes/FooterHooks.php"
},
"ExtensionMessagesFiles": {
"RelatedArticlesMagic": "RelatedArticles.i18n.magic.php"
},
"Hooks": {
- "ResourceLoaderTestModules": [
-
"RelatedArticles\\ReadMoreHooks::onResourceLoaderTestModules"
- ],
"ParserFirstCallInit": [
"RelatedArticles\\Hooks::onParserFirstCallInit"
],
@@ -31,29 +29,35 @@
"OutputPageParserOutput": [
"RelatedArticles\\Hooks::onOutputPageParserOutput"
],
- "@SkinBuildSidebar": [
- "RelatedArticles\\Hooks::onSkinBuildSidebar"
- ],
- "SkinTemplateToolboxEnd": [
- "RelatedArticles\\Hooks::onSkinTemplateToolboxEnd"
- ],
+
"UnitTestsList": [
"RelatedArticles\\Hooks::onUnitTestsList"
],
+ "ResourceLoaderTestModules": [
+ "RelatedArticles\\Hooks::onResourceLoaderTestModules"
+ ],
+
+ "@SkinBuildSidebar": [
+ "RelatedArticles\\SidebarHooks::onSkinBuildSidebar"
+ ],
+ "SkinTemplateToolboxEnd": [
+
"RelatedArticles\\SidebarHooks::onSkinTemplateToolboxEnd"
+ ],
+
"MakeGlobalVariablesScript": [
-
"RelatedArticles\\ReadMoreHooks::onMakeGlobalVariablesScript"
+
"RelatedArticles\\FooterHooks::onMakeGlobalVariablesScript"
],
"BeforePageDisplay": [
- "RelatedArticles\\ReadMoreHooks::onBeforePageDisplay"
+ "RelatedArticles\\FooterHooks::onBeforePageDisplay"
],
"EventLoggingRegisterSchemas": [
-
"RelatedArticles\\ReadMoreHooks::onEventLoggingRegisterSchemas"
+
"RelatedArticles\\FooterHooks::onEventLoggingRegisterSchemas"
],
"ResourceLoaderGetConfigVars": [
-
"RelatedArticles\\ReadMoreHooks::onResourceLoaderGetConfigVars"
+
"RelatedArticles\\FooterHooks::onResourceLoaderGetConfigVars"
],
"ResourceLoaderRegisterModules": [
-
"RelatedArticles\\ReadMoreHooks::onResourceLoaderRegisterModules"
+
"RelatedArticles\\FooterHooks::onResourceLoaderRegisterModules"
]
},
"MessagesDirs": {
diff --git a/includes/ReadMoreHooks.php b/includes/FooterHooks.php
similarity index 85%
rename from includes/ReadMoreHooks.php
rename to includes/FooterHooks.php
index c823342..c6dad41 100644
--- a/includes/ReadMoreHooks.php
+++ b/includes/FooterHooks.php
@@ -3,36 +3,11 @@
namespace RelatedArticles;
use OutputPage;
+use ConfigFactory;
use ResourceLoader;
use Skin;
-use ConfigFactory;
-class ReadMoreHooks {
- /**
- * 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;
- }
+class FooterHooks {
/**
* Handler for the <code>MakeGlobalVariablesScript</code> hook.
diff --git a/includes/Hooks.php b/includes/Hooks.php
index 49fde85..c22fcae 100644
--- a/includes/Hooks.php
+++ b/includes/Hooks.php
@@ -4,13 +4,9 @@
use Parser;
use Exception;
-use Title;
-use SkinTemplate;
-use BaseTemplate;
-use Skin;
-use Html;
use OutputPage;
use ParserOutput;
+use ResourceLoader;
class Hooks {
@@ -104,135 +100,6 @@
}
/**
- * 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 = array();
-
- 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[] = array(
- 'href' => $title->getLocalURL(),
- 'text' => $altText ?:
$title->getPrefixedText(),
- 'class' => 'interwiki-relart'
- );
- }
- };
-
- return $relatedPagesUrls;
- }
-
- /**
- * Handler for the <code>SkinBuildSidebar</code> hook.
- *
- * Retrieves the list of related pages
- * and adds its HTML representation to the sidebar.
- *
- * @param Skin $skin
- * @param array $bar
- * @return boolean Always <code>true</code>
- */
- public static function onSkinBuildSidebar( Skin $skin, &$bar ) {
- $out = $skin->getOutput();
- $relatedPages = $out->getProperty( 'RelatedArticles' );
-
- if ( !$relatedPages ) {
- return true;
- }
-
- $relatedPagesUrls = self::getRelatedPagesUrls( $relatedPages );
-
- // build relatedarticles <li>'s
- $relatedPages = array();
- foreach ( (array) $relatedPagesUrls as $url ) {
- $relatedPages[] =
- Html::rawElement( 'li', array( 'class' =>
htmlspecialchars( $url['class'] ) ),
- Html::element( 'a', array( 'href' =>
htmlspecialchars( $url['href'] ) ),
- $url['text']
- )
- );
- }
-
- // build complete html
- $bar[$skin->msg( 'relatedarticles-title' )->text()] =
- Html::rawElement( 'ul', array(),
- implode( '', $relatedPages )
- );
-
- return true;
- }
-
- /**
- * Handler for the <code>SkinTemplateToolboxEnd</code> hook.
- *
- * Retrieves the list of related pages from the template and
- * <code>echo</code>s its HTML representation to the sidebar.
- *
- * @param SkinTemplate $skinTpl
- * @return boolean Always <code>true</code>
- */
- public static function onSkinTemplateToolboxEnd( BaseTemplate &$skinTpl
) {
- $relatedPages = $skinTpl->getSkin()->getOutput()->getProperty(
'RelatedArticles' );
-
- if ( !$relatedPages ) {
- return true;
- }
-
- $relatedPagesUrls = self::getRelatedPagesUrls( $relatedPages );
-
- // build relatedarticles <li>'s
- $relatedPages = array();
- foreach ( (array) $relatedPagesUrls as $url ) {
- $relatedPages[] =
- Html::rawElement( 'li', array( 'class' =>
htmlspecialchars( $url['class'] ) ),
- Html::element( 'a', array( 'href' =>
htmlspecialchars( $url['href'] ) ),
- $url['text']
- )
- );
- }
-
- // build complete html
- echo
- Html::closeElement( 'ul' ) .
- Html::closeElement( 'div' ) .
- Html::closeElement( 'div' ) .
- Html::openElement( 'div', array(
- 'class' => 'portal',
- 'role' => 'navigation',
- 'id' => 'p-relatedarticles',
- ) ) .
- Html::element( 'h3', array(), wfMessage(
'relatedarticles-title' )->text() ) .
- Html::openElement( 'div', array( 'class' => 'body' ) ) .
- Html::openElement( 'ul' ) .
- implode( '', $relatedPages );
-
- return true;
- }
-
- /**
* Handler for the <code>UnitTestsList</code> hook.
*
* Adds the path to this extension's PHPUnit test suite to the set of
@@ -246,4 +113,34 @@
return true;
}
+
+ /**
+ * Handler for the <code>ResourceLoaderTestModules<code> hook.
+ *
+ * Register QUnit tests.
+ *
+ * @see
https://www.mediawiki.org/wiki/Manual:Hooks/ResourceLoaderTestModules
+ *
+ * @param array $modules
+ * @param ResourceLoader $rl
+ * @return bool
+ */
+ public static function onResourceLoaderTestModules( array &$modules,
ResourceLoader &$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;
+ }
+
}
diff --git a/includes/SidebarHooks.php b/includes/SidebarHooks.php
new file mode 100644
index 0000000..100fd67
--- /dev/null
+++ b/includes/SidebarHooks.php
@@ -0,0 +1,140 @@
+<?php
+
+namespace RelatedArticles;
+
+use Title;
+use Skin;
+use Html;
+use BaseTemplate;
+use SkinTemplate;
+
+class SidebarHooks {
+
+ /**
+ * Handler for the <code>SkinBuildSidebar</code> hook.
+ *
+ * Retrieves the list of related pages and adds its HTML representation
to the sidebar.
+ *
+ * @param Skin $skin
+ * @param array $bar
+ * @return boolean Always <code>true</code>
+ */
+ public static function onSkinBuildSidebar( Skin $skin, &$bar ) {
+ $out = $skin->getOutput();
+ $relatedPages = $out->getProperty( 'RelatedArticles' );
+
+ if ( !$relatedPages ) {
+ return true;
+ }
+
+ $relatedPagesUrls = self::getRelatedPagesUrls( $relatedPages );
+
+ // build relatedarticles <li>'s
+ $relatedPages = array();
+ foreach ( (array) $relatedPagesUrls as $url ) {
+ $relatedPages[] =
+ Html::rawElement( 'li', array( 'class' =>
htmlspecialchars( $url['class'] ) ),
+ Html::element( 'a', array( 'href' =>
htmlspecialchars( $url['href'] ) ),
+ $url['text']
+ )
+ );
+ }
+
+ // build complete html
+ $bar[$skin->msg( 'relatedarticles-title' )->text()] =
+ Html::rawElement( 'ul', array(),
+ implode( '', $relatedPages )
+ );
+
+ return true;
+ }
+
+ /**
+ * Handler for the <code>SkinTemplateToolboxEnd</code> hook.
+ *
+ * Retrieves the list of related pages from the template and
<code>echo</code>s its HTML
+ * representation to the sidebar.
+ *
+ * @param SkinTemplate $skinTpl
+ * @return boolean Always <code>true</code>
+ */
+ public static function onSkinTemplateToolboxEnd( BaseTemplate &$skinTpl
) {
+ $relatedPages = $skinTpl->getSkin()->getOutput()->getProperty(
'RelatedArticles' );
+
+ if ( !$relatedPages ) {
+ return true;
+ }
+
+ $relatedPagesUrls = self::getRelatedPagesUrls( $relatedPages );
+
+ // build relatedarticles <li>'s
+ $relatedPages = array();
+ foreach ( (array) $relatedPagesUrls as $url ) {
+ $relatedPages[] =
+ Html::rawElement( 'li', array( 'class' =>
htmlspecialchars( $url['class'] ) ),
+ Html::element( 'a', array( 'href' =>
htmlspecialchars( $url['href'] ) ),
+ $url['text']
+ )
+ );
+ }
+
+ // build complete html
+ echo
+ Html::closeElement( 'ul' ) .
+ Html::closeElement( 'div' ) .
+ Html::closeElement( 'div' ) .
+ Html::openElement( 'div', array(
+ 'class' => 'portal',
+ 'role' => 'navigation',
+ 'id' => 'p-relatedarticles',
+ ) ) .
+ Html::element( 'h3', array(), wfMessage(
'relatedarticles-title' )->text() ) .
+ Html::openElement( 'div', array( 'class' => 'body' ) ) .
+ Html::openElement( '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 = array();
+
+ 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[] = array(
+ 'href' => $title->getLocalURL(),
+ 'text' => $altText ?:
$title->getPrefixedText(),
+ 'class' => 'interwiki-relart'
+ );
+ }
+ };
+
+ return $relatedPagesUrls;
+ }
+}
--
To view, visit https://gerrit.wikimedia.org/r/253919
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Idde57905d828e63309bfdc360a3a09e64e291304
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/RelatedArticles
Gerrit-Branch: dev
Gerrit-Owner: Phuedx <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits