Bsitu has submitted this change and it was merged.
Change subject: Adding GetNewMessagesAlert hook and wgUserNewMsgRevisionId JS
global
......................................................................
Adding GetNewMessagesAlert hook and wgUserNewMsgRevisionId JS global
This hook allows extensions to disable or modify the new messages
alert ('orange bar of doom') while still allowing the user_newtalk
table to be updated.
The wgUserNewMsgRevisionId JS global allows gadgets and extensions
to create their own new message alerts on the client side.
I also threw in a few comment updates for good measure!
See also Echo change I3f35a56b which utilizes this.
Bug: 47962
Change-Id: I2105bdd2bcd5b27f6f36ec8d8fa7fa99d60a2d82
---
M RELEASE-NOTES-1.22
M docs/hooks.txt
M includes/OutputPage.php
M includes/Skin.php
M includes/User.php
M includes/WikiPage.php
6 files changed, 67 insertions(+), 15 deletions(-)
Approvals:
Bsitu: Verified; Looks good to me, approved
diff --git a/RELEASE-NOTES-1.22 b/RELEASE-NOTES-1.22
index ce4c949..a42a25a 100644
--- a/RELEASE-NOTES-1.22
+++ b/RELEASE-NOTES-1.22
@@ -54,6 +54,12 @@
well.
* (bug 45535) introduced the new 'LanguageLinks' hook for manipulating the
language links associated with a page before display.
+* New GetNewMessagesAlert hook allowing extensions to disable or modify the new
+ messages alert
+* New wgUserNewMsgRevisionId JS global for logged in users. This will be null
+ if the user has no new talk page messages. Otherwise it will be set to the
+ revision ID of the oldest new talk page message. This will allow gadgets and
+ extensions to create their own new message alerts on the client side.
=== Bug fixes in 1.22 ===
* Disable Special:PasswordReset when $wgEnableEmail. Previously one could still
diff --git a/docs/hooks.txt b/docs/hooks.txt
index de51024..9424a73 100644
--- a/docs/hooks.txt
+++ b/docs/hooks.txt
@@ -1187,6 +1187,14 @@
the media handler metadata output.
&$version: Array of version strings
+'GetNewMessagesAlert': Disable or modify the new messages alert
+&$newMessagesAlert: An empty string by default. If the user has new talk page
+messages, this should be populated with an alert message to that effect
+$newtalks: An empty array if the user has no new messages or an array
containing
+links and revisions if there are new messages (See User::getNewMessageLinks)
+$user: The user object of the user who is loading the page
+$out: OutputPage object (to check what type of page the user is on)
+
'GetPreferences': Modify user preferences.
$user: User whose preferences are being modified.
&$preferences: Preferences description array, to be fed to an HTMLForm object
diff --git a/includes/OutputPage.php b/includes/OutputPage.php
index 2f1f62e..74dc107 100644
--- a/includes/OutputPage.php
+++ b/includes/OutputPage.php
@@ -3065,6 +3065,10 @@
$vars['wgUserEditCount'] = $user->getEditCount();
$userReg = wfTimestampOrNull( TS_UNIX,
$user->getRegistration() );
$vars['wgUserRegistration'] = $userReg !== null ? (
$userReg * 1000 ) : null;
+ // Get the revision ID of the oldest new message on the
user's talk
+ // page. This can be used for constructing new message
alerts on
+ // the client side.
+ $vars['wgUserNewMsgRevisionId'] =
$user->getNewMessageRevisionId();
}
if ( $wgContLang->hasVariants() ) {
$vars['wgUserVariant'] =
$wgContLang->getPreferredVariant();
diff --git a/includes/Skin.php b/includes/Skin.php
index cc957c4..1aa1f05 100644
--- a/includes/Skin.php
+++ b/includes/Skin.php
@@ -1294,17 +1294,27 @@
}
/**
- * Gets new talk page messages for the current user.
- * @return MediaWiki message or if no new talk page messages, nothing
+ * Gets new talk page messages for the current user and returns an
+ * appropriate alert message (or an empty string if there are no
messages)
+ * @return String
*/
function getNewtalks() {
+
+ $newMessagesAlert = '';
+ $user = $this->getUser();
+ $newtalks = $user->getNewMessageLinks();
$out = $this->getOutput();
- $newtalks = $this->getUser()->getNewMessageLinks();
- $ntl = '';
+ // Allow extensions to disable or modify the new messages alert
+ if ( !wfRunHooks( 'GetNewMessagesAlert', array(
&$newMessagesAlert, $newtalks, $user, $out ) ) ) {
+ return '';
+ }
+ if ( $newMessagesAlert ) {
+ return $newMessagesAlert;
+ }
if ( count( $newtalks ) == 1 && $newtalks[0]['wiki'] ===
wfWikiID() ) {
- $uTalkTitle = $this->getUser()->getTalkPage();
+ $uTalkTitle = $user->getTalkPage();
if ( !$uTalkTitle->equals( $out->getTitle() ) ) {
$lastSeenRev = isset( $newtalks[0]['rev'] ) ?
$newtalks[0]['rev'] : null;
@@ -1343,26 +1353,25 @@
);
if ( $nofAuthors >= 1 && $nofAuthors <= 10 ) {
- $ntl = $this->msg(
+ $newMessagesAlert = $this->msg(
'youhavenewmessagesfromusers',
$newMessagesLink,
$newMessagesDiffLink
)->numParams( $nofAuthors );
} else {
// $nofAuthors === 11 signifies "11 or
more" ("more than 10")
- $ntl = $this->msg(
+ $newMessagesAlert = $this->msg(
$nofAuthors > 10 ?
'youhavenewmessagesmanyusers' : 'youhavenewmessages',
$newMessagesLink,
$newMessagesDiffLink
);
}
- $ntl = $ntl->text();
+ $newMessagesAlert = $newMessagesAlert->text();
# Disable Squid cache
$out->setSquidMaxage( 0 );
}
} elseif ( count( $newtalks ) ) {
- // _>" " for BC <= 1.16
- $sep = str_replace( '_', ' ', $this->msg(
'newtalkseparator' )->escaped() );
+ $sep = $this->msg( 'newtalkseparator' )->escaped();
$msgs = array();
foreach ( $newtalks as $newtalk ) {
@@ -1372,11 +1381,11 @@
);
}
$parts = implode( $sep, $msgs );
- $ntl = $this->msg( 'youhavenewmessagesmulti'
)->rawParams( $parts )->escaped();
+ $newMessagesAlert = $this->msg(
'youhavenewmessagesmulti' )->rawParams( $parts )->escaped();
$out->setSquidMaxage( 0 );
}
- return $ntl;
+ return $newMessagesAlert;
}
/**
diff --git a/includes/User.php b/includes/User.php
index 37a384c..1ae1720 100644
--- a/includes/User.php
+++ b/includes/User.php
@@ -1807,8 +1807,11 @@
}
/**
- * Return the talk page(s) this user has new messages on.
- * @return Array of String page URLs
+ * Return the revision and link for the oldest new talk page message for
+ * this user.
+ * Note: This function was designed to accomodate multiple talk pages,
but
+ * currently only returns a single link and revision.
+ * @return Array
*/
public function getNewMessageLinks() {
$talks = array();
@@ -1829,6 +1832,27 @@
}
/**
+ * Get the revision ID for the oldest new talk page message for this
user
+ * @return Integer or null if there are no new messages
+ */
+ public function getNewMessageRevisionId() {
+ $newMessageRevisionId = null;
+ $newMessageLinks = $this->getNewMessageLinks();
+ if ( $newMessageLinks ) {
+ // Note: getNewMessageLinks() never returns more than a
single link
+ // and it is always for the same wiki, but we
double-check here in
+ // case that changes some time in the future.
+ if ( count( $newMessageLinks ) === 1 &&
$newMessageLinks[0]['wiki'] === wfWikiID() ) {
+ $newMessageRevision =
$newMessageLinks[0]['rev'];
+ $newMessageRevisionId =
$newMessageRevision->getId();
+ } else {
+ throw new MWException( "Unexpected values from
User::getNewMessageLinks()" );
+ }
+ }
+ return $newMessageRevisionId;
+ }
+
+ /**
* Internal uncached check for new messages
*
* @see getNewtalk()
diff --git a/includes/WikiPage.php b/includes/WikiPage.php
index 8c00e1b..f2c9c29 100644
--- a/includes/WikiPage.php
+++ b/includes/WikiPage.php
@@ -2053,7 +2053,8 @@
$content = $revision->getContent();
// Parse the text
- // Be careful not to double-PST: $text is usually already
PST-ed once
+ // Be careful not to do pre-save transform twice: $text is
usually
+ // already pre-save transformed once.
if ( !$this->mPreparedEdit ||
$this->mPreparedEdit->output->getFlag( 'vary-revision' ) ) {
wfDebug( __METHOD__ . ": No prepared edit or
vary-revision is set...\n" );
$editInfo = $this->prepareContentForEdit( $content,
$revision->getId(), $user );
--
To view, visit https://gerrit.wikimedia.org/r/62539
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I2105bdd2bcd5b27f6f36ec8d8fa7fa99d60a2d82
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: wmf/1.22wmf3
Gerrit-Owner: Bsitu <[email protected]>
Gerrit-Reviewer: Bsitu <[email protected]>
Gerrit-Reviewer: Kaldari <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits