Merge "Make DBAccessBase use DBConnRef, rename $wiki, and hide getLoadBalancer()"
[lhc/web/wiklou.git] / includes / specials / pagers / NewPagesPager.php
index 5788bb2..c50563d 100644 (file)
@@ -22,6 +22,8 @@
 /**
  * @ingroup Pager
  */
+use MediaWiki\MediaWikiServices;
+
 class NewPagesPager extends ReverseChronologicalPager {
 
        /**
@@ -50,9 +52,6 @@ class NewPagesPager extends ReverseChronologicalPager {
                $conds = [];
                $conds['rc_new'] = 1;
 
-               $namespace = $this->opts->getValue( 'namespace' );
-               $namespace = ( $namespace === 'all' ) ? false : intval( $namespace );
-
                $username = $this->opts->getValue( 'username' );
                $user = Title::makeTitleSafe( NS_USER, $username );
 
@@ -65,25 +64,21 @@ class NewPagesPager extends ReverseChronologicalPager {
                        }
                }
 
-               if ( $namespace !== false ) {
-                       if ( $this->opts->getValue( 'invert' ) ) {
-                               $conds[] = 'rc_namespace != ' . $this->mDb->addQuotes( $namespace );
-                       } else {
-                               $conds['rc_namespace'] = $namespace;
-                       }
-               }
-
                if ( $user ) {
                        $conds[] = ActorMigration::newMigration()->getWhere(
                                $this->mDb, 'rc_user', User::newFromName( $user->getText(), false ), false
                        )['conds'];
-               } elseif ( User::groupHasPermission( '*', 'createpage' ) &&
+               } elseif ( MediaWikiServices::getInstance()
+                                       ->getPermissionManager()
+                                       ->groupHasPermission( '*', 'createpage' ) &&
                        $this->opts->getValue( 'hideliu' )
                ) {
                        # If anons cannot make new pages, don't "exclude logged in users"!
                        $conds[] = ActorMigration::newMigration()->isAnon( $rcQuery['fields']['rc_user'] );
                }
 
+               $conds = array_merge( $conds, $this->getNamespaceCond() );
+
                # If this user cannot see patrolled edits or they are off, don't do dumb queries!
                if ( $this->opts->getValue( 'hidepatrolled' ) && $this->getUser()->useNPPatrol() ) {
                        $conds['rc_patrolled'] = RecentChange::PRC_UNPATROLLED;
@@ -130,6 +125,32 @@ class NewPagesPager extends ReverseChronologicalPager {
                return $info;
        }
 
+       // Based on ContribsPager.php
+       function getNamespaceCond() {
+               $namespace = $this->opts->getValue( 'namespace' );
+               if ( $namespace === 'all' || $namespace === '' ) {
+                       return [];
+               }
+
+               $namespace = intval( $namespace );
+               $invert = $this->opts->getValue( 'invert' );
+               $associated = $this->opts->getValue( 'associated' );
+
+               $eq_op = $invert ? '!=' : '=';
+               $bool_op = $invert ? 'AND' : 'OR';
+
+               if ( !$associated ) {
+                       return [ "rc_namespace $eq_op " . $this->mDb->addQuotes( $namespace ) ];
+               }
+
+               $associatedNS = MediaWikiServices::getInstance()->getNamespaceInfo()->getAssociated( $namespace );
+               return [
+                       "rc_namespace $eq_op " . $this->mDb->addQuotes( $namespace ) .
+                       $bool_op .
+                       " rc_namespace $eq_op " . $this->mDb->addQuotes( $associatedNS )
+               ];
+       }
+
        function getIndexField() {
                return 'rc_timestamp';
        }