Merge "Disallow css attr() with url type"
[lhc/web/wiklou.git] / includes / changes / ChangesList.php
index 342b31d..77038ed 100644 (file)
@@ -21,6 +21,8 @@
  *
  * @file
  */
+use MediaWiki\Linker\LinkRenderer;
+use MediaWiki\MediaWikiServices;
 
 class ChangesList extends ContextSource {
        /**
@@ -39,6 +41,11 @@ class ChangesList extends ContextSource {
        /** @var BagOStuff */
        protected $watchMsgCache;
 
+       /**
+        * @var LinkRenderer
+        */
+       protected $linkRenderer;
+
        /**
         * Changeslist constructor
         *
@@ -54,6 +61,7 @@ class ChangesList extends ContextSource {
                }
                $this->preCacheMessages();
                $this->watchMsgCache = new HashBagOStuff( [ 'maxKeys' => 50 ] );
+               $this->linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
        }
 
        /**
@@ -132,7 +140,7 @@ class ChangesList extends ContextSource {
                $f = '';
                foreach ( array_keys( $this->getConfig()->get( 'RecentChangesFlags' ) ) as $flag ) {
                        $f .= isset( $flags[$flag] ) && $flags[$flag]
-                               ? self::flag( $flag )
+                               ? self::flag( $flag, $this->getContext() )
                                : $nothing;
                }
 
@@ -168,40 +176,40 @@ class ChangesList extends ContextSource {
        }
 
        /**
-        * Provide the "<abbr>" element appropriate to a given abbreviated flag,
-        * namely the flag indicating a new page, a minor edit, a bot edit, or an
-        * unpatrolled edit.  By default in English it will contain "N", "m", "b",
-        * "!" respectively, plus it will have an appropriate title and class.
+        * Make an "<abbr>" element for a given change flag. The flag indicating a new page, minor edit,
+        * bot edit, or unpatrolled edit. In English it typically contains "N", "m", "b", or "!".
         *
         * @param string $flag One key of $wgRecentChangesFlags
-        * @return string Raw HTML
+        * @param IContextSource $context
+        * @return string HTML
         */
-       public static function flag( $flag ) {
+       public static function flag( $flag, IContextSource $context = null ) {
+               static $map = [ 'minoredit' => 'minor', 'botedit' => 'bot' ];
                static $flagInfos = null;
+
                if ( is_null( $flagInfos ) ) {
                        global $wgRecentChangesFlags;
                        $flagInfos = [];
                        foreach ( $wgRecentChangesFlags as $key => $value ) {
-                               $flagInfos[$key]['letter'] = wfMessage( $value['letter'] )->escaped();
-                               $flagInfos[$key]['title'] = wfMessage( $value['title'] )->escaped();
+                               $flagInfos[$key]['letter'] = $value['letter'];
+                               $flagInfos[$key]['title'] = $value['title'];
                                // Allow customized class name, fall back to flag name
-                               $flagInfos[$key]['class'] = Sanitizer::escapeClass(
-                                       isset( $value['class'] ) ? $value['class'] : $key );
+                               $flagInfos[$key]['class'] = isset( $value['class'] ) ? $value['class'] : $key;
                        }
                }
 
-               // Inconsistent naming, bleh, kepted for b/c
-               $map = [
-                       'minoredit' => 'minor',
-                       'botedit' => 'bot',
-               ];
+               $context = $context ?: RequestContext::getMain();
+
+               // Inconsistent naming, kepted for b/c
                if ( isset( $map[$flag] ) ) {
                        $flag = $map[$flag];
                }
 
-               return "<abbr class='" . $flagInfos[$flag]['class'] . "' title='" .
-                       $flagInfos[$flag]['title'] . "'>" . $flagInfos[$flag]['letter'] .
-                       '</abbr>';
+               $info = $flagInfos[$flag];
+               return Html::element( 'abbr', [
+                       'class' => $info['class'],
+                       'title' => wfMessage( $info['title'] )->setContext( $context )->text(),
+               ], wfMessage( $info['letter'] )->setContext( $context )->text() );
        }
 
        /**
@@ -228,6 +236,9 @@ class ChangesList extends ContextSource {
 
        /**
         * Show formatted char difference
+        *
+        * Needs the css module 'mediawiki.special.changeslist' to style output
+        *
         * @param int $old Number of bytes
         * @param int $new Number of bytes
         * @param IContextSource $context
@@ -337,16 +348,18 @@ class ChangesList extends ContextSource {
         */
        public function insertLog( &$s, $title, $logtype ) {
                $page = new LogPage( $logtype );
-               $logname = $page->getName()->setContext( $this->getContext() )->escaped();
-               $s .= $this->msg( 'parentheses' )->rawParams( Linker::linkKnown( $title, $logname ) )->escaped();
+               $logname = $page->getName()->setContext( $this->getContext() )->text();
+               $s .= $this->msg( 'parentheses' )->rawParams(
+                       $this->linkRenderer->makeKnownLink( $title, $logname )
+               )->escaped();
        }
 
        /**
         * @param string $s HTML to update
         * @param RecentChange $rc
-        * @param bool $unpatrolled
+        * @param bool|null $unpatrolled Unused variable, since 1.27.
         */
-       public function insertDiffHist( &$s, &$rc, $unpatrolled ) {
+       public function insertDiffHist( &$s, &$rc, $unpatrolled = null ) {
                # Diff link
                if (
                        $rc->mAttribs['rc_type'] == RC_NEW ||
@@ -363,10 +376,10 @@ class ChangesList extends ContextSource {
                                'oldid' => $rc->mAttribs['rc_last_oldid']
                        ];
 
-                       $diffLink = Linker::linkKnown(
+                       $diffLink = $this->linkRenderer->makeKnownLink(
                                $rc->getTitle(),
-                               $this->message['diff'],
-                               [ 'tabindex' => $rc->counter ],
+                               new HtmlArmor( $this->message['diff'] ),
+                               [],
                                $query
                        );
                }
@@ -375,9 +388,9 @@ class ChangesList extends ContextSource {
                } else {
                        $diffhist = $diffLink . $this->message['pipe-separator'];
                        # History link
-                       $diffhist .= Linker::linkKnown(
+                       $diffhist .= $this->linkRenderer->makeKnownLink(
                                $rc->getTitle(),
-                               $this->message['hist'],
+                               new HtmlArmor( $this->message['hist'] ),
                                [],
                                [
                                        'curid' => $rc->mAttribs['rc_cur_id'],
@@ -415,7 +428,7 @@ class ChangesList extends ContextSource {
                        $params = [ 'redirect' => 'no' ];
                }
 
-               $articlelink = Linker::link(
+               $articlelink = $this->linkRenderer->makeLink(
                        $rc->getTitle(),
                        null,
                        [ 'class' => 'mw-changeslist-title' ],