Merge "Show protection log on creation-protected pages"
[lhc/web/wiklou.git] / includes / actions / InfoAction.php
index 49b9ab7..68dda37 100644 (file)
@@ -23,6 +23,7 @@
  */
 
 use MediaWiki\MediaWikiServices;
+use Wikimedia\Rdbms\Database;
 
 /**
  * Displays information about a page.
@@ -72,8 +73,9 @@ class InfoAction extends FormlessAction {
                        $revid = $revision ? $revision->getId() : null;
                }
                if ( $revid !== null ) {
-                       $key = self::getCacheKey( $title, $revid );
-                       ObjectCache::getMainWANInstance()->delete( $key );
+                       $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
+                       $key = self::getCacheKey( $cache, $title, $revid );
+                       $cache->delete( $key );
                }
        }
 
@@ -125,7 +127,10 @@ class InfoAction extends FormlessAction {
                        // Messages:
                        // pageinfo-header-basic, pageinfo-header-edits, pageinfo-header-restrictions,
                        // pageinfo-header-properties, pageinfo-category-info
-                       $content .= $this->makeHeader( $this->msg( "pageinfo-${header}" )->escaped() ) . "\n";
+                       $content .= $this->makeHeader(
+                               $this->msg( "pageinfo-${header}" )->escaped(),
+                               "mw-pageinfo-${header}"
+                       ) . "\n";
                        $table = "\n";
                        foreach ( $infoTable as $infoRow ) {
                                $name = ( $infoRow[0] instanceof Message ) ? $infoRow[0]->escaped() : $infoRow[0];
@@ -150,10 +155,11 @@ class InfoAction extends FormlessAction {
         * @param string $header The header text.
         * @return string The HTML.
         */
-       protected function makeHeader( $header ) {
-               $spanAttribs = [ 'class' => 'mw-headline', 'id' => Sanitizer::escapeId( $header ) ];
+       protected function makeHeader( $header, $canonicalId ) {
+               $spanAttribs = [ 'class' => 'mw-headline', 'id' => Sanitizer::escapeIdForAttribute( $header ) ];
+               $h2Attribs = [ 'id' => Sanitizer::escapeIdForAttribute( $canonicalId ) ];
 
-               return Html::rawElement( 'h2', [], Html::element( 'span', $spanAttribs, $header ) );
+               return Html::rawElement( 'h2', $h2Attribs, Html::element( 'span', $spanAttribs, $header ) );
        }
 
        /**
@@ -261,28 +267,29 @@ class InfoAction extends FormlessAction {
                // Language in which the page content is (supposed to be) written
                $pageLang = $title->getPageLanguage()->getCode();
 
+               $pageLangHtml = $pageLang . ' - ' .
+                       Language::fetchLanguageName( $pageLang, $lang->getCode() );
+               // Link to Special:PageLanguage with pre-filled page title if user has permissions
                if ( $config->get( 'PageLanguageUseDB' )
-                       && $this->getTitle()->userCan( 'pagelang', $this->getUser() )
+                       && $title->userCan( 'pagelang', $user )
                ) {
-                       // Link to Special:PageLanguage with pre-filled page title if user has permissions
-                       $titleObj = SpecialPage::getTitleFor( 'PageLanguage', $title->getPrefixedText() );
-                       $langDisp = $linkRenderer->makeLink(
-                               $titleObj,
-                               $this->msg( 'pageinfo-language' )->text()
-                       );
-               } else {
-                       // Display just the message
-                       $langDisp = $this->msg( 'pageinfo-language' )->escaped();
+                       $pageLangHtml .= ' ' . $this->msg( 'parentheses' )->rawParams( $linkRenderer->makeLink(
+                               SpecialPage::getTitleValueFor( 'PageLanguage', $title->getPrefixedText() ),
+                               $this->msg( 'pageinfo-language-change' )->text()
+                       ) )->escaped();
                }
 
-               $pageInfo['header-basic'][] = [ $langDisp,
-                       Language::fetchLanguageName( $pageLang, $lang->getCode() )
-                       . ' ' . $this->msg( 'parentheses', $pageLang )->escaped() ];
+               $pageInfo['header-basic'][] = [
+                       $this->msg( 'pageinfo-language' )->escaped(),
+                       $pageLangHtml
+               ];
 
                // Content model of the page
                $modelHtml = htmlspecialchars( ContentHandler::getLocalizedName( $title->getContentModel() ) );
                // If the user can change it, add a link to Special:ChangeContentModel
-               if ( $title->quickUserCan( 'editcontentmodel' ) ) {
+               if ( $config->get( 'ContentHandlerUseDB' )
+                       && $title->userCan( 'editcontentmodel', $user )
+               ) {
                        $modelHtml .= ' ' . $this->msg( 'parentheses' )->rawParams( $linkRenderer->makeLink(
                                SpecialPage::getTitleValueFor( 'ChangeContentModel', $title->getPrefixedText() ),
                                $this->msg( 'pageinfo-content-model-change' )->text()
@@ -387,7 +394,10 @@ class InfoAction extends FormlessAction {
                        $prefixIndex = SpecialPage::getTitleFor(
                                'Prefixindex', $title->getPrefixedText() . '/' );
                        $pageInfo['header-basic'][] = [
-                               Linker::link( $prefixIndex, $this->msg( 'pageinfo-subpages-name' )->escaped() ),
+                               $linkRenderer->makeLink(
+                                       $prefixIndex,
+                                       $this->msg( 'pageinfo-subpages-name' )->text()
+                               ),
                                $this->msg( 'pageinfo-subpages-value' )
                                        ->numParams(
                                                $pageCounts['subpages']['total'],
@@ -474,7 +484,7 @@ class InfoAction extends FormlessAction {
                        }
                        $expiry = $title->getRestrictionExpiry( $restrictionType );
                        $formattedexpiry = $this->msg( 'parentheses',
-                               $this->getLanguage()->formatExpiry( $expiry ) )->escaped();
+                               $lang->formatExpiry( $expiry ) )->escaped();
                        $message .= $this->msg( 'word-separator' )->escaped() . $formattedexpiry;
 
                        // Messages: restriction-edit, restriction-move, restriction-create,
@@ -688,9 +698,10 @@ class InfoAction extends FormlessAction {
        protected function pageCounts( Page $page ) {
                $fname = __METHOD__;
                $config = $this->context->getConfig();
+               $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
 
-               return ObjectCache::getMainWANInstance()->getWithSetCallback(
-                       self::getCacheKey( $page->getTitle(), $page->getLatest() ),
+               return $cache->getWithSetCallback(
+                       self::getCacheKey( $cache, $page->getTitle(), $page->getLatest() ),
                        WANObjectCache::TTL_WEEK,
                        function ( $oldValue, &$ttl, &$setOpts ) use ( $page, $config, $fname ) {
                                $title = $page->getTitle();
@@ -834,7 +845,7 @@ class InfoAction extends FormlessAction {
                $real_names = [];
                $user_names = [];
                $anon_ips = [];
-               $linkRenderer = MediaWikiServices::getLinkRenderer();
+               $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
 
                # Sift for real versus user names
                /** @var $user User */
@@ -901,11 +912,12 @@ class InfoAction extends FormlessAction {
        }
 
        /**
+        * @param WANObjectCache $cache
         * @param Title $title
         * @param int $revId
         * @return string
         */
-       protected static function getCacheKey( Title $title, $revId ) {
-               return wfMemcKey( 'infoaction', md5( $title->getPrefixedText() ), $revId, self::VERSION );
+       protected static function getCacheKey( WANObjectCache $cache, Title $title, $revId ) {
+               return $cache->makeKey( 'infoaction', md5( $title->getPrefixedText() ), $revId, self::VERSION );
        }
 }