Make edit stash keys less preference sensitive
[lhc/web/wiklou.git] / includes / api / ApiStashEdit.php
index 93003cc..01153a5 100644 (file)
@@ -46,6 +46,10 @@ class ApiStashEdit extends ApiBase {
                $user = $this->getUser();
                $params = $this->extractRequestParams();
 
+               if ( $user->isBot() ) { // sanity
+                       $this->dieUsage( 'This interface is not supported for bots', 'botsnotsupported' );
+               }
+
                $page = $this->getTitleOrPageId( $params );
                $title = $page->getTitle();
 
@@ -123,6 +127,8 @@ class ApiStashEdit extends ApiBase {
                        $status = 'busy';
                }
 
+               $this->getStats()->increment( "editstash.cache_stores.$status" );
+
                $this->getResult()->addValue( null, $this->getModuleName(), [ 'status' => $status ] );
        }
 
@@ -259,6 +265,10 @@ class ApiStashEdit extends ApiBase {
         * @return stdClass|bool Returns false on cache miss
         */
        public static function checkCache( Title $title, Content $content, User $user ) {
+               if ( $user->isBot() ) {
+                       return false; // bots never stash - don't pollute stats
+               }
+
                $cache = ObjectCache::getLocalClusterInstance();
                $logger = LoggerFactory::getInstance( 'StashEdit' );
                $stats = RequestContext::getMain()->getStats();
@@ -396,11 +406,15 @@ class ApiStashEdit extends ApiBase {
         */
        private static function getStashKey( Title $title, Content $content, User $user ) {
                $hash = sha1( implode( ':', [
+                       // Account for the edit model/text
                        $content->getModel(),
                        $content->getDefaultFormat(),
                        sha1( $content->serialize( $content->getDefaultFormat() ) ),
-                       $user->getId() ?: md5( $user->getName() ), // account for user parser options
-                       $user->getId() ? $user->getDBTouched() : '-' // handle preference change races
+                       // Account for user name related variables like signatures
+                       $user->getId(),
+                       md5( $user->getName() ),
+                       (string)$user->getOption( 'nickname' ),
+                       (int)$user->getBoolOption( 'fancysig' )
                ] ) );
 
                return wfMemcKey( 'prepared-edit', md5( $title->getPrefixedDBkey() ), $hash );