2007-12-01 13:37:02 +00:00
|
|
|
<?php
|
2010-02-23 18:05:46 +00:00
|
|
|
/**
|
2010-08-07 19:59:42 +00:00
|
|
|
* Created on Dec 01, 2007
|
|
|
|
|
*
|
2012-07-15 20:13:02 +00:00
|
|
|
* Copyright © 2007 Yuri Astrakhan "<Firstname><Lastname>@gmail.com"
|
2007-12-01 13:37:02 +00:00
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
2010-06-21 13:13:32 +00:00
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2007-12-01 13:37:02 +00:00
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
2010-08-07 19:59:42 +00:00
|
|
|
*
|
|
|
|
|
* @file
|
2007-12-01 13:37:02 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup API
|
2007-12-01 13:37:02 +00:00
|
|
|
*/
|
|
|
|
|
class ApiParse extends ApiBase {
|
2012-08-21 14:15:12 +00:00
|
|
|
|
2014-04-15 18:12:09 +00:00
|
|
|
/** @var string $section */
|
2012-08-21 14:15:12 +00:00
|
|
|
private $section = null;
|
|
|
|
|
|
|
|
|
|
/** @var Content $content */
|
|
|
|
|
private $content = null;
|
|
|
|
|
|
|
|
|
|
/** @var Content $pstContent */
|
|
|
|
|
private $pstContent = null;
|
2010-10-20 18:50:33 +00:00
|
|
|
|
2007-12-01 13:37:02 +00:00
|
|
|
public function execute() {
|
2010-07-23 07:17:56 +00:00
|
|
|
// The data is hot but user-dependent, like page views, so we set vary cookies
|
|
|
|
|
$this->getMain()->setCacheMode( 'anon-public-user-private' );
|
|
|
|
|
|
2007-12-01 13:37:02 +00:00
|
|
|
// Get parameters
|
|
|
|
|
$params = $this->extractRequestParams();
|
|
|
|
|
$text = $params['text'];
|
|
|
|
|
$title = $params['title'];
|
2013-06-19 14:53:57 +00:00
|
|
|
if ( $title === null ) {
|
2013-06-19 10:21:19 +00:00
|
|
|
$titleProvided = false;
|
2013-06-19 14:53:57 +00:00
|
|
|
// A title is needed for parsing, so arbitrarily choose one
|
2013-06-19 10:21:19 +00:00
|
|
|
$title = 'API';
|
|
|
|
|
} else {
|
|
|
|
|
$titleProvided = true;
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-29 14:47:27 +00:00
|
|
|
$page = $params['page'];
|
2010-05-10 14:17:21 +00:00
|
|
|
$pageid = $params['pageid'];
|
2008-04-10 10:51:40 +00:00
|
|
|
$oldid = $params['oldid'];
|
2010-05-10 18:27:58 +00:00
|
|
|
|
2012-08-21 14:15:12 +00:00
|
|
|
$model = $params['contentmodel'];
|
|
|
|
|
$format = $params['contentformat'];
|
|
|
|
|
|
2013-06-19 10:21:19 +00:00
|
|
|
if ( !is_null( $page ) && ( !is_null( $text ) || $titleProvided ) ) {
|
2013-11-14 18:03:09 +00:00
|
|
|
$this->dieUsage(
|
|
|
|
|
'The page parameter cannot be used together with the text and title parameters',
|
|
|
|
|
'params'
|
|
|
|
|
);
|
2010-02-23 18:05:46 +00:00
|
|
|
}
|
2012-01-21 21:36:07 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
$prop = array_flip( $params['prop'] );
|
2010-05-25 13:47:22 +00:00
|
|
|
|
2010-05-10 18:27:58 +00:00
|
|
|
if ( isset( $params['section'] ) ) {
|
|
|
|
|
$this->section = $params['section'];
|
|
|
|
|
} else {
|
|
|
|
|
$this->section = false;
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2008-12-20 20:00:07 +00:00
|
|
|
// The parser needs $wgTitle to be set, apparently the
|
|
|
|
|
// $title parameter in Parser::parse isn't enough *sigh*
|
2011-10-26 23:27:01 +00:00
|
|
|
// TODO: Does this still need $wgTitle?
|
2012-04-22 23:42:38 +00:00
|
|
|
global $wgParser, $wgTitle;
|
2010-05-10 14:17:21 +00:00
|
|
|
|
2013-11-14 18:03:09 +00:00
|
|
|
// Currently unnecessary, code to act as a safeguard against any change
|
|
|
|
|
// in current behavior of uselang
|
2010-03-09 11:52:43 +00:00
|
|
|
$oldLang = null;
|
2013-11-14 18:03:09 +00:00
|
|
|
if ( isset( $params['uselang'] )
|
|
|
|
|
&& $params['uselang'] != $this->getContext()->getLanguage()->getCode()
|
|
|
|
|
) {
|
2012-04-22 23:42:38 +00:00
|
|
|
$oldLang = $this->getContext()->getLanguage(); // Backup language
|
|
|
|
|
$this->getContext()->setLanguage( Language::factory( $params['uselang'] ) );
|
2010-03-08 22:32:17 +00:00
|
|
|
}
|
2010-05-10 14:17:21 +00:00
|
|
|
|
2008-10-24 12:28:14 +00:00
|
|
|
$redirValues = null;
|
2011-01-06 23:35:59 +00:00
|
|
|
|
2011-06-30 01:06:17 +00:00
|
|
|
// Return result
|
|
|
|
|
$result = $this->getResult();
|
|
|
|
|
|
2010-05-10 14:17:21 +00:00
|
|
|
if ( !is_null( $oldid ) || !is_null( $pageid ) || !is_null( $page ) ) {
|
2010-02-23 18:05:46 +00:00
|
|
|
if ( !is_null( $oldid ) ) {
|
2010-01-23 22:52:40 +00:00
|
|
|
// Don't use the parser cache
|
2010-01-11 15:55:52 +00:00
|
|
|
$rev = Revision::newFromID( $oldid );
|
2010-02-23 18:05:46 +00:00
|
|
|
if ( !$rev ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->dieUsage( "There is no revision ID $oldid", 'missingrev' );
|
2010-02-23 18:05:46 +00:00
|
|
|
}
|
2011-12-18 14:07:01 +00:00
|
|
|
if ( !$rev->userCan( Revision::DELETED_TEXT, $this->getUser() ) ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->dieUsage( "You don't have permission to view deleted revisions", 'permissiondenied' );
|
2010-02-23 18:05:46 +00:00
|
|
|
}
|
2010-01-23 22:47:49 +00:00
|
|
|
|
2008-04-10 10:51:40 +00:00
|
|
|
$titleObj = $rev->getTitle();
|
2008-12-20 20:00:07 +00:00
|
|
|
$wgTitle = $titleObj;
|
2012-08-11 19:44:12 +00:00
|
|
|
$pageObj = WikiPage::factory( $titleObj );
|
2013-06-06 16:04:40 +00:00
|
|
|
$popts = $this->makeParserOptions( $pageObj, $params );
|
2010-05-10 18:27:58 +00:00
|
|
|
|
2010-12-30 17:06:09 +00:00
|
|
|
// If for some reason the "oldid" is actually the current revision, it may be cached
|
2013-01-26 21:11:09 +00:00
|
|
|
if ( $rev->isCurrent() ) {
|
2011-08-05 16:05:41 +00:00
|
|
|
// May get from/save to parser cache
|
2012-10-05 13:30:43 +00:00
|
|
|
$p_result = $this->getParsedContent( $pageObj, $popts,
|
2013-02-09 21:44:24 +00:00
|
|
|
$pageid, isset( $prop['wikitext'] ) );
|
2011-01-06 23:35:59 +00:00
|
|
|
} else { // This is an old revision, so get the text differently
|
2012-08-21 14:15:12 +00:00
|
|
|
$this->content = $rev->getContent( Revision::FOR_THIS_USER, $this->getUser() );
|
2010-05-10 18:27:58 +00:00
|
|
|
|
2010-10-24 19:16:46 +00:00
|
|
|
if ( $this->section !== false ) {
|
2012-08-21 14:15:12 +00:00
|
|
|
$this->content = $this->getSectionContent( $this->content, 'r' . $rev->getId() );
|
2010-10-24 19:16:46 +00:00
|
|
|
}
|
|
|
|
|
|
2011-08-05 16:05:41 +00:00
|
|
|
// Should we save old revision parses to the parser cache?
|
2012-10-19 20:12:55 +00:00
|
|
|
$p_result = $this->content->getParserOutput( $titleObj, $rev->getId(), $popts );
|
2010-10-24 19:16:46 +00:00
|
|
|
}
|
2011-08-05 13:07:09 +00:00
|
|
|
} else { // Not $oldid, but $pageid or $page
|
2011-06-17 15:57:00 +00:00
|
|
|
if ( $params['redirects'] ) {
|
|
|
|
|
$reqParams = array(
|
|
|
|
|
'action' => 'query',
|
|
|
|
|
'redirects' => '',
|
|
|
|
|
);
|
2013-11-14 12:47:20 +00:00
|
|
|
if ( !is_null( $pageid ) ) {
|
2011-06-17 15:57:00 +00:00
|
|
|
$reqParams['pageids'] = $pageid;
|
|
|
|
|
} else { // $page
|
|
|
|
|
$reqParams['titles'] = $page;
|
2010-02-23 18:05:46 +00:00
|
|
|
}
|
2011-06-17 15:57:00 +00:00
|
|
|
$req = new FauxRequest( $reqParams );
|
|
|
|
|
$main = new ApiMain( $req );
|
|
|
|
|
$main->execute();
|
|
|
|
|
$data = $main->getResultData();
|
|
|
|
|
$redirValues = isset( $data['query']['redirects'] )
|
|
|
|
|
? $data['query']['redirects']
|
|
|
|
|
: array();
|
|
|
|
|
$to = $page;
|
|
|
|
|
foreach ( (array)$redirValues as $r ) {
|
|
|
|
|
$to = $r['to'];
|
2010-05-10 14:17:21 +00:00
|
|
|
}
|
2012-08-11 19:44:12 +00:00
|
|
|
$pageParams = array( 'title' => $to );
|
|
|
|
|
} elseif ( !is_null( $pageid ) ) {
|
|
|
|
|
$pageParams = array( 'pageid' => $pageid );
|
|
|
|
|
} else { // $page
|
|
|
|
|
$pageParams = array( 'title' => $page );
|
2010-02-23 18:05:46 +00:00
|
|
|
}
|
2012-08-11 19:44:12 +00:00
|
|
|
|
|
|
|
|
$pageObj = $this->getTitleOrPageId( $pageParams, 'fromdb' );
|
|
|
|
|
$titleObj = $pageObj->getTitle();
|
2012-10-16 15:42:54 +00:00
|
|
|
if ( !$titleObj || !$titleObj->exists() ) {
|
|
|
|
|
$this->dieUsage( "The page you specified doesn't exist", 'missingtitle' );
|
|
|
|
|
}
|
2010-05-10 14:17:21 +00:00
|
|
|
$wgTitle = $titleObj;
|
2007-12-01 13:37:02 +00:00
|
|
|
|
2010-02-23 18:05:46 +00:00
|
|
|
if ( isset( $prop['revid'] ) ) {
|
2012-08-11 19:44:12 +00:00
|
|
|
$oldid = $pageObj->getLatest();
|
2010-02-23 18:05:46 +00:00
|
|
|
}
|
|
|
|
|
|
2013-06-06 16:04:40 +00:00
|
|
|
$popts = $this->makeParserOptions( $pageObj, $params );
|
2012-08-21 14:15:12 +00:00
|
|
|
|
2011-08-05 13:07:09 +00:00
|
|
|
// Potentially cached
|
2012-10-10 18:13:40 +00:00
|
|
|
$p_result = $this->getParsedContent( $pageObj, $popts, $pageid,
|
2013-02-09 21:44:24 +00:00
|
|
|
isset( $prop['wikitext'] ) );
|
2008-01-29 14:47:27 +00:00
|
|
|
}
|
2011-01-06 23:35:59 +00:00
|
|
|
} else { // Not $oldid, $pageid, $page. Hence based on $text
|
2010-01-11 15:55:52 +00:00
|
|
|
$titleObj = Title::newFromText( $title );
|
2013-03-01 15:01:26 +00:00
|
|
|
if ( !$titleObj || $titleObj->isExternal() ) {
|
2011-05-20 17:19:06 +00:00
|
|
|
$this->dieUsageMsg( array( 'invalidtitle', $title ) );
|
2010-02-23 18:05:46 +00:00
|
|
|
}
|
2008-12-20 20:00:07 +00:00
|
|
|
$wgTitle = $titleObj;
|
2014-01-09 16:53:08 +00:00
|
|
|
if ( $titleObj->canExist() ) {
|
|
|
|
|
$pageObj = WikiPage::factory( $titleObj );
|
|
|
|
|
} else {
|
|
|
|
|
// Do like MediaWiki::initializeArticle()
|
|
|
|
|
$article = Article::newFromTitle( $titleObj, $this->getContext() );
|
|
|
|
|
$pageObj = $article->getPage();
|
|
|
|
|
}
|
2012-08-11 19:44:12 +00:00
|
|
|
|
2013-06-06 16:04:40 +00:00
|
|
|
$popts = $this->makeParserOptions( $pageObj, $params );
|
2014-01-19 05:58:45 +00:00
|
|
|
$textProvided = !is_null( $text );
|
2010-05-10 18:27:58 +00:00
|
|
|
|
2014-01-19 05:58:45 +00:00
|
|
|
if ( !$textProvided ) {
|
2013-06-19 10:21:19 +00:00
|
|
|
if ( $titleProvided && ( $prop || $params['generatexml'] ) ) {
|
2013-05-10 15:59:11 +00:00
|
|
|
$this->setWarning(
|
|
|
|
|
"'title' used without 'text', and parsed page properties were requested " .
|
|
|
|
|
"(did you mean to use 'page' instead of 'title'?)"
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
// Prevent warning from ContentHandler::makeContent()
|
|
|
|
|
$text = '';
|
2012-08-21 14:15:12 +00:00
|
|
|
}
|
|
|
|
|
|
2013-06-19 10:21:19 +00:00
|
|
|
// If we are parsing text, do not use the content model of the default
|
|
|
|
|
// API title, but default to wikitext to keep BC.
|
2014-01-19 05:58:45 +00:00
|
|
|
if ( $textProvided && !$titleProvided && is_null( $model ) ) {
|
2013-06-19 10:21:19 +00:00
|
|
|
$model = CONTENT_MODEL_WIKITEXT;
|
2013-06-19 14:53:57 +00:00
|
|
|
$this->setWarning( "No 'title' or 'contentmodel' was given, assuming $model." );
|
2013-06-19 10:21:19 +00:00
|
|
|
}
|
|
|
|
|
|
2012-08-21 14:15:12 +00:00
|
|
|
try {
|
|
|
|
|
$this->content = ContentHandler::makeContent( $text, $titleObj, $model, $format );
|
|
|
|
|
} catch ( MWContentSerializationException $ex ) {
|
|
|
|
|
$this->dieUsage( $ex->getMessage(), 'parseerror' );
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-10 18:27:58 +00:00
|
|
|
if ( $this->section !== false ) {
|
2014-07-23 01:26:53 +00:00
|
|
|
$this->content = $this->getSectionContent( $this->content, $titleObj->getPrefixedText() );
|
2010-05-10 18:27:58 +00:00
|
|
|
}
|
|
|
|
|
|
2010-02-23 18:05:46 +00:00
|
|
|
if ( $params['pst'] || $params['onlypst'] ) {
|
2012-08-21 14:15:12 +00:00
|
|
|
$this->pstContent = $this->content->preSaveTransform( $titleObj, $this->getUser(), $popts );
|
2010-02-23 18:05:46 +00:00
|
|
|
}
|
|
|
|
|
if ( $params['onlypst'] ) {
|
2008-12-04 15:51:39 +00:00
|
|
|
// Build a result and bail out
|
2011-08-05 16:05:41 +00:00
|
|
|
$result_array = array();
|
2008-12-04 15:51:39 +00:00
|
|
|
$result_array['text'] = array();
|
2013-04-30 18:16:36 +00:00
|
|
|
ApiResult::setContent( $result_array['text'], $this->pstContent->serialize( $format ) );
|
2011-01-28 01:47:08 +00:00
|
|
|
if ( isset( $prop['wikitext'] ) ) {
|
|
|
|
|
$result_array['wikitext'] = array();
|
2013-04-30 18:16:36 +00:00
|
|
|
ApiResult::setContent( $result_array['wikitext'], $this->content->serialize( $format ) );
|
2011-01-28 01:47:08 +00:00
|
|
|
}
|
2011-06-30 01:06:17 +00:00
|
|
|
$result->addValue( null, $this->getModuleName(), $result_array );
|
2013-11-14 12:47:20 +00:00
|
|
|
|
2008-12-04 15:51:39 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2012-08-21 14:15:12 +00:00
|
|
|
|
2011-08-05 13:07:09 +00:00
|
|
|
// Not cached (save or load)
|
2012-08-21 14:15:12 +00:00
|
|
|
if ( $params['pst'] ) {
|
2012-10-19 23:17:59 +00:00
|
|
|
$p_result = $this->pstContent->getParserOutput( $titleObj, null, $popts );
|
2012-08-21 14:15:12 +00:00
|
|
|
} else {
|
2012-10-19 23:17:59 +00:00
|
|
|
$p_result = $this->content->getParserOutput( $titleObj, null, $popts );
|
2012-08-21 14:15:12 +00:00
|
|
|
}
|
2008-01-29 14:47:27 +00:00
|
|
|
}
|
2007-12-01 13:37:02 +00:00
|
|
|
|
2008-01-15 21:33:08 +00:00
|
|
|
$result_array = array();
|
2011-01-04 21:37:18 +00:00
|
|
|
|
|
|
|
|
$result_array['title'] = $titleObj->getPrefixedText();
|
|
|
|
|
|
|
|
|
|
if ( !is_null( $oldid ) ) {
|
|
|
|
|
$result_array['revid'] = intval( $oldid );
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-23 18:05:46 +00:00
|
|
|
if ( $params['redirects'] && !is_null( $redirValues ) ) {
|
2008-10-24 12:28:14 +00:00
|
|
|
$result_array['redirects'] = $redirValues;
|
2010-02-23 18:05:46 +00:00
|
|
|
}
|
|
|
|
|
|
2013-12-17 22:31:17 +00:00
|
|
|
if ( $params['disabletoc'] ) {
|
|
|
|
|
$p_result->setTOCEnabled( false );
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( isset( $prop['text'] ) ) {
|
2008-01-15 21:33:08 +00:00
|
|
|
$result_array['text'] = array();
|
2013-04-30 18:16:36 +00:00
|
|
|
ApiResult::setContent( $result_array['text'], $p_result->getText() );
|
2008-01-15 21:33:08 +00:00
|
|
|
}
|
2010-02-23 18:05:46 +00:00
|
|
|
|
2010-01-31 17:45:51 +00:00
|
|
|
if ( !is_null( $params['summary'] ) ) {
|
|
|
|
|
$result_array['parsedsummary'] = array();
|
2013-11-14 18:03:09 +00:00
|
|
|
ApiResult::setContent(
|
|
|
|
|
$result_array['parsedsummary'],
|
|
|
|
|
Linker::formatComment( $params['summary'], $titleObj )
|
|
|
|
|
);
|
2010-01-31 17:45:51 +00:00
|
|
|
}
|
2010-02-23 18:05:46 +00:00
|
|
|
|
2014-07-01 13:34:33 +00:00
|
|
|
if ( isset( $prop['langlinks'] ) ) {
|
2013-04-19 11:19:06 +00:00
|
|
|
$langlinks = $p_result->getLanguageLinks();
|
|
|
|
|
|
|
|
|
|
if ( $params['effectivelanglinks'] ) {
|
|
|
|
|
// Link flags are ignored for now, but may in the future be
|
|
|
|
|
// included in the result.
|
|
|
|
|
$linkFlags = array();
|
|
|
|
|
wfRunHooks( 'LanguageLinks', array( $titleObj, &$langlinks, &$linkFlags ) );
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$langlinks = false;
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-23 18:05:46 +00:00
|
|
|
if ( isset( $prop['langlinks'] ) ) {
|
2013-04-19 11:19:06 +00:00
|
|
|
$result_array['langlinks'] = $this->formatLangLinks( $langlinks );
|
2010-02-23 18:05:46 +00:00
|
|
|
}
|
|
|
|
|
if ( isset( $prop['categories'] ) ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
$result_array['categories'] = $this->formatCategoryLinks( $p_result->getCategories() );
|
2010-02-23 18:05:46 +00:00
|
|
|
}
|
2010-12-06 18:31:09 +00:00
|
|
|
if ( isset( $prop['categorieshtml'] ) ) {
|
|
|
|
|
$categoriesHtml = $this->categoriesHtml( $p_result->getCategories() );
|
|
|
|
|
$result_array['categorieshtml'] = array();
|
2013-04-30 18:16:36 +00:00
|
|
|
ApiResult::setContent( $result_array['categorieshtml'], $categoriesHtml );
|
2010-12-06 18:31:09 +00:00
|
|
|
}
|
2010-02-23 18:05:46 +00:00
|
|
|
if ( isset( $prop['links'] ) ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
$result_array['links'] = $this->formatLinks( $p_result->getLinks() );
|
2010-02-23 18:05:46 +00:00
|
|
|
}
|
|
|
|
|
if ( isset( $prop['templates'] ) ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
$result_array['templates'] = $this->formatLinks( $p_result->getTemplates() );
|
2010-02-23 18:05:46 +00:00
|
|
|
}
|
|
|
|
|
if ( isset( $prop['images'] ) ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
$result_array['images'] = array_keys( $p_result->getImages() );
|
2010-02-23 18:05:46 +00:00
|
|
|
}
|
|
|
|
|
if ( isset( $prop['externallinks'] ) ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
$result_array['externallinks'] = array_keys( $p_result->getExternalLinks() );
|
2010-02-23 18:05:46 +00:00
|
|
|
}
|
|
|
|
|
if ( isset( $prop['sections'] ) ) {
|
2008-01-15 21:33:08 +00:00
|
|
|
$result_array['sections'] = $p_result->getSections();
|
2010-02-23 18:05:46 +00:00
|
|
|
}
|
2010-05-25 13:47:22 +00:00
|
|
|
|
2010-02-23 18:05:46 +00:00
|
|
|
if ( isset( $prop['displaytitle'] ) ) {
|
2009-01-31 16:35:23 +00:00
|
|
|
$result_array['displaytitle'] = $p_result->getDisplayTitle() ?
|
2013-11-14 12:47:20 +00:00
|
|
|
$p_result->getDisplayTitle() :
|
|
|
|
|
$titleObj->getPrefixedText();
|
2010-02-23 18:05:46 +00:00
|
|
|
}
|
|
|
|
|
|
2010-05-24 16:35:23 +00:00
|
|
|
if ( isset( $prop['headitems'] ) || isset( $prop['headhtml'] ) ) {
|
2011-10-28 18:10:41 +00:00
|
|
|
$context = $this->getContext();
|
2011-07-22 10:45:07 +00:00
|
|
|
$context->setTitle( $titleObj );
|
2014-06-24 08:43:31 +00:00
|
|
|
$context->getOutput()->addParserOutputMetadata( $p_result );
|
2010-05-24 16:35:23 +00:00
|
|
|
|
2011-02-24 23:03:55 +00:00
|
|
|
if ( isset( $prop['headitems'] ) ) {
|
|
|
|
|
$headItems = $this->formatHeadItems( $p_result->getHeadItems() );
|
2010-05-24 16:35:23 +00:00
|
|
|
|
2011-06-03 11:04:49 +00:00
|
|
|
$css = $this->formatCss( $context->getOutput()->buildCssLinksArray() );
|
2010-05-24 16:35:23 +00:00
|
|
|
|
2011-07-22 10:45:07 +00:00
|
|
|
$scripts = array( $context->getOutput()->getHeadScripts() );
|
2010-05-24 16:35:23 +00:00
|
|
|
|
2011-02-24 23:03:55 +00:00
|
|
|
$result_array['headitems'] = array_merge( $headItems, $css, $scripts );
|
|
|
|
|
}
|
2010-02-23 18:05:46 +00:00
|
|
|
|
2011-02-24 23:03:55 +00:00
|
|
|
if ( isset( $prop['headhtml'] ) ) {
|
|
|
|
|
$result_array['headhtml'] = array();
|
2013-11-14 18:03:09 +00:00
|
|
|
ApiResult::setContent(
|
|
|
|
|
$result_array['headhtml'],
|
|
|
|
|
$context->getOutput()->headElement( $context->getSkin() )
|
|
|
|
|
);
|
2011-02-24 23:03:55 +00:00
|
|
|
}
|
2010-02-09 20:47:35 +00:00
|
|
|
}
|
2010-07-23 07:33:40 +00:00
|
|
|
|
2014-04-16 21:07:54 +00:00
|
|
|
if ( isset( $prop['modules'] ) ) {
|
|
|
|
|
$result_array['modules'] = array_values( array_unique( $p_result->getModules() ) );
|
|
|
|
|
$result_array['modulescripts'] = array_values( array_unique( $p_result->getModuleScripts() ) );
|
|
|
|
|
$result_array['modulestyles'] = array_values( array_unique( $p_result->getModuleStyles() ) );
|
|
|
|
|
$result_array['modulemessages'] = array_values( array_unique( $p_result->getModuleMessages() ) );
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-25 13:47:22 +00:00
|
|
|
if ( isset( $prop['iwlinks'] ) ) {
|
|
|
|
|
$result_array['iwlinks'] = $this->formatIWLinks( $p_result->getInterwikiLinks() );
|
|
|
|
|
}
|
2011-05-17 08:32:10 +00:00
|
|
|
|
2011-01-28 01:47:08 +00:00
|
|
|
if ( isset( $prop['wikitext'] ) ) {
|
|
|
|
|
$result_array['wikitext'] = array();
|
2013-04-30 18:16:36 +00:00
|
|
|
ApiResult::setContent( $result_array['wikitext'], $this->content->serialize( $format ) );
|
2012-08-21 14:15:12 +00:00
|
|
|
if ( !is_null( $this->pstContent ) ) {
|
2011-01-28 01:47:08 +00:00
|
|
|
$result_array['psttext'] = array();
|
2013-04-30 18:16:36 +00:00
|
|
|
ApiResult::setContent( $result_array['psttext'], $this->pstContent->serialize( $format ) );
|
2011-01-28 01:47:08 +00:00
|
|
|
}
|
|
|
|
|
}
|
2012-05-05 18:08:58 +00:00
|
|
|
if ( isset( $prop['properties'] ) ) {
|
|
|
|
|
$result_array['properties'] = $this->formatProperties( $p_result->getProperties() );
|
|
|
|
|
}
|
2010-02-23 18:05:46 +00:00
|
|
|
|
2014-02-04 19:16:59 +00:00
|
|
|
if ( isset( $prop['limitreportdata'] ) ) {
|
2014-04-24 19:50:01 +00:00
|
|
|
$result_array['limitreportdata'] =
|
|
|
|
|
$this->formatLimitReportData( $p_result->getLimitReportData() );
|
2014-02-04 19:16:59 +00:00
|
|
|
}
|
|
|
|
|
if ( isset( $prop['limitreporthtml'] ) ) {
|
|
|
|
|
$limitreportHtml = EditPage::getPreviewLimitReport( $p_result );
|
|
|
|
|
$result_array['limitreporthtml'] = array();
|
|
|
|
|
ApiResult::setContent( $result_array['limitreporthtml'], $limitreportHtml );
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-20 14:55:28 +00:00
|
|
|
if ( $params['generatexml'] ) {
|
2012-08-21 14:15:12 +00:00
|
|
|
if ( $this->content->getModel() != CONTENT_MODEL_WIKITEXT ) {
|
|
|
|
|
$this->dieUsage( "generatexml is only supported for wikitext content", "notwikitext" );
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-20 14:55:28 +00:00
|
|
|
$wgParser->startExternalParse( $titleObj, $popts, OT_PREPROCESS );
|
2012-08-21 14:15:12 +00:00
|
|
|
$dom = $wgParser->preprocessToDom( $this->content->getNativeData() );
|
2012-08-20 14:55:28 +00:00
|
|
|
if ( is_callable( array( $dom, 'saveXML' ) ) ) {
|
|
|
|
|
$xml = $dom->saveXML();
|
|
|
|
|
} else {
|
|
|
|
|
$xml = $dom->__toString();
|
|
|
|
|
}
|
|
|
|
|
$result_array['parsetree'] = array();
|
2013-04-30 18:16:36 +00:00
|
|
|
ApiResult::setContent( $result_array['parsetree'], $xml );
|
2012-08-20 14:55:28 +00:00
|
|
|
}
|
|
|
|
|
|
2007-12-01 13:37:02 +00:00
|
|
|
$result_mapping = array(
|
2008-10-24 12:28:14 +00:00
|
|
|
'redirects' => 'r',
|
2007-12-01 13:37:02 +00:00
|
|
|
'langlinks' => 'll',
|
|
|
|
|
'categories' => 'cl',
|
|
|
|
|
'links' => 'pl',
|
|
|
|
|
'templates' => 'tl',
|
|
|
|
|
'images' => 'img',
|
|
|
|
|
'externallinks' => 'el',
|
2010-05-25 13:47:22 +00:00
|
|
|
'iwlinks' => 'iw',
|
2007-12-27 20:14:07 +00:00
|
|
|
'sections' => 's',
|
2010-05-24 16:35:23 +00:00
|
|
|
'headitems' => 'hi',
|
2014-04-16 21:07:54 +00:00
|
|
|
'modules' => 'm',
|
|
|
|
|
'modulescripts' => 'm',
|
|
|
|
|
'modulestyles' => 'm',
|
|
|
|
|
'modulemessages' => 'm',
|
2012-05-05 18:08:58 +00:00
|
|
|
'properties' => 'pp',
|
2014-02-04 19:16:59 +00:00
|
|
|
'limitreportdata' => 'lr',
|
2007-12-01 13:37:02 +00:00
|
|
|
);
|
|
|
|
|
$this->setIndexedTagNames( $result_array, $result_mapping );
|
|
|
|
|
$result->addValue( null, $this->getModuleName(), $result_array );
|
2010-05-10 14:17:21 +00:00
|
|
|
|
2010-03-09 11:52:43 +00:00
|
|
|
if ( !is_null( $oldLang ) ) {
|
2012-04-22 23:42:38 +00:00
|
|
|
$this->getContext()->setLanguage( $oldLang ); // Reset language to $oldLang
|
2010-03-08 22:32:17 +00:00
|
|
|
}
|
2007-12-01 13:37:02 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2013-06-06 16:04:40 +00:00
|
|
|
/**
|
|
|
|
|
* Constructs a ParserOptions object
|
|
|
|
|
*
|
|
|
|
|
* @param WikiPage $pageObj
|
|
|
|
|
* @param array $params
|
|
|
|
|
*
|
|
|
|
|
* @return ParserOptions
|
|
|
|
|
*/
|
|
|
|
|
protected function makeParserOptions( WikiPage $pageObj, array $params ) {
|
|
|
|
|
wfProfileIn( __METHOD__ );
|
|
|
|
|
|
|
|
|
|
$popts = $pageObj->makeParserOptions( $this->getContext() );
|
|
|
|
|
$popts->enableLimitReport( !$params['disablepp'] );
|
2013-06-12 22:46:04 +00:00
|
|
|
$popts->setIsPreview( $params['preview'] || $params['sectionpreview'] );
|
|
|
|
|
$popts->setIsSectionPreview( $params['sectionpreview'] );
|
2014-06-21 06:09:18 +00:00
|
|
|
$popts->setEditSection( !$params['disableeditsection'] );
|
2013-06-06 16:04:40 +00:00
|
|
|
|
|
|
|
|
wfProfileOut( __METHOD__ );
|
2013-11-14 12:47:20 +00:00
|
|
|
|
2013-06-06 16:04:40 +00:00
|
|
|
return $popts;
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-01 23:01:24 +00:00
|
|
|
/**
|
2014-04-15 18:12:09 +00:00
|
|
|
* @param WikiPage $page
|
|
|
|
|
* @param ParserOptions $popts
|
|
|
|
|
* @param int $pageId
|
|
|
|
|
* @param bool $getWikitext
|
2011-01-01 23:01:24 +00:00
|
|
|
* @return ParserOutput
|
|
|
|
|
*/
|
2012-08-21 14:15:12 +00:00
|
|
|
private function getParsedContent( WikiPage $page, $popts, $pageId = null, $getWikitext = false ) {
|
|
|
|
|
$this->content = $page->getContent( Revision::RAW ); //XXX: really raw?
|
2011-11-18 21:36:57 +00:00
|
|
|
|
2012-10-22 18:48:09 +00:00
|
|
|
if ( $this->section !== false && $this->content !== null ) {
|
2012-10-08 15:26:11 +00:00
|
|
|
$this->content = $this->getSectionContent(
|
|
|
|
|
$this->content,
|
2014-07-23 01:26:53 +00:00
|
|
|
!is_null( $pageId ) ? 'page id ' . $pageId : $page->getTitle()->getPrefixedText()
|
2013-11-17 19:54:11 +00:00
|
|
|
);
|
2011-01-01 23:01:24 +00:00
|
|
|
|
2011-08-05 13:07:09 +00:00
|
|
|
// Not cached (save or load)
|
2012-10-19 23:17:59 +00:00
|
|
|
return $this->content->getParserOutput( $page->getTitle(), null, $popts );
|
2013-11-17 19:54:11 +00:00
|
|
|
}
|
2013-11-14 12:47:20 +00:00
|
|
|
|
2013-11-17 19:54:11 +00:00
|
|
|
// Try the parser cache first
|
|
|
|
|
// getParserOutput will save to Parser cache if able
|
|
|
|
|
$pout = $page->getParserOutput( $popts );
|
|
|
|
|
if ( !$pout ) {
|
|
|
|
|
$this->dieUsage( "There is no revision ID {$page->getLatest()}", 'missingrev' );
|
|
|
|
|
}
|
|
|
|
|
if ( $getWikitext ) {
|
|
|
|
|
$this->content = $page->getContent( Revision::RAW );
|
2011-01-01 23:01:24 +00:00
|
|
|
}
|
2013-11-17 19:54:11 +00:00
|
|
|
|
|
|
|
|
return $pout;
|
2011-01-01 23:01:24 +00:00
|
|
|
}
|
|
|
|
|
|
2014-07-23 01:26:53 +00:00
|
|
|
/**
|
|
|
|
|
* @param Content $content
|
|
|
|
|
* @param string $what Identifies the content in error messages, e.g. page title.
|
2014-08-23 20:34:25 +00:00
|
|
|
* @return Content|bool
|
2014-07-23 01:26:53 +00:00
|
|
|
*/
|
2012-08-21 14:15:12 +00:00
|
|
|
private function getSectionContent( Content $content, $what ) {
|
2011-08-05 13:07:09 +00:00
|
|
|
// Not cached (save or load)
|
2012-08-21 14:15:12 +00:00
|
|
|
$section = $content->getSection( $this->section );
|
|
|
|
|
if ( $section === false ) {
|
2010-05-10 18:27:58 +00:00
|
|
|
$this->dieUsage( "There is no section {$this->section} in " . $what, 'nosuchsection' );
|
|
|
|
|
}
|
2012-08-21 14:15:12 +00:00
|
|
|
if ( $section === null ) {
|
|
|
|
|
$this->dieUsage( "Sections are not supported by " . $what, 'nosuchsection' );
|
|
|
|
|
$section = false;
|
|
|
|
|
}
|
2013-11-14 12:47:20 +00:00
|
|
|
|
2012-08-21 14:15:12 +00:00
|
|
|
return $section;
|
2010-05-10 18:27:58 +00:00
|
|
|
}
|
|
|
|
|
|
2007-12-01 13:37:02 +00:00
|
|
|
private function formatLangLinks( $links ) {
|
2007-12-01 13:49:39 +00:00
|
|
|
$result = array();
|
2010-01-11 15:55:52 +00:00
|
|
|
foreach ( $links as $link ) {
|
2007-12-01 13:37:02 +00:00
|
|
|
$entry = array();
|
2009-09-28 18:36:15 +00:00
|
|
|
$bits = explode( ':', $link, 2 );
|
2011-01-28 01:09:47 +00:00
|
|
|
$title = Title::newFromText( $link );
|
2011-05-17 08:32:10 +00:00
|
|
|
|
2007-12-01 13:37:02 +00:00
|
|
|
$entry['lang'] = $bits[0];
|
2011-01-28 01:09:47 +00:00
|
|
|
if ( $title ) {
|
2011-08-19 15:46:08 +00:00
|
|
|
$entry['url'] = wfExpandUrl( $title->getFullURL(), PROTO_CURRENT );
|
2014-02-09 12:31:15 +00:00
|
|
|
// localised language name in user language (maybe set by uselang=)
|
2014-04-24 19:50:01 +00:00
|
|
|
$entry['langname'] = Language::fetchLanguageName(
|
|
|
|
|
$title->getInterwiki(),
|
|
|
|
|
$this->getLanguage()->getCode()
|
|
|
|
|
);
|
|
|
|
|
|
2014-02-09 12:31:15 +00:00
|
|
|
// native language name
|
|
|
|
|
$entry['autonym'] = Language::fetchLanguageName( $title->getInterwiki() );
|
2011-01-28 01:09:47 +00:00
|
|
|
}
|
2013-04-30 18:16:36 +00:00
|
|
|
ApiResult::setContent( $entry, $bits[1] );
|
2007-12-01 13:37:02 +00:00
|
|
|
$result[] = $entry;
|
|
|
|
|
}
|
2013-11-14 12:47:20 +00:00
|
|
|
|
2007-12-01 13:37:02 +00:00
|
|
|
return $result;
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-12-01 13:37:02 +00:00
|
|
|
private function formatCategoryLinks( $links ) {
|
2007-12-01 13:49:39 +00:00
|
|
|
$result = array();
|
2013-10-02 18:58:54 +00:00
|
|
|
|
|
|
|
|
if ( !$links ) {
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Fetch hiddencat property
|
|
|
|
|
$lb = new LinkBatch;
|
|
|
|
|
$lb->setArray( array( NS_CATEGORY => $links ) );
|
|
|
|
|
$db = $this->getDB();
|
|
|
|
|
$res = $db->select( array( 'page', 'page_props' ),
|
|
|
|
|
array( 'page_title', 'pp_propname' ),
|
|
|
|
|
$lb->constructSet( 'page', $db ),
|
|
|
|
|
__METHOD__,
|
|
|
|
|
array(),
|
|
|
|
|
array( 'page_props' => array(
|
|
|
|
|
'LEFT JOIN', array( 'pp_propname' => 'hiddencat', 'pp_page = page_id' )
|
|
|
|
|
) )
|
|
|
|
|
);
|
|
|
|
|
$hiddencats = array();
|
|
|
|
|
foreach ( $res as $row ) {
|
|
|
|
|
$hiddencats[$row->page_title] = isset( $row->pp_propname );
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
foreach ( $links as $link => $sortkey ) {
|
2007-12-01 13:37:02 +00:00
|
|
|
$entry = array();
|
|
|
|
|
$entry['sortkey'] = $sortkey;
|
2013-04-30 18:16:36 +00:00
|
|
|
ApiResult::setContent( $entry, $link );
|
2013-10-02 18:58:54 +00:00
|
|
|
if ( !isset( $hiddencats[$link] ) ) {
|
|
|
|
|
$entry['missing'] = '';
|
|
|
|
|
} elseif ( $hiddencats[$link] ) {
|
|
|
|
|
$entry['hidden'] = '';
|
|
|
|
|
}
|
2007-12-01 13:37:02 +00:00
|
|
|
$result[] = $entry;
|
|
|
|
|
}
|
2013-10-02 18:58:54 +00:00
|
|
|
|
2007-12-01 13:37:02 +00:00
|
|
|
return $result;
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2010-12-06 18:31:09 +00:00
|
|
|
private function categoriesHtml( $categories ) {
|
2011-10-28 18:10:41 +00:00
|
|
|
$context = $this->getContext();
|
2011-07-08 16:18:31 +00:00
|
|
|
$context->getOutput()->addCategoryLinks( $categories );
|
2013-11-14 12:47:20 +00:00
|
|
|
|
2011-07-08 16:18:31 +00:00
|
|
|
return $context->getSkin()->getCategories();
|
2010-12-06 18:31:09 +00:00
|
|
|
}
|
|
|
|
|
|
2007-12-01 13:37:02 +00:00
|
|
|
private function formatLinks( $links ) {
|
2007-12-01 13:49:39 +00:00
|
|
|
$result = array();
|
2010-01-11 15:55:52 +00:00
|
|
|
foreach ( $links as $ns => $nslinks ) {
|
|
|
|
|
foreach ( $nslinks as $title => $id ) {
|
2007-12-01 13:37:02 +00:00
|
|
|
$entry = array();
|
|
|
|
|
$entry['ns'] = $ns;
|
2013-04-30 18:16:36 +00:00
|
|
|
ApiResult::setContent( $entry, Title::makeTitle( $ns, $title )->getFullText() );
|
2010-02-23 18:05:46 +00:00
|
|
|
if ( $id != 0 ) {
|
2007-12-01 13:37:02 +00:00
|
|
|
$entry['exists'] = '';
|
2010-02-23 18:05:46 +00:00
|
|
|
}
|
2007-12-01 13:37:02 +00:00
|
|
|
$result[] = $entry;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-11-14 12:47:20 +00:00
|
|
|
|
2007-12-01 13:37:02 +00:00
|
|
|
return $result;
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2010-05-25 13:47:22 +00:00
|
|
|
private function formatIWLinks( $iw ) {
|
|
|
|
|
$result = array();
|
|
|
|
|
foreach ( $iw as $prefix => $titles ) {
|
2010-11-06 16:11:19 +00:00
|
|
|
foreach ( array_keys( $titles ) as $title ) {
|
2010-05-25 13:47:22 +00:00
|
|
|
$entry = array();
|
|
|
|
|
$entry['prefix'] = $prefix;
|
2010-07-23 07:33:40 +00:00
|
|
|
|
2010-05-25 18:37:55 +00:00
|
|
|
$title = Title::newFromText( "{$prefix}:{$title}" );
|
|
|
|
|
if ( $title ) {
|
2011-08-19 15:46:08 +00:00
|
|
|
$entry['url'] = wfExpandUrl( $title->getFullURL(), PROTO_CURRENT );
|
2010-05-25 18:37:55 +00:00
|
|
|
}
|
2010-07-23 07:33:40 +00:00
|
|
|
|
2013-04-30 18:16:36 +00:00
|
|
|
ApiResult::setContent( $entry, $title->getFullText() );
|
2010-05-25 13:47:22 +00:00
|
|
|
$result[] = $entry;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-11-14 12:47:20 +00:00
|
|
|
|
2010-05-25 13:47:22 +00:00
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-16 13:07:58 +00:00
|
|
|
private function formatHeadItems( $headItems ) {
|
|
|
|
|
$result = array();
|
2010-01-23 15:25:14 +00:00
|
|
|
foreach ( $headItems as $tag => $content ) {
|
2010-01-16 13:07:58 +00:00
|
|
|
$entry = array();
|
|
|
|
|
$entry['tag'] = $tag;
|
2013-04-30 18:16:36 +00:00
|
|
|
ApiResult::setContent( $entry, $content );
|
2010-01-16 13:07:58 +00:00
|
|
|
$result[] = $entry;
|
|
|
|
|
}
|
2013-11-14 12:47:20 +00:00
|
|
|
|
2010-01-16 13:07:58 +00:00
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-05 18:08:58 +00:00
|
|
|
private function formatProperties( $properties ) {
|
|
|
|
|
$result = array();
|
|
|
|
|
foreach ( $properties as $name => $value ) {
|
|
|
|
|
$entry = array();
|
|
|
|
|
$entry['name'] = $name;
|
2013-04-30 18:16:36 +00:00
|
|
|
ApiResult::setContent( $entry, $value );
|
2012-05-05 18:08:58 +00:00
|
|
|
$result[] = $entry;
|
|
|
|
|
}
|
2013-11-14 12:47:20 +00:00
|
|
|
|
2012-05-05 18:08:58 +00:00
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-24 16:35:23 +00:00
|
|
|
private function formatCss( $css ) {
|
|
|
|
|
$result = array();
|
|
|
|
|
foreach ( $css as $file => $link ) {
|
|
|
|
|
$entry = array();
|
|
|
|
|
$entry['file'] = $file;
|
2013-04-30 18:16:36 +00:00
|
|
|
ApiResult::setContent( $entry, $link );
|
2010-05-24 16:35:23 +00:00
|
|
|
$result[] = $entry;
|
|
|
|
|
}
|
2013-11-14 12:47:20 +00:00
|
|
|
|
2010-05-24 16:35:23 +00:00
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-04 19:16:59 +00:00
|
|
|
private function formatLimitReportData( $limitReportData ) {
|
|
|
|
|
$result = array();
|
|
|
|
|
$apiResult = $this->getResult();
|
|
|
|
|
|
|
|
|
|
foreach ( $limitReportData as $name => $value ) {
|
|
|
|
|
$entry = array();
|
|
|
|
|
$entry['name'] = $name;
|
|
|
|
|
if ( !is_array( $value ) ) {
|
|
|
|
|
$value = array( $value );
|
|
|
|
|
}
|
|
|
|
|
$apiResult->setIndexedTagName( $value, 'param' );
|
|
|
|
|
$apiResult->setIndexedTagName_recursive( $value, 'param' );
|
|
|
|
|
$entry = array_merge( $entry, $value );
|
|
|
|
|
$result[] = $entry;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
2007-12-01 13:37:02 +00:00
|
|
|
private function setIndexedTagNames( &$array, $mapping ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
foreach ( $mapping as $key => $name ) {
|
2010-02-23 18:05:46 +00:00
|
|
|
if ( isset( $array[$key] ) ) {
|
2007-12-01 13:49:39 +00:00
|
|
|
$this->getResult()->setIndexedTagName( $array[$key], $name );
|
2010-02-23 18:05:46 +00:00
|
|
|
}
|
2007-12-01 13:37:02 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-28 19:05:26 +00:00
|
|
|
public function getAllowedParams() {
|
2010-02-23 18:05:46 +00:00
|
|
|
return array(
|
2013-06-19 14:53:57 +00:00
|
|
|
'title' => null,
|
2008-01-15 21:33:08 +00:00
|
|
|
'text' => null,
|
2010-01-31 17:45:51 +00:00
|
|
|
'summary' => null,
|
2008-01-29 14:47:27 +00:00
|
|
|
'page' => null,
|
2011-04-04 20:51:41 +00:00
|
|
|
'pageid' => array(
|
|
|
|
|
ApiBase::PARAM_TYPE => 'integer',
|
|
|
|
|
),
|
2008-10-24 12:28:14 +00:00
|
|
|
'redirects' => false,
|
2011-04-04 20:51:41 +00:00
|
|
|
'oldid' => array(
|
|
|
|
|
ApiBase::PARAM_TYPE => 'integer',
|
|
|
|
|
),
|
2008-01-15 21:33:08 +00:00
|
|
|
'prop' => array(
|
2013-11-14 18:03:09 +00:00
|
|
|
ApiBase::PARAM_DFLT => 'text|langlinks|categories|links|templates|' .
|
|
|
|
|
'images|externallinks|sections|revid|displaytitle|iwlinks|properties',
|
2010-02-23 18:05:46 +00:00
|
|
|
ApiBase::PARAM_ISMULTI => true,
|
|
|
|
|
ApiBase::PARAM_TYPE => array(
|
2008-01-15 21:33:08 +00:00
|
|
|
'text',
|
|
|
|
|
'langlinks',
|
|
|
|
|
'categories',
|
2010-12-06 18:31:09 +00:00
|
|
|
'categorieshtml',
|
2008-01-15 21:33:08 +00:00
|
|
|
'links',
|
|
|
|
|
'templates',
|
|
|
|
|
'images',
|
|
|
|
|
'externallinks',
|
2008-03-28 13:27:44 +00:00
|
|
|
'sections',
|
2009-01-31 16:29:15 +00:00
|
|
|
'revid',
|
|
|
|
|
'displaytitle',
|
2010-02-09 20:47:35 +00:00
|
|
|
'headitems',
|
2010-05-25 13:47:22 +00:00
|
|
|
'headhtml',
|
2014-04-16 21:07:54 +00:00
|
|
|
'modules',
|
2010-05-25 13:47:22 +00:00
|
|
|
'iwlinks',
|
2011-01-28 01:47:08 +00:00
|
|
|
'wikitext',
|
2012-05-05 18:08:58 +00:00
|
|
|
'properties',
|
2014-02-04 19:16:59 +00:00
|
|
|
'limitreportdata',
|
|
|
|
|
'limitreporthtml',
|
2008-01-15 21:33:08 +00:00
|
|
|
)
|
2008-12-04 15:51:39 +00:00
|
|
|
),
|
|
|
|
|
'pst' => false,
|
|
|
|
|
'onlypst' => false,
|
2013-04-19 11:19:06 +00:00
|
|
|
'effectivelanglinks' => false,
|
2010-05-10 18:27:58 +00:00
|
|
|
'uselang' => null,
|
|
|
|
|
'section' => null,
|
2010-08-04 07:44:23 +00:00
|
|
|
'disablepp' => false,
|
2014-06-21 06:09:18 +00:00
|
|
|
'disableeditsection' => false,
|
2012-08-20 14:55:28 +00:00
|
|
|
'generatexml' => false,
|
2013-06-06 16:04:40 +00:00
|
|
|
'preview' => false,
|
2013-06-12 22:46:04 +00:00
|
|
|
'sectionpreview' => false,
|
2013-12-17 22:31:17 +00:00
|
|
|
'disabletoc' => false,
|
2012-08-21 14:15:12 +00:00
|
|
|
'contentformat' => array(
|
|
|
|
|
ApiBase::PARAM_TYPE => ContentHandler::getAllContentFormats(),
|
|
|
|
|
),
|
|
|
|
|
'contentmodel' => array(
|
|
|
|
|
ApiBase::PARAM_TYPE => ContentHandler::getContentModels(),
|
|
|
|
|
)
|
2007-12-01 13:37:02 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-28 19:05:26 +00:00
|
|
|
public function getParamDescription() {
|
2010-05-11 22:30:18 +00:00
|
|
|
$p = $this->getModulePrefix();
|
2014-02-11 15:34:27 +00:00
|
|
|
$wikitext = CONTENT_MODEL_WIKITEXT;
|
2013-11-14 12:47:20 +00:00
|
|
|
|
2010-02-23 18:05:46 +00:00
|
|
|
return array(
|
2013-06-19 14:53:57 +00:00
|
|
|
'text' => "Text to parse. Use {$p}title or {$p}contentmodel to control the content model",
|
2010-05-11 22:30:18 +00:00
|
|
|
'summary' => 'Summary to parse',
|
2011-06-17 15:57:00 +00:00
|
|
|
'redirects' => "If the {$p}page or the {$p}pageid parameter is set to a redirect, resolve it",
|
2013-06-19 14:53:57 +00:00
|
|
|
'title' => "Title of page the text belongs to. " .
|
2014-01-19 05:58:45 +00:00
|
|
|
"If omitted, {$p}contentmodel must be specified, and \"API\" will be used as the title",
|
2010-05-11 22:30:18 +00:00
|
|
|
'page' => "Parse the content of this page. Cannot be used together with {$p}text and {$p}title",
|
|
|
|
|
'pageid' => "Parse the content of this page. Overrides {$p}page",
|
|
|
|
|
'oldid' => "Parse the content of this revision. Overrides {$p}page and {$p}pageid",
|
2010-06-23 19:36:26 +00:00
|
|
|
'prop' => array(
|
|
|
|
|
'Which pieces of information to get',
|
|
|
|
|
' text - Gives the parsed text of the wikitext',
|
2010-12-14 11:47:13 +00:00
|
|
|
' langlinks - Gives the language links in the parsed wikitext',
|
|
|
|
|
' categories - Gives the categories in the parsed wikitext',
|
|
|
|
|
' categorieshtml - Gives the HTML version of the categories',
|
2010-06-23 19:36:26 +00:00
|
|
|
' links - Gives the internal links in the parsed wikitext',
|
|
|
|
|
' templates - Gives the templates in the parsed wikitext',
|
|
|
|
|
' images - Gives the images in the parsed wikitext',
|
|
|
|
|
' externallinks - Gives the external links in the parsed wikitext',
|
|
|
|
|
' sections - Gives the sections in the parsed wikitext',
|
2010-12-14 11:47:13 +00:00
|
|
|
' revid - Adds the revision ID of the parsed page',
|
2010-06-23 19:36:26 +00:00
|
|
|
' displaytitle - Adds the title of the parsed wikitext',
|
|
|
|
|
' headitems - Gives items to put in the <head> of the page',
|
|
|
|
|
' headhtml - Gives parsed <head> of the page',
|
2014-04-16 21:07:54 +00:00
|
|
|
' modules - Gives the ResourceLoader modules used on the page',
|
2010-06-23 19:36:26 +00:00
|
|
|
' iwlinks - Gives interwiki links in the parsed wikitext',
|
2011-01-28 01:47:08 +00:00
|
|
|
' wikitext - Gives the original wikitext that was parsed',
|
2012-05-05 18:08:58 +00:00
|
|
|
' properties - Gives various properties defined in the parsed wikitext',
|
2014-02-04 19:16:59 +00:00
|
|
|
' limitreportdata - Gives the limit report in a structured way.',
|
|
|
|
|
" Gives no data, when {$p}disablepp is set.",
|
|
|
|
|
' limitreporthtml - Gives the HTML version of the limit report.',
|
|
|
|
|
" Gives no data, when {$p}disablepp is set.",
|
2008-01-29 14:47:27 +00:00
|
|
|
),
|
2013-04-19 11:19:06 +00:00
|
|
|
'effectivelanglinks' => array(
|
|
|
|
|
'Includes language links supplied by extensions',
|
2014-07-01 13:34:33 +00:00
|
|
|
'(for use with prop=langlinks)',
|
2013-04-19 11:19:06 +00:00
|
|
|
),
|
2010-06-23 19:36:26 +00:00
|
|
|
'pst' => array(
|
|
|
|
|
'Do a pre-save transform on the input before parsing it',
|
2013-06-19 14:53:57 +00:00
|
|
|
"Only valid when used with {$p}text",
|
2008-12-04 15:51:39 +00:00
|
|
|
),
|
2010-06-23 19:36:26 +00:00
|
|
|
'onlypst' => array(
|
|
|
|
|
'Do a pre-save transform (PST) on the input, but don\'t parse it',
|
2013-06-19 14:53:57 +00:00
|
|
|
'Returns the same wikitext, after a PST has been applied.',
|
|
|
|
|
"Only valid when used with {$p}text",
|
2008-12-04 15:51:39 +00:00
|
|
|
),
|
2010-05-11 22:30:18 +00:00
|
|
|
'uselang' => 'Which language to parse the request in',
|
2010-05-10 18:27:58 +00:00
|
|
|
'section' => 'Only retrieve the content of this section number',
|
2010-08-04 07:44:23 +00:00
|
|
|
'disablepp' => 'Disable the PP Report from the parser output',
|
2014-06-21 06:09:18 +00:00
|
|
|
'disableeditsection' => 'Disable edit section links from the parser output',
|
2013-06-19 14:53:57 +00:00
|
|
|
'generatexml' => "Generate XML parse tree (requires contentmodel=$wikitext)",
|
2013-06-06 16:04:40 +00:00
|
|
|
'preview' => 'Parse in preview mode',
|
2013-06-12 22:46:04 +00:00
|
|
|
'sectionpreview' => 'Parse in section preview mode (enables preview mode too)',
|
2013-12-17 22:31:17 +00:00
|
|
|
'disabletoc' => 'Disable table of contents in output',
|
2013-06-19 14:53:57 +00:00
|
|
|
'contentformat' => array(
|
|
|
|
|
'Content serialization format used for the input text',
|
|
|
|
|
"Only valid when used with {$p}text",
|
|
|
|
|
),
|
|
|
|
|
'contentmodel' => array(
|
2014-01-19 05:58:45 +00:00
|
|
|
"Content model of the input text. If omitted, ${p}title must be specified, " .
|
|
|
|
|
"and default will be the model of the specified ${p}title",
|
2013-06-19 14:53:57 +00:00
|
|
|
"Only valid when used with {$p}text",
|
|
|
|
|
),
|
2007-12-01 13:37:02 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-28 19:05:26 +00:00
|
|
|
public function getDescription() {
|
2013-06-19 14:53:57 +00:00
|
|
|
$p = $this->getModulePrefix();
|
2013-11-14 12:47:20 +00:00
|
|
|
|
2012-05-05 18:08:58 +00:00
|
|
|
return array(
|
2014-03-09 20:22:47 +00:00
|
|
|
'Parses content and returns parser output.',
|
2013-11-14 18:03:09 +00:00
|
|
|
'See the various prop-Modules of action=query to get information from the current' .
|
2014-03-09 20:22:47 +00:00
|
|
|
'version of a page.',
|
2013-06-19 14:53:57 +00:00
|
|
|
'There are several ways to specify the text to parse:',
|
|
|
|
|
"1) Specify a page or revision, using {$p}page, {$p}pageid, or {$p}oldid.",
|
|
|
|
|
"2) Specify content explicitly, using {$p}text, {$p}title, and {$p}contentmodel.",
|
2014-03-09 20:22:47 +00:00
|
|
|
"3) Specify only a summary to parse. {$p}prop should be given an empty value.",
|
2012-05-05 18:08:58 +00:00
|
|
|
);
|
2007-12-01 13:37:02 +00:00
|
|
|
}
|
2010-02-23 18:05:46 +00:00
|
|
|
|
2011-08-17 22:24:21 +00:00
|
|
|
public function getExamples() {
|
2010-02-23 18:05:46 +00:00
|
|
|
return array(
|
2013-05-10 15:59:11 +00:00
|
|
|
'api.php?action=parse&page=Project:Sandbox' => 'Parse a page',
|
2014-01-19 05:58:45 +00:00
|
|
|
'api.php?action=parse&text={{Project:Sandbox}}&contentmodel=wikitext' => 'Parse wikitext',
|
2013-11-14 18:03:09 +00:00
|
|
|
'api.php?action=parse&text={{PAGENAME}}&title=Test'
|
|
|
|
|
=> 'Parse wikitext, specifying the page title',
|
2013-05-10 15:59:11 +00:00
|
|
|
'api.php?action=parse&summary=Some+[[link]]&prop=' => 'Parse a summary',
|
2007-12-01 13:37:02 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-17 16:38:24 +00:00
|
|
|
public function getHelpUrls() {
|
2011-11-28 15:43:11 +00:00
|
|
|
return 'https://www.mediawiki.org/wiki/API:Parsing_wikitext#parse';
|
2011-07-17 16:38:24 +00:00
|
|
|
}
|
2010-07-23 07:17:56 +00:00
|
|
|
}
|