44 $this->
getMain()->setCacheMode(
'anon-public-user-private' );
57 if ( $title ===
null ) {
58 $titleProvided =
false;
62 $titleProvided =
true;
69 $model =
$params[
'contentmodel'];
70 $format =
$params[
'contentformat'];
75 $this->section =
$params[
'section'];
76 if ( !
preg_match(
'/^((T-)?\d+|new)$/', $this->section ) ) {
80 $this->section =
false;
90 $needContent =
isset( $prop[
'wikitext'] ) ||
97 if ( $this->section ===
'new' ) {
98 $this->
dieWithError(
'apierror-invalidparammix-parse-new-section',
'invalidparammix' );
104 $this->
dieWithError( [
'apierror-nosuchrevid', $oldid ] );
110 [
'apierror-permissiondenied', $this->
msg(
'action-deletedtext' ) ]
114 $titleObj =
$rev->getTitle();
116 $pageObj = WikiPage::factory( $titleObj );
119 $pageObj, $popts, $suppressCache, $pageid,
$rev, $needContent
127 $reqParams[
'pageids'] =
$pageid;
129 $reqParams[
'titles'] = $page;
135 $redirValues = $pageSet->getRedirectTitlesAsResult( $this->
getResult() );
138 foreach ( $pageSet->getRedirectTitles() as $title ) {
139 $to = $title->getFullText();
141 $pageParams = [
'title' => $to ];
143 $pageParams = [
'pageid' =>
$pageid ];
145 $pageParams = [
'title' => $page ];
149 $titleObj = $pageObj->getTitle();
150 if ( !$titleObj || !$titleObj->exists() ) {
157 if (
isset( $prop[
'revid'] ) ) {
158 $oldid = $pageObj->getLatest();
163 $pageObj, $popts, $suppressCache, $pageid,
null, $needContent
167 $titleObj = Title::newFromText( $title );
168 if ( !$titleObj || $titleObj->isExternal() ) {
172 if ( $revid !==
null ) {
175 $this->
dieWithError( [
'apierror-nosuchrevid', $revid ] );
178 $titleObj =
$rev->getTitle();
179 if ( $titleProvided ) {
180 if ( !$titleObj->equals( $pTitleObj ) ) {
187 $titleProvided =
true;
191 if ( $titleObj->canExist() ) {
192 $pageObj = WikiPage::factory( $titleObj );
200 $textProvided = !
is_null( $text );
202 if ( !$textProvided ) {
203 if ( $titleProvided && ( $prop ||
$params[
'generatexml'] ) ) {
204 if ( $revid !==
null ) {
205 $this->
addWarning(
'apiwarn-parse-revidwithouttext' );
207 $this->
addWarning(
'apiwarn-parse-titlewithouttext' );
216 if ( $textProvided && !$titleProvided &&
is_null( $model ) ) {
218 $this->
addWarning( [
'apiwarn-parse-nocontentmodel', $model ] );
222 $this->content = ContentHandler::makeContent( $text, $titleObj, $model, $format );
225 'wrap' =>
ApiMessage::create(
'apierror-contentserializationexception',
'parseerror' )
229 if ( $this->section !==
false ) {
230 if ( $this->section ===
'new' ) {
233 $this->content = $this->content->addSectionHeader(
$params[
'sectiontitle'] );
236 $this->content = $this->
getSectionContent( $this->content, $titleObj->getPrefixedText() );
241 $this->pstContent = $this->content->preSaveTransform( $titleObj, $this->
getUser(), $popts );
246 $result_array[
'text'] = $this->pstContent->serialize( $format );
248 if (
isset( $prop[
'wikitext'] ) ) {
249 $result_array[
'wikitext'] = $this->content->serialize( $format );
253 ( !
is_null(
$params[
'sectiontitle'] ) && $this->section ===
'new' )
259 $result->addValue(
null, $this->
getModuleName(), $result_array );
266 $p_result = $this->pstContent->getParserOutput( $titleObj, $revid, $popts );
268 $p_result = $this->content->getParserOutput( $titleObj, $revid, $popts );
274 $result_array[
'title'] = $titleObj->getPrefixedText();
275 $result_array[
'pageid'] = $pageid ?: $pageObj->getId();
276 if ( $this->contentIsDeleted ) {
277 $result_array[
'textdeleted'] =
true;
279 if ( $this->contentIsSuppressed ) {
280 $result_array[
'textsuppressed'] =
true;
284 $factory = MediaWikiServices::getInstance()->getSkinFactory();
285 $skin = $factory->makeSkin( Skin::normalizeKey(
$params[
'useskin'] ) );
291 if ( $skin ||
isset( $prop[
'headhtml'] ) ||
isset( $prop[
'categorieshtml'] ) ) {
316 $outputPage->addParserOutputMetadata( $p_result );
317 if ( $this->content ) {
318 $outputPage->addContentOverride( $titleObj, $this->content );
324 $skin->setupSkinUserCss( $outputPage );
326 $outputPage->loadSkinModules( $skin );
329 Hooks::run(
'ApiParseMakeOutputPage', [ $this, $outputPage ] );
333 $result_array[
'revid'] = (
int)$oldid;
340 if (
isset( $prop[
'text'] ) ) {
341 $result_array[
'text'] = $p_result->getText( [
342 'allowTOC' => !
$params[
'disabletoc'],
343 'enableSectionEditLinks' => !
$params[
'disableeditsection'],
344 'wrapperDivClass' =>
$params[
'wrapoutputclass'],
345 'deduplicateStyles' => !
$params[
'disablestylededuplication'],
351 ( !
is_null(
$params[
'sectiontitle'] ) && $this->section ===
'new' )
357 if (
isset( $prop[
'langlinks'] ) ) {
359 $langlinks = $outputPage->getLanguageLinks();
361 $langlinks = $p_result->getLanguageLinks();
365 if (
$params[
'effectivelanglinks'] ) {
367 Hooks::run(
'LanguageLinks', [ $titleObj, &$langlinks, &$linkFlags ] );
373 if (
isset( $prop[
'categories'] ) ) {
376 if (
isset( $prop[
'categorieshtml'] ) ) {
377 $result_array[
'categorieshtml'] = $outputPage->getSkin()->getCategories();
380 if (
isset( $prop[
'links'] ) ) {
381 $result_array[
'links'] = $this->
formatLinks( $p_result->getLinks() );
383 if (
isset( $prop[
'templates'] ) ) {
384 $result_array[
'templates'] = $this->
formatLinks( $p_result->getTemplates() );
386 if (
isset( $prop[
'images'] ) ) {
387 $result_array[
'images'] =
array_keys( $p_result->getImages() );
389 if (
isset( $prop[
'externallinks'] ) ) {
390 $result_array[
'externallinks'] =
array_keys( $p_result->getExternalLinks() );
392 if (
isset( $prop[
'sections'] ) ) {
393 $result_array[
'sections'] = $p_result->getSections();
395 if (
isset( $prop[
'parsewarnings'] ) ) {
396 $result_array[
'parsewarnings'] = $p_result->getWarnings();
399 if (
isset( $prop[
'displaytitle'] ) ) {
400 $result_array[
'displaytitle'] = $p_result->getDisplayTitle() !==
false
401 ? $p_result->getDisplayTitle() : $titleObj->getPrefixedText();
404 if (
isset( $prop[
'headitems'] ) ) {
406 $result_array[
'headitems'] = $this->
formatHeadItems( $outputPage->getHeadItemsArray() );
408 $result_array[
'headitems'] = $this->
formatHeadItems( $p_result->getHeadItems() );
412 if (
isset( $prop[
'headhtml'] ) ) {
413 $result_array[
'headhtml'] = $outputPage->headElement(
$context->
getSkin() );
417 if (
isset( $prop[
'modules'] ) ) {
419 $result_array[
'modules'] = $outputPage->getModules();
421 $result_array[
'modulescripts'] = [];
422 $result_array[
'modulestyles'] = $outputPage->getModuleStyles();
426 $result_array[
'modulescripts'] = [];
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 $xml =
$wgParser->preprocessToDom( $this->content->getText() )->__toString();
493 $result_array[
'parsetree'] = $xml;
500 'categories' =>
'cl',
504 'externallinks' =>
'el',
509 'indicators' =>
'ind',
510 'modulescripts' =>
'm',
511 'modulestyles' =>
'm',
512 'properties' =>
'pp',
513 'limitreportdata' =>
'lr',
514 'parsewarnings' =>
'pw'
517 $result->addValue(
null, $this->
getModuleName(), $result_array );
529 $popts = $pageObj->makeParserOptions( $this->
getContext() );
530 $popts->enableLimitReport( !
$params[
'disablepp'] && !
$params[
'disablelimitreport'] );
531 $popts->setIsPreview(
$params[
'preview'] ||
$params[
'sectionpreview'] );
532 $popts->setIsSectionPreview(
$params[
'sectionpreview'] );
533 if (
$params[
'disabletidy'] ) {
534 $popts->setTidy(
false );
536 if (
$params[
'wrapoutputclass'] !==
'' ) {
537 $popts->setWrapOutputClass(
$params[
'wrapoutputclass'] );
541 $suppressCache =
false;
542 Hooks::run(
'ApiMakeParserOptions',
543 [ $popts, $pageObj->getTitle(),
$params, $this, &$reset, &$suppressCache ] );
546 $suppressCache = $suppressCache || !$popts->isSafeToCache();
561 WikiPage $page, $popts, $suppressCache, $pageId,
$rev, $getContent
563 $revId =
$rev ?
$rev->getId() :
null;
566 if ( $getContent || $this->section !==
false || $isDeleted ) {
569 if ( !$this->content ) {
570 $this->
dieWithError( [
'apierror-missingcontent-revid', $revId ] );
574 if ( !$this->content ) {
579 $this->contentIsSuppressed =
$rev &&
583 if ( $this->section !==
false ) {
586 $pageId ===
null ? $page->getTitle()->getPrefixedText() : $this->
msg(
'pageid', $pageId )
588 return $this->content->getParserOutput( $page->getTitle(), $revId, $popts );
593 $pout = $this->content->getParserOutput( $page->getTitle(), $revId, $popts );
596 $pout = $page->getParserOutput( $popts, $revId, $suppressCache );
599 $this->
dieWithError( [
'apierror-nosuchrevid', $revId ?: $page->getLatest() ] );
616 $this->
dieWithError( [
'apierror-nosuchsection-what', $this->section, $what ],
'nosuchsection' );
619 $this->
dieWithError( [
'apierror-sectionsnotsupported-what', $what ],
'nosuchsection' );
635 $summary =
$params[
'summary'] ??
'';
636 $sectionTitle =
$params[
'sectiontitle'] ??
'';
638 if ( $this->section ===
'new' && ( $sectionTitle ===
'' || $summary ===
'' ) ) {
639 if ( $sectionTitle !==
'' ) {
640 $summary =
$params[
'sectiontitle'];
642 if ( $summary !==
'' ) {
643 $summary =
wfMessage(
'newsectionsummary' )
644 ->rawParams(
$wgParser->stripSectionName( $summary ) )
645 ->inContentLanguage()->text();
653 foreach ( $links as
$link ) {
655 $bits = explode(
':',
$link, 2 );
656 $title = Title::newFromText(
$link );
658 $entry[
'lang'] = $bits[0];
662 $entry[
'langname'] = Language::fetchLanguageName(
663 $title->getInterwiki(),
664 $this->getLanguage()->getCode()
668 $entry[
'autonym'] = Language::fetchLanguageName( $title->getInterwiki() );
687 $db = $this->
getDB();
688 $res = $db->select( [
'page',
'page_props' ],
689 [
'page_title',
'pp_propname' ],
690 $lb->constructSet(
'page', $db ),
694 'LEFT JOIN', [
'pp_propname' =>
'hiddencat',
'pp_page = page_id' ]
698 foreach (
$res as $row ) {
699 $hiddencats[$row->page_title] =
isset( $row->pp_propname );
702 $linkCache = MediaWikiServices::getInstance()->getLinkCache();
704 foreach ( $links as
$link => $sortkey ) {
710 $entry[
'missing'] =
true;
715 $linkCache->addBadLinkObj( $title );
716 if ( $title->isKnown() ) {
717 $entry[
'known'] =
true;
720 $entry[
'hidden'] =
true;
730 foreach ( $links as $ns => $nslinks ) {
731 foreach ( $nslinks as $title => $id ) {
735 $entry[
'exists'] = $id != 0;
745 foreach ( $iw as $prefix =>
$titles ) {
748 $entry[
'prefix'] = $prefix;
750 $title = Title::newFromText(
"{$prefix}:{$title}" );
765 foreach ( $headItems as $tag =>
$content ) {
767 $entry[
'tag'] = $tag;
778 foreach ( $limitReportData as $name =>
$value ) {
780 $entry[
'name'] =
$name;
793 foreach ( $mapping as $key => $name ) {
794 if (
isset( $array[$key] ) ) {
814 'redirects' =>
false,
820 'images|externallinks|sections|revid|displaytitle|iwlinks|' .
821 'properties|parsewarnings',
838 'encodedjsconfigvars',
853 'headitems' =>
'apiwarn-deprecation-parse-headitems',
856 'wrapoutputclass' =>
'mw-parser-output',
859 'effectivelanglinks' => [
871 'disablelimitreport' =>
false,
872 'disableeditsection' =>
false,
877 'disablestylededuplication' =>
false,
886 'sectionpreview' =>
false,
887 'disabletoc' =>
false,
902 'action=parse&page=Project:Sandbox'
903 =>
'apihelp-parse-example-page',
904 'action=parse&text={{Project:Sandbox}}&contentmodel=wikitext'
905 =>
'apihelp-parse-example-text',
906 'action=parse&text={{PAGENAME}}&title=Test'
907 =>
'apihelp-parse-example-texttitle',
908 'action=parse&summary=Some+[[link]]&prop='
909 =>
'apihelp-parse-example-summary',
914 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Parsing_wikitext#parse';
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
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'] !='') $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.
checkTitleUserPermissions(Title $title, $actions, $options=[])
Helper function for permission-denied errors.
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.
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.
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
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.
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.
msg( $key)
Get a Message object with context set Parameters are the same as wfMessage()
getContext()
Get the base IContextSource object.
An IContextSource implementation which will inherit context from another source but allow individual ...
static getPreviewLimitReport(ParserOutput $output=null)
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.
Class representing a MediaWiki article and history.
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
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 use $formDescriptor instead 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
return true to allow those checks to and false if checking is done remove or add to the links of a group of changes in EnhancedChangesList Hook subscribers can return false to omit this line from recentchanges use this to change the tables headers change it to an object instance and return false override the list derivative used the name of the old file & $article
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.
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
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))