$this->section = $params['section'];
if ( !preg_match( '/^((T-)?\d+|new)$/', $this->section ) ) {
$this->dieUsage(
- "The section parameter must be a valid section id or 'new'", "invalidsection"
+ 'The section parameter must be a valid section id or "new"', 'invalidsection'
);
}
} else {
$titleObj = $rev->getTitle();
$wgTitle = $titleObj;
$pageObj = WikiPage::factory( $titleObj );
- $popts = $this->makeParserOptions( $pageObj, $params );
+ list( $popts, $reset, $suppressCache ) = $this->makeParserOptions( $pageObj, $params );
// If for some reason the "oldid" is actually the current revision, it may be cached
// Deliberately comparing $pageObj->getLatest() with $rev->getId(), rather than
// checking $rev->isCurrent(), because $pageObj is what actually ends up being used,
// and if its ->getLatest() is outdated, $rev->isCurrent() won't tell us that.
- if ( $rev->getId() == $pageObj->getLatest() ) {
+ if ( !$suppressCache && $rev->getId() == $pageObj->getLatest() ) {
// May get from/save to parser cache
$p_result = $this->getParsedContent( $pageObj, $popts,
$pageid, isset( $prop['wikitext'] ) );
}
} else { // Not $oldid, but $pageid or $page
if ( $params['redirects'] ) {
- $reqParams = array(
+ $reqParams = [
'redirects' => '',
- );
+ ];
if ( !is_null( $pageid ) ) {
$reqParams['pageids'] = $pageid;
} else { // $page
foreach ( $pageSet->getRedirectTitles() as $title ) {
$to = $title->getFullText();
}
- $pageParams = array( 'title' => $to );
+ $pageParams = [ 'title' => $to ];
} elseif ( !is_null( $pageid ) ) {
- $pageParams = array( 'pageid' => $pageid );
+ $pageParams = [ 'pageid' => $pageid ];
} else { // $page
- $pageParams = array( 'title' => $page );
+ $pageParams = [ 'title' => $page ];
}
$pageObj = $this->getTitleOrPageId( $pageParams, 'fromdb' );
$oldid = $pageObj->getLatest();
}
- $popts = $this->makeParserOptions( $pageObj, $params );
+ list( $popts, $reset, $suppressCache ) = $this->makeParserOptions( $pageObj, $params );
// Don't pollute the parser cache when setting options that aren't
// in ParserOptions::optionsHash()
/// @todo: This should be handled closer to the actual cache instead of here, see T110269
- $suppressCache =
+ $suppressCache = $suppressCache ||
$params['disablepp'] ||
$params['disablelimitreport'] ||
$params['preview'] ||
} else { // Not $oldid, $pageid, $page. Hence based on $text
$titleObj = Title::newFromText( $title );
if ( !$titleObj || $titleObj->isExternal() ) {
- $this->dieUsageMsg( array( 'invalidtitle', $title ) );
+ $this->dieUsageMsg( [ 'invalidtitle', $title ] );
}
$wgTitle = $titleObj;
if ( $titleObj->canExist() ) {
$pageObj = $article->getPage();
}
- $popts = $this->makeParserOptions( $pageObj, $params );
+ list( $popts, $reset ) = $this->makeParserOptions( $pageObj, $params );
$textProvided = !is_null( $text );
if ( !$textProvided ) {
}
if ( $params['onlypst'] ) {
// Build a result and bail out
- $result_array = array();
+ $result_array = [];
$result_array['text'] = $this->pstContent->serialize( $format );
$result_array[ApiResult::META_BC_SUBELEMENTS][] = 'text';
if ( isset( $prop['wikitext'] ) ) {
}
}
- $result_array = array();
+ $result_array = [];
$result_array['title'] = $titleObj->getPrefixedText();
- $result_array['pageid'] = $pageid ? $pageid : $pageObj->getId();
+ $result_array['pageid'] = $pageid ?: $pageObj->getId();
if ( !is_null( $oldid ) ) {
$result_array['revid'] = intval( $oldid );
if ( $params['effectivelanglinks'] ) {
// Link flags are ignored for now, but may in the future be
// included in the result.
- $linkFlags = array();
- Hooks::run( 'LanguageLinks', array( $titleObj, &$langlinks, &$linkFlags ) );
+ $linkFlags = [];
+ Hooks::run( 'LanguageLinks', [ $titleObj, &$langlinks, &$linkFlags ] );
}
} else {
$langlinks = false;
}
if ( isset( $prop['displaytitle'] ) ) {
- $result_array['displaytitle'] = $p_result->getDisplayTitle() ?
- $p_result->getDisplayTitle() :
+ $result_array['displaytitle'] = $p_result->getDisplayTitle() ?:
$titleObj->getPrefixedText();
}
$css = $this->formatCss( $context->getOutput()->buildCssLinksArray() );
- $scripts = array( $context->getOutput()->getHeadScripts() );
+ $scripts = [ $context->getOutput()->getHeadScripts() ];
$result_array['headitems'] = array_merge( $headItems, $css, $scripts );
}
$result_array['modulescripts'] = array_values( array_unique( $p_result->getModuleScripts() ) );
$result_array['modulestyles'] = array_values( array_unique( $p_result->getModuleStyles() ) );
// To be removed in 1.27
- $result_array['modulemessages'] = array();
+ $result_array['modulemessages'] = [];
$this->setWarning( 'modulemessages is deprecated since MediaWiki 1.26' );
}
if ( isset( $prop['modules'] ) &&
!isset( $prop['jsconfigvars'] ) && !isset( $prop['encodedjsconfigvars'] ) ) {
- $this->setWarning( "Property 'modules' was set but not 'jsconfigvars' " .
- "or 'encodedjsconfigvars'. Configuration variables are necessary " .
- "for proper module usage." );
+ $this->setWarning( 'Property "modules" was set but not "jsconfigvars" ' .
+ 'or "encodedjsconfigvars". Configuration variables are necessary ' .
+ 'for proper module usage.' );
}
if ( isset( $prop['indicators'] ) ) {
if ( isset( $prop['parsetree'] ) || $params['generatexml'] ) {
if ( $this->content->getModel() != CONTENT_MODEL_WIKITEXT ) {
- $this->dieUsage( "parsetree is only supported for wikitext content", "notwikitext" );
+ $this->dieUsage( 'parsetree is only supported for wikitext content', 'notwikitext' );
}
$wgParser->startExternalParse( $titleObj, $popts, Parser::OT_PREPROCESS );
$dom = $wgParser->preprocessToDom( $this->content->getNativeData() );
- if ( is_callable( array( $dom, 'saveXML' ) ) ) {
+ if ( is_callable( [ $dom, 'saveXML' ] ) ) {
$xml = $dom->saveXML();
} else {
$xml = $dom->__toString();
$result_array[ApiResult::META_BC_SUBELEMENTS][] = 'parsetree';
}
- $result_mapping = array(
+ $result_mapping = [
'redirects' => 'r',
'langlinks' => 'll',
'categories' => 'cl',
'modulemessages' => 'm',
'properties' => 'pp',
'limitreportdata' => 'lr',
- );
+ ];
$this->setIndexedTagNames( $result_array, $result_mapping );
$result->addValue( null, $this->getModuleName(), $result_array );
}
* @param WikiPage $pageObj
* @param array $params
*
- * @return ParserOptions
+ * @return array [ ParserOptions, ScopedCallback, bool $suppressCache ]
*/
protected function makeParserOptions( WikiPage $pageObj, array $params ) {
-
$popts = $pageObj->makeParserOptions( $this->getContext() );
$popts->enableLimitReport( !$params['disablepp'] && !$params['disablelimitreport'] );
$popts->setIsPreview( $params['preview'] || $params['sectionpreview'] );
$popts->setTidy( false );
}
- return $popts;
+ $reset = null;
+ $suppressCache = false;
+ Hooks::run( 'ApiMakeParserOptions',
+ [ $popts, $pageObj->getTitle(), $params, $this, &$reset, &$suppressCache ] );
+
+ return [ $popts, $reset, $suppressCache ];
}
/**
// Not cached (save or load)
$section = $content->getSection( $this->section );
if ( $section === false ) {
- $this->dieUsage( "There is no section {$this->section} in " . $what, 'nosuchsection' );
+ $this->dieUsage( "There is no section {$this->section} in $what", 'nosuchsection' );
}
if ( $section === null ) {
- $this->dieUsage( "Sections are not supported by " . $what, 'nosuchsection' );
+ $this->dieUsage( "Sections are not supported by $what", 'nosuchsection' );
$section = false;
}
}
private function formatLangLinks( $links ) {
- $result = array();
+ $result = [];
foreach ( $links as $link ) {
- $entry = array();
+ $entry = [];
$bits = explode( ':', $link, 2 );
$title = Title::newFromText( $link );
}
private function formatCategoryLinks( $links ) {
- $result = array();
+ $result = [];
if ( !$links ) {
return $result;
// Fetch hiddencat property
$lb = new LinkBatch;
- $lb->setArray( array( NS_CATEGORY => $links ) );
+ $lb->setArray( [ NS_CATEGORY => $links ] );
$db = $this->getDB();
- $res = $db->select( array( 'page', 'page_props' ),
- array( 'page_title', 'pp_propname' ),
+ $res = $db->select( [ 'page', 'page_props' ],
+ [ 'page_title', 'pp_propname' ],
$lb->constructSet( 'page', $db ),
__METHOD__,
- array(),
- array( 'page_props' => array(
- 'LEFT JOIN', array( 'pp_propname' => 'hiddencat', 'pp_page = page_id' )
- ) )
+ [],
+ [ 'page_props' => [
+ 'LEFT JOIN', [ 'pp_propname' => 'hiddencat', 'pp_page = page_id' ]
+ ] ]
);
- $hiddencats = array();
+ $hiddencats = [];
foreach ( $res as $row ) {
$hiddencats[$row->page_title] = isset( $row->pp_propname );
}
foreach ( $links as $link => $sortkey ) {
- $entry = array();
+ $entry = [];
$entry['sortkey'] = $sortkey;
// array keys will cast numeric category names to ints, so cast back to string
ApiResult::setContentValue( $entry, 'category', (string)$link );
}
private function formatLinks( $links ) {
- $result = array();
+ $result = [];
foreach ( $links as $ns => $nslinks ) {
foreach ( $nslinks as $title => $id ) {
- $entry = array();
+ $entry = [];
$entry['ns'] = $ns;
ApiResult::setContentValue( $entry, 'title', Title::makeTitle( $ns, $title )->getFullText() );
$entry['exists'] = $id != 0;
}
private function formatIWLinks( $iw ) {
- $result = array();
+ $result = [];
foreach ( $iw as $prefix => $titles ) {
foreach ( array_keys( $titles ) as $title ) {
- $entry = array();
+ $entry = [];
$entry['prefix'] = $prefix;
$title = Title::newFromText( "{$prefix}:{$title}" );
}
private function formatHeadItems( $headItems ) {
- $result = array();
+ $result = [];
foreach ( $headItems as $tag => $content ) {
- $entry = array();
+ $entry = [];
$entry['tag'] = $tag;
ApiResult::setContentValue( $entry, 'content', $content );
$result[] = $entry;
}
private function formatCss( $css ) {
- $result = array();
+ $result = [];
foreach ( $css as $file => $link ) {
- $entry = array();
+ $entry = [];
$entry['file'] = $file;
ApiResult::setContentValue( $entry, 'link', $link );
$result[] = $entry;
}
private function formatLimitReportData( $limitReportData ) {
- $result = array();
+ $result = [];
foreach ( $limitReportData as $name => $value ) {
- $entry = array();
+ $entry = [];
$entry['name'] = $name;
if ( !is_array( $value ) ) {
- $value = array( $value );
+ $value = [ $value ];
}
ApiResult::setIndexedTagNameRecursive( $value, 'param' );
$entry = array_merge( $entry, $value );
}
public function getAllowedParams() {
- return array(
+ return [
'title' => null,
- 'text' => array(
+ 'text' => [
ApiBase::PARAM_TYPE => 'text',
- ),
+ ],
'summary' => null,
'page' => null,
- 'pageid' => array(
+ 'pageid' => [
ApiBase::PARAM_TYPE => 'integer',
- ),
+ ],
'redirects' => false,
- 'oldid' => array(
+ 'oldid' => [
ApiBase::PARAM_TYPE => 'integer',
- ),
- 'prop' => array(
+ ],
+ 'prop' => [
ApiBase::PARAM_DFLT => 'text|langlinks|categories|links|templates|' .
'images|externallinks|sections|revid|displaytitle|iwlinks|properties',
ApiBase::PARAM_ISMULTI => true,
- ApiBase::PARAM_TYPE => array(
+ ApiBase::PARAM_TYPE => [
'text',
'langlinks',
'categories',
'limitreportdata',
'limitreporthtml',
'parsetree',
- ),
- ApiBase::PARAM_HELP_MSG_PER_VALUE => array(
- 'parsetree' => array( 'apihelp-parse-paramvalue-prop-parsetree', CONTENT_MODEL_WIKITEXT ),
- ),
- ),
+ ],
+ ApiBase::PARAM_HELP_MSG_PER_VALUE => [
+ 'parsetree' => [ 'apihelp-parse-paramvalue-prop-parsetree', CONTENT_MODEL_WIKITEXT ],
+ ],
+ ],
'pst' => false,
'onlypst' => false,
'effectivelanglinks' => false,
'section' => null,
- 'sectiontitle' => array(
+ 'sectiontitle' => [
ApiBase::PARAM_TYPE => 'string',
- ),
- 'disablepp' => array(
+ ],
+ 'disablepp' => [
ApiBase::PARAM_DFLT => false,
ApiBase::PARAM_DEPRECATED => true,
- ),
+ ],
'disablelimitreport' => false,
'disableeditsection' => false,
'disabletidy' => false,
- 'generatexml' => array(
+ 'generatexml' => [
ApiBase::PARAM_DFLT => false,
- ApiBase::PARAM_HELP_MSG => array(
+ ApiBase::PARAM_HELP_MSG => [
'apihelp-parse-param-generatexml', CONTENT_MODEL_WIKITEXT
- ),
+ ],
ApiBase::PARAM_DEPRECATED => true,
- ),
+ ],
'preview' => false,
'sectionpreview' => false,
'disabletoc' => false,
- 'contentformat' => array(
+ 'contentformat' => [
ApiBase::PARAM_TYPE => ContentHandler::getAllContentFormats(),
- ),
- 'contentmodel' => array(
+ ],
+ 'contentmodel' => [
ApiBase::PARAM_TYPE => ContentHandler::getContentModels(),
- )
- );
+ ]
+ ];
}
protected function getExamplesMessages() {
- return array(
+ return [
'action=parse&page=Project:Sandbox'
=> 'apihelp-parse-example-page',
'action=parse&text={{Project:Sandbox}}&contentmodel=wikitext'
=> 'apihelp-parse-example-texttitle',
'action=parse&summary=Some+[[link]]&prop='
=> 'apihelp-parse-example-summary',
- );
+ ];
}
public function getHelpUrls() {