SpecialContributions: Use PoolCounter to limit concurrency
[lhc/web/wiklou.git] / includes / specials / SpecialContributions.php
index 8f92cd5..c39094e 100644 (file)
@@ -239,19 +239,38 @@ class SpecialContributions extends IncludableSpecialPage {
                        } elseif ( !$pager->getNumRows() ) {
                                $out->addWikiMsg( 'nocontribs', $target );
                        } else {
-                               # Show a message about replica DB lag, if applicable
-                               $lag = $pager->getDatabase()->getSessionLagStatus()['lag'];
-                               if ( $lag > 0 ) {
-                                       $out->showLagWarning( $lag );
-                               }
-
-                               $output = $pager->getBody();
-                               if ( !$this->including() ) {
-                                       $output = $pager->getNavigationBar() .
-                                               $output .
-                                               $pager->getNavigationBar();
+                               // @todo We just want a wiki ID here, not a "DB domain", but
+                               // current status of MediaWiki conflates the two. See T235955.
+                               $poolKey = WikiMap::getCurrentWikiDbDomain() . ':SpecialContributions:';
+                               if ( $this->getUser()->isAnon() ) {
+                                       $poolKey .= 'a:' . $this->getUser()->getName();
+                               } else {
+                                       $poolKey .= 'u:' . $this->getUser()->getId();
                                }
-                               $out->addHTML( $output );
+                               $work = new PoolCounterWorkViaCallback( 'SpecialContributions', $poolKey, [
+                                       'doWork' => function () use ( $pager, $out ) {
+                                               # Show a message about replica DB lag, if applicable
+                                               $lag = $pager->getDatabase()->getSessionLagStatus()['lag'];
+                                               if ( $lag > 0 ) {
+                                                       $out->showLagWarning( $lag );
+                                               }
+
+                                               $output = $pager->getBody();
+                                               if ( !$this->including() ) {
+                                                       $output = $pager->getNavigationBar() .
+                                                               $output .
+                                                               $pager->getNavigationBar();
+                                               }
+                                               $out->addHTML( $output );
+                                       },
+                                       'error' => function () use ( $out ) {
+                                               $msg = $this->getUser()->isAnon()
+                                                       ? 'sp-contributions-concurrency-ip'
+                                                       : 'sp-contributions-concurrency-user';
+                                               $out->wrapWikiMsg( "<div class='errorbox'>\n$1\n</div>", $msg );
+                                       }
+                               ] );
+                               $work->execute();
                        }
 
                        $out->preventClickjacking( $pager->getPreventClickjacking() );