Add small HtmlCacheUpdater service class to normalize purging code
[lhc/web/wiklou.git] / includes / Title.php
index 6e75102..674767d 100644 (file)
@@ -23,6 +23,7 @@
  */
 
 use MediaWiki\Permissions\PermissionManager;
+use MediaWiki\Storage\RevisionRecord;
 use Wikimedia\Assert\Assert;
 use Wikimedia\Rdbms\Database;
 use Wikimedia\Rdbms\IDatabase;
@@ -181,7 +182,8 @@ class Title implements LinkTarget, IDBAccessObject {
        private $mPageLanguage = false;
 
        /** @var string|bool|null The page language code from the database, null if not saved in
-        * the database or false if not loaded, yet. */
+        * the database or false if not loaded, yet.
+        */
        private $mDbPageLanguage = false;
 
        /** @var TitleValue|null A corresponding TitleValue object */
@@ -1770,6 +1772,7 @@ class Title implements LinkTarget, IDBAccessObject {
                if (
                        !MediaWikiServices::getInstance()->getNamespaceInfo()->
                                hasSubpages( $this->mNamespace )
+                       || strtok( $this->getText(), '/' ) === false
                ) {
                        return $this->getText();
                }
@@ -1887,7 +1890,12 @@ class Title implements LinkTarget, IDBAccessObject {
         * @since 1.20
         */
        public function getSubpage( $text ) {
-               return self::makeTitleSafe( $this->mNamespace, $this->getText() . '/' . $text );
+               return self::makeTitleSafe(
+                       $this->mNamespace,
+                       $this->getText() . '/' . $text,
+                       '',
+                       $this->mInterwiki
+               );
        }
 
        /**
@@ -2294,34 +2302,6 @@ class Title implements LinkTarget, IDBAccessObject {
                        ->getPermissionErrors( $action, $user, $this, $rigor, $ignoreErrors );
        }
 
-       /**
-        * Add the resulting error code to the errors array
-        *
-        * @param array $errors List of current errors
-        * @param array|string|MessageSpecifier|false $result Result of errors
-        *
-        * @return array List of errors
-        */
-       private function resultToError( $errors, $result ) {
-               if ( is_array( $result ) && count( $result ) && !is_array( $result[0] ) ) {
-                       // A single array representing an error
-                       $errors[] = $result;
-               } elseif ( is_array( $result ) && is_array( $result[0] ) ) {
-                       // A nested array representing multiple errors
-                       $errors = array_merge( $errors, $result );
-               } elseif ( $result !== '' && is_string( $result ) ) {
-                       // A string representing a message-id
-                       $errors[] = [ $result ];
-               } elseif ( $result instanceof MessageSpecifier ) {
-                       // A message specifier representing an error
-                       $errors[] = [ $result ];
-               } elseif ( $result === false ) {
-                       // a generic "We don't want them to do that"
-                       $errors[] = [ 'badaccess-group0' ];
-               }
-               return $errors;
-       }
-
        /**
         * Get a filtered list of all restriction types supported by this wiki.
         * @param bool $exists True to get all restriction types that apply to
@@ -2949,7 +2929,7 @@ class Title implements LinkTarget, IDBAccessObject {
                        $this->mHasSubpages = false;
                        $subpages = $this->getSubpages( 1 );
                        if ( $subpages instanceof TitleArray ) {
-                               $this->mHasSubpages = (bool)$subpages->count();
+                               $this->mHasSubpages = (bool)$subpages->current();
                        }
                }
 
@@ -3452,12 +3432,10 @@ class Title implements LinkTarget, IDBAccessObject {
 
        /**
         * Purge all applicable CDN URLs
+        * @deprecated 1.34 Use HtmlCacheUpdater
         */
        public function purgeSquid() {
-               DeferredUpdates::addUpdate(
-                       new CdnCacheUpdate( $this->getCdnUrls() ),
-                       DeferredUpdates::PRESEND
-               );
+               MediaWikiServices::getInstance()->getHtmlCacheUpdater()->purge( $this->getCdnUrls() );
        }
 
        /**
@@ -3969,17 +3947,18 @@ class Title implements LinkTarget, IDBAccessObject {
                if ( $old->getId() === $new->getId() ) {
                        return ( $old_cmp === '>' && $new_cmp === '<' ) ?
                                [] :
-                               [ $old->getUserText( Revision::RAW ) ];
+                               [ $old->getUserText( RevisionRecord::RAW ) ];
                } elseif ( $old->getId() === $new->getParentId() ) {
                        if ( $old_cmp === '>=' && $new_cmp === '<=' ) {
-                               $authors[] = $old->getUserText( Revision::RAW );
-                               if ( $old->getUserText( Revision::RAW ) != $new->getUserText( Revision::RAW ) ) {
-                                       $authors[] = $new->getUserText( Revision::RAW );
+                               $authors[] = $oldUserText = $old->getUserText( RevisionRecord::RAW );
+                               $newUserText = $new->getUserText( RevisionRecord::RAW );
+                               if ( $oldUserText != $newUserText ) {
+                                       $authors[] = $newUserText;
                                }
                        } elseif ( $old_cmp === '>=' ) {
-                               $authors[] = $old->getUserText( Revision::RAW );
+                               $authors[] = $old->getUserText( RevisionRecord::RAW );
                        } elseif ( $new_cmp === '<=' ) {
-                               $authors[] = $new->getUserText( Revision::RAW );
+                               $authors[] = $new->getUserText( RevisionRecord::RAW );
                        }
                        return $authors;
                }
@@ -4264,12 +4243,21 @@ class Title implements LinkTarget, IDBAccessObject {
         * on the number of links. Typically called on create and delete.
         */
        public function touchLinks() {
-               DeferredUpdates::addUpdate( new HTMLCacheUpdate( $this, 'pagelinks', 'page-touch' ) );
+               $jobs = [];
+               $jobs[] = HTMLCacheUpdateJob::newForBacklinks(
+                       $this,
+                       'pagelinks',
+                       [ 'causeAction' => 'page-touch' ]
+               );
                if ( $this->mNamespace == NS_CATEGORY ) {
-                       DeferredUpdates::addUpdate(
-                               new HTMLCacheUpdate( $this, 'categorylinks', 'category-touch' )
+                       $jobs[] = HTMLCacheUpdateJob::newForBacklinks(
+                               $this,
+                               'categorylinks',
+                               [ 'causeAction' => 'category-touch' ]
                        );
                }
+
+               JobQueueGroup::singleton()->lazyPush( $jobs );
        }
 
        /**
@@ -4290,7 +4278,7 @@ class Title implements LinkTarget, IDBAccessObject {
         * Get the timestamp when this page was updated since the user last saw it.
         *
         * @param User|null $user
-        * @return string|null
+        * @return string|bool|null String timestamp, false if not watched, null if nothing is unseen
         */
        public function getNotificationTimestamp( $user = null ) {
                global $wgUser;