r52544 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r52543‎ | r52544 | r52545 >
Date:14:56, 29 June 2009
Author:werdna
Status:deferred
Tags:
Comment:
Compatibility code for old user properties format.
Modified paths:
  • /trunk/extensions/LiquidThreads/classes/LqtNewMessages.php (modified) (history)
  • /trunk/extensions/LiquidThreads/pages/TalkpageView.php (modified) (history)

Diff [purge]

Index: trunk/extensions/LiquidThreads/classes/LqtNewMessages.php
@@ -60,25 +60,39 @@
6161 $rootWhere = $dbw->makeList( $rootWhere, LIST_AND );
6262
6363 $where_clause = $dbw->makeList( array( $talkpageWhere, $rootWhere ), LIST_OR );
 64+
 65+ // <= 1.15 compatibility, it kinda sucks having to do all this up here.
 66+ $tables = array( 'watchlist', 'user_message_state' );
 67+ $joins = array( 'user_message_state' =>
 68+ array( 'left join',
 69+ array( 'ums_user=wl_user', 'ums_thread' => $t->id() ) ) );
 70+ $fields = array( 'wl_user', 'ums_user', 'ums_read_timestamp' );
 71+
 72+ $oldPrefCompat = false;
 73+ global $wgVersion;
 74+ if ( version_compare( $wgVersion, '1.15', '<=' ) ) {
 75+ $oldPrefCompat = true;
 76+
 77+ $tables[] = 'user';
 78+ $joins['user'] = array( 'left join', 'user_id=wl_user' );
 79+ $fields[] = 'user_options';
 80+ } else {
 81+ $tables[] = 'user_properties';
 82+ $joins['user_properties'] =
 83+ array(
 84+ 'left join',
 85+ array( 'up_user=wl_user',
 86+ 'up_property' => 'lqtnotifytalk',
 87+ )
 88+ );
 89+ $fields[] = 'up_value';
 90+ }
6491
6592 // Pull users to update the message state for, including whether or not a
6693 // user_message_state row exists for them, and whether or not to send an email
6794 // notification.
6895 $dbr = wfGetDB( DB_SLAVE );
69 - $res = $dbr->select( array( 'watchlist', 'user_message_state', 'user_properties' ),
70 - array( 'wl_user', 'ums_user', 'ums_read_timestamp', 'up_value' ),
71 - $where_clause, __METHOD__, array(),
72 - array( 'user_message_state' =>
73 - array( 'left join', array( 'ums_user=wl_user',
74 - 'ums_thread' => $t->id() ) ),
75 - 'user_properties' => array(
76 - 'left join',
77 - array( 'up_user=wl_user',
78 - 'up_property' => 'lqtnotifytalk',
79 - )
80 - ),
81 - )
82 - );
 96+ $res = $dbr->select( $tables, $fields, $where_clause, __METHOD__, array(), $joins);
8397
8498 $insert_rows = array();
8599 $update_tuples = array();
@@ -99,8 +113,20 @@
100114 );
101115 }
102116
103 - if ( ( is_null($row->up_value) && User::getDefaultOption( 'lqtnotifytalk' ) )
104 - || $row->up_value ) {
 117+ $wantsTalkNotification = false;
 118+
 119+ if ( $oldPrefCompat ) {
 120+ $decodedOptions = self::decodeUserOptions( $row->user_options );
 121+
 122+ $wantsTalkNotification = ( is_null( $decodedOptions['lqtnotifytalk'] ) &&
 123+ User::getDefaultOption( 'lqtnotifytalk' ) ) || $row->up_value;
 124+ } else {
 125+ $wantsTalkNotification =
 126+ (is_null($row->up_value) && User::getDefaultOption( 'lqtnotifytalk' ) )
 127+ || $row->up_value;
 128+ }
 129+
 130+ if ( $wantsTalkNotification ) {
105131 $notify_users[] = $row->wl_user;
106132 }
107133 }
@@ -134,6 +160,21 @@
135161 }
136162 }
137163
 164+ // Would refactor User::decodeOptions, but the whole point is that this is
 165+ // compatible with old code :)
 166+ static function decodeUserOptions( $str ) {
 167+ $opts = array();
 168+ $a = explode( "\n", $str );
 169+ foreach ( $a as $s ) {
 170+ $m = array();
 171+ if ( preg_match( "/^(.[^=]*)=(.*)$/", $s, $m ) ) {
 172+ $opts[$m[1]] = $m[2];
 173+ }
 174+ }
 175+
 176+ return $opts;
 177+ }
 178+
138179 static function notifyUsersByMail( $t, $watching_users, $timestamp, $type ) {
139180 wfLoadExtensionMessages( 'LiquidThreads' );
140181 $messages = array(
Index: trunk/extensions/LiquidThreads/pages/TalkpageView.php
@@ -407,7 +407,9 @@
408408 function getNavigationBar() {
409409 global $wgStylePath, $wgContLang;
410410
411 - if ( !$this->isNavigationBarShown() ) return '';
 411+ if ( method_exists( $this, 'isNavigationBarShown' ) &&
 412+ !$this->isNavigationBarShown() )
 413+ return '';
412414
413415 $path = "$wgStylePath/common/images";
414416 $labels = array(

Status & tagging log