Merge "Convert Special:DeletedContributions to use OOUI."
[lhc/web/wiklou.git] / includes / OutputPage.php
index 50629ba..bae871e 100644 (file)
@@ -21,6 +21,7 @@
  */
 
 use MediaWiki\Logger\LoggerFactory;
+use MediaWiki\MediaWikiServices;
 use MediaWiki\Session\SessionManager;
 use WrappedString\WrappedString;
 use WrappedString\WrappedStringList;
@@ -107,7 +108,10 @@ class OutputPage extends ContextSource {
        protected $mCategoryLinks = [];
 
        /** @var array */
-       protected $mCategories = [];
+       protected $mCategories = [
+               'hidden' => [],
+               'normal' => [],
+       ];
 
        /** @var array */
        protected $mIndicators = [];
@@ -1007,8 +1011,9 @@ class OutputPage extends ContextSource {
                if ( $title->isRedirect() ) {
                        $query['redirect'] = 'no';
                }
+               $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
                return wfMessage( 'backlinksubtitle' )
-                       ->rawParams( Linker::link( $title, null, [], $query ) );
+                       ->rawParams( $linkRenderer->makeLink( $title, null, [], $query ) );
        }
 
        /**
@@ -1249,31 +1254,7 @@ class OutputPage extends ContextSource {
                        return;
                }
 
-               # Add the links to a LinkBatch
-               $arr = [ NS_CATEGORY => $categories ];
-               $lb = new LinkBatch;
-               $lb->setArray( $arr );
-
-               # Fetch existence plus the hiddencat property
-               $dbr = wfGetDB( DB_REPLICA );
-               $fields = array_merge(
-                       LinkCache::getSelectFields(),
-                       [ 'page_namespace', 'page_title', 'pp_value' ]
-               );
-
-               $res = $dbr->select( [ 'page', 'page_props' ],
-                       $fields,
-                       $lb->constructSet( 'page', $dbr ),
-                       __METHOD__,
-                       [],
-                       [ 'page_props' => [ 'LEFT JOIN', [
-                               'pp_propname' => 'hiddencat',
-                               'pp_page = page_id'
-                       ] ] ]
-               );
-
-               # Add the results to the link cache
-               $lb->addResultToCache( LinkCache::singleton(), $res );
+               $res = $this->addCategoryLinksToLBAndGetResult( $categories );
 
                # Set all the values to 'normal'.
                $categories = array_fill_keys( array_keys( $categories ), 'normal' );
@@ -1290,6 +1271,7 @@ class OutputPage extends ContextSource {
                        'OutputPageMakeCategoryLinks',
                        [ &$this, $categories, &$this->mCategoryLinks ] )
                ) {
+                       $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
                        foreach ( $categories as $category => $type ) {
                                // array keys will cast numeric category names to ints, so cast back to string
                                $category = (string)$category;
@@ -1303,12 +1285,46 @@ class OutputPage extends ContextSource {
                                        continue;
                                }
                                $text = $wgContLang->convertHtml( $title->getText() );
-                               $this->mCategories[] = $title->getText();
-                               $this->mCategoryLinks[$type][] = Linker::link( $title, $text );
+                               $this->mCategories[$type][] = $title->getText();
+                               $this->mCategoryLinks[$type][] = $linkRenderer->makeLink( $title, new HtmlArmor( $text ) );
                        }
                }
        }
 
+       /**
+        * @param array $categories
+        * @return bool|ResultWrapper
+        */
+       protected function addCategoryLinksToLBAndGetResult( array $categories ) {
+               # Add the links to a LinkBatch
+               $arr = [ NS_CATEGORY => $categories ];
+               $lb = new LinkBatch;
+               $lb->setArray( $arr );
+
+               # Fetch existence plus the hiddencat property
+               $dbr = wfGetDB( DB_REPLICA );
+               $fields = array_merge(
+                       LinkCache::getSelectFields(),
+                       [ 'page_namespace', 'page_title', 'pp_value' ]
+               );
+
+               $res = $dbr->select( [ 'page', 'page_props' ],
+                       $fields,
+                       $lb->constructSet( 'page', $dbr ),
+                       __METHOD__,
+                       [],
+                       [ 'page_props' => [ 'LEFT JOIN', [
+                               'pp_propname' => 'hiddencat',
+                               'pp_page = page_id'
+                       ] ] ]
+               );
+
+               # Add the results to the link cache
+               $lb->addResultToCache( LinkCache::singleton(), $res );
+
+               return $res;
+       }
+
        /**
         * Reset the category links (but not the category list) and add $categories
         *
@@ -1332,12 +1348,26 @@ class OutputPage extends ContextSource {
        }
 
        /**
-        * Get the list of category names this page belongs to
+        * Get the list of category names this page belongs to.
         *
+        * @param string $type The type of categories which should be returned. Possible values:
+        *  * all: all categories of all types
+        *  * hidden: only the hidden categories
+        *  * normal: all categories, except hidden categories
         * @return array Array of strings
         */
-       public function getCategories() {
-               return $this->mCategories;
+       public function getCategories( $type = 'all' ) {
+               if ( $type === 'all' ) {
+                       $allCategories = [];
+                       foreach ( $this->mCategories as $categories ) {
+                               $allCategories = array_merge( $allCategories, $categories );
+                       }
+                       return $allCategories;
+               }
+               if ( !isset( $this->mCategories[$type] ) ) {
+                       throw new InvalidArgumentException( 'Invalid category type given: ' . $type );
+               }
+               return $this->mCategories[$type];
        }
 
        /**
@@ -2626,8 +2656,10 @@ class OutputPage extends ContextSource {
         * @param array $options Options array to pass to Linker
         */
        public function addReturnTo( $title, array $query = [], $text = null, $options = [] ) {
+               $linkRenderer = MediaWikiServices::getInstance()
+                       ->getLinkRendererFactory()->createFromLegacyOptions( $options );
                $link = $this->msg( 'returnto' )->rawParams(
-                       Linker::link( $title, $text, [], $query, $options ) )->escaped();
+                       $linkRenderer->makeLink( $title, $text, [], $query ) )->escaped();
                $this->addHTML( "<p id=\"mw-returnto\">{$link}</p>\n" );
        }
 
@@ -2708,7 +2740,6 @@ class OutputPage extends ContextSource {
                                'site.styles',
                                'noscript',
                                'user.styles',
-                               'user.cssprefs',
                        ] );
                        $this->getSkin()->setupSkinUserCss( $this );
 
@@ -2821,6 +2852,14 @@ class OutputPage extends ContextSource {
                $bodyClasses[] = $userdir;
                $bodyClasses[] = "sitedir-$sitedir";
 
+               $underline = $this->getUser()->getOption( 'underline' );
+               if ( $underline < 2 ) {
+                       // The following classes can be used here:
+                       // * mw-underline-always
+                       // * mw-underline-never
+                       $bodyClasses[] = 'mw-underline-' . ( $underline ? 'always' : 'never' );
+               }
+
                if ( $this->getLanguage()->capitalizeAllNouns() ) {
                        # A <body> class is probably not the best way to do this . . .
                        $bodyClasses[] = 'capitalize-all-nouns';