Add talk namespace option to Special:NewPages

Bug: T47133
Change-Id: Ie263e9cb956cc9efe734ccc5832df350d005e5d9
This commit is contained in:
DannyS712 2019-07-16 21:57:51 +00:00
parent cbf8446b74
commit 8b10455f4d
2 changed files with 39 additions and 11 deletions

View file

@ -56,6 +56,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 );
@ -229,6 +230,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';
@ -251,6 +253,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',

View 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,14 +64,6 @@ 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
@ -84,6 +75,8 @@ class NewPagesPager extends ReverseChronologicalPager {
$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 +123,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';
}