Legoktm has uploaded a new change for review.
https://gerrit.wikimedia.org/r/194040
Change subject: Move SiteNoticeAfter hook to separate file
......................................................................
Move SiteNoticeAfter hook to separate file
Change-Id: If1a928e522ac9cb420d33d83070255bc74922cf4
---
A DismissableSiteNotice.hooks.php
M DismissableSiteNotice.php
2 files changed, 49 insertions(+), 42 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DismissableSiteNotice
refs/changes/40/194040/1
diff --git a/DismissableSiteNotice.hooks.php b/DismissableSiteNotice.hooks.php
new file mode 100644
index 0000000..86a739b
--- /dev/null
+++ b/DismissableSiteNotice.hooks.php
@@ -0,0 +1,47 @@
+<?php
+
+class DismissableSiteNoticeHooks {
+
+ /**
+ * @param string $notice
+ * @param Skin $skin
+ * @return bool true
+ */
+ public static function onSiteNoticeAfter( &$notice, $skin ) {
+ global $wgMajorSiteNoticeID, $wgDismissableSiteNoticeForAnons;
+
+ if ( !$notice ) {
+ return true;
+ }
+
+ // Dismissal for anons is configurable
+ if ( $wgDismissableSiteNoticeForAnons ||
$skin->getUser()->isLoggedIn() ) {
+ // Cookie value consists of two parts
+ $major = (int) $wgMajorSiteNoticeID;
+ $minor = (int) $skin->msg( 'sitenotice_id'
)->inContentLanguage()->text();
+
+ $out = $skin->getOutput();
+ $out->addModules( 'ext.dismissableSiteNotice' );
+ $out->addJsConfigVars( 'wgSiteNoticeId',
"$major.$minor" );
+
+ $notice = Html::rawElement( 'div', array( 'class' =>
'mw-dismissable-notice' ),
+ Html::rawElement( 'div', array( 'class' =>
'mw-dismissable-notice-close' ),
+ $skin->msg( 'sitenotice_close-brackets'
)
+ ->rawParams(
+ Html::element( 'a',
array( 'href' => '#' ), $skin->msg( 'sitenotice_close' )->text() )
+ )
+ ->escaped()
+ ) .
+ Html::rawElement( 'div', array( 'class' =>
'mw-dismissable-notice-body' ), $notice )
+ );
+ }
+
+ if ( $skin->getUser()->isAnon() ) {
+ // Hide the sitenotice from search engines (see bug
9209 comment 4)
+ // XXX: Does this actually work?
+ $notice = Html::inlineScript( Xml::encodeJsCall(
'document.write', array( $notice ) ) );
+ }
+
+ return true;
+ }
+}
diff --git a/DismissableSiteNotice.php b/DismissableSiteNotice.php
index 4e91e04..9aee23f 100644
--- a/DismissableSiteNotice.php
+++ b/DismissableSiteNotice.php
@@ -34,6 +34,7 @@
$wgMessagesDirs['DismissableSiteNotice'] = __DIR__ . '/i18n';
$wgExtensionMessagesFiles['DismissableSiteNotice'] = __DIR__ .
'/DismissableSiteNotice.i18n.php';
+$wgAutoloadClasses['DismissableSiteNoticeHooks'] = __DIR__ .
'/DismissableSiteNotice.hooks.php';
$wgResourceModules['ext.dismissableSiteNotice'] = array(
'localBasePath' => __DIR__ . '/modules',
@@ -48,48 +49,7 @@
'position' => 'top',
);
-/**
- * @param string $notice
- * @param Skin $skin
- * @return bool true
- */
-$wgHooks['SiteNoticeAfter'][] = function( &$notice, $skin ) {
- global $wgMajorSiteNoticeID, $wgDismissableSiteNoticeForAnons;
-
- if ( !$notice ) {
- return true;
- }
-
- // Dismissal for anons is configurable
- if ( $wgDismissableSiteNoticeForAnons || $skin->getUser()->isLoggedIn()
) {
- // Cookie value consists of two parts
- $major = (int) $wgMajorSiteNoticeID;
- $minor = (int) $skin->msg( 'sitenotice_id'
)->inContentLanguage()->text();
-
- $out = $skin->getOutput();
- $out->addModules( 'ext.dismissableSiteNotice' );
- $out->addJsConfigVars( 'wgSiteNoticeId', "$major.$minor" );
-
- $notice = Html::rawElement( 'div', array( 'class' =>
'mw-dismissable-notice' ),
- Html::rawElement( 'div', array( 'class' =>
'mw-dismissable-notice-close' ),
- $skin->msg( 'sitenotice_close-brackets' )
- ->rawParams(
- Html::element( 'a', array( 'href' =>
'#' ), $skin->msg( 'sitenotice_close' )->text() )
- )
- ->escaped()
- ) .
- Html::rawElement( 'div', array( 'class' =>
'mw-dismissable-notice-body' ), $notice )
- );
- }
-
- if ( $skin->getUser()->isAnon() ) {
- // Hide the sitenotice from search engines (see bug 9209
comment 4)
- // XXX: Does this actually work?
- $notice = Html::inlineScript( Xml::encodeJsCall(
'document.write', array( $notice ) ) );
- }
-
- return true;
-};
+$wgHooks['SiteNoticeAfter'][] =
'DismissableSiteNoticeHooks::onSiteNoticeAfter';
// Default settings
$wgMajorSiteNoticeID = 1;
--
To view, visit https://gerrit.wikimedia.org/r/194040
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: If1a928e522ac9cb420d33d83070255bc74922cf4
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/DismissableSiteNotice
Gerrit-Branch: master
Gerrit-Owner: Legoktm <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits