Update wikimedia/timestamp to v2.2.0
[lhc/web/wiklou.git] / includes / Title.php
index 1bff30f..59164e0 100644 (file)
@@ -1480,6 +1480,22 @@ class Title implements LinkTarget {
                );
        }
 
+       /**
+        * Is this a message which can contain raw HTML?
+        *
+        * @return bool
+        * @since 1.32
+        */
+       public function isRawHtmlMessage() {
+               global $wgRawHtmlMessages;
+
+               if ( !$this->inNamespace( NS_MEDIAWIKI ) ) {
+                       return false;
+               }
+               $message = lcfirst( $this->getRootTitle()->getDBkey() );
+               return in_array( $message, $wgRawHtmlMessages, true );
+       }
+
        /**
         * Is this a talk page of some sort?
         *
@@ -1649,7 +1665,7 @@ class Title implements LinkTarget {
                        if ( $nsText === false ) {
                                // See T165149. Awkward, but better than erroneously linking to the main namespace.
                                $nsText = MediaWikiServices::getInstance()->getContentLanguage()->
-                                       getNsText( NS_SPECIAL ) .  ":Badtitle/NS{$this->mNamespace}";
+                                       getNsText( NS_SPECIAL ) . ":Badtitle/NS{$this->mNamespace}";
                        }
 
                        $p .= $nsText . ':';
@@ -2392,6 +2408,13 @@ class Title implements LinkTarget {
                                $error = [ 'sitejsonprotected', $action ];
                        } elseif ( $this->isSiteJsConfigPage() && !$user->isAllowed( 'editsitejs' ) ) {
                                $error = [ 'sitejsprotected', $action ];
+                       } elseif ( $this->isRawHtmlMessage() ) {
+                               // Raw HTML can be used to deploy CSS or JS so require rights for both.
+                               if ( !$user->isAllowed( 'editsitejs' ) ) {
+                                       $error = [ 'sitejsprotected', $action ];
+                               } elseif ( !$user->isAllowed( 'editsitecss' ) ) {
+                                       $error = [ 'sitecssprotected', $action ];
+                               }
                        }
 
                        if ( $error ) {
@@ -3331,11 +3354,12 @@ class Title implements LinkTarget {
                $id = $this->getArticleID();
                if ( $id ) {
                        $cache = ObjectCache::getMainWANInstance();
+                       $fname = __METHOD__;
                        $rows = $cache->getWithSetCallback(
                                // Page protections always leave a new null revision
                                $cache->makeKey( 'page-restrictions', $id, $this->getLatestRevID() ),
                                $cache::TTL_DAY,
-                               function ( $curValue, &$ttl, array &$setOpts ) {
+                               function ( $curValue, &$ttl, array &$setOpts ) use ( $fname ) {
                                        $dbr = wfGetDB( DB_REPLICA );
 
                                        $setOpts += Database::getCacheSetOptions( $dbr );
@@ -3345,7 +3369,7 @@ class Title implements LinkTarget {
                                                        'page_restrictions',
                                                        [ 'pr_type', 'pr_expiry', 'pr_level', 'pr_cascade' ],
                                                        [ 'pr_page' => $this->getArticleID() ],
-                                                       __METHOD__
+                                                       $fname
                                                )
                                        );
                                }
@@ -4404,7 +4428,7 @@ class Title implements LinkTarget {
                                $revQuery['joins']
                        );
                        if ( $row ) {
-                               return new Revision( $row );
+                               return new Revision( $row, 0, $this );
                        }
                }
                return null;