Index: trunk/extensions/FlaggedRevs/FRUserActivity.php |
— | — | @@ -64,24 +64,35 @@ |
65 | 65 | global $wgMemc; |
66 | 66 | $key = wfMemcKey( 'flaggedrevs', 'userReviewingPage', $pageId ); |
67 | 67 | $val = array( $user->getName(), wfTimestampNow() ); |
| 68 | + $wasSet = false; |
| 69 | + |
| 70 | + $wgMemc->lock( $key, 4 ); // 4 sec timeout |
68 | 71 | if ( !$wgMemc->get( $key ) ) { // no flag set |
69 | | - # Set the flag (use locks if available) |
70 | | - $wgMemc->lock( $key, 4000 ); // 4 sec timeout |
71 | 72 | $wgMemc->set( $key, $val, 20*60 ); // 20 min |
72 | | - $wgMemc->unlock( $key ); |
73 | | - return true; |
| 73 | + $wasSet = true; |
74 | 74 | } |
75 | | - return false; |
| 75 | + $wgMemc->unlock( $key ); |
| 76 | + |
| 77 | + return $wasSet; |
76 | 78 | } |
77 | 79 | |
78 | 80 | /* |
79 | 81 | * Clear the flag for who is reviewing a page |
| 82 | + * @param User $user |
80 | 83 | * @param int $pageId |
81 | 84 | */ |
82 | | - public static function clearUserReviewingPage( $pageId ) { |
| 85 | + public static function clearUserReviewingPage( $user, $pageId ) { |
83 | 86 | global $wgMemc; |
84 | 87 | $key = wfMemcKey( 'flaggedrevs', 'userReviewingPage', $pageId ); |
85 | | - $wgMemc->delete( $key ); |
| 88 | + $wgMemc->lock( $key, 4 ); // 4 sec timeout |
| 89 | + $val = $wgMemc->get( $key ); |
| 90 | + if ( is_array( $val ) && count( $val ) == 2 ) { // flag set |
| 91 | + list( $u, $ts ) = $val; |
| 92 | + if ( $u === $user->getName() ) { |
| 93 | + $wgMemc->delete( $key ); |
| 94 | + } |
| 95 | + } |
| 96 | + $this->unlock(); |
86 | 97 | } |
87 | 98 | |
88 | 99 | /* |
— | — | @@ -110,23 +121,35 @@ |
111 | 122 | global $wgMemc; |
112 | 123 | $key = wfMemcKey( 'flaggedrevs', 'userReviewingDiff', $oldId, $newId ); |
113 | 124 | $val = array( $user->getName(), wfTimestampNow() ); |
| 125 | + $wasSet = false; |
| 126 | + |
| 127 | + $wgMemc->lock( $key, 4 ); // 4 sec timeout |
114 | 128 | if ( !$wgMemc->get( $key ) ) { // no flag set |
115 | | - # Set the flag (use locks if available) |
116 | | - $wgMemc->lock( $key, 4000 ); // 4 sec timeout |
117 | 129 | $wgMemc->set( $key, $val, 6*20 ); // 6 min |
118 | | - $wgMemc->unlock( $key ); |
119 | | - return true; |
| 130 | + $wasSet = true; |
120 | 131 | } |
121 | | - return false; |
| 132 | + $wgMemc->unlock( $key ); |
| 133 | + |
| 134 | + return $wasSet; |
122 | 135 | } |
123 | 136 | |
124 | 137 | /* |
125 | 138 | * Clear the flag for who is reviewing a diff |
126 | | - * @param int $pageId |
| 139 | + * @param User $user |
| 140 | + * @param int $oldId |
| 141 | + * @param int $newId |
127 | 142 | */ |
128 | | - public static function clearUserReviewingDiff( $oldId, $newId ) { |
| 143 | + public static function clearUserReviewingDiff( $user, $oldId, $newId ) { |
129 | 144 | global $wgMemc; |
130 | 145 | $key = wfMemcKey( 'flaggedrevs', 'userReviewingDiff', $oldId, $newId ); |
131 | | - $wgMemc->delete( $key ); |
| 146 | + $wgMemc->lock( $key, 4 ); // 4 sec timeout |
| 147 | + $val = $wgMemc->get( $key ); |
| 148 | + if ( is_array( $val ) && count( $val ) == 2 ) { // flag set |
| 149 | + list( $u, $ts ) = $val; |
| 150 | + if ( $u === $user->getName() ) { |
| 151 | + $wgMemc->delete( $key ); |
| 152 | + } |
| 153 | + } |
| 154 | + $this->unlock(); |
132 | 155 | } |
133 | 156 | } |