* (T214706) LinksUpdate::getAddedExternalLinks() and
LinksUpdate::getRemovedExternalLinks() were introduced.
* (T213893) Added 'MaintenanceUpdateAddParams' hook
+* (T219655) The MarkPatrolled hook has a new parameter for the tags
+ associated with this entry in the patrol log.
=== External library changes in 1.33 ===
==== New external libraries ====
$wcOnlySysopsCanPatrol: config setting indicating whether the user needs to be a
sysop in order to mark an edit patrolled.
$auto: true if the edit is being marked as patrolled automatically
+&$tags: the tags to be applied to the patrol log entry
'MarkPatrolledComplete': After an edit is marked patrolled.
$rcid: ID of the revision marked as patrolled
public function doMarkPatrolled( User $user, $auto = false, $tags = null ) {
global $wgUseRCPatrol, $wgUseNPPatrol, $wgUseFilePatrol;
+ // Fix up $tags so that the MarkPatrolled hook below always gets an array
+ if ( $tags === null ) {
+ $tags = [];
+ } elseif ( is_string( $tags ) ) {
+ $tags = [ $tags ];
+ }
+
$errors = [];
// If recentchanges patrol is disabled, only new pages or new file versions
// can be patrolled, provided the appropriate config variable is set
$right = $auto ? 'autopatrol' : 'patrol';
$errors = array_merge( $errors, $this->getTitle()->getUserPermissionsErrors( $right, $user ) );
if ( !Hooks::run( 'MarkPatrolled',
- [ $this->getAttribute( 'rc_id' ), &$user, false, $auto ] )
+ [ $this->getAttribute( 'rc_id' ), &$user, false, $auto, &$tags ] )
) {
$errors[] = [ 'hookaborted' ];
}
* @file
* @defgroup JobQueue JobQueue
*/
-use MediaWiki\MediaWikiServices;
+use Liuggio\StatsdClient\Factory\StatsdDataFactoryInterface;
/**
* Class to handle enqueueing and running of background jobs
protected $maxTries;
/** @var string|bool Read only rationale (or false if r/w) */
protected $readOnlyReason;
+ /** @var StatsdDataFactoryInterface */
+ protected $stats;
/** @var BagOStuff */
protected $dupCache;
if ( !in_array( $this->order, $this->supportedOrders() ) ) {
throw new JobQueueError( __CLASS__ . " does not support '{$this->order}' order." );
}
- $this->dupCache = wfGetCache( CACHE_ANYTHING );
$this->readOnlyReason = $params['readOnlyReason'] ?? false;
+ $this->stats = $params['stats'] ?? new NullStatsdDataFactory();
+ $this->dupCache = $params['stash'] ?? new EmptyBagOStuff();
}
/**
* of jobs simply means re-inserting them into the queue. Jobs can be
* attempted up to three times before being discarded.
* - readOnlyReason : Set this to a string to make the queue read-only.
+ * - stash : A BagOStuff instance that can be used for root job deduplication
+ * - stats : A StatsdDataFactoryInterface [optional]
*
* Queue classes should throw an exception if they do not support the options given.
*
}
/**
- * @return string Wiki ID
+ * @return string Database domain ID
*/
final public function getDomain() {
return $this->domain;
* @return Job|bool Returns false if there are no jobs
*/
final public function pop() {
- global $wgJobClasses;
-
$this->assertNotReadOnly();
- if ( !WikiMap::isCurrentWikiDbDomain( $this->domain ) ) {
- throw new JobQueueError(
- "Cannot pop '{$this->type}' job off foreign '{$this->domain}' wiki queue." );
- } elseif ( !isset( $wgJobClasses[$this->type] ) ) {
- // Do not pop jobs if there is no class for the queue type
- throw new JobQueueError( "Unrecognized job type '{$this->type}'." );
- }
$job = $this->doPop();
// Flag this job as an old duplicate based on its "root" job...
try {
if ( $job && $this->isRootJobOldDuplicate( $job ) ) {
- self::incrStats( 'dupe_pops', $this->type );
+ $this->incrStats( 'dupe_pops', $this->type );
$job = DuplicateJob::newFromJob( $job ); // convert to a no-op
}
} catch ( Exception $e ) {
}
// Update the timestamp of the last root job started at the location...
- return $this->dupCache->set( $key, $params['rootJobTimestamp'], JobQueueDB::ROOTJOB_TTL );
+ return $this->dupCache->set( $key, $params['rootJobTimestamp'], self::ROOTJOB_TTL );
}
/**
* @param int $delta
* @since 1.22
*/
- public static function incrStats( $key, $type, $delta = 1 ) {
- static $stats;
- if ( !$stats ) {
- $stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
- }
- $stats->updateCount( "jobqueue.{$key}.all", $delta );
- $stats->updateCount( "jobqueue.{$key}.{$type}", $delta );
+ protected function incrStats( $key, $type, $delta = 1 ) {
+ $this->stats->updateCount( "jobqueue.{$key}.all", $delta );
+ $this->stats->updateCount( "jobqueue.{$key}.{$type}", $delta );
}
}
* If not specified, the primary DB cluster for the wiki will be used.
* This can be overridden with a custom cluster so that DB handles will
* be retrieved via LBFactory::getExternalLB() and getConnection().
+ * - wanCache : An instance of WANObjectCache to use for caching.
* @param array $params
*/
protected function __construct( array $params ) {
$this->cluster = $params['cluster'];
}
- $this->cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
+ $this->cache = $params['wanCache'] ?? WANObjectCache::newEmpty();
}
protected function supportedOrders() {
foreach ( array_chunk( $rows, 50 ) as $rowBatch ) {
$dbw->insert( 'job', $rowBatch, $method );
}
- JobQueue::incrStats( 'inserts', $this->type, count( $rows ) );
- JobQueue::incrStats( 'dupe_inserts', $this->type,
+ $this->incrStats( 'inserts', $this->type, count( $rows ) );
+ $this->incrStats( 'dupe_inserts', $this->type,
count( $rowSet ) + count( $rowList ) - count( $rows )
);
} catch ( DBError $e ) {
if ( !$row ) {
break; // nothing to do
}
- JobQueue::incrStats( 'pops', $this->type );
+ $this->incrStats( 'pops', $this->type );
// Get the job object from the row...
$title = Title::makeTitle( $row->job_namespace, $row->job_title );
$job = Job::factory( $row->job_cmd, $title,
__METHOD__
);
- JobQueue::incrStats( 'acks', $this->type );
+ $this->incrStats( 'acks', $this->type );
} catch ( DBError $e ) {
$this->throwDBException( $e );
}
);
$affected = $dbw->affectedRows();
$count += $affected;
- JobQueue::incrStats( 'recycles', $this->type, $affected );
+ $this->incrStats( 'recycles', $this->type, $affected );
}
}
$dbw->delete( 'job', [ 'job_id' => $ids ], __METHOD__ );
$affected = $dbw->affectedRows();
$count += $affected;
- JobQueue::incrStats( 'abandons', $this->type, $affected );
+ $this->incrStats( 'abandons', $this->type, $affected );
}
$dbw->unlock( "jobqueue-recycle-{$this->type}", __METHOD__ );
$conf['readOnlyReason'] = $this->readOnlyReason;
}
+ $services = MediaWikiServices::getInstance();
+ $conf['stats'] = $services->getStatsdDataFactory();
+ $conf['wanCache'] = $services->getMainWANObjectCache();
+ $conf['stash'] = $services->getMainObjectStash();
+
return JobQueue::factory( $conf );
}
* @return Job|bool Returns false on failure
*/
public function pop( $qtype = self::TYPE_DEFAULT, $flags = 0, array $blacklist = [] ) {
+ global $wgJobClasses;
+
$job = false;
+ if ( !WikiMap::isCurrentWikiDbDomain( $this->domain ) ) {
+ throw new JobQueueError(
+ "Cannot pop '{$qtype}' job off foreign '{$this->domain}' wiki queue." );
+ } elseif ( is_string( $qtype ) && !isset( $wgJobClasses[$qtype] ) ) {
+ // Do not pop jobs if there is no class for the queue type
+ throw new JobQueueError( "Unrecognized job type '$qtype'." );
+ }
+
if ( is_string( $qtype ) ) { // specific job type
if ( !in_array( $qtype, $blacklist ) ) {
$job = $this->get( $qtype )->pop();
/** @var array[] */
protected static $data = [];
+ public function __construct( array $params ) {
+ parent::__construct( $params );
+
+ $this->dupCache = new HashBagOStuff();
+ }
+
/**
* @see JobQueue::doBatchPush
*
foreach ( $jobs as $job ) {
if ( $job->ignoreDuplicates() ) {
- $sha1 = Wikimedia\base_convert(
- sha1( serialize( $job->getDeduplicationInfo() ) ),
- 16, 36, 31
- );
+ $sha1 = sha1( serialize( $job->getDeduplicationInfo() ) );
if ( !isset( $unclaimed[$sha1] ) ) {
$unclaimed[$sha1] = $job;
}
$failed += count( $itemBatch );
}
}
- JobQueue::incrStats( 'inserts', $this->type, count( $items ) );
- JobQueue::incrStats( 'inserts_actual', $this->type, $pushed );
- JobQueue::incrStats( 'dupe_inserts', $this->type,
+ $this->incrStats( 'inserts', $this->type, count( $items ) );
+ $this->incrStats( 'inserts_actual', $this->type, $pushed );
+ $this->incrStats( 'dupe_inserts', $this->type,
count( $items ) - $failed - $pushed );
if ( $failed > 0 ) {
$err = "Could not insert {$failed} {$this->type} job(s).";
break; // no jobs; nothing to do
}
- JobQueue::incrStats( 'pops', $this->type );
+ $this->incrStats( 'pops', $this->type );
$item = $this->unserialize( $blob );
if ( $item === false ) {
wfDebugLog( 'JobQueueRedis', "Could not unserialize {$this->type} job." );
return false;
}
- JobQueue::incrStats( 'acks', $this->type );
+ $this->incrStats( 'acks', $this->type );
} catch ( RedisException $e ) {
$this->throwRedisException( $conn, $e );
}
/**
* Get CSS selector templates used by this module.
- * @return string
+ * @return string[]
*/
public function getSelectors() {
$this->loadFromDefinition();
'selectorWithVariant',
] as $member ) {
$options[$member] = $this->{$member};
- };
+ }
$summary[] = [
'options' => $options,
'cssclass' => 'mw-block-confirm',
];
- // Block Id if a block already exists matching the target
- $a['BlockId'] = [
- 'type' => 'hidden',
- 'default' => '',
- ];
-
- // Has the form been submitted
- $a['WasPosted'] = [
- 'type' => 'hidden',
- 'default' => '',
- ];
-
$this->maybeAlterFormDefaults( $a );
// Allow extensions to add more fields
$fields['Expiry']['default'] = wfTimestamp( TS_RFC2822, $block->getExpiry() );
}
- $fields['BlockId']['default'] = $block->getId();
-
$this->alreadyBlocked = true;
$this->preErrors[] = [ 'ipb-needreblock', wfEscapeWikiText( (string)$block->getTarget() ) ];
}
- if ( $this->getRequest()->wasPosted() ) {
- $fields['WasPosted']['default'] = true;
+ if ( $this->alreadyBlocked || $this->getRequest()->wasPosted()
+ || $this->getRequest()->getCheck( 'wpCreateAccount' )
+ ) {
+ $this->getOutput()->addJsConfigVars( 'wgCreateAccountDirty', true );
}
# We always need confirmation to do HideUser
pageRestrictionsWidget = infuseIfExists( $( '#mw-input-wpPageRestrictions' ) ),
namespaceRestrictionsWidget = infuseIfExists( $( '#mw-input-wpNamespaceRestrictions' ) ),
createAccountWidget = infuseIfExists( $( '#mw-input-wpCreateAccount' ) ),
- userChangedCreateAccount = $( '#mw-input-wpBlockId' ).val() || $( '#mw-input-wpWasPosted' ).val() || false,
+ userChangedCreateAccount = mw.config.get( 'wgCreateAccountDirty' ),
updatingBlockOptions = false;
function updateBlockOptions() {
}
$baseConfig['type'] = 'null';
$baseConfig['domain'] = WikiMap::getCurrentWikiDbDomain()->getId();
+ $baseConfig['stash'] = new HashBagOStuff();
+ $baseConfig['wanCache'] = new WANObjectCache( [ 'cache' => new HashBagOStuff() ] );
$variants = [
'queueRand' => [ 'order' => 'random', 'claimTTL' => 0 ],
'queueRandTTL' => [ 'order' => 'random', 'claimTTL' => 10 ],