43 if ( is_null(
$params[
'text'] ) && is_null(
$params[
'appendtext'] ) &&
44 is_null(
$params[
'prependtext'] ) &&
51 $titleObj = $pageObj->getTitle();
55 if (
$params[
'prependtext'] === null &&
$params[
'appendtext'] === null
58 $this->
dieUsage(
'You have attempted to edit using the "redirect"-following'
59 .
' mode, which must be used in conjuction with section=new, prependtext'
60 .
', or appendtext.',
'redirect-appendonly' );
62 if ( $titleObj->isRedirect() ) {
75 if ( !isset(
$titles[$id - 1] ) ) {
80 'from' =>
$titles[$id - 1]->getPrefixedText(),
81 'to' => $newTitle->getPrefixedText()
84 $titleObj = $newTitle;
88 $apiResult->addValue( null,
'redirects', $redirValues );
95 if ( !isset(
$params[
'contentmodel'] ) ||
$params[
'contentmodel'] ==
'' ) {
96 $contentHandler = $pageObj->getContentHandler();
100 $contentModel = $contentHandler->getModelID();
102 $name = $titleObj->getPrefixedDBkey();
103 $model = $contentHandler->getModelID();
107 } elseif ( $contentHandler->supportsDirectApiEditing() ===
false ) {
109 "Direct editing via API is not supported for content model $model used by $name",
114 if ( !isset(
$params[
'contentformat'] ) ||
$params[
'contentformat'] ==
'' ) {
115 $contentFormat = $contentHandler->getDefaultFormat();
117 $contentFormat =
$params[
'contentformat'];
120 if ( !$contentHandler->isSupportedFormat( $contentFormat ) ) {
122 $this->
dieUsage(
"The requested format $contentFormat is not supported for content model " .
123 " $model used by $name",
'badformat' );
126 if (
$params[
'createonly'] && $titleObj->exists() ) {
129 if (
$params[
'nocreate'] && !$titleObj->exists() ) {
134 $errors = $titleObj->getUserPermissionsErrors(
'edit',
$user );
135 if ( !$titleObj->exists() ) {
136 $errors = array_merge( $errors, $titleObj->getUserPermissionsErrors(
'create',
$user ) );
138 if ( count( $errors ) ) {
139 if ( is_array( $errors[0] ) ) {
140 switch ( $errors[0][0] ) {
143 'You have been blocked from editing',
149 case 'autoblockedtext':
151 'Your IP address has been blocked automatically, because it was used by a blocked user',
166 if ( !is_null(
$params[
'appendtext'] ) || !is_null(
$params[
'prependtext'] ) ) {
171 # If this is a MediaWiki:x message, then load the messages
172 # and return the message value for x.
173 $text = $titleObj->getDefaultMessageText();
174 if ( $text ===
false ) {
181 $this->
dieUsage( $ex->getMessage(),
'parseerror' );
186 # Otherwise, make a new empty content.
187 $content = $contentHandler->makeEmptyContent();
194 $mode = $contentHandler->getModelID();
195 $this->
dieUsage(
"Can't append to pages using content model $mode",
'appendnotsupported' );
198 if ( !is_null(
$params[
'section'] ) ) {
199 if ( !$contentHandler->supportsSections() ) {
200 $modelName = $contentHandler->getModelID();
202 "Sections are not supported for this content model: $modelName.",
203 'sectionsnotsupported'
207 if (
$params[
'section'] ==
'new' ) {
216 $this->
dieUsage(
"There is no section {$section}.",
'nosuchsection' );
224 $text =
$content->serialize( $contentFormat );
232 if (
$params[
'undoafter'] > 0 ) {
244 if (
$params[
'undoafter'] == 0 ) {
245 $undoafterRev = $undoRev->getPrevious();
251 if ( $undoRev->getPage() != $pageObj->getId() ) {
252 $this->
dieUsageMsg( [
'revwrongpage', $undoRev->getId(),
253 $titleObj->getPrefixedText() ] );
255 if ( $undoafterRev->getPage() != $pageObj->getId() ) {
256 $this->
dieUsageMsg( [
'revwrongpage', $undoafterRev->getId(),
257 $titleObj->getPrefixedText() ] );
260 $newContent = $contentHandler->getUndoContent(
261 $pageObj->getRevision(),
266 if ( !$newContent ) {
269 if ( empty(
$params[
'contentmodel'] )
270 && empty(
$params[
'contentformat'] )
277 if ( !$newContent->isSupportedFormat( $contentFormat ) ) {
278 $contentFormat = $undoafterRev->getContentFormat();
281 $contentModel = $newContent->getModel();
283 $params[
'text'] = $newContent->serialize( $contentFormat );
286 if ( is_null(
$params[
'summary'] ) &&
287 $titleObj->getNextRevisionID( $undoafterRev->getId() ) ==
$params[
'undo']
290 ->params(
$params[
'undo'], $undoRev->getUserText() )->inContentLanguage()->text();
295 if ( !is_null(
$params[
'md5'] ) && md5( $toMD5 ) !==
$params[
'md5'] ) {
302 'wpTextbox1' =>
$params[
'text'],
303 'format' => $contentFormat,
304 'model' => $contentModel,
305 'wpEditToken' =>
$params[
'token'],
306 'wpIgnoreBlankSummary' =>
true,
307 'wpIgnoreBlankArticle' =>
true,
308 'wpIgnoreSelfRedirect' =>
true,
312 if ( !is_null(
$params[
'summary'] ) ) {
313 $requestArray[
'wpSummary'] =
$params[
'summary'];
316 if ( !is_null(
$params[
'sectiontitle'] ) ) {
317 $requestArray[
'wpSectionTitle'] =
$params[
'sectiontitle'];
322 $requestArray[
'wpUndidRevision'] =
$params[
'undo'];
327 if (
$params[
'basetimestamp'] !== null && (
bool)$this->
getMain()->getVal(
'basetimestamp' ) ) {
328 $requestArray[
'wpEdittime'] =
$params[
'basetimestamp'];
330 $requestArray[
'wpEdittime'] = $pageObj->getTimestamp();
333 if (
$params[
'starttimestamp'] !== null ) {
334 $requestArray[
'wpStarttime'] =
$params[
'starttimestamp'];
339 if (
$params[
'minor'] || ( !
$params[
'notminor'] &&
$user->getOption(
'minordefault' ) ) ) {
340 $requestArray[
'wpMinoredit'] =
'';
344 $requestArray[
'wpRecreate'] =
'';
347 if ( !is_null(
$params[
'section'] ) ) {
349 if ( !preg_match(
'/^((T-)?\d+|new)$/',
$section ) ) {
350 $this->
dieUsage(
"The section parameter must be a valid section id or 'new'",
357 $this->
dieUsage(
"There is no section {$section}.",
'nosuchsection' );
359 $requestArray[
'wpSection'] =
$params[
'section'];
361 $requestArray[
'wpSection'] =
'';
369 } elseif (
$params[
'unwatch'] ) {
374 $requestArray[
'wpWatchthis'] =
'';
378 if ( count(
$params[
'tags'] ) ) {
380 if ( $tagStatus->isOK() ) {
381 $requestArray[
'wpChangeTags'] = implode(
',',
$params[
'tags'] );
389 $requestArray += $this->
getRequest()->getValues();
397 $wgTitle = $titleObj;
401 $articleContext->setWikiPage( $pageObj );
402 $articleContext->setUser( $this->
getUser() );
407 $ep =
new EditPage( $articleObject );
409 $ep->setApiEditOverride(
true );
410 $ep->setContextTitle( $titleObj );
411 $ep->importFormData(
$req );
420 $r[
'result'] =
'Failure';
430 $oldRevId = $articleObject->getRevIdFetched();
438 $wgRequest = $oldRequest;
443 if ( isset(
$status->apiHookResult ) ) {
445 $r[
'result'] =
'Failure';
466 'You have been blocked from editing',
514 $r[
'result'] =
'Success';
515 $r[
'pageid'] = intval( $titleObj->getArticleID() );
516 $r[
'title'] = $titleObj->getPrefixedText();
517 $r[
'contentmodel'] = $articleObject->getContentModel();
518 $newRevId = $articleObject->getLatest();
519 if ( $newRevId == $oldRevId ) {
520 $r[
'nochange'] =
true;
522 $r[
'oldrevid'] = intval( $oldRevId );
523 $r[
'newrevid'] = intval( $newRevId );
525 $pageObj->getTimestamp() );
536 $errors =
$status->getErrorsArray();
577 'starttimestamp' => [
581 'createonly' =>
false,
636 'action=edit&title=Test&summary=test%20summary&' .
637 'text=article%20content&basetimestamp=2007-08-24T12:34:54Z&token=123ABC'
638 =>
'apihelp-edit-example-edit',
639 'action=edit&title=Test&summary=NOTOC&minor=&' .
640 'prependtext=__NOTOC__%0A&basetimestamp=2007-08-24T12:34:54Z&token=123ABC'
641 =>
'apihelp-edit-example-prepend',
642 'action=edit&title=Test&undo=13585&undoafter=13579&' .
643 'basetimestamp=2007-08-24T12:34:54Z&token=123ABC'
644 =>
'apihelp-edit-example-undo',
649 return 'https://www.mediawiki.org/wiki/API:Edit';
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
const AS_READ_ONLY_PAGE_ANON
Status: this anonymous user is not allowed to edit this page.
getResult()
Get the result object.
setRequest(WebRequest $r)
Set the WebRequest object.
Group all the pieces relevant to the context of a request into one instance.
processing should stop and the error should be shown to the user * false
static getAllContentFormats()
const AS_ARTICLE_WAS_DELETED
Status: article was deleted while editing and param wpRecreate == false or form was not posted...
if(!$wgDBerrorLogTZ) $wgRequest
const AS_HOOK_ERROR
Status: Article update aborted by a hook function.
static getForModelID($modelId)
Returns the ContentHandler singleton for the given model ID.
useTransactionalTimeLimit()
Call wfTransactionalTimeLimit() if this request was POSTed.
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
getMain()
Get the main module.
static getContentModels()
The edit page/HTML interface (split from Article) The actual database and text munging is still in Ar...
Similar to FauxRequest, but only fakes URL parameters and method (POST or GET) and use the base reque...
const AS_SUMMARY_NEEDED
Status: no edit summary given and the user has forceeditsummary set and the user is not editing in hi...
const AS_HOOK_ERROR_EXPECTED
Status: A hook function returned an error.
getWatchlistValue($watchlist, $titleObj, $userOption=null)
Return true if we're to watch the page, false if not, null if no change.
extractRequestParams($parseLimit=true)
Using getAllowedParams(), this function makes an array of the values provided by the user...
const AS_BLOCKED_PAGE_FOR_USER
Status: User is blocked from editing this page.
const AS_NO_CREATE_PERMISSION
Status: user tried to create this page, but is not allowed to do that ( Title->userCan('create') == f...
when a variable name is used in a it is silently declared as a new local masking the global
static newFromTitle(LinkTarget $linkTarget, $id=0, $flags=0)
Load either the current, or a specified, revision that's attached to a given link target...
const TS_ISO_8601
ISO 8601 format with no timezone: 1986-02-09T20:00:00Z.
static setIndexedTagName(array &$arr, $tag)
Set the tag name for numeric-keyed values in XML format.
getTitle()
Get the Title object.
static getBlockInfo(Block $block)
Get basic info about a given block.
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message.Please note the header message cannot receive/use parameters. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item.Return false to stop further processing of the tag $reader:XMLReader object $logInfo:Array of information 'ImportHandlePageXMLTag':When parsing a XML tag in a page.Return false to stop further processing of the tag $reader:XMLReader object &$pageInfo:Array of information 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision.Return false to stop further processing of the tag $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information 'ImportHandleToplevelXMLTag':When parsing a top level XML tag.Return false to stop further processing of the tag $reader:XMLReader object 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload.Return false to stop further processing of the tag $reader:XMLReader object $revisionInfo:Array of information 'ImportLogInterwikiLink':Hook to change the interwiki link used in log entries and edit summaries for transwiki imports.&$fullInterwikiPrefix:Interwiki prefix, may contain colons.&$pageTitle:String that contains page title. 'ImportSources':Called when reading from the $wgImportSources configuration variable.Can be used to lazy-load the import sources list.&$importSources:The value of $wgImportSources.Modify as necessary.See the comment in DefaultSettings.php for the detail of how to structure this array. 'InfoAction':When building information to display on the action=info page.$context:IContextSource object &$pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect.&$title:Title object for the current page &$request:WebRequest &$ignoreRedirect:boolean to skip redirect check &$target:Title/string of redirect target &$article:Article object 'InternalParseBeforeLinks':during Parser's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings.&$parser:Parser object &$text:string containing partially parsed text &$stripState:Parser's internal StripState object 'InternalParseBeforeSanitize':during Parser's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings.Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments.&$parser:Parser object &$text:string containing partially parsed text &$stripState:Parser's internal StripState object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not.Return true without providing an interwiki to continue interwiki search.$prefix:interwiki prefix we are looking for.&$iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InvalidateEmailComplete':Called after a user's email has been invalidated successfully.$user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification.Callee may modify $url and $query, URL will be constructed as $url.$query &$url:URL to index.php &$query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) &$article:article(object) being checked 'IsTrustedProxy':Override the result of IP::isTrustedProxy() &$ip:IP being check &$result:Change this value to override the result of IP::isTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from &$allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of Sanitizer::validateEmail(), for instance to return false if the domain name doesn't match your organization.$addr:The e-mail address entered by the user &$result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user &$result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we're looking for a messages file for &$file:The messages file path, you can override this to change the location. 'LanguageGetMagic':DEPRECATED!Use $magicWords in a file listed in $wgExtensionMessagesFiles instead.Use this to define synonyms of magic words depending of the language &$magicExtensions:associative array of magic words synonyms $lang:language code(string) 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces.Do not use this hook to add namespaces.Use CanonicalNamespaces for that.&$namespaces:Array of namespaces indexed by their numbers 'LanguageGetSpecialPageAliases':DEPRECATED!Use $specialPageAliases in a file listed in $wgExtensionMessagesFiles instead.Use to define aliases of special pages names depending of the language &$specialPageAliases:associative array of magic words synonyms $lang:language code(string) 'LanguageGetTranslatedLanguageNames':Provide translated language names.&$names:array of language code=> language name $code:language of the preferred translations 'LanguageLinks':Manipulate a page's language links.This is called in various places to allow extensions to define the effective language links for a page.$title:The page's Title.&$links:Associative array mapping language codes to prefixed links of the form"language:title".&$linkFlags:Associative array mapping prefixed links to arrays of flags.Currently unused, but planned to provide support for marking individual language links in the UI, e.g.for featured articles. 'LanguageSelector':Hook to change the language selector available on a page.$out:The output page.$cssClassName:CSS class name of the language selector. 'LinkBegin':DEPRECATED!Use HtmlPageLinkRendererBegin instead.Used when generating internal and interwiki links in Linker::link(), before processing starts.Return false to skip default processing and return $ret.See documentation for Linker::link() for details on the expected meanings of parameters.$skin:the Skin object $target:the Title that the link is pointing to &$html:the contents that the< a > tag should have(raw HTML) $result
const AS_CONTENT_TOO_BIG
Status: Content too big (> $wgMaxArticleSize)
wfTimestamp($outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
getRequest()
Get the WebRequest object.
const PARAM_HELP_MSG_APPEND
((string|array|Message)[]) Specify additional i18n messages to append to the normal message for this ...
getTitleOrPageId($params, $load=false)
Get a WikiPage object from a title or pageid param, if possible.
Content object implementation for representing flat text.
const AS_SPAM_ERROR
Status: summary contained spam according to one of the regexes in $wgSummarySpamRegex.
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock()-offset Set to overwrite offset parameter in $wgRequest set to ''to unsetoffset-wrap String Wrap the message in html(usually something like"<
const AS_SUCCESS_UPDATE
Status: Article successfully updated.
const AS_READ_ONLY_PAGE
Status: wiki is in readonly mode (wfReadOnly() == true)
getConfig()
Get the Config object.
A module that allows for editing and creating pages.
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
const AS_NO_CHANGE_CONTENT_MODEL
Status: user tried to modify the content model, but is not allowed to do that ( User::isAllowed('edit...
getModuleName()
Get the name of the module being executed by this instance.
static dieReadOnly()
Helper function for readonly errors.
static run($event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
static makeContent($text, Title $title=null, $modelId=null, $format=null)
Convenience function for creating a Content object from a given textual representation.
const AS_SUCCESS_NEW_ARTICLE
Status: Article successfully created.
const AS_IMAGE_REDIRECT_LOGGED
Status: logged in user is not allowed to upload (User::isAllowed('upload') == false) ...
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
const AS_END
Status: WikiPage::doEdit() was unsuccessful.
usually copyright or history_copyright This message must be in HTML not wikitext if the section is included from a template $section
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
static newFromId($id, $flags=0)
Load a page revision from a given revision ID number.
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
this hook is for auditing only $req
linkcache txt The LinkCache class maintains a list of article titles and the information about whether or not the article exists in the database This is used to mark up links when displaying a page If the same link appears more than once on any page then it only has to be looked up once In most cases link lookups are done in batches with the LinkBatch class or the equivalent in so the link cache is mostly useful for short snippets of parsed and for links in the navigation areas of the skin The link cache was formerly used to track links used in a document for the purposes of updating the link tables This application is now deprecated To create a you can use the following $titles
const AS_RATE_LIMITED
Status: rate limiter for action 'edit' was tripped.
const AS_MAX_ARTICLE_SIZE_EXCEEDED
Status: article is too big (> $wgMaxArticleSize), after merging in the new section.
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
const AS_IMAGE_REDIRECT_ANON
Status: anonymous user is not allowed to upload (User::isAllowed('upload') == false) ...
const AS_TEXTBOX_EMPTY
Status: user tried to create a new section without content.
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
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
This abstract class implements many basic API functions, and is the base of all API classes...
const AS_BLANK_ARTICLE
Status: user tried to create a blank page and wpIgnoreBlankArticle == false.
const PARAM_DEPRECATED
(boolean) Is the parameter deprecated (will show a warning)?
if(!$wgRequest->checkUrlExtension()) if(!$wgEnableAPI) $wgTitle
const AS_CONFLICT_DETECTED
Status: (non-resolvable) edit conflict.
static newFromWikiPage(WikiPage $page, IContextSource $context)
Create an Article object of the appropriate class for the given page.
dieStatus($status)
Throw a UsageException based on the errors in the Status object.
const AS_READ_ONLY_PAGE_LOGGED
Status: this logged in user is not allowed to edit this page.
const AS_PARSE_ERROR
Status: can't parse content.
getUser()
Get the User object.
dieUsageMsg($error)
Output the error message related to a certain array.
Exception representing a failure to serialize or unserialize a content object.
const AS_CHANGE_TAG_ERROR
Status: an error relating to change tagging.
Allows to change the fields on the form that will be generated $name