Merge "Add help link to Special:NewSection"
[lhc/web/wiklou.git] / includes / specials / SpecialNewpages.php
index 8051b0b..493f6db 100644 (file)
@@ -21,6 +21,8 @@
  * @ingroup SpecialPage
  */
 
+use MediaWiki\MediaWikiServices;
+
 /**
  * A special page that list newly created pages
  *
@@ -39,8 +41,10 @@ class SpecialNewpages extends IncludableSpecialPage {
                parent::__construct( 'Newpages' );
        }
 
+       /**
+        * @param string|null $par
+        */
        protected function setup( $par ) {
-               // Options
                $opts = new FormOptions();
                $this->opts = $opts; // bind
                $opts->add( 'hideliu', false );
@@ -54,6 +58,7 @@ class SpecialNewpages extends IncludableSpecialPage {
                $opts->add( 'feed', '' );
                $opts->add( 'tagfilter', '' );
                $opts->add( 'invert', false );
+               $opts->add( 'associated', false );
                $opts->add( 'size-mode', 'max' );
                $opts->add( 'size', 0 );
 
@@ -63,16 +68,17 @@ class SpecialNewpages extends IncludableSpecialPage {
                        $opts->add( $key, $params['default'] );
                }
 
-               // Set values
                $opts->fetchValuesFromRequest( $this->getRequest() );
                if ( $par ) {
                        $this->parseParams( $par );
                }
 
-               // Validate
                $opts->validateIntBounds( 'limit', 0, 5000 );
        }
 
+       /**
+        * @param string $par
+        */
        protected function parseParams( $par ) {
                $bits = preg_split( '/\s*,\s*/', trim( $par ) );
                foreach ( $bits as $bit ) {
@@ -118,7 +124,7 @@ class SpecialNewpages extends IncludableSpecialPage {
        /**
         * Show a form for filtering namespace and username
         *
-        * @param string $par
+        * @param string|null $par
         */
        public function execute( $par ) {
                $out = $this->getOutput();
@@ -157,6 +163,8 @@ class SpecialNewpages extends IncludableSpecialPage {
                                $navigation = $pager->getNavigationBar();
                        }
                        $out->addHTML( $navigation . $pager->getBody() . $navigation );
+                       // Add styles for change tags
+                       $out->addModuleStyles( 'mediawiki.interface.helpers.styles' );
                } else {
                        $out->addWikiMsg( 'specialpage-empty' );
                }
@@ -178,7 +186,9 @@ class SpecialNewpages extends IncludableSpecialPage {
                }
 
                // Disable some if needed
-               if ( !User::groupHasPermission( '*', 'createpage' ) ) {
+               if ( !MediaWikiServices::getInstance()->getPermissionManager()
+                               ->groupHasPermission( '*', 'createpage' )
+               ) {
                        unset( $filters['hideliu'] );
                }
                if ( !$this->getUser()->useNPPatrol() ) {
@@ -192,9 +202,12 @@ class SpecialNewpages extends IncludableSpecialPage {
                // wfArrayToCgi(), called from LinkRenderer/Title, will not output null and false values
                // to the URL, which would omit some options (T158504). Fix it by explicitly setting them
                // to 0 or 1.
-               $changed = array_map( function ( $value ) {
-                       return $value ? '1' : '0';
-               }, $changed );
+               // Also do this only for boolean options, not eg. namespace or tagfilter
+               foreach ( $changed as $key => $value ) {
+                       if ( array_key_exists( $key, $filters ) ) {
+                               $changed[$key] = $changed[$key] ? '1' : '0';
+                       }
+               }
 
                $self = $this->getPageTitle();
                $linkRenderer = $this->getLinkRenderer();
@@ -221,6 +234,7 @@ class SpecialNewpages extends IncludableSpecialPage {
                $username = $this->opts->consumeValue( 'username' );
                $tagFilterVal = $this->opts->consumeValue( 'tagfilter' );
                $nsinvert = $this->opts->consumeValue( 'invert' );
+               $nsassociated = $this->opts->consumeValue( 'associated' );
 
                $size = $this->opts->consumeValue( 'size' );
                $max = $this->opts->consumeValue( 'size-mode' ) === 'max';
@@ -243,6 +257,13 @@ class SpecialNewpages extends IncludableSpecialPage {
                                'default' => $nsinvert,
                                'tooltip' => 'invert',
                        ],
+                       'nsassociated' => [
+                               'type' => 'check',
+                               'name' => 'associated',
+                               'label-message' => 'namespace_association',
+                               'default' => $nsassociated,
+                               'tooltip' => 'namespace_association',
+                       ],
                        'tagFilter' => [
                                'type' => 'tagfilter',
                                'name' => 'tagfilter',