53 ->isSupportedFormat(
$params[
'contentformat'] )
55 $this->
dieUsage(
'Unsupported content model/format',
'badmodelformat' );
59 $text = rtrim( str_replace(
"\r\n",
"\n",
$params[
'text'] ) );
64 if (
$page->exists() ) {
68 $this->
dieUsage(
"No revision ID {$params['baserevid']}",
'missingrev' );
70 $currentRev =
$page->getRevision();
72 $this->
dieUsage(
"No current revision of page ID {$page->getId()}",
'missingrev' );
75 $editContent =
$page->replaceSectionAtRev(
81 if ( !$editContent ) {
82 $this->
dieUsage(
'Could not merge updated section.',
'replacefailed' );
84 if ( $currentRev->getId() == $baseRev->getId() ) {
89 $baseContent = $baseRev->getContent();
90 $currentContent = $currentRev->getContent();
91 if ( !$baseContent || !$currentContent ) {
92 $this->
dieUsage(
"Missing content for page ID {$page->getId()}",
'missingrev' );
109 ignore_user_abort(
true );
117 if (
$user->pingLimiter(
'stashedit' ) ) {
119 } elseif ( $dbw->lock(
$key, __METHOD__, 1 ) ) {
121 $dbw->unlock(
$key, __METHOD__ );
138 $logger = LoggerFactory::getInstance(
'StashEdit' );
143 if ( $editInfo && $editInfo->output ) {
147 Hooks::run(
'ParserOutputStashForEdit', [ $page, $content, $editInfo->output ] );
149 list( $stashInfo, $ttl ) = self::buildStashValue(
150 $editInfo->pstContent, $editInfo->output, $editInfo->timestamp
157 $logger->debug(
"Cached parser output for key '$key'." );
158 return self::ERROR_NONE;
160 $logger->error(
"Failed to cache parser output for key '$key'." );
161 return self::ERROR_CACHE;
164 $logger->info(
"Uncacheable parser output for key '$key'." );
165 return self::ERROR_UNCACHEABLE;
169 return self::ERROR_PARSE;
196 $logger = LoggerFactory::getInstance(
'StashEdit' );
214 $canonicalPOpts = $page->makeParserOptions(
'canonical' );
215 $canonicalPOpts->setIsPreview(
true );
216 $canonicalPOpts->setTimestamp( $pOpts->
getTimestamp() );
217 if ( !$pOpts->
matches( $canonicalPOpts ) ) {
218 $logger->info(
"Uncacheable preview output for key '$key' (options)." );
223 list( $stashInfo, $ttl ) = self::buildStashValue( $pstContent, $pOut,
$timestamp );
225 $logger->info(
"Uncacheable parser output for key '$key' (rev/TTL)." );
231 $logger->error(
"Failed to cache preview parser output for key '$key'." );
233 $logger->debug(
"Cached preview output for key '$key'." );
258 $logger = LoggerFactory::getInstance(
'StashEdit' );
261 $key = self::getStashKey( $title, $content, $user );
263 if ( !is_object( $editInfo ) ) {
264 $start = microtime(
true );
270 $dbw = $lb->getAnyOpenConnection( $lb->getWriterIndex() );
271 if ( $dbw && $dbw->lock(
$key, __METHOD__, 30 ) ) {
273 $dbw->unlock(
$key, __METHOD__ );
276 $timeMs = 1000 * max( 0, microtime(
true ) - $start );
277 $stats->timing(
'editstash.lock_wait_time', $timeMs );
280 if ( !is_object( $editInfo ) || !$editInfo->output ) {
281 $stats->increment(
'editstash.cache_misses.no_stash' );
282 $logger->debug(
"No cache value for key '$key'." );
287 if ( $age <= self::PRESUME_FRESH_TTL_SEC ) {
288 $stats->increment(
'editstash.cache_hits.presumed_fresh' );
289 $logger->debug(
"Timestamp-based cache hit for key '$key' (age: $age sec)." );
297 foreach ( $editInfo->output->getTemplateIds()
as $ns => $stuff ) {
298 foreach ( $stuff
as $dbkey =>
$revId ) {
304 if ( count( $templates ) ) {
307 [
'ns' =>
'page_namespace',
'dbk' =>
'page_title',
'page_latest' ],
308 $dbr->makeWhereFrom2d( $templates,
'page_namespace',
'page_title' ),
312 foreach (
$res as $row ) {
313 $changed = $changed || ( $row->page_latest != $templates[$row->ns][$row->dbk] );
316 if ( $changed ||
$res->numRows() != $templateUses ) {
317 $stats->increment(
'editstash.cache_misses.proven_stale' );
318 $logger->info(
"Stale cache for key '$key'; template changed. (age: $age sec)" );
324 foreach ( $editInfo->output->getFileSearchOptions()
as $name =>
$options ) {
331 [
'name' =>
'img_name',
'img_sha1' ],
332 [
'img_name' => array_keys(
$files ) ],
336 foreach (
$res as $row ) {
337 $changed = $changed || ( $row->img_sha1 !=
$files[$row->name] );
340 if ( $changed ||
$res->numRows() != count(
$files ) ) {
341 $stats->increment(
'editstash.cache_misses.proven_stale' );
342 $logger->info(
"Stale cache for key '$key'; file changed. (age: $age sec)" );
347 $stats->increment(
'editstash.cache_hits.proven_fresh' );
348 $logger->debug(
"Verified cache hit for key '$key' (age: $age sec)." );
366 $hash = sha1( implode(
':', [
394 if ( $ttl > 0 && !$parserOutput->
getFlag(
'vary-revision' ) ) {
397 'pstContent' => $pstContent,
398 'output' => $parserOutput,
401 return [ $stashInfo, $ttl ];
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below...
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
wfGetDB($db, $groups=[], $wiki=false)
Get a Database object.
getResult()
Get the result object.
magic word the default is to use $key to get the and $key value or $key value text $key value html to format the value $key
serialize($format=null)
Convenience method for serializing this Content object.
Prepare an edit in shared cache so that it can be reused on edit.
static checkCache(Title $title, Content $content, User $user)
Check that a prepared edit is in cache and still up-to-date.
static getAllContentFormats()
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
static getForModelID($modelId)
Returns the ContentHandler singleton for the given model ID.
Set options of the Parser.
static getContentModels()
const PARAM_REQUIRED
(boolean) Is the parameter required?
extractRequestParams($parseLimit=true)
Using getAllowedParams(), this function makes an array of the values provided by the user...
This code would result in ircNotify being run twice when an article is and once for brion Hooks can return three possible true was required This is the default since MediaWiki *some string
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context $revId
static getLocalClusterInstance()
Get the main cluster-local cache object.
getDBTouched()
Get the user_touched timestamp field (time of last DB updates)
Represents a title within MediaWiki.
static newFromPageId($pageId, $revId=0, $flags=0)
Load either the current, or a specified, revision that's attached to a given page ID...
globals will be eliminated from MediaWiki replaced by an application object which would be passed to constructors Whether that would be an convenient solution remains to be but certainly PHP makes such object oriented programming models easier than they were in previous versions For the time being MediaWiki programmers will have to work in an environment with some global context At the time of globals were initialised on startup by MediaWiki of these were configuration which are documented in DefaultSettings php There is no comprehensive documentation for the remaining however some of the most important ones are listed below They are typically initialised either in index php or in Setup php For a description of the see design txt $wgTitle Title object created from the request URL $wgOut OutputPage object for HTTP response $wgUser User object for the user associated with the current request $wgLang Language object selected by user preferences $wgContLang Language object associated with the wiki being viewed $wgParser Parser object Parser extensions register their hooks here $wgRequest WebRequest object
getName()
Get the user name, or the IP of an anonymous user.
static buildStashValue(Content $pstContent, ParserOutput $parserOutput, $timestamp)
Build a value to store in memcached based on the PST content and parser output.
wfTimestamp($outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
getTitleOrPageId($params, $load=false)
Get a WikiPage object from a title or pageid param, if possible.
Interface for type hinting (accepts WikiPage, Article, ImagePage, CategoryPage)
getCacheExpiry()
Returns the number of seconds after which this object should expire.
wfGetLB($wiki=false)
Get a load balancer object.
static getMain()
Static methods.
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context $parserOutput
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context $options
Base interface for content objects.
getTitle()
Get the title object of the article.
namespace and then decline to actually register it file or subcat img or subcat $title
getModuleName()
Get the name of the module being executed by this instance.
static run($event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
static parseAndStash(WikiPage $page, Content $content, User $user)
static makeContent($text, Title $title=null, $modelId=null, $format=null)
Convenience function for creating a Content object from a given textual representation.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account $user
Class representing a MediaWiki article and history.
prepareContentForEdit(Content $content, $revision=null, User $user=null, $serialFormat=null, $useCache=true)
Prepare content which is about to be saved.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
getId()
Get the user's ID.
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content $content
static stashEditFromPreview(Page $page, Content $content, Content $pstContent, ParserOutput $pOut, ParserOptions $pstOpts, ParserOptions $pOpts, $timestamp)
Attempt to cache PST content and corresponding parser output in passing.
dieUsage($description, $errorCode, $httpRespCode=0, $extradata=null)
Throw a UsageException, which will (if uncaught) call the main module's error handler and die with an...
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set $status
MediaWiki Logger LoggerFactory implements a PSR[0] compatible message logging system Named Psr Log LoggerInterface instances can be obtained from the MediaWiki Logger LoggerFactory::getInstance() static method.MediaWiki\Logger\LoggerFactory expects a class implementing the MediaWiki\Logger\Spi interface to act as a factory for new Psr\Log\LoggerInterface instances.The"Spi"in MediaWiki\Logger\Spi stands for"service provider interface".An SPI is an API intended to be implemented or extended by a third party.This software design pattern is intended to enable framework extension and replaceable components.It is specifically used in the MediaWiki\Logger\LoggerFactory service to allow alternate PSR-3 logging implementations to be easily integrated with MediaWiki.The service provider interface allows the backend logging library to be implemented in multiple ways.The $wgMWLoggerDefaultSpi global provides the classname of the default MediaWiki\Logger\Spi implementation to be loaded at runtime.This can either be the name of a class implementing the MediaWiki\Logger\Spi with a zero argument const ructor or a callable that will return an MediaWiki\Logger\Spi instance.Alternately the MediaWiki\Logger\LoggerFactory MediaWiki Logger LoggerFactory
This abstract class implements many basic API functions, and is the base of all API classes...
wfMemcKey()
Make a cache key for the local wiki.
const TS_UNIX
Unix time - the number of seconds since 1970-01-01 00:00:00 UTC.
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable modifiable after all normalizations have been except for the $wgMaxImageArea check set to true or false to override the $wgMaxImageArea check result gives extension the possibility to transform it themselves $handler
getModel()
Returns the ID of the content model used by this Content object.
getUser()
Get the User object.
getDefaultFormat()
Convenience method that returns the default serialization format for the content model that this Cont...
const PRESUME_FRESH_TTL_SEC
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached $page
getPrefixedDBkey()
Get the prefixed database key form.
matches(ParserOptions $other)
Check if these options match that of another options set.
Allows to change the fields on the form that will be generated $name
static getStashKey(Title $title, Content $content, User $user)
Get the temporary prepared edit stash key for a user.