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' );
140 $format =
$content->getDefaultFormat();
143 if ( $editInfo && $editInfo->output ) {
147 Hooks::run(
'ParserOutputStashForEdit', [
$page,
$content, $editInfo->output ] );
150 $editInfo->pstContent, $editInfo->output, $editInfo->timestamp
154 $ok =
$cache->set( $key, $stashInfo, $ttl );
157 $logger->debug(
"Cached parser output for key '$key'." );
160 $logger->error(
"Failed to cache parser output for key '$key'." );
164 $logger->info(
"Uncacheable parser output for key '$key'." );
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)." );
225 $logger->info(
"Uncacheable parser output for key '$key' (rev/TTL)." );
229 $ok =
$cache->set( $key, $stashInfo, $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' );
262 $editInfo =
$cache->get( $key );
263 if ( !is_object( $editInfo ) ) {
264 $start = microtime(
true );
270 $dbw = $lb->getAnyOpenConnection( $lb->getWriterIndex() );
271 if ( $dbw && $dbw->lock( $key, __METHOD__, 30 ) ) {
272 $editInfo =
$cache->get( $key );
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(
':', [
374 return wfMemcKey(
'prepared-edit', md5(
$title->getPrefixedDBkey() ), $hash );
392 $ttl = min(
$parserOutput->getCacheExpiry() - $since, 5 * 60 );
394 if ( $ttl > 0 && !
$parserOutput->getFlag(
'vary-revision' ) ) {
397 'pstContent' => $pstContent,
401 return [ $stashInfo, $ttl ];
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
wfGetLB( $wiki=false)
Get a load balancer object.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
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.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
This abstract class implements many basic API functions, and is the base of all API classes.
const PARAM_REQUIRED
(boolean) Is the parameter required?
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below.
extractRequestParams( $parseLimit=true)
Using getAllowedParams(), this function makes an array of the values provided by the user,...
getResult()
Get the result object.
getModuleName()
Get the name of the module being executed by this instance.
getTitleOrPageId( $params, $load=false)
Get a WikiPage object from a title or pageid param, if possible.
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...
Prepare an edit in shared cache so that it can be reused on edit.
const PRESUME_FRESH_TTL_SEC
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
isInternal()
Indicates whether this module is "internal" Internal API modules are not (yet) intended for 3rd party...
static parseAndStash(WikiPage $page, Content $content, User $user)
needsToken()
Returns the token type this module requires in order to execute.
static getStashKey(Title $title, Content $content, User $user)
Get the temporary prepared edit stash key for a user.
isWriteMode()
Indicates whether this module requires write mode.
static checkCache(Title $title, Content $content, User $user)
Check that a prepared edit is in cache and still up-to-date.
static buildStashValue(Content $pstContent, ParserOutput $parserOutput, $timestamp)
Build a value to store in memcached based on the PST content and parser output.
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.
mustBePosted()
Indicates whether this module must be called with a POST request.
static getAllContentFormats()
static makeContent( $text, Title $title=null, $modelId=null, $format=null)
Convenience function for creating a Content object from a given textual representation.
static getForModelID( $modelId)
Returns the ContentHandler singleton for the given model ID.
static getContentModels()
getUser()
Get the User object.
static getLocalClusterInstance()
Get the main cluster-local cache object.
Set options of the Parser.
matches(ParserOptions $other)
Check if these options match that of another options set.
static getMain()
Static methods.
static newFromPageId( $pageId, $revId=0, $flags=0)
Load either the current, or a specified, revision that's attached to a given page ID.
Represents a title within MediaWiki.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Class representing a MediaWiki article and history.
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
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
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
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
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
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
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
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
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
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 as context $options
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
namespace and then decline to actually register it file or subcat img or subcat $title
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
Allows to change the fields on the form that will be generated $name
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
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
Base interface for content objects.
Interface for type hinting (accepts WikiPage, Article, ImagePage, CategoryPage)