46 $this->
getMain()->setCacheMode(
'anon-public-user-private' );
59 if ( $title ===
null ) {
60 $titleProvided =
false;
64 $titleProvided =
true;
71 $model =
$params[
'contentmodel'];
72 $format =
$params[
'contentformat'];
74 $prop = array_flip(
$params[
'prop'] );
76 if ( isset(
$params[
'section'] ) ) {
77 $this->section =
$params[
'section'];
78 if ( !preg_match(
'/^((T-)?\d+|new)$/', $this->section ) ) {
82 $this->section =
false;
92 $needContent = isset( $prop[
'wikitext'] ) ||
93 isset( $prop[
'parsetree'] ) ||
$params[
'generatexml'];
98 if ( !is_null( $oldid ) || !is_null( $pageid ) || !is_null( $page ) ) {
99 if ( $this->section ===
'new' ) {
100 $this->
dieWithError(
'apierror-invalidparammix-parse-new-section',
'invalidparammix' );
102 if ( !is_null( $oldid ) ) {
106 $this->
dieWithError( [
'apierror-nosuchrevid', $oldid ] );
112 [
'apierror-permissiondenied', $this->
msg(
'action-deletedtext' ) ]
116 $titleObj =
$rev->getTitle();
121 $pageObj, $popts, $suppressCache, $pageid,
$rev, $needContent
128 if ( !is_null( $pageid ) ) {
129 $reqParams[
'pageids'] = $pageid;
131 $reqParams[
'titles'] = $page;
137 $redirValues = $pageSet->getRedirectTitlesAsResult( $this->
getResult() );
140 foreach ( $pageSet->getRedirectTitles() as $title ) {
141 $to = $title->getFullText();
143 $pageParams = [
'title' => $to ];
144 } elseif ( !is_null( $pageid ) ) {
145 $pageParams = [
'pageid' => $pageid ];
147 $pageParams = [
'title' => $page ];
151 $titleObj = $pageObj->getTitle();
152 if ( !$titleObj || !$titleObj->exists() ) {
159 if ( isset( $prop[
'revid'] ) ) {
160 $oldid = $pageObj->getLatest();
165 $pageObj, $popts, $suppressCache, $pageid,
null, $needContent
169 $titleObj = Title::newFromText( $title );
170 if ( !$titleObj || $titleObj->isExternal() ) {
174 if ( $revid !==
null ) {
177 $this->
dieWithError( [
'apierror-nosuchrevid', $revid ] );
179 $pTitleObj = $titleObj;
180 $titleObj =
$rev->getTitle();
181 if ( $titleProvided ) {
182 if ( !$titleObj->equals( $pTitleObj ) ) {
189 $titleProvided =
true;
193 if ( $titleObj->canExist() ) {
198 $pageObj = $article->getPage();
202 $textProvided = !is_null( $text );
204 if ( !$textProvided ) {
205 if ( $titleProvided && ( $prop ||
$params[
'generatexml'] ) ) {
206 if ( $revid !==
null ) {
207 $this->
addWarning(
'apiwarn-parse-revidwithouttext' );
209 $this->
addWarning(
'apiwarn-parse-titlewithouttext' );
218 if ( $textProvided && !$titleProvided && is_null( $model ) ) {
220 $this->
addWarning( [
'apiwarn-parse-nocontentmodel', $model ] );
227 'wrap' =>
ApiMessage::create(
'apierror-contentserializationexception',
'parseerror' )
231 if ( $this->section !==
false ) {
232 if ( $this->section ===
'new' ) {
234 if ( !is_null(
$params[
'sectiontitle'] ) &&
$params[
'sectiontitle'] !==
'' ) {
235 $this->content = $this->content->addSectionHeader(
$params[
'sectiontitle'] );
238 $this->content = $this->
getSectionContent( $this->content, $titleObj->getPrefixedText() );
243 $this->pstContent = $this->content->preSaveTransform( $titleObj, $this->
getUser(), $popts );
248 if ( $this->contentIsDeleted ) {
249 $result_array[
'textdeleted'] =
true;
251 if ( $this->contentIsSuppressed ) {
252 $result_array[
'textsuppressed'] =
true;
254 $result_array[
'text'] = $this->pstContent->serialize( $format );
256 if ( isset( $prop[
'wikitext'] ) ) {
257 $result_array[
'wikitext'] = $this->content->serialize( $format );
260 if ( !is_null(
$params[
'summary'] ) ||
261 ( !is_null(
$params[
'sectiontitle'] ) && $this->section ===
'new' )
267 $result->addValue(
null, $this->
getModuleName(), $result_array );
274 $p_result = $this->pstContent->getParserOutput( $titleObj, $revid, $popts );
276 $p_result = $this->content->getParserOutput( $titleObj, $revid, $popts );
282 $result_array[
'title'] = $titleObj->getPrefixedText();
283 $result_array[
'pageid'] = $pageid ?: $pageObj->getId();
284 if ( $this->contentIsDeleted ) {
285 $result_array[
'textdeleted'] =
true;
287 if ( $this->contentIsSuppressed ) {
288 $result_array[
'textsuppressed'] =
true;
292 $p_result->setTOCEnabled(
false );
295 if ( isset(
$params[
'useskin'] ) ) {
296 $factory = MediaWikiServices::getInstance()->getSkinFactory();
303 if ( $skin || isset( $prop[
'headhtml'] ) || isset( $prop[
'categorieshtml'] ) ) {
328 $outputPage->addParserOutputMetadata( $p_result );
333 foreach ( $skin->getDefaultModules() as $group ) {
334 $outputPage->addModules( $group );
339 if ( !is_null( $oldid ) ) {
340 $result_array[
'revid'] = intval( $oldid );
343 if (
$params[
'redirects'] && !is_null( $redirValues ) ) {
344 $result_array[
'redirects'] = $redirValues;
347 if ( isset( $prop[
'text'] ) ) {
348 $result_array[
'text'] = $p_result->getText();
352 if ( !is_null(
$params[
'summary'] ) ||
353 ( !is_null(
$params[
'sectiontitle'] ) && $this->section ===
'new' )
359 if ( isset( $prop[
'langlinks'] ) ) {
361 $langlinks = $outputPage->getLanguageLinks();
363 $langlinks = $p_result->getLanguageLinks();
367 if (
$params[
'effectivelanglinks'] ) {
369 Hooks::run(
'LanguageLinks', [ $titleObj, &$langlinks, &$linkFlags ] );
375 if ( isset( $prop[
'categories'] ) ) {
378 if ( isset( $prop[
'categorieshtml'] ) ) {
379 $result_array[
'categorieshtml'] = $outputPage->getSkin()->getCategories();
382 if ( isset( $prop[
'links'] ) ) {
383 $result_array[
'links'] = $this->
formatLinks( $p_result->getLinks() );
385 if ( isset( $prop[
'templates'] ) ) {
386 $result_array[
'templates'] = $this->
formatLinks( $p_result->getTemplates() );
388 if ( isset( $prop[
'images'] ) ) {
389 $result_array[
'images'] = array_keys( $p_result->getImages() );
391 if ( isset( $prop[
'externallinks'] ) ) {
392 $result_array[
'externallinks'] = array_keys( $p_result->getExternalLinks() );
394 if ( isset( $prop[
'sections'] ) ) {
395 $result_array[
'sections'] = $p_result->getSections();
397 if ( isset( $prop[
'parsewarnings'] ) ) {
398 $result_array[
'parsewarnings'] = $p_result->getWarnings();
401 if ( isset( $prop[
'displaytitle'] ) ) {
402 $result_array[
'displaytitle'] = $p_result->getDisplayTitle() ?:
403 $titleObj->getPrefixedText();
406 if ( isset( $prop[
'headitems'] ) ) {
408 $result_array[
'headitems'] = $this->
formatHeadItems( $outputPage->getHeadItemsArray() );
410 $result_array[
'headitems'] = $this->
formatHeadItems( $p_result->getHeadItems() );
414 if ( isset( $prop[
'headhtml'] ) ) {
415 $result_array[
'headhtml'] = $outputPage->headElement(
$context->
getSkin() );
419 if ( isset( $prop[
'modules'] ) ) {
421 $result_array[
'modules'] = $outputPage->getModules();
422 $result_array[
'modulescripts'] = $outputPage->getModuleScripts();
423 $result_array[
'modulestyles'] = $outputPage->getModuleStyles();
425 $result_array[
'modules'] = array_values( array_unique( $p_result->getModules() ) );
426 $result_array[
'modulescripts'] = array_values( array_unique( $p_result->getModuleScripts() ) );
427 $result_array[
'modulestyles'] = array_values( array_unique( $p_result->getModuleStyles() ) );
431 if ( isset( $prop[
'jsconfigvars'] ) ) {
432 $jsconfigvars = $skin ? $outputPage->getJsConfigVars() : $p_result->getJsConfigVars();
436 if ( isset( $prop[
'encodedjsconfigvars'] ) ) {
437 $jsconfigvars = $skin ? $outputPage->getJsConfigVars() : $p_result->getJsConfigVars();
438 $result_array[
'encodedjsconfigvars'] = FormatJson::encode(
446 if ( isset( $prop[
'modules'] ) &&
447 !isset( $prop[
'jsconfigvars'] ) && !isset( $prop[
'encodedjsconfigvars'] ) ) {
448 $this->
addWarning(
'apiwarn-moduleswithoutvars' );
451 if ( isset( $prop[
'indicators'] ) ) {
453 $result_array[
'indicators'] = (
array)$outputPage->getIndicators();
455 $result_array[
'indicators'] = (
array)$p_result->getIndicators();
460 if ( isset( $prop[
'iwlinks'] ) ) {
461 $result_array[
'iwlinks'] = $this->
formatIWLinks( $p_result->getInterwikiLinks() );
464 if ( isset( $prop[
'wikitext'] ) ) {
465 $result_array[
'wikitext'] = $this->content->serialize( $format );
467 if ( !is_null( $this->pstContent ) ) {
468 $result_array[
'psttext'] = $this->pstContent->serialize( $format );
472 if ( isset( $prop[
'properties'] ) ) {
473 $result_array[
'properties'] = (
array)$p_result->getProperties();
477 if ( isset( $prop[
'limitreportdata'] ) ) {
478 $result_array[
'limitreportdata'] =
481 if ( isset( $prop[
'limitreporthtml'] ) ) {
486 if ( isset( $prop[
'parsetree'] ) ||
$params[
'generatexml'] ) {
488 $this->
dieWithError(
'apierror-parsetree-notwikitext',
'notwikitext' );
491 $wgParser->startExternalParse( $titleObj, $popts, Parser::OT_PREPROCESS );
492 $dom =
$wgParser->preprocessToDom( $this->content->getNativeData() );
493 if ( is_callable( [ $dom,
'saveXML' ] ) ) {
494 $xml = $dom->saveXML();
496 $xml = $dom->__toString();
498 $result_array[
'parsetree'] = $xml;
505 'categories' =>
'cl',
509 'externallinks' =>
'el',
514 'indicators' =>
'ind',
515 'modulescripts' =>
'm',
516 'modulestyles' =>
'm',
517 'properties' =>
'pp',
518 'limitreportdata' =>
'lr',
519 'parsewarnings' =>
'pw'
522 $result->addValue(
null, $this->
getModuleName(), $result_array );
534 $popts = $pageObj->makeParserOptions( $this->
getContext() );
535 $popts->enableLimitReport( !
$params[
'disablepp'] && !
$params[
'disablelimitreport'] );
536 $popts->setIsPreview(
$params[
'preview'] ||
$params[
'sectionpreview'] );
537 $popts->setIsSectionPreview(
$params[
'sectionpreview'] );
538 $popts->setEditSection( !
$params[
'disableeditsection'] );
539 if (
$params[
'disabletidy'] ) {
540 $popts->setTidy(
false );
542 $popts->setWrapOutputClass(
543 $params[
'wrapoutputclass'] ===
'' ?
false :
$params[
'wrapoutputclass']
547 $suppressCache =
false;
548 Hooks::run(
'ApiMakeParserOptions',
549 [ $popts, $pageObj->getTitle(),
$params, $this, &$reset, &$suppressCache ] );
552 $suppressCache = $suppressCache || !$popts->isSafeToCache();
554 return [ $popts, $reset, $suppressCache ];
567 WikiPage $page, $popts, $suppressCache, $pageId,
$rev, $getContent
569 $revId =
$rev ?
$rev->getId() :
null;
572 if ( $getContent || $this->section !==
false || $isDeleted ) {
575 if ( !$this->content ) {
576 $this->
dieWithError( [
'apierror-missingcontent-revid', $revId ] );
580 if ( !$this->content ) {
581 $this->
dieWithError( [
'apierror-missingcontent-pageid', $pageId ] );
584 $this->contentIsDeleted = $isDeleted;
585 $this->contentIsSuppressed =
$rev &&
589 if ( $this->section !==
false ) {
592 $pageId ===
null ? $page->
getTitle()->getPrefixedText() : $this->
msg(
'pageid', $pageId )
594 return $this->content->getParserOutput( $page->
getTitle(), $revId, $popts );
599 $pout = $this->content->getParserOutput( $page->
getTitle(), $revId, $popts );
622 $this->
dieWithError( [
'apierror-nosuchsection-what', $this->section, $what ],
'nosuchsection' );
625 $this->
dieWithError( [
'apierror-sectionsnotsupported-what', $what ],
'nosuchsection' );
641 $summary = !is_null(
$params[
'summary'] ) ?
$params[
'summary'] :
'';
642 $sectionTitle = !is_null(
$params[
'sectiontitle'] ) ?
$params[
'sectiontitle'] :
'';
644 if ( $this->section ===
'new' && ( $sectionTitle ===
'' || $summary ===
'' ) ) {
645 if ( $sectionTitle !==
'' ) {
646 $summary =
$params[
'sectiontitle'];
648 if ( $summary !==
'' ) {
649 $summary =
wfMessage(
'newsectionsummary' )
650 ->rawParams(
$wgParser->stripSectionName( $summary ) )
651 ->inContentLanguage()->text();
659 foreach ( $links as
$link ) {
661 $bits = explode(
':',
$link, 2 );
662 $title = Title::newFromText(
$link );
664 $entry[
'lang'] = $bits[0];
668 $entry[
'langname'] = Language::fetchLanguageName(
669 $title->getInterwiki(),
670 $this->getLanguage()->getCode()
674 $entry[
'autonym'] = Language::fetchLanguageName( $title->getInterwiki() );
693 $db = $this->
getDB();
694 $res = $db->select( [
'page',
'page_props' ],
695 [
'page_title',
'pp_propname' ],
696 $lb->constructSet(
'page', $db ),
700 'LEFT JOIN', [
'pp_propname' =>
'hiddencat',
'pp_page = page_id' ]
704 foreach (
$res as $row ) {
705 $hiddencats[$row->page_title] = isset( $row->pp_propname );
708 $linkCache = LinkCache::singleton();
710 foreach ( $links as
$link => $sortkey ) {
712 $entry[
'sortkey'] = $sortkey;
715 if ( !isset( $hiddencats[
$link] ) ) {
716 $entry[
'missing'] =
true;
721 $linkCache->addBadLinkObj( $title );
722 if ( $title->isKnown() ) {
723 $entry[
'known'] =
true;
725 } elseif ( $hiddencats[
$link] ) {
726 $entry[
'hidden'] =
true;
736 foreach ( $links as $ns => $nslinks ) {
737 foreach ( $nslinks as $title => $id ) {
741 $entry[
'exists'] = $id != 0;
751 foreach ( $iw as $prefix =>
$titles ) {
752 foreach ( array_keys(
$titles ) as $title ) {
754 $entry[
'prefix'] = $prefix;
756 $title = Title::newFromText(
"{$prefix}:{$title}" );
771 foreach ( $headItems as $tag =>
$content ) {
773 $entry[
'tag'] = $tag;
784 foreach ( $limitReportData as $name =>
$value ) {
786 $entry[
'name'] =
$name;
787 if ( !is_array(
$value ) ) {
791 $entry = array_merge( $entry,
$value );
799 foreach ( $mapping as $key => $name ) {
800 if ( isset( $array[$key] ) ) {
820 'redirects' =>
false,
826 'images|externallinks|sections|revid|displaytitle|iwlinks|' .
827 'properties|parsewarnings',
844 'encodedjsconfigvars',
859 'headitems' =>
'apiwarn-deprecation-parse-headitems',
862 'wrapoutputclass' =>
'mw-parser-output',
865 'effectivelanglinks' => [
877 'disablelimitreport' =>
false,
878 'disableeditsection' =>
false,
879 'disabletidy' =>
false,
888 'sectionpreview' =>
false,
889 'disabletoc' =>
false,
904 'action=parse&page=Project:Sandbox'
905 =>
'apihelp-parse-example-page',
906 'action=parse&text={{Project:Sandbox}}&contentmodel=wikitext'
907 =>
'apihelp-parse-example-text',
908 'action=parse&text={{PAGENAME}}&title=Test'
909 =>
'apihelp-parse-example-texttitle',
910 'action=parse&summary=Some+[[link]]&prop='
911 =>
'apihelp-parse-example-summary',
916 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Parsing_wikitext#parse';
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
if(! $wgRequest->checkUrlExtension()) if(isset($_SERVER[ 'PATH_INFO']) &&$_SERVER[ 'PATH_INFO'] !='') if(! $wgEnableAPI) $wgTitle
This abstract class implements many basic API functions, and is the base of all API classes.
const PARAM_DEPRECATED
(boolean) Is the parameter deprecated (will show a warning)?
getDB()
Gets a default replica DB connection object.
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
const PARAM_DEPRECATED_VALUES
(array) When PARAM_TYPE is an array, this indicates which of the values are deprecated.
getMain()
Get the main module.
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below.
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
extractRequestParams( $parseLimit=true)
Using getAllowedParams(), this function makes an array of the values provided by the user,...
const PARAM_HELP_MSG_PER_VALUE
((string|array|Message)[]) When PARAM_TYPE is an array, this is an array mapping those values to $msg...
getResult()
Get the result object.
requireMaxOneParameter( $params, $required)
Die if more than one of a certain set of parameters is set and not false.
dieWithException( $exception, array $options=[])
Abort execution with an error derived from an exception.
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
addWarning( $msg, $code=null, $data=null)
Add a warning for this module.
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.
checkTitleUserPermissions(Title $title, $actions, $user=null)
Helper function for permission-denied errors.
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
This is the main API class, used for both external and internal processing.
static create( $msg, $code=null, array $data=null)
Create an IApiMessage for the message.
This class contains a list of pages that the client has requested.
formatSummary( $title, $params)
This mimicks the behavior of EditPage in formatting a summary.
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
getParsedContent(WikiPage $page, $popts, $suppressCache, $pageId, $rev, $getContent)
formatHeadItems( $headItems)
getExamplesMessages()
Returns usage examples for this module.
formatCategoryLinks( $links)
formatLimitReportData( $limitReportData)
makeParserOptions(WikiPage $pageObj, array $params)
Constructs a ParserOptions object.
bool $contentIsSuppressed
getSectionContent(Content $content, $what)
Extract the requested section from the given Content.
getHelpUrls()
Return links to more detailed help pages about the module.
setIndexedTagNames(&$array, $mapping)
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
static setArrayType(array &$arr, $type, $kvpKeyName=null)
Set the array data type.
static addMetadataToResultVars( $vars, $forceHash=true)
Add the correct metadata to an array of vars we want to export through the API.
const META_SUBELEMENTS
Key for the 'subelements' metadata item.
const META_BC_SUBELEMENTS
Key for the 'BC subelements' metadata item.
static setIndexedTagName(array &$arr, $tag)
Set the tag name for numeric-keyed values in XML format.
static setContentValue(array &$arr, $name, $value, $flags=0)
Add an output value to the array by name and mark as META_CONTENT.
static setIndexedTagNameRecursive(array &$arr, $tag)
Set indexed tag name on $arr and all subarrays.
static newFromTitle( $title, IContextSource $context)
Create an Article object of the appropriate class for the given page.
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 getContentModels()
msg( $key)
Get a Message object with context set Parameters are the same as wfMessage()
getUser()
Get the User object.
getContext()
Get the base IContextSource object.
An IContextSource implementation which will inherit context from another source but allow individual ...
static getPreviewLimitReport( $output)
Get the Limit report for page previews.
WebRequest clone which takes values from a provided array.
Class representing a list of titles The execute() method checks them all for existence and adds them ...
setArray( $array)
Set the link list to a given 2-d array First key is the namespace, second is the DB key,...
static formatComment( $comment, $title=null, $local=false, $wikiId=null)
This function is called by all recent changes variants, by the page history, and by the user contribu...
Exception representing a failure to serialize or unserialize a content object.
This class should be covered by a general architecture document which does not exist as of January 20...
static newFromId( $id, $flags=0)
Load a page revision from a given revision ID number.
static getAllowedSkins()
Fetch the list of user-selectable skins in regards to $wgSkipSkins.
static normalizeKey( $key)
Normalize a skin preference value to a form that can be loaded.
Class representing a MediaWiki article and history.
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
getLatest()
Get the page_latest field.
getParserOutput(ParserOptions $parserOptions, $oldid=null, $forceParse=false)
Get a ParserOutput for the given ParserOptions and revision ID.
getContent( $audience=Revision::FOR_PUBLIC, User $user=null)
Get the content of the current revision.
getTitle()
Get the title object of the article.
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 hook is for auditing only $req
the array() calling protocol came about after MediaWiki 1.4rc1.
namespace being checked & $result
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 unset offset - wrap String Wrap the message in html(usually something like "<div ...>$1</div>"). - flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException':Called before an exception(or PHP error) is logged. This is meant for integration with external error aggregation services
usually copyright or history_copyright This message must be in HTML not wikitext & $link
Allows to change the fields on the form that will be generated $name
presenting them properly to the user as errors is done by the caller return true use this to change the list i e etc $rev
const CONTENT_MODEL_WIKITEXT
Base interface for content objects.
getSkin()
Get the Skin object.
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