Jack Phoenix has uploaded a new change for review.
https://gerrit.wikimedia.org/r/142518
Change subject: Integrated the essential bits and pieces of wikiHow's
Notifications extension.
......................................................................
Integrated the essential bits and pieces of wikiHow's Notifications extension.
This is needed to prevent fatals if neither Echo nor Notifications are
available.
Theoretically the orange bar of death could be removed in favor of this code,
but I'm keeping it in for the time being.
Also restored the Special:Notifications link in the personal tools menu if Echo
is installed.
Change-Id: Icce3cc2d7c23e05dff8ae4b1a831f9bbe1801a7a
---
M BlueSky.skin.php
M i18n/en.json
2 files changed, 126 insertions(+), 6 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/skins/BlueSky
refs/changes/18/142518/1
diff --git a/BlueSky.skin.php b/BlueSky.skin.php
index 3183fbe..951db0c 100644
--- a/BlueSky.skin.php
+++ b/BlueSky.skin.php
@@ -1238,13 +1238,19 @@
// our particular use case :-( As a result of
not using that
// method, the PersonalUrls hook never gets
called for this skin
if ( $isLoggedIn ) {
+ $myNotifications = '';
+ if ( class_exists( 'EchoEvent' ) ) {
+ $myNotifications = Linker::link(
+
SpecialPage::getTitleFor( 'Notifications' ),
+ $this->msg(
'bluesky-my-notifications' )->plain()
+ );
+ }
$html = Linker::link( Title::makeTitle(
NS_SPECIAL, 'Mytalk', 'post' ), $this->msg( 'mytalk' )->plain() ) .
Linker::link(
SpecialPage::getTitleFor( 'Mypage' ), $this->msg( 'bluesky-my-page' )->plain()
) .
- #Linker::link(
Title::makeTitle( NS_SPECIAL, 'Notifications' ), $this->msg( 'mynotifications'
)->text() ) .
+ $myNotifications .
Linker::link(
SpecialPage::getTitleFor( 'Watchlist' ), $this->msg( 'watchlist' )->plain() ) .
#Linker::link(
Title::makeTitle( NS_SPECIAL, 'Drafts' ), $this->msg( 'mydrafts' )->text() ) .
Linker::link(
SpecialPage::getTitleFor( 'Mypages', 'Contributions' ), $this->msg( 'mycontris'
)->plain() ) .
- #Linker::link(
SpecialPage::getTitleFor( 'Mypages', 'Fanmail' ), $this->msg( 'myfanmail'
)->text() ) .
Linker::link(
SpecialPage::getTitleFor( 'Preferences' ), $this->msg( 'mypreferences'
)->plain() ) .
Linker::link(
SpecialPage::getTitleFor( 'Userlogout' ), $this->msg( 'logout' )->plain() );
} else {
@@ -1359,9 +1365,17 @@
} else {
// old school
- $ret =
Notifications::loadNotifications();
- if ( is_array( $ret ) ) {
- list( $html,
$this->notifications_count ) = $ret;
+ if ( class_exists( 'Notifications' ) ) {
+ $ret =
Notifications::loadNotifications();
+ if ( is_array( $ret ) ) {
+ list( $html,
$this->notifications_count ) = $ret;
+ }
+ } else {
+ // the wikiHow notifications
ext. isn't installed either,
+ // so we essentially
reimplement its logic here
+ list( $notes, $count, $newTalk
) = $this->getNotifications();
+ $html =
$this->formatNotifications( $notes, $newTalk );
+ $this->notifications_count =
$count;
}
}
@@ -1377,6 +1391,108 @@
}
/**
+ * Get all notifications for the current user.
+ *
+ * @return array array( HTML output, total amount of all notifications,
has new User_talk messages? )
+ */
+ private function getNotifications() {
+ global $wgUser, $wgMemc;
+
+ $memKey = wfMemcKey( 'notification_box_' . $wgUser->getId() );
+ $box = $wgMemc->get( $memKey );
+
+ if ( !is_array( $box ) ) {
+ $notes = array();
+
+ // Talk messages
+ $talkCount = 0;
+ if ( $wgUser->getNewtalk() ) {
+ $talkCount = self::getCount( 'user_newtalk' );
+ $msg = '<div class="note_row"><div
class="note_icon_talk"></div>' .
+ Linker::link(
+ $wgUser->getTalkPage(),
+ $this->msg(
'bluesky-notifications-new-talk' )->numParams( $talkCount )->parse()
+ ) . '</div>';
+ $notes[] = $msg;
+ $newTalk = true;
+ } else {
+ $newTalk = false;
+ }
+
+ // Kudos (fan mail) and Thumbs Up removed for the time
being due to
+ // being rather wikiHow-specific and generally the way
how it was
+ // done was ugly. Hooks, people; use hooks instead of
hard-coding
+ // things!
+
+ $totalCount = $talkCount;
+
+ $box = array( $notes, $totalCount, $newTalk );
+ }
+
+ return $box;
+ }
+
+ /**
+ * Fetch the COUNT() of some entries in the given $table.
+ *
+ * @param string $table Database table name
+ * @return int Amount of entries
+ */
+ private static function getCount( $table ) {
+ global $wgUser;
+
+ if ( $wgUser->getId() > 0 ) {
+ $field = 'user_id';
+ $id = $wgUser->getId();
+ } else {
+ $field = 'user_ip';
+ $id = $wgUser->getName();
+ }
+
+ $db = wfGetDB( DB_MASTER );
+ $count = $db->selectField(
+ $table,
+ 'COUNT(' . $field . ')',
+ array( $field => $id ),
+ __METHOD__
+ );
+
+ return $count;
+ }
+
+ /**
+ * @param array $notes Notification HTML for each notification in an
array
+ * @param bool $newTalk Does the current user have new talk page
messages?
+ * @return string HTML output
+ */
+ private function formatNotifications( $notes, $newTalk ) {
+ global $wgUser;
+
+ $html = '';
+ $talkPage = $wgUser->getTalkPage()->getPrefixedText();
+
+ foreach ( $notes as $note ) {
+ $html .= $note;
+ }
+
+ if ( $html ) {
+ // no line at the top
+ $html = preg_replace( '/note_row/', 'note_row
first_note_row', $html, 1 );
+ if ( !$newTalk ) {
+ $html .= '<div class="note_row note_empty">' .
+ $this->msg(
'bluesky-notifications-no-talk', $talkPage )->text() .
+ '</div>';
+ }
+ } else {
+ $html = '<div class="note_row note_empty">' .
+ $this->msg( 'bluesky-notifications-none',
$talkPage )->text() .
+ '</div>';
+ }
+
+ return $html;
+ }
+
+ /**
* This is only available in MediaWiki 1.23+, but...
*
* @param OutputPage|null $out
diff --git a/i18n/en.json b/i18n/en.json
index 0eb7390..6f3e783 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -18,6 +18,7 @@
"bluesky-more-ideas": "More ideas...",
"bluesky-more-ideas-url": "Project:Contribute to {{SITENAME}}",
"bluesky-mylinks": "My Links",
+ "bluesky-my-notifications": "My notifications",
"bluesky-my-page": "My page",
"bluesky-navbar-explore": "Explore",
"bluesky-navbar-help": "Help us",
@@ -25,7 +26,10 @@
"bluesky-navbar-profile": "My profile",
"bluesky-navmenu-aboutus": "About us",
"bluesky-navmenu-categories": "Categories",
- "bluesku-navmenu-tipspatrol": "Patrol tips",
+ "bluesky-navmenu-tipspatrol": "Patrol tips",
+ "bluesky-notifications-new-talk": "You have $1 new talk
{{PLURAL:$1|message|messages}}.",
+ "bluesky-notifications-none": "You have no notifications at this
time.\nVisit your [[$1|talk page]] to see past messages.",
+ "bluesky-notifications-no-talk": "Visit your [[$1|talk page]] to see
past messages.",
"bluesky-site-footer-anon": "",
"bluesky-site-footer": "<ul>\n<li
class=\"top\">[[{{int:mainpage}}|Home]]</li>\n<li>[[{{int:aboutpage}}|{{int:about}}]]</li>\n<li>[[{{int:disclaimerpage}}|{{int:disclaimers}}]]</li>\n<li>[[{{int:privacypage}}|{{int:privacy}}]]</li>\n</ul>",
"bluesky-unread-notifications": "{{PLURAL:$1|One unread|$1 unread}}",
--
To view, visit https://gerrit.wikimedia.org/r/142518
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Icce3cc2d7c23e05dff8ae4b1a831f9bbe1801a7a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/skins/BlueSky
Gerrit-Branch: master
Gerrit-Owner: Jack Phoenix <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits