/**
* @ingroup Pager
*/
+use MediaWiki\MediaWikiServices;
+
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 );
}
}
- 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' ) &&
- $this->opts->getValue( 'hideliu' )
- ) {
+ } elseif ( $this->canAnonymousUsersCreatePages() && $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;
return $info;
}
+ private function canAnonymousUsersCreatePages() {
+ $pm = MediaWikiServices::getInstance()->getPermissionManager();
+ return ( $pm->groupHasPermission( '*', 'createpage' ) ||
+ $pm->groupHasPermission( '*', 'createtalk' )
+ );
+ }
+
+ // 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';
+
+ $selectedNS = $this->mDb->addQuotes( $namespace );
+ if ( !$associated ) {
+ return [ "rc_namespace $eq_op $selectedNS" ];
+ }
+
+ $associatedNS = $this->mDb->addQuotes(
+ MediaWikiServices::getInstance()->getNamespaceInfo()->getAssociated( $namespace )
+ );
+ return [
+ "rc_namespace $eq_op $selectedNS " .
+ $bool_op .
+ " rc_namespace $eq_op $associatedNS"
+ ];
+ }
+
function getIndexField() {
return 'rc_timestamp';
}