Merge "Clean up handling of 'infinity'"
[lhc/web/wiklou.git] / includes / page / WikiPage.php
index 5caffab..8754fb9 100644 (file)
@@ -1150,28 +1150,24 @@ class WikiPage implements Page, IDBAccessObject {
         * @return bool
         */
        public function doPurge() {
-               global $wgUseSquid;
-
                if ( !Hooks::run( 'ArticlePurge', array( &$this ) ) ) {
                        return false;
                }
 
-               // Invalidate the cache
-               $this->mTitle->invalidateCache();
-
-               if ( $wgUseSquid ) {
-                       // Commit the transaction before the purge is sent
-                       $dbw = wfGetDB( DB_MASTER );
-                       $dbw->commit( __METHOD__ );
-
-                       // Send purge
-                       $update = SquidUpdate::newSimplePurge( $this->mTitle );
-                       $update->doUpdate();
-               }
+               $title = $this->mTitle;
+               wfGetDB( DB_MASTER )->onTransactionIdle( function() use ( $title ) {
+                       global $wgUseSquid;
+                       // Invalidate the cache in auto-commit mode
+                       $title->invalidateCache();
+                       if ( $wgUseSquid ) {
+                               // Send purge now that page_touched update was committed above
+                               $update = SquidUpdate::newSimplePurge( $title );
+                               $update->doUpdate();
+                       }
+               } );
 
                if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
                        // @todo move this logic to MessageCache
-
                        if ( $this->exists() ) {
                                // NOTE: use transclusion text for messages.
                                //       This is consistent with  MessageCache::getMsgFromNamespace()
@@ -1188,6 +1184,7 @@ class WikiPage implements Page, IDBAccessObject {
 
                        MessageCache::singleton()->replace( $this->mTitle->getDBkey(), $text );
                }
+
                return true;
        }
 
@@ -2078,7 +2075,7 @@ class WikiPage implements Page, IDBAccessObject {
                }
 
                // The edit may have already been prepared via api.php?action=stashedit
-               $cachedEdit = $useCache && $wgAjaxEditStash
+               $cachedEdit = $useCache && $wgAjaxEditStash && !$user->isAllowed( 'bot' )
                        ? ApiStashEdit::checkCache( $this->getTitle(), $content, $user )
                        : false;
 
@@ -2370,8 +2367,8 @@ class WikiPage implements Page, IDBAccessObject {
                $dbw = wfGetDB( DB_MASTER );
 
                foreach ( $restrictionTypes as $action ) {
-                       if ( !isset( $expiry[$action] ) ) {
-                               $expiry[$action] = $dbw->getInfinity();
+                       if ( !isset( $expiry[$action] ) || $expiry[$action] === $dbw->getInfinity() ) {
+                               $expiry[$action] = 'infinity';
                        }
                        if ( !isset( $limit[$action] ) ) {
                                $limit[$action] = '';
@@ -2611,10 +2608,8 @@ class WikiPage implements Page, IDBAccessObject {
         */
        protected function formatExpiry( $expiry ) {
                global $wgContLang;
-               $dbr = wfGetDB( DB_SLAVE );
 
-               $encodedExpiry = $dbr->encodeExpiry( $expiry );
-               if ( $encodedExpiry != 'infinity' ) {
+               if ( $expiry != 'infinity' ) {
                        return wfMessage(
                                'protect-expiring',
                                $wgContLang->timeanddate( $expiry, false, false ),