Nikerabbit has uploaded a new change for review.
https://gerrit.wikimedia.org/r/51836
Change subject: Make (en|dis)couraging changes immediately visible
......................................................................
Make (en|dis)couraging changes immediately visible
Introduced MessageGroups::setPriority that handles
cache clearing
Change-Id: I3049ffcacd169d3fa41a2f00572415ffa95f6477
---
M MessageGroups.php
M tag/SpecialPageTranslation.php
2 files changed, 52 insertions(+), 30 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Translate
refs/changes/36/51836/1
diff --git a/MessageGroups.php b/MessageGroups.php
index 8477820..5cd04d5 100644
--- a/MessageGroups.php
+++ b/MessageGroups.php
@@ -15,6 +15,11 @@
* @todo Clean up the mixed static/member method interface.
*/
class MessageGroups {
+ /**
+ * @var Array Cache for message group priorities
+ */
+ protected static $prioritycache = null;
+
protected static $groups = null;
/// Initialises the list of groups (but not the groups itself if
possible).
@@ -213,9 +218,8 @@
* @since 2011-12-12
*/
public static function getPriority( $group ) {
- static $groups = null;
- if ( $groups === null ) {
- $groups = array();
+ if ( !isset( self::$prioritycache ) ) {
+ self::$prioritycache = array();
// Abusing this table originally intented for other
purposes
$db = wfGetDB( DB_MASTER );
$table = 'translate_groupreviews';
@@ -223,7 +227,7 @@
$conds = array( 'tgr_lang' => '*priority' );
$res = $db->select( $table, $fields, $conds, __METHOD__
);
foreach ( $res as $row ) {
- $groups[$row->tgr_group] = $row->tgr_state;
+ self::$prioritycache[$row->tgr_group] =
$row->tgr_state;
}
}
@@ -232,7 +236,41 @@
} else {
$id = $group;
}
- return isset( $groups[$id] ) ? $groups[$id] : '';
+ return isset( self::$prioritycache[$id] ) ?
self::$prioritycache[$id] : '';
+ }
+
+ /**
+ * Sets the message group priority.
+ * @see MessageGroups::getPriority
+ *
+ * @param MessageGroup|string $group Message group
+ * @param string Priority (empty string to unset)
+ * @since 2013-03-01
+ */
+ public static function setPriority( $group, $priority = '' ) {
+ if ( $group instanceof MessageGroup ) {
+ $id = $group->getId();
+ } else {
+ $id = $group;
+ }
+
+ self::$prioritycache[$id] = $priority;
+
+ $dbw = wfGetDB( DB_MASTER );
+ $table = 'translate_groupreviews';
+ $row = array(
+ 'tgr_group' => $id,
+ 'tgr_lang' => '*priority',
+ 'tgr_state' => $priority,
+ );
+
+ if ( $priority === '' ) {
+ unset( $row['tgr_state'] );
+ $dbw->delete( $table, $row, __METHOD__ );
+ } else {
+ $index = array( 'tgr_group', 'tgr_lang' );
+ $dbw->replace( $table, array( $index ), $row,
__METHOD__ );
+ }
}
/// @since 2011-12-28
diff --git a/tag/SpecialPageTranslation.php b/tag/SpecialPageTranslation.php
index 9827332..c131734 100644
--- a/tag/SpecialPageTranslation.php
+++ b/tag/SpecialPageTranslation.php
@@ -66,37 +66,21 @@
if ( $action === 'discourage' || $action === 'encourage' ) {
$id = TranslatablePage::getMessageGroupIdFromTitle(
$title );
- $dbw = wfGetDB( DB_MASTER );
- $table = 'translate_groupreviews';
- $row = array(
- 'tgr_group' => $id,
- 'tgr_lang' => '*priority',
- 'tgr_state' => 'discouraged',
- );
+ $current = MessageGroups::getPriority( $id );
- $priority = MessageGroups::getPriority( $id );
+ if ( $action === 'encourage' ) {
+ $new = '';
+ } else {
+ $new = 'discouraged';
+ }
- // encouraged is default priority (''). Only do this if
the priority is discouraged.
- if ( $action === 'encourage' && $priority ===
'discouraged' ) {
- $dbw->delete( $table, $row, __METHOD__ );
-
- $entry = new ManualLogEntry( 'pagetranslation',
'encourage' );
+ if ( $new !== $current ) {
+ MessageGroups::setPriority( $id, $new );
+ $entry = new ManualLogEntry( 'pagetranslation',
$action );
$entry->setPerformer( $user );
$entry->setTarget( $title );
$logid = $entry->insert();
$entry->publish( $logid );
- } else {
- $index = array( 'tgr_group', 'tgr_lang' );
- $dbw->replace( $table, array( $index ), $row,
__METHOD__ );
-
- // Prevent duplicate log entries.
- if ( $priority !== 'discouraged' ) {
- $entry = new ManualLogEntry(
'pagetranslation', 'discourage' );
- $entry->setPerformer( $user );
- $entry->setTarget( $title );
- $logid = $entry->insert();
- $entry->publish( $logid );
- }
}
$this->listPages();
--
To view, visit https://gerrit.wikimedia.org/r/51836
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I3049ffcacd169d3fa41a2f00572415ffa95f6477
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Translate
Gerrit-Branch: master
Gerrit-Owner: Nikerabbit <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits