2020-09-25 22:32:01 +00:00
|
|
|
<?php
|
|
|
|
|
2021-01-02 13:41:31 +00:00
|
|
|
namespace MediaWiki\Extension\AbuseFilter\Variables;
|
2020-09-25 22:32:01 +00:00
|
|
|
|
|
|
|
use ContentHandler;
|
|
|
|
use Diff;
|
|
|
|
use Language;
|
|
|
|
use MediaWiki\Extension\AbuseFilter\Hooks\AbuseFilterHookRunner;
|
|
|
|
use MediaWiki\Extension\AbuseFilter\Parser\AFPData;
|
|
|
|
use MediaWiki\Extension\AbuseFilter\Parser\AFPException;
|
2021-01-02 13:41:31 +00:00
|
|
|
use MediaWiki\Extension\AbuseFilter\TextExtractor;
|
2020-09-25 22:32:01 +00:00
|
|
|
use MediaWiki\Storage\RevisionLookup;
|
|
|
|
use MediaWiki\Storage\RevisionStore;
|
|
|
|
use Parser;
|
|
|
|
use ParserOptions;
|
|
|
|
use Psr\Log\LoggerInterface;
|
|
|
|
use stdClass;
|
|
|
|
use StringUtils;
|
|
|
|
use TextContent;
|
|
|
|
use Title;
|
|
|
|
use UnifiedDiffFormatter;
|
|
|
|
use User;
|
|
|
|
use WANObjectCache;
|
|
|
|
use Wikimedia\Rdbms\Database;
|
|
|
|
use Wikimedia\Rdbms\ILoadBalancer;
|
|
|
|
use WikiPage;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Service used to compute lazy-loaded variable.
|
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
class LazyVariableComputer {
|
|
|
|
public const SERVICE_NAME = 'AbuseFilterLazyVariableComputer';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var float The amount of time to subtract from profiling
|
|
|
|
* @todo This is a hack
|
|
|
|
*/
|
|
|
|
public static $profilingExtraTime = 0;
|
|
|
|
|
2020-09-29 18:48:51 +00:00
|
|
|
/** @var TextExtractor */
|
|
|
|
private $textExtractor;
|
|
|
|
|
2020-09-25 22:32:01 +00:00
|
|
|
/** @var AbuseFilterHookRunner */
|
|
|
|
private $hookRunner;
|
|
|
|
|
|
|
|
/** @var LoggerInterface */
|
|
|
|
private $logger;
|
|
|
|
|
|
|
|
/** @var ILoadBalancer */
|
|
|
|
private $loadBalancer;
|
|
|
|
|
|
|
|
/** @var WANObjectCache */
|
|
|
|
private $wanCache;
|
|
|
|
|
|
|
|
/** @var RevisionLookup */
|
|
|
|
private $revisionLookup;
|
|
|
|
|
|
|
|
/** @var RevisionStore */
|
|
|
|
private $revisionStore;
|
|
|
|
|
|
|
|
/** @var Language */
|
|
|
|
private $contentLanguage;
|
|
|
|
|
|
|
|
/** @var Parser */
|
|
|
|
private $parser;
|
|
|
|
|
|
|
|
/** @var string */
|
|
|
|
private $wikiID;
|
|
|
|
|
|
|
|
/**
|
2020-09-29 18:48:51 +00:00
|
|
|
* @param TextExtractor $textExtractor
|
2020-09-25 22:32:01 +00:00
|
|
|
* @param AbuseFilterHookRunner $hookRunner
|
|
|
|
* @param LoggerInterface $logger
|
|
|
|
* @param ILoadBalancer $loadBalancer
|
|
|
|
* @param WANObjectCache $wanCache
|
|
|
|
* @param RevisionLookup $revisionLookup
|
|
|
|
* @param RevisionStore $revisionStore
|
|
|
|
* @param Language $contentLanguage
|
|
|
|
* @param Parser $parser
|
|
|
|
* @param string $wikiID
|
|
|
|
*/
|
|
|
|
public function __construct(
|
2020-09-29 18:48:51 +00:00
|
|
|
TextExtractor $textExtractor,
|
2020-09-25 22:32:01 +00:00
|
|
|
AbuseFilterHookRunner $hookRunner,
|
|
|
|
LoggerInterface $logger,
|
|
|
|
ILoadBalancer $loadBalancer,
|
|
|
|
WANObjectCache $wanCache,
|
|
|
|
RevisionLookup $revisionLookup,
|
|
|
|
RevisionStore $revisionStore,
|
|
|
|
Language $contentLanguage,
|
|
|
|
Parser $parser,
|
|
|
|
string $wikiID
|
|
|
|
) {
|
2020-09-29 18:48:51 +00:00
|
|
|
$this->textExtractor = $textExtractor;
|
2020-09-25 22:32:01 +00:00
|
|
|
$this->hookRunner = $hookRunner;
|
|
|
|
$this->logger = $logger;
|
|
|
|
$this->loadBalancer = $loadBalancer;
|
|
|
|
$this->wanCache = $wanCache;
|
|
|
|
$this->revisionLookup = $revisionLookup;
|
|
|
|
$this->revisionStore = $revisionStore;
|
|
|
|
$this->contentLanguage = $contentLanguage;
|
|
|
|
$this->parser = $parser;
|
|
|
|
$this->wikiID = $wikiID;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-10-18 22:25:05 +00:00
|
|
|
* XXX: $getVarCB is a hack to hide the cyclic dependency with VariablesManager. See T261069 for possible
|
|
|
|
* solutions. This might also be merged into VariablesManager, but it would bring a ton of dependencies.
|
2021-01-08 17:17:41 +00:00
|
|
|
* @todo Should we remove $vars parameter (check hooks)?
|
2020-10-18 22:25:05 +00:00
|
|
|
*
|
2021-01-02 14:01:00 +00:00
|
|
|
* @param LazyLoadedVariable $var
|
|
|
|
* @param VariableHolder $vars
|
2020-10-18 22:25:05 +00:00
|
|
|
* @param callable $getVarCB
|
|
|
|
* @phan-param callable(string $name):AFPData $getVarCB
|
2020-09-25 22:32:01 +00:00
|
|
|
* @return AFPData
|
|
|
|
* @throws AFPException
|
|
|
|
*/
|
2021-01-02 14:01:00 +00:00
|
|
|
public function compute( LazyLoadedVariable $var, VariableHolder $vars, callable $getVarCB ) {
|
|
|
|
$parameters = $var->getParameters();
|
|
|
|
$varMethod = $var->getMethod();
|
2020-09-25 22:32:01 +00:00
|
|
|
$result = null;
|
|
|
|
|
|
|
|
if ( !$this->hookRunner->onAbuseFilterInterceptVariable(
|
2021-01-02 14:01:00 +00:00
|
|
|
$varMethod,
|
2020-09-25 22:32:01 +00:00
|
|
|
$vars,
|
|
|
|
$parameters,
|
|
|
|
$result
|
|
|
|
) ) {
|
|
|
|
return $result instanceof AFPData
|
|
|
|
? $result : AFPData::newFromPHPVar( $result );
|
|
|
|
}
|
|
|
|
|
2021-01-02 14:01:00 +00:00
|
|
|
switch ( $varMethod ) {
|
2020-09-25 22:32:01 +00:00
|
|
|
case 'diff':
|
|
|
|
$text1Var = $parameters['oldtext-var'];
|
|
|
|
$text2Var = $parameters['newtext-var'];
|
2020-10-18 22:25:05 +00:00
|
|
|
$text1 = $getVarCB( $text1Var )->toString();
|
|
|
|
$text2 = $getVarCB( $text2Var )->toString();
|
2020-09-25 22:32:01 +00:00
|
|
|
// T74329: if there's no text, don't return an array with the empty string
|
|
|
|
$text1 = $text1 === '' ? [] : explode( "\n", $text1 );
|
|
|
|
$text2 = $text2 === '' ? [] : explode( "\n", $text2 );
|
|
|
|
$diffs = new Diff( $text1, $text2 );
|
|
|
|
$format = new UnifiedDiffFormatter();
|
|
|
|
$result = $format->format( $diffs );
|
|
|
|
break;
|
|
|
|
case 'diff-split':
|
2020-10-18 22:25:05 +00:00
|
|
|
$diff = $getVarCB( $parameters['diff-var'] )->toString();
|
2020-09-25 22:32:01 +00:00
|
|
|
$line_prefix = $parameters['line-prefix'];
|
|
|
|
$diff_lines = explode( "\n", $diff );
|
|
|
|
$result = [];
|
|
|
|
foreach ( $diff_lines as $line ) {
|
|
|
|
if ( substr( $line, 0, 1 ) === $line_prefix ) {
|
|
|
|
$result[] = substr( $line, strlen( $line_prefix ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'links-from-wikitext':
|
|
|
|
// This should ONLY be used when sharing a parse operation with the edit.
|
|
|
|
|
|
|
|
/** @var WikiPage $article */
|
|
|
|
$article = $parameters['article'];
|
|
|
|
if ( $article->getContentModel() === CONTENT_MODEL_WIKITEXT ) {
|
|
|
|
// Shared with the edit, don't count it in profiling
|
|
|
|
$startTime = microtime( true );
|
|
|
|
$textVar = $parameters['text-var'];
|
|
|
|
|
2020-10-18 22:25:05 +00:00
|
|
|
$new_text = $getVarCB( $textVar )->toString();
|
2020-09-25 22:32:01 +00:00
|
|
|
$content = ContentHandler::makeContent( $new_text, $article->getTitle() );
|
|
|
|
$editInfo = $article->prepareContentForEdit( $content );
|
|
|
|
$result = array_keys( $editInfo->output->getExternalLinks() );
|
|
|
|
self::$profilingExtraTime += ( microtime( true ) - $startTime );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// Otherwise fall back to database
|
|
|
|
case 'links-from-wikitext-or-database':
|
|
|
|
// TODO: use Content object instead, if available!
|
2021-01-08 17:17:41 +00:00
|
|
|
/** @var WikiPage $article */
|
|
|
|
$article = $article ?? $parameters['article'];
|
2020-09-25 22:32:01 +00:00
|
|
|
|
|
|
|
if ( $vars->forFilter ) {
|
|
|
|
$links = $this->getLinksFromDB( $article );
|
|
|
|
$this->logger->debug( 'Loading old links from DB' );
|
|
|
|
} elseif ( $article->getContentModel() === CONTENT_MODEL_WIKITEXT ) {
|
|
|
|
$this->logger->debug( 'Loading old links from Parser' );
|
|
|
|
$textVar = $parameters['text-var'];
|
|
|
|
|
2020-10-18 22:25:05 +00:00
|
|
|
$wikitext = $getVarCB( $textVar )->toString();
|
2020-09-25 22:32:01 +00:00
|
|
|
$editInfo = $this->parseNonEditWikitext(
|
|
|
|
$wikitext,
|
|
|
|
$article,
|
|
|
|
$parameters['contextUser']
|
|
|
|
);
|
|
|
|
$links = array_keys( $editInfo->output->getExternalLinks() );
|
|
|
|
} else {
|
|
|
|
// TODO: Get links from Content object. But we don't have the content object.
|
|
|
|
// And for non-text content, $wikitext is usually not going to be a valid
|
|
|
|
// serialization, but rather some dummy text for filtering.
|
|
|
|
$links = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
$result = $links;
|
|
|
|
break;
|
|
|
|
case 'link-diff-added':
|
|
|
|
case 'link-diff-removed':
|
|
|
|
$oldLinkVar = $parameters['oldlink-var'];
|
|
|
|
$newLinkVar = $parameters['newlink-var'];
|
|
|
|
|
2020-10-18 22:25:05 +00:00
|
|
|
$oldLinks = $getVarCB( $oldLinkVar )->toString();
|
|
|
|
$newLinks = $getVarCB( $newLinkVar )->toString();
|
2020-09-25 22:32:01 +00:00
|
|
|
|
|
|
|
$oldLinks = explode( "\n", $oldLinks );
|
|
|
|
$newLinks = explode( "\n", $newLinks );
|
|
|
|
|
2021-01-02 14:01:00 +00:00
|
|
|
if ( $varMethod === 'link-diff-added' ) {
|
2020-09-25 22:32:01 +00:00
|
|
|
$result = array_diff( $newLinks, $oldLinks );
|
|
|
|
}
|
2021-01-02 14:01:00 +00:00
|
|
|
if ( $varMethod === 'link-diff-removed' ) {
|
2020-09-25 22:32:01 +00:00
|
|
|
$result = array_diff( $oldLinks, $newLinks );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'parse-wikitext':
|
|
|
|
// Should ONLY be used when sharing a parse operation with the edit.
|
2021-01-08 17:17:41 +00:00
|
|
|
// TODO: use Content object instead, if available!
|
2020-09-25 22:32:01 +00:00
|
|
|
/* @var WikiPage $article */
|
|
|
|
$article = $parameters['article'];
|
|
|
|
if ( $article->getContentModel() === CONTENT_MODEL_WIKITEXT ) {
|
|
|
|
// Shared with the edit, don't count it in profiling
|
|
|
|
$startTime = microtime( true );
|
|
|
|
$textVar = $parameters['wikitext-var'];
|
|
|
|
|
2020-10-18 22:25:05 +00:00
|
|
|
$new_text = $getVarCB( $textVar )->toString();
|
2020-09-25 22:32:01 +00:00
|
|
|
$content = ContentHandler::makeContent( $new_text, $article->getTitle() );
|
|
|
|
$editInfo = $article->prepareContentForEdit( $content );
|
|
|
|
if ( isset( $parameters['pst'] ) && $parameters['pst'] ) {
|
|
|
|
$result = $editInfo->pstContent->serialize( $editInfo->format );
|
|
|
|
} else {
|
|
|
|
$newHTML = $editInfo->output->getText();
|
|
|
|
// Kill the PP limit comments. Ideally we'd just remove these by not setting the
|
|
|
|
// parser option, but then we can't share a parse operation with the edit, which is bad.
|
|
|
|
// @fixme No awfulness scale can measure how awful this hack is.
|
|
|
|
$re = '/<!--\s*NewPP limit [^>]*-->\s*(?:<!--\s*Transclusion [^>]+-->\s*)?(?:<\/div>\s*)?$/i';
|
|
|
|
$result = preg_replace( $re, '', $newHTML );
|
|
|
|
}
|
|
|
|
self::$profilingExtraTime += ( microtime( true ) - $startTime );
|
|
|
|
} else {
|
|
|
|
$result = '';
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'strip-html':
|
|
|
|
$htmlVar = $parameters['html-var'];
|
2020-10-18 22:25:05 +00:00
|
|
|
$html = $getVarCB( $htmlVar )->toString();
|
2020-09-25 22:32:01 +00:00
|
|
|
$stripped = StringUtils::delimiterReplace( '<', '>', '', $html );
|
|
|
|
// We strip extra spaces to the right because the stripping above
|
|
|
|
// could leave a lot of whitespace.
|
|
|
|
// @fixme Find a better way to do this.
|
|
|
|
$result = TextContent::normalizeLineEndings( $stripped );
|
|
|
|
break;
|
|
|
|
case 'load-recent-authors':
|
2021-01-08 17:17:41 +00:00
|
|
|
$result = $this->getLastPageAuthors( $parameters['title'] );
|
2020-09-25 22:32:01 +00:00
|
|
|
break;
|
|
|
|
case 'load-first-author':
|
2021-01-08 17:17:41 +00:00
|
|
|
$revision = $this->revisionLookup->getFirstRevision( $parameters['title'] );
|
2020-09-25 22:32:01 +00:00
|
|
|
if ( $revision ) {
|
|
|
|
$user = $revision->getUser();
|
|
|
|
$result = $user === null ? '' : $user->getName();
|
|
|
|
} else {
|
|
|
|
$result = '';
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'get-page-restrictions':
|
|
|
|
$action = $parameters['action'];
|
2021-01-08 17:17:41 +00:00
|
|
|
/** @var Title $title */
|
|
|
|
$title = $parameters['title'];
|
2020-09-25 22:32:01 +00:00
|
|
|
|
|
|
|
$result = $title->getRestrictions( $action );
|
|
|
|
break;
|
2021-01-10 11:27:08 +00:00
|
|
|
case 'user-editcount':
|
|
|
|
/** @var User $user */
|
2020-09-25 22:32:01 +00:00
|
|
|
$user = $parameters['user'];
|
2021-01-10 11:27:08 +00:00
|
|
|
$result = $user->getEditCount();
|
|
|
|
break;
|
|
|
|
case 'user-emailconfirm':
|
|
|
|
/** @var User $user */
|
|
|
|
$user = $parameters['user'];
|
|
|
|
$result = $user->getEmailAuthenticationTimestamp();
|
|
|
|
break;
|
|
|
|
case 'user-groups':
|
|
|
|
/** @var User $user */
|
|
|
|
$user = $parameters['user'];
|
|
|
|
$result = $user->getEffectiveGroups();
|
|
|
|
break;
|
|
|
|
case 'user-rights':
|
|
|
|
/** @var User $user */
|
|
|
|
$user = $parameters['user'];
|
|
|
|
$result = $user->getRights();
|
2020-09-25 22:32:01 +00:00
|
|
|
break;
|
|
|
|
case 'user-block':
|
2021-01-10 11:27:08 +00:00
|
|
|
// @todo Support partial blocks?
|
|
|
|
/** @var User $user */
|
2020-09-25 22:32:01 +00:00
|
|
|
$user = $parameters['user'];
|
|
|
|
$result = (bool)$user->getBlock();
|
|
|
|
break;
|
|
|
|
case 'user-age':
|
2021-01-08 17:17:41 +00:00
|
|
|
/** @var User $user */
|
2020-09-25 22:32:01 +00:00
|
|
|
$user = $parameters['user'];
|
|
|
|
$asOf = $parameters['asof'];
|
|
|
|
|
2021-01-08 17:17:41 +00:00
|
|
|
if ( !$user->isRegistered() ) {
|
2020-09-25 22:32:01 +00:00
|
|
|
$result = 0;
|
|
|
|
} else {
|
|
|
|
$registration = $user->getRegistration();
|
|
|
|
// HACK: If there's no registration date, assume 2008-01-15, Wikipedia Day
|
|
|
|
// in the year before the new user log was created. See T243469.
|
|
|
|
if ( $registration === null ) {
|
|
|
|
$registration = "20080115000000";
|
|
|
|
}
|
|
|
|
$result = (int)wfTimestamp( TS_UNIX, $asOf ) - (int)wfTimestamp( TS_UNIX, $registration );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'page-age':
|
2021-01-08 17:17:41 +00:00
|
|
|
/** @var Title $title */
|
|
|
|
$title = $parameters['title'];
|
2020-09-25 22:32:01 +00:00
|
|
|
|
2021-01-08 17:17:41 +00:00
|
|
|
$firstRev = $this->revisionLookup->getFirstRevision( $title );
|
|
|
|
$firstRevisionTime = $firstRev ? $firstRev->getTimestamp() : null;
|
2020-09-25 22:32:01 +00:00
|
|
|
if ( !$firstRevisionTime ) {
|
|
|
|
$result = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
$asOf = $parameters['asof'];
|
|
|
|
$result = (int)wfTimestamp( TS_UNIX, $asOf ) - (int)wfTimestamp( TS_UNIX, $firstRevisionTime );
|
|
|
|
break;
|
|
|
|
case 'length':
|
2020-10-18 22:25:05 +00:00
|
|
|
$s = $getVarCB( $parameters['length-var'] )->toString();
|
2020-09-25 22:32:01 +00:00
|
|
|
$result = strlen( $s );
|
|
|
|
break;
|
|
|
|
case 'subtract-int':
|
2020-10-18 22:25:05 +00:00
|
|
|
$v1 = $getVarCB( $parameters['val1-var'] )->toInt();
|
|
|
|
$v2 = $getVarCB( $parameters['val2-var'] )->toInt();
|
2020-09-25 22:32:01 +00:00
|
|
|
$result = $v1 - $v2;
|
|
|
|
break;
|
|
|
|
case 'revision-text-by-id':
|
|
|
|
$revRec = $this->revisionLookup->getRevisionById( $parameters['revid'] );
|
2020-09-29 18:48:51 +00:00
|
|
|
$result = $this->textExtractor->revisionToString( $revRec, $parameters['contextUser'] );
|
2020-09-25 22:32:01 +00:00
|
|
|
break;
|
|
|
|
case 'get-wiki-name':
|
|
|
|
$result = $this->wikiID;
|
|
|
|
break;
|
|
|
|
case 'get-wiki-language':
|
|
|
|
$result = $this->contentLanguage->getCode();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if ( $this->hookRunner->onAbuseFilterComputeVariable(
|
2021-01-02 14:01:00 +00:00
|
|
|
$varMethod,
|
2020-09-25 22:32:01 +00:00
|
|
|
$vars,
|
|
|
|
$parameters,
|
|
|
|
$result
|
|
|
|
) ) {
|
2021-01-02 14:01:00 +00:00
|
|
|
throw new AFPException( 'Unknown variable compute type ' . $varMethod );
|
2020-09-25 22:32:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result instanceof AFPData
|
|
|
|
? $result : AFPData::newFromPHPVar( $result );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param WikiPage $article
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
private function getLinksFromDB( WikiPage $article ) {
|
|
|
|
// Stolen from ConfirmEdit, SimpleCaptcha::getLinksFromTracker
|
|
|
|
$id = $article->getId();
|
|
|
|
if ( !$id ) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
$dbr = $this->loadBalancer->getConnectionRef( DB_REPLICA );
|
|
|
|
return $dbr->selectFieldValues(
|
|
|
|
'externallinks',
|
|
|
|
'el_to',
|
|
|
|
[ 'el_from' => $id ],
|
|
|
|
__METHOD__
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-01-14 16:18:13 +00:00
|
|
|
* @todo Move to MW core (T272050)
|
2020-09-25 22:32:01 +00:00
|
|
|
* @param Title $title
|
|
|
|
* @return string[] Usernames of the last 10 (unique) authors from $title
|
|
|
|
*/
|
|
|
|
private function getLastPageAuthors( Title $title ) {
|
|
|
|
if ( !$title->exists() ) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
$fname = __METHOD__;
|
|
|
|
|
|
|
|
return $this->wanCache->getWithSetCallback(
|
|
|
|
$this->wanCache->makeKey( 'last-10-authors', 'revision', $title->getLatestRevID() ),
|
|
|
|
WANObjectCache::TTL_MINUTE,
|
|
|
|
function ( $oldValue, &$ttl, array &$setOpts ) use ( $title, $fname ) {
|
|
|
|
$dbr = $this->loadBalancer->getConnectionRef( DB_REPLICA );
|
|
|
|
$setOpts += Database::getCacheSetOptions( $dbr );
|
|
|
|
// Get the last 100 edit authors with a trivial query (avoid T116557)
|
|
|
|
$revQuery = $this->revisionStore->getQueryInfo();
|
|
|
|
$revAuthors = $dbr->selectFieldValues(
|
|
|
|
$revQuery['tables'],
|
|
|
|
$revQuery['fields']['rev_user_text'],
|
|
|
|
[ 'rev_page' => $title->getArticleID() ],
|
|
|
|
$fname,
|
|
|
|
// Some pages have < 10 authors but many revisions (e.g. bot pages)
|
|
|
|
[ 'ORDER BY' => 'rev_timestamp DESC, rev_id DESC',
|
|
|
|
'LIMIT' => 100,
|
|
|
|
// Force index per T116557
|
|
|
|
'USE INDEX' => [ 'revision' => 'page_timestamp' ],
|
|
|
|
],
|
|
|
|
$revQuery['joins']
|
|
|
|
);
|
|
|
|
// Get the last 10 distinct authors within this set of edits
|
|
|
|
$users = [];
|
|
|
|
foreach ( $revAuthors as $author ) {
|
|
|
|
$users[$author] = 1;
|
|
|
|
if ( count( $users ) >= 10 ) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return array_keys( $users );
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* It's like Article::prepareContentForEdit, but not for editing (old wikitext usually)
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param string $wikitext
|
|
|
|
* @param WikiPage $article
|
|
|
|
* @param User $user Context user
|
|
|
|
*
|
|
|
|
* @return stdClass
|
|
|
|
*/
|
|
|
|
private function parseNonEditWikitext( $wikitext, WikiPage $article, User $user ) {
|
|
|
|
static $cache = [];
|
|
|
|
|
|
|
|
$cacheKey = md5( $wikitext ) . ':' . $article->getTitle()->getPrefixedText();
|
|
|
|
|
|
|
|
if ( isset( $cache[$cacheKey] ) ) {
|
|
|
|
return $cache[$cacheKey];
|
|
|
|
}
|
|
|
|
|
|
|
|
$edit = (object)[];
|
|
|
|
$options = ParserOptions::newFromUser( $user );
|
|
|
|
$edit->output = $this->parser->parse( $wikitext, $article->getTitle(), $options );
|
|
|
|
$cache[$cacheKey] = $edit;
|
|
|
|
|
|
|
|
return $edit;
|
|
|
|
}
|
|
|
|
}
|