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'];
|
2015-03-10 21:27:01 +00:00
|
|
|
if ( !preg_match( '/^((T-)?\d+|new)$/', $this->section ) ) {
|
2015-06-04 10:32:23 +00:00
|
|
|
$this->dieUsage(
|
2016-03-08 08:04:45 +00:00
|
|
|
'The section parameter must be a valid section id or "new"', 'invalidsection'
|
2015-06-04 10:32:23 +00:00
|
|
|
);
|
2015-03-10 21:27:01 +00:00
|
|
|
}
|
2010-05-10 18:27:58 +00:00
|
|
|
} 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
|
|
|
|
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 ) ) {
|
2015-03-25 23:55:16 +00:00
|
|
|
if ( $this->section === 'new' ) {
|
2015-06-04 10:32:23 +00:00
|
|
|
$this->dieUsage(
|
|
|
|
|
'section=new cannot be combined with oldid, pageid or page parameters. ' .
|
|
|
|
|
'Please use text', 'params'
|
|
|
|
|
);
|
2015-03-25 23:55:16 +00:00
|
|
|
}
|
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
|
2014-12-02 18:13:06 +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
|
2015-04-08 21:55:44 +00:00
|
|
|
// 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() ) {
|
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'] ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$reqParams = [
|
2011-06-17 15:57:00 +00:00
|
|
|
'redirects' => '',
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
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 );
|
API: Overhaul ApiResult, make format=xml not throw, and add json formatversion
ApiResult was a mess: some methods could only be used with an array
reference instead of manipulating the stored data, methods that had both
array-ref and internal-data versions had names that didn't at all
correspond, some methods that worked on an array reference were
annoyingly non-static, and then the whole mess with setIndexedTagName.
ApiFormatXml is also entirely annoying to deal with, as it liked to
throw exceptions if certain metadata wasn't provided that no other
formatter required. Its legacy also means we have this silly convention
of using empty-string rather than boolean true, annoying restrictions on
keys (leading to things that should be hashes being arrays of key-value
object instead), '*' used as a key all over the place, and so on.
So, changes here:
* ApiResult is no longer an ApiBase or a ContextSource.
* Wherever sensible, ApiResult provides a static method working on an
arrayref and a non-static method working on internal data.
* Metadata is now always added to ApiResult's internal data structure.
Formatters are responsible for stripping it if necessary. "raw mode"
is deprecated.
* New metadata to replace the '*' key, solve the array() => '[]' vs '{}'
question, and so on.
* New class for formatting warnings and errors using i18n messages, and
support for multiple errors and a more machine-readable format for
warnings. For the moment, though, the actual output will not be changing
yet (see T47843 for future plans).
* New formatversion parameter for format=json and format=php, to select
between BC mode and the modern output.
* In BC mode, booleans will be converted to empty-string presence style;
modules currently returning booleans will need to use
ApiResult::META_BC_BOOLS to preserve their current output.
Actual changes to the API modules' output (e.g. actually returning
booleans for the new formatversion) beyond the use of
ApiResult::setContentValue() are left for a future change.
Bug: T76728
Bug: T57371
Bug: T33629
Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2014-12-03 22:14:22 +00:00
|
|
|
$pageSet = new ApiPageSet( $main );
|
|
|
|
|
$pageSet->execute();
|
2015-05-01 19:50:25 +00:00
|
|
|
$redirValues = $pageSet->getRedirectTitlesAsResult( $this->getResult() );
|
API: Overhaul ApiResult, make format=xml not throw, and add json formatversion
ApiResult was a mess: some methods could only be used with an array
reference instead of manipulating the stored data, methods that had both
array-ref and internal-data versions had names that didn't at all
correspond, some methods that worked on an array reference were
annoyingly non-static, and then the whole mess with setIndexedTagName.
ApiFormatXml is also entirely annoying to deal with, as it liked to
throw exceptions if certain metadata wasn't provided that no other
formatter required. Its legacy also means we have this silly convention
of using empty-string rather than boolean true, annoying restrictions on
keys (leading to things that should be hashes being arrays of key-value
object instead), '*' used as a key all over the place, and so on.
So, changes here:
* ApiResult is no longer an ApiBase or a ContextSource.
* Wherever sensible, ApiResult provides a static method working on an
arrayref and a non-static method working on internal data.
* Metadata is now always added to ApiResult's internal data structure.
Formatters are responsible for stripping it if necessary. "raw mode"
is deprecated.
* New metadata to replace the '*' key, solve the array() => '[]' vs '{}'
question, and so on.
* New class for formatting warnings and errors using i18n messages, and
support for multiple errors and a more machine-readable format for
warnings. For the moment, though, the actual output will not be changing
yet (see T47843 for future plans).
* New formatversion parameter for format=json and format=php, to select
between BC mode and the modern output.
* In BC mode, booleans will be converted to empty-string presence style;
modules currently returning booleans will need to use
ApiResult::META_BC_BOOLS to preserve their current output.
Actual changes to the API modules' output (e.g. actually returning
booleans for the new formatversion) beyond the use of
ApiResult::setContentValue() are left for a future change.
Bug: T76728
Bug: T57371
Bug: T33629
Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2014-12-03 22:14:22 +00:00
|
|
|
|
2011-06-17 15:57:00 +00:00
|
|
|
$to = $page;
|
API: Overhaul ApiResult, make format=xml not throw, and add json formatversion
ApiResult was a mess: some methods could only be used with an array
reference instead of manipulating the stored data, methods that had both
array-ref and internal-data versions had names that didn't at all
correspond, some methods that worked on an array reference were
annoyingly non-static, and then the whole mess with setIndexedTagName.
ApiFormatXml is also entirely annoying to deal with, as it liked to
throw exceptions if certain metadata wasn't provided that no other
formatter required. Its legacy also means we have this silly convention
of using empty-string rather than boolean true, annoying restrictions on
keys (leading to things that should be hashes being arrays of key-value
object instead), '*' used as a key all over the place, and so on.
So, changes here:
* ApiResult is no longer an ApiBase or a ContextSource.
* Wherever sensible, ApiResult provides a static method working on an
arrayref and a non-static method working on internal data.
* Metadata is now always added to ApiResult's internal data structure.
Formatters are responsible for stripping it if necessary. "raw mode"
is deprecated.
* New metadata to replace the '*' key, solve the array() => '[]' vs '{}'
question, and so on.
* New class for formatting warnings and errors using i18n messages, and
support for multiple errors and a more machine-readable format for
warnings. For the moment, though, the actual output will not be changing
yet (see T47843 for future plans).
* New formatversion parameter for format=json and format=php, to select
between BC mode and the modern output.
* In BC mode, booleans will be converted to empty-string presence style;
modules currently returning booleans will need to use
ApiResult::META_BC_BOOLS to preserve their current output.
Actual changes to the API modules' output (e.g. actually returning
booleans for the new formatversion) beyond the use of
ApiResult::setContentValue() are left for a future change.
Bug: T76728
Bug: T57371
Bug: T33629
Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2014-12-03 22:14:22 +00:00
|
|
|
foreach ( $pageSet->getRedirectTitles() as $title ) {
|
|
|
|
|
$to = $title->getFullText();
|
2010-05-10 14:17:21 +00:00
|
|
|
}
|
2016-02-17 09:09:32 +00:00
|
|
|
$pageParams = [ 'title' => $to ];
|
2012-08-11 19:44:12 +00:00
|
|
|
} elseif ( !is_null( $pageid ) ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$pageParams = [ 'pageid' => $pageid ];
|
2012-08-11 19:44:12 +00:00
|
|
|
} else { // $page
|
2016-02-17 09:09:32 +00:00
|
|
|
$pageParams = [ '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
|
|
|
|
2015-08-24 05:05:09 +00:00
|
|
|
// Don't pollute the parser cache when setting options that aren't
|
|
|
|
|
// in ParserOptions::optionsHash()
|
2015-08-26 13:39:29 +00:00
|
|
|
/// @todo: This should be handled closer to the actual cache instead of here, see T110269
|
2015-08-24 05:05:09 +00:00
|
|
|
$suppressCache =
|
|
|
|
|
$params['disablepp'] ||
|
|
|
|
|
$params['disablelimitreport'] ||
|
|
|
|
|
$params['preview'] ||
|
|
|
|
|
$params['sectionpreview'] ||
|
|
|
|
|
$params['disabletidy'];
|
|
|
|
|
|
|
|
|
|
if ( $suppressCache ) {
|
|
|
|
|
$this->content = $this->getContent( $pageObj, $pageid );
|
|
|
|
|
$p_result = $this->content->getParserOutput( $titleObj, null, $popts );
|
|
|
|
|
} else {
|
|
|
|
|
// Potentially cached
|
|
|
|
|
$p_result = $this->getParsedContent( $pageObj, $popts, $pageid,
|
|
|
|
|
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() ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->dieUsageMsg( [ '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 ) {
|
2015-03-10 21:27:01 +00:00
|
|
|
if ( $this->section === 'new' ) {
|
|
|
|
|
// Insert the section title above the content.
|
|
|
|
|
if ( !is_null( $params['sectiontitle'] ) && $params['sectiontitle'] !== '' ) {
|
|
|
|
|
$this->content = $this->content->addSectionHeader( $params['sectiontitle'] );
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$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
|
2016-02-17 09:09:32 +00:00
|
|
|
$result_array = [];
|
2015-01-16 19:00:07 +00:00
|
|
|
$result_array['text'] = $this->pstContent->serialize( $format );
|
|
|
|
|
$result_array[ApiResult::META_BC_SUBELEMENTS][] = 'text';
|
2011-01-28 01:47:08 +00:00
|
|
|
if ( isset( $prop['wikitext'] ) ) {
|
2015-01-16 19:00:07 +00:00
|
|
|
$result_array['wikitext'] = $this->content->serialize( $format );
|
|
|
|
|
$result_array[ApiResult::META_BC_SUBELEMENTS][] = 'wikitext';
|
2011-01-28 01:47:08 +00:00
|
|
|
}
|
2015-03-19 21:20:53 +00:00
|
|
|
if ( !is_null( $params['summary'] ) ||
|
|
|
|
|
( !is_null( $params['sectiontitle'] ) && $this->section === 'new' )
|
|
|
|
|
) {
|
2015-01-16 19:00:07 +00:00
|
|
|
$result_array['parsedsummary'] = $this->formatSummary( $titleObj, $params );
|
|
|
|
|
$result_array[ApiResult::META_BC_SUBELEMENTS][] = 'parsedsummary';
|
2014-12-18 13:14:54 +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
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$result_array = [];
|
2011-01-04 21:37:18 +00:00
|
|
|
|
|
|
|
|
$result_array['title'] = $titleObj->getPrefixedText();
|
2016-03-08 07:27:13 +00:00
|
|
|
$result_array['pageid'] = $pageid ?: $pageObj->getId();
|
2011-01-04 21:37:18 +00:00
|
|
|
|
|
|
|
|
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'] ) ) {
|
2015-01-16 19:00:07 +00:00
|
|
|
$result_array['text'] = $p_result->getText();
|
|
|
|
|
$result_array[ApiResult::META_BC_SUBELEMENTS][] = 'text';
|
2008-01-15 21:33:08 +00:00
|
|
|
}
|
2010-02-23 18:05:46 +00:00
|
|
|
|
2015-03-19 21:20:53 +00:00
|
|
|
if ( !is_null( $params['summary'] ) ||
|
|
|
|
|
( !is_null( $params['sectiontitle'] ) && $this->section === 'new' )
|
|
|
|
|
) {
|
2015-01-16 19:00:07 +00:00
|
|
|
$result_array['parsedsummary'] = $this->formatSummary( $titleObj, $params );
|
|
|
|
|
$result_array[ApiResult::META_BC_SUBELEMENTS][] = 'parsedsummary';
|
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.
|
2016-02-17 09:09:32 +00:00
|
|
|
$linkFlags = [];
|
|
|
|
|
Hooks::run( 'LanguageLinks', [ $titleObj, &$langlinks, &$linkFlags ] );
|
2013-04-19 11:19:06 +00:00
|
|
|
}
|
|
|
|
|
} 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'] ) ) {
|
2015-01-16 19:00:07 +00:00
|
|
|
$result_array['categorieshtml'] = $this->categoriesHtml( $p_result->getCategories() );
|
|
|
|
|
$result_array[ApiResult::META_BC_SUBELEMENTS][] = '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'] ) ) {
|
2016-03-08 07:27:13 +00:00
|
|
|
$result_array['displaytitle'] = $p_result->getDisplayTitle() ?:
|
2013-11-14 12:47:20 +00:00
|
|
|
$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
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$scripts = [ $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'] ) ) {
|
2015-01-16 19:00:07 +00:00
|
|
|
$result_array['headhtml'] = $context->getOutput()->headElement( $context->getSkin() );
|
|
|
|
|
$result_array[ApiResult::META_BC_SUBELEMENTS][] = 'headhtml';
|
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() ) );
|
2015-05-13 19:17:35 +00:00
|
|
|
// To be removed in 1.27
|
2016-02-17 09:09:32 +00:00
|
|
|
$result_array['modulemessages'] = [];
|
2015-05-13 19:17:35 +00:00
|
|
|
$this->setWarning( 'modulemessages is deprecated since MediaWiki 1.26' );
|
2014-04-16 21:07:54 +00:00
|
|
|
}
|
|
|
|
|
|
2015-01-23 23:27:11 +00:00
|
|
|
if ( isset( $prop['jsconfigvars'] ) ) {
|
2015-06-04 10:32:23 +00:00
|
|
|
$result_array['jsconfigvars'] =
|
|
|
|
|
ApiResult::addMetadataToResultVars( $p_result->getJsConfigVars() );
|
2015-01-23 23:27:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( isset( $prop['encodedjsconfigvars'] ) ) {
|
|
|
|
|
$result_array['encodedjsconfigvars'] = FormatJson::encode(
|
|
|
|
|
$p_result->getJsConfigVars(), false, FormatJson::ALL_OK
|
|
|
|
|
);
|
|
|
|
|
$result_array[ApiResult::META_SUBELEMENTS][] = 'encodedjsconfigvars';
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-04 10:32:23 +00:00
|
|
|
if ( isset( $prop['modules'] ) &&
|
|
|
|
|
!isset( $prop['jsconfigvars'] ) && !isset( $prop['encodedjsconfigvars'] ) ) {
|
2016-03-08 08:04:45 +00:00
|
|
|
$this->setWarning( 'Property "modules" was set but not "jsconfigvars" ' .
|
|
|
|
|
'or "encodedjsconfigvars". Configuration variables are necessary ' .
|
|
|
|
|
'for proper module usage.' );
|
2015-06-04 10:32:23 +00:00
|
|
|
}
|
|
|
|
|
|
Implement page status indicators
Page status indicators are icons (or short text snippets) usually
displayed in the top-right corner of the page, outside of the main
content. Basically, <indicator name="foo">[[File:Foo.svg|20px]]</indicator>
may be used on a page to place the icon in the indicator area. They
are also known as top icons, page icons, heading icons or title icons.
I found the discussion on bug 23796 highly illuminating. I suggest
that everyone read it before suggesting different design choices.
I spent some time with a thesaurus pondering the name. "Emblems" and
"badges" were also considered, but the former has a much more limited
meaning and the latter is already taken by Wikidata, with a similar
but subtly different feature set. I am not aware of any naming
conflicts ;) besides new talk page message "indicator" (used by core
and Echo in some documents) and OOjs UI indicators (tiny icons like
the arrow on a dropdown form element), which shouldn't be confusing.
Potential use cases include:
* "Lock" indicators for page protection levels
* Featured/good article indicators
* Redirect shortcuts display ("WP:VPT")
* Links to help/manual for special pages
* Coordinates?… or globe icon for inline pop-up maps
Design features:
* Skin-customizable. Skins can fully control where and how indicators
are shown, or may just do <?php echo $this->getIndicators(); ?> to
output the default structure. By default they are not shown at all.
* Extension-customizable. Extensions can call ParserOutput::addIndicator()
to insert an indicator from one of the numerous parser hooks.
* Wiki-customizable. In addition to just using the parser functions,
on-wiki styles and scripts can use the provided classes and ids
(.mw-indicator, #mw-indicator-<name>) to customize their display.
Design limitations:
* Every indicator must have a unique identifier (name). It's not
possible to create arrays, or to have several indicators with the
same name. In case of duplicates, the latest occurrence of the
parser function wins.
* Indicators are displayed ordered by their names (and not occurrence
order). This ensures consistency across pages and provides a simple
means of ordering or grouping them.
* Indicators are not stored, tracked or accessible outside of
ParserOutput (in particular they're not in the page_props table).
They are intended to merely reflect the content or metadata that is
already present on the page, and not be data themselves. If you ever
think you need to list pages with a given status indicator, instead
figure out what it means and use the appropriate tracking category,
special page report, already existing page_prop, or other means.
Corresponding patch in Vector: I90a8ae15ac8275d084ea5f47b6b2684d5e6c7412.
I'll implement support in the other three skins included in the tarball
and document it on mediawiki.org after this is merged.
Bug: 23796
Change-Id: I2389ff9a5332a2b1d033eb75f0946e5241cfaaf4
2014-09-24 10:44:16 +00:00
|
|
|
if ( isset( $prop['indicators'] ) ) {
|
2015-01-16 19:00:07 +00:00
|
|
|
$result_array['indicators'] = (array)$p_result->getIndicators();
|
|
|
|
|
ApiResult::setArrayType( $result_array['indicators'], 'BCkvp', 'name' );
|
Implement page status indicators
Page status indicators are icons (or short text snippets) usually
displayed in the top-right corner of the page, outside of the main
content. Basically, <indicator name="foo">[[File:Foo.svg|20px]]</indicator>
may be used on a page to place the icon in the indicator area. They
are also known as top icons, page icons, heading icons or title icons.
I found the discussion on bug 23796 highly illuminating. I suggest
that everyone read it before suggesting different design choices.
I spent some time with a thesaurus pondering the name. "Emblems" and
"badges" were also considered, but the former has a much more limited
meaning and the latter is already taken by Wikidata, with a similar
but subtly different feature set. I am not aware of any naming
conflicts ;) besides new talk page message "indicator" (used by core
and Echo in some documents) and OOjs UI indicators (tiny icons like
the arrow on a dropdown form element), which shouldn't be confusing.
Potential use cases include:
* "Lock" indicators for page protection levels
* Featured/good article indicators
* Redirect shortcuts display ("WP:VPT")
* Links to help/manual for special pages
* Coordinates?… or globe icon for inline pop-up maps
Design features:
* Skin-customizable. Skins can fully control where and how indicators
are shown, or may just do <?php echo $this->getIndicators(); ?> to
output the default structure. By default they are not shown at all.
* Extension-customizable. Extensions can call ParserOutput::addIndicator()
to insert an indicator from one of the numerous parser hooks.
* Wiki-customizable. In addition to just using the parser functions,
on-wiki styles and scripts can use the provided classes and ids
(.mw-indicator, #mw-indicator-<name>) to customize their display.
Design limitations:
* Every indicator must have a unique identifier (name). It's not
possible to create arrays, or to have several indicators with the
same name. In case of duplicates, the latest occurrence of the
parser function wins.
* Indicators are displayed ordered by their names (and not occurrence
order). This ensures consistency across pages and provides a simple
means of ordering or grouping them.
* Indicators are not stored, tracked or accessible outside of
ParserOutput (in particular they're not in the page_props table).
They are intended to merely reflect the content or metadata that is
already present on the page, and not be data themselves. If you ever
think you need to list pages with a given status indicator, instead
figure out what it means and use the appropriate tracking category,
special page report, already existing page_prop, or other means.
Corresponding patch in Vector: I90a8ae15ac8275d084ea5f47b6b2684d5e6c7412.
I'll implement support in the other three skins included in the tarball
and document it on mediawiki.org after this is merged.
Bug: 23796
Change-Id: I2389ff9a5332a2b1d033eb75f0946e5241cfaaf4
2014-09-24 10:44:16 +00:00
|
|
|
}
|
|
|
|
|
|
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'] ) ) {
|
2015-01-16 19:00:07 +00:00
|
|
|
$result_array['wikitext'] = $this->content->serialize( $format );
|
|
|
|
|
$result_array[ApiResult::META_BC_SUBELEMENTS][] = 'wikitext';
|
2012-08-21 14:15:12 +00:00
|
|
|
if ( !is_null( $this->pstContent ) ) {
|
2015-01-16 19:00:07 +00:00
|
|
|
$result_array['psttext'] = $this->pstContent->serialize( $format );
|
|
|
|
|
$result_array[ApiResult::META_BC_SUBELEMENTS][] = 'psttext';
|
2011-01-28 01:47:08 +00:00
|
|
|
}
|
|
|
|
|
}
|
2012-05-05 18:08:58 +00:00
|
|
|
if ( isset( $prop['properties'] ) ) {
|
2015-01-16 19:00:07 +00:00
|
|
|
$result_array['properties'] = (array)$p_result->getProperties();
|
|
|
|
|
ApiResult::setArrayType( $result_array['properties'], 'BCkvp', 'name' );
|
2012-05-05 18:08:58 +00:00
|
|
|
}
|
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'] ) ) {
|
2015-01-16 19:00:07 +00:00
|
|
|
$result_array['limitreporthtml'] = EditPage::getPreviewLimitReport( $p_result );
|
|
|
|
|
$result_array[ApiResult::META_BC_SUBELEMENTS][] = 'limitreporthtml';
|
2014-02-04 19:16:59 +00:00
|
|
|
}
|
|
|
|
|
|
2015-06-05 09:22:17 +00:00
|
|
|
if ( isset( $prop['parsetree'] ) || $params['generatexml'] ) {
|
2012-08-21 14:15:12 +00:00
|
|
|
if ( $this->content->getModel() != CONTENT_MODEL_WIKITEXT ) {
|
2016-03-08 08:04:45 +00:00
|
|
|
$this->dieUsage( 'parsetree is only supported for wikitext content', 'notwikitext' );
|
2012-08-21 14:15:12 +00:00
|
|
|
}
|
|
|
|
|
|
2014-10-24 18:40:19 +00:00
|
|
|
$wgParser->startExternalParse( $titleObj, $popts, Parser::OT_PREPROCESS );
|
2012-08-21 14:15:12 +00:00
|
|
|
$dom = $wgParser->preprocessToDom( $this->content->getNativeData() );
|
2016-02-17 09:09:32 +00:00
|
|
|
if ( is_callable( [ $dom, 'saveXML' ] ) ) {
|
2012-08-20 14:55:28 +00:00
|
|
|
$xml = $dom->saveXML();
|
|
|
|
|
} else {
|
|
|
|
|
$xml = $dom->__toString();
|
|
|
|
|
}
|
2015-01-16 19:00:07 +00:00
|
|
|
$result_array['parsetree'] = $xml;
|
|
|
|
|
$result_array[ApiResult::META_BC_SUBELEMENTS][] = 'parsetree';
|
2012-08-20 14:55:28 +00:00
|
|
|
}
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$result_mapping = [
|
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',
|
Implement page status indicators
Page status indicators are icons (or short text snippets) usually
displayed in the top-right corner of the page, outside of the main
content. Basically, <indicator name="foo">[[File:Foo.svg|20px]]</indicator>
may be used on a page to place the icon in the indicator area. They
are also known as top icons, page icons, heading icons or title icons.
I found the discussion on bug 23796 highly illuminating. I suggest
that everyone read it before suggesting different design choices.
I spent some time with a thesaurus pondering the name. "Emblems" and
"badges" were also considered, but the former has a much more limited
meaning and the latter is already taken by Wikidata, with a similar
but subtly different feature set. I am not aware of any naming
conflicts ;) besides new talk page message "indicator" (used by core
and Echo in some documents) and OOjs UI indicators (tiny icons like
the arrow on a dropdown form element), which shouldn't be confusing.
Potential use cases include:
* "Lock" indicators for page protection levels
* Featured/good article indicators
* Redirect shortcuts display ("WP:VPT")
* Links to help/manual for special pages
* Coordinates?… or globe icon for inline pop-up maps
Design features:
* Skin-customizable. Skins can fully control where and how indicators
are shown, or may just do <?php echo $this->getIndicators(); ?> to
output the default structure. By default they are not shown at all.
* Extension-customizable. Extensions can call ParserOutput::addIndicator()
to insert an indicator from one of the numerous parser hooks.
* Wiki-customizable. In addition to just using the parser functions,
on-wiki styles and scripts can use the provided classes and ids
(.mw-indicator, #mw-indicator-<name>) to customize their display.
Design limitations:
* Every indicator must have a unique identifier (name). It's not
possible to create arrays, or to have several indicators with the
same name. In case of duplicates, the latest occurrence of the
parser function wins.
* Indicators are displayed ordered by their names (and not occurrence
order). This ensures consistency across pages and provides a simple
means of ordering or grouping them.
* Indicators are not stored, tracked or accessible outside of
ParserOutput (in particular they're not in the page_props table).
They are intended to merely reflect the content or metadata that is
already present on the page, and not be data themselves. If you ever
think you need to list pages with a given status indicator, instead
figure out what it means and use the appropriate tracking category,
special page report, already existing page_prop, or other means.
Corresponding patch in Vector: I90a8ae15ac8275d084ea5f47b6b2684d5e6c7412.
I'll implement support in the other three skins included in the tarball
and document it on mediawiki.org after this is merged.
Bug: 23796
Change-Id: I2389ff9a5332a2b1d033eb75f0946e5241cfaaf4
2014-09-24 10:44:16 +00:00
|
|
|
'indicators' => 'ind',
|
2014-04-16 21:07:54 +00:00
|
|
|
'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',
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2007-12-01 13:37:02 +00:00
|
|
|
$this->setIndexedTagNames( $result_array, $result_mapping );
|
|
|
|
|
$result->addValue( null, $this->getModuleName(), $result_array );
|
|
|
|
|
}
|
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 ) {
|
|
|
|
|
|
|
|
|
|
$popts = $pageObj->makeParserOptions( $this->getContext() );
|
2015-08-24 05:05:09 +00:00
|
|
|
$popts->enableLimitReport( !$params['disablepp'] && !$params['disablelimitreport'] );
|
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'] );
|
2015-08-24 05:05:09 +00:00
|
|
|
if ( $params['disabletidy'] ) {
|
|
|
|
|
$popts->setTidy( false );
|
|
|
|
|
}
|
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 ) {
|
2015-08-24 05:05:09 +00:00
|
|
|
$this->content = $this->getContent( $page, $pageId );
|
2011-11-18 21:36:57 +00:00
|
|
|
|
2012-10-22 18:48:09 +00:00
|
|
|
if ( $this->section !== false && $this->content !== null ) {
|
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
|
|
|
/**
|
2015-08-24 05:05:09 +00:00
|
|
|
* Get the content for the given page and the requested section.
|
|
|
|
|
*
|
|
|
|
|
* @param WikiPage $page
|
|
|
|
|
* @param int $pageId
|
|
|
|
|
* @return Content
|
|
|
|
|
*/
|
|
|
|
|
private function getContent( WikiPage $page, $pageId = null ) {
|
2015-09-11 13:44:59 +00:00
|
|
|
$content = $page->getContent( Revision::RAW ); // XXX: really raw?
|
2015-08-24 05:05:09 +00:00
|
|
|
|
|
|
|
|
if ( $this->section !== false && $content !== null ) {
|
|
|
|
|
$content = $this->getSectionContent(
|
|
|
|
|
$content,
|
|
|
|
|
!is_null( $pageId ) ? 'page id ' . $pageId : $page->getTitle()->getPrefixedText()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return $content;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Extract the requested section from the given Content
|
|
|
|
|
*
|
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 ) {
|
2016-03-08 08:04:45 +00:00
|
|
|
$this->dieUsage( "There is no section {$this->section} in $what", 'nosuchsection' );
|
2010-05-10 18:27:58 +00:00
|
|
|
}
|
2012-08-21 14:15:12 +00:00
|
|
|
if ( $section === null ) {
|
2016-03-08 08:04:45 +00:00
|
|
|
$this->dieUsage( "Sections are not supported by $what", 'nosuchsection' );
|
2012-08-21 14:15:12 +00:00
|
|
|
$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
|
|
|
}
|
|
|
|
|
|
2015-03-19 21:20:53 +00:00
|
|
|
/**
|
|
|
|
|
* This mimicks the behavior of EditPage in formatting a summary
|
|
|
|
|
*
|
|
|
|
|
* @param Title $title of the page being parsed
|
|
|
|
|
* @param Array $params the API parameters of the request
|
|
|
|
|
* @return Content|bool
|
|
|
|
|
*/
|
|
|
|
|
private function formatSummary( $title, $params ) {
|
|
|
|
|
global $wgParser;
|
|
|
|
|
$summary = !is_null( $params['summary'] ) ? $params['summary'] : '';
|
|
|
|
|
$sectionTitle = !is_null( $params['sectiontitle'] ) ? $params['sectiontitle'] : '';
|
|
|
|
|
|
|
|
|
|
if ( $this->section === 'new' && ( $sectionTitle === '' || $summary === '' ) ) {
|
2015-06-04 10:32:23 +00:00
|
|
|
if ( $sectionTitle !== '' ) {
|
2015-03-19 21:20:53 +00:00
|
|
|
$summary = $params['sectiontitle'];
|
|
|
|
|
}
|
|
|
|
|
if ( $summary !== '' ) {
|
2015-06-04 10:32:23 +00:00
|
|
|
$summary = wfMessage( 'newsectionsummary' )
|
|
|
|
|
->rawParams( $wgParser->stripSectionName( $summary ) )
|
|
|
|
|
->inContentLanguage()->text();
|
2015-03-19 21:20:53 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return Linker::formatComment( $summary, $title, $this->section === 'new' );
|
|
|
|
|
}
|
|
|
|
|
|
2007-12-01 13:37:02 +00:00
|
|
|
private function formatLangLinks( $links ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$result = [];
|
2010-01-11 15:55:52 +00:00
|
|
|
foreach ( $links as $link ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$entry = [];
|
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 );
|
API: HTMLize and internationalize the help, add Special:ApiHelp
The existing API help, formatted as basically a plain-text document
embedded in XML and with a little bolding and a few links
syntax-highlighted in after the fact, works ok for experienced programmers
but isn't at all newbie-friendly. Further, all the help is hard-coded in
English, which isn't very friendly to non-English speakers.
So let's rewrite it. The help text is now obtained from i18n messages
and output in HTML, with the default display consisting of help for a
single module with links to help for other modules. This, of course,
necessitates deprecating many of the existing help-related methods and
hooks and replacing them with new ones, but backwards compatibility is
maintained for almost everything.
At the same time, action=paraminfo also needs to support the
'description' and other help-related fields being output in wikitext or
HTML, and I11cb063d (to access all modules via the 'modules' parameter
instead of having 'modules', 'formatmodules', 'querymodules', and so on)
is folded in.
And we also add Special:ApiHelp. When directly accessed, it simply
redirects to api.php with appropriate parameters. But it's also
transcludable to allow up-to-date API help text to be included within
the on-wiki documentation.
Note this patch doesn't actually add i18n messages for any API modules
besides ApiMain and ApiHelp. That will come in a followup patch, but for
the moment the backwards-compatibility code handles them nicely.
While we're messing with the documentation, we may as well add the
"internal" flag requested in bug 62905 (although the 'includeinternal'
parameter it also requests doesn't make much sense anymore) and a
"deprecated" flag that's needed by several modules now.
Bug: 30936
Bug: 38126
Bug: 42343
Bug: 45641
Bug: 62905
Bug: 63211
Change-Id: Ib14c00df06d85c2f6364d83b2b10ce34c7f513cc
2014-09-16 17:54:01 +00:00
|
|
|
// localised language name in 'uselang' language
|
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
|
|
|
}
|
API: Overhaul ApiResult, make format=xml not throw, and add json formatversion
ApiResult was a mess: some methods could only be used with an array
reference instead of manipulating the stored data, methods that had both
array-ref and internal-data versions had names that didn't at all
correspond, some methods that worked on an array reference were
annoyingly non-static, and then the whole mess with setIndexedTagName.
ApiFormatXml is also entirely annoying to deal with, as it liked to
throw exceptions if certain metadata wasn't provided that no other
formatter required. Its legacy also means we have this silly convention
of using empty-string rather than boolean true, annoying restrictions on
keys (leading to things that should be hashes being arrays of key-value
object instead), '*' used as a key all over the place, and so on.
So, changes here:
* ApiResult is no longer an ApiBase or a ContextSource.
* Wherever sensible, ApiResult provides a static method working on an
arrayref and a non-static method working on internal data.
* Metadata is now always added to ApiResult's internal data structure.
Formatters are responsible for stripping it if necessary. "raw mode"
is deprecated.
* New metadata to replace the '*' key, solve the array() => '[]' vs '{}'
question, and so on.
* New class for formatting warnings and errors using i18n messages, and
support for multiple errors and a more machine-readable format for
warnings. For the moment, though, the actual output will not be changing
yet (see T47843 for future plans).
* New formatversion parameter for format=json and format=php, to select
between BC mode and the modern output.
* In BC mode, booleans will be converted to empty-string presence style;
modules currently returning booleans will need to use
ApiResult::META_BC_BOOLS to preserve their current output.
Actual changes to the API modules' output (e.g. actually returning
booleans for the new formatversion) beyond the use of
ApiResult::setContentValue() are left for a future change.
Bug: T76728
Bug: T57371
Bug: T33629
Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2014-12-03 22:14:22 +00:00
|
|
|
ApiResult::setContentValue( $entry, 'title', $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 ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$result = [];
|
2013-10-02 18:58:54 +00:00
|
|
|
|
|
|
|
|
if ( !$links ) {
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Fetch hiddencat property
|
|
|
|
|
$lb = new LinkBatch;
|
2016-02-17 09:09:32 +00:00
|
|
|
$lb->setArray( [ NS_CATEGORY => $links ] );
|
2013-10-02 18:58:54 +00:00
|
|
|
$db = $this->getDB();
|
2016-02-17 09:09:32 +00:00
|
|
|
$res = $db->select( [ 'page', 'page_props' ],
|
|
|
|
|
[ 'page_title', 'pp_propname' ],
|
2013-10-02 18:58:54 +00:00
|
|
|
$lb->constructSet( 'page', $db ),
|
|
|
|
|
__METHOD__,
|
2016-02-17 09:09:32 +00:00
|
|
|
[],
|
|
|
|
|
[ 'page_props' => [
|
|
|
|
|
'LEFT JOIN', [ 'pp_propname' => 'hiddencat', 'pp_page = page_id' ]
|
|
|
|
|
] ]
|
2013-10-02 18:58:54 +00:00
|
|
|
);
|
2016-02-17 09:09:32 +00:00
|
|
|
$hiddencats = [];
|
2013-10-02 18:58:54 +00:00
|
|
|
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 ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$entry = [];
|
2007-12-01 13:37:02 +00:00
|
|
|
$entry['sortkey'] = $sortkey;
|
2015-12-03 14:15:59 +00:00
|
|
|
// array keys will cast numeric category names to ints, so cast back to string
|
|
|
|
|
ApiResult::setContentValue( $entry, 'category', (string)$link );
|
2013-10-02 18:58:54 +00:00
|
|
|
if ( !isset( $hiddencats[$link] ) ) {
|
2015-01-16 19:00:07 +00:00
|
|
|
$entry['missing'] = true;
|
2013-10-02 18:58:54 +00:00
|
|
|
} elseif ( $hiddencats[$link] ) {
|
2015-01-16 19:00:07 +00:00
|
|
|
$entry['hidden'] = true;
|
2013-10-02 18:58:54 +00:00
|
|
|
}
|
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 ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$result = [];
|
2010-01-11 15:55:52 +00:00
|
|
|
foreach ( $links as $ns => $nslinks ) {
|
|
|
|
|
foreach ( $nslinks as $title => $id ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$entry = [];
|
2007-12-01 13:37:02 +00:00
|
|
|
$entry['ns'] = $ns;
|
API: Overhaul ApiResult, make format=xml not throw, and add json formatversion
ApiResult was a mess: some methods could only be used with an array
reference instead of manipulating the stored data, methods that had both
array-ref and internal-data versions had names that didn't at all
correspond, some methods that worked on an array reference were
annoyingly non-static, and then the whole mess with setIndexedTagName.
ApiFormatXml is also entirely annoying to deal with, as it liked to
throw exceptions if certain metadata wasn't provided that no other
formatter required. Its legacy also means we have this silly convention
of using empty-string rather than boolean true, annoying restrictions on
keys (leading to things that should be hashes being arrays of key-value
object instead), '*' used as a key all over the place, and so on.
So, changes here:
* ApiResult is no longer an ApiBase or a ContextSource.
* Wherever sensible, ApiResult provides a static method working on an
arrayref and a non-static method working on internal data.
* Metadata is now always added to ApiResult's internal data structure.
Formatters are responsible for stripping it if necessary. "raw mode"
is deprecated.
* New metadata to replace the '*' key, solve the array() => '[]' vs '{}'
question, and so on.
* New class for formatting warnings and errors using i18n messages, and
support for multiple errors and a more machine-readable format for
warnings. For the moment, though, the actual output will not be changing
yet (see T47843 for future plans).
* New formatversion parameter for format=json and format=php, to select
between BC mode and the modern output.
* In BC mode, booleans will be converted to empty-string presence style;
modules currently returning booleans will need to use
ApiResult::META_BC_BOOLS to preserve their current output.
Actual changes to the API modules' output (e.g. actually returning
booleans for the new formatversion) beyond the use of
ApiResult::setContentValue() are left for a future change.
Bug: T76728
Bug: T57371
Bug: T33629
Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2014-12-03 22:14:22 +00:00
|
|
|
ApiResult::setContentValue( $entry, 'title', Title::makeTitle( $ns, $title )->getFullText() );
|
2015-01-16 19:00:07 +00:00
|
|
|
$entry['exists'] = $id != 0;
|
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 ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$result = [];
|
2010-05-25 13:47:22 +00:00
|
|
|
foreach ( $iw as $prefix => $titles ) {
|
2010-11-06 16:11:19 +00:00
|
|
|
foreach ( array_keys( $titles ) as $title ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$entry = [];
|
2010-05-25 13:47:22 +00:00
|
|
|
$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
|
|
|
|
API: Overhaul ApiResult, make format=xml not throw, and add json formatversion
ApiResult was a mess: some methods could only be used with an array
reference instead of manipulating the stored data, methods that had both
array-ref and internal-data versions had names that didn't at all
correspond, some methods that worked on an array reference were
annoyingly non-static, and then the whole mess with setIndexedTagName.
ApiFormatXml is also entirely annoying to deal with, as it liked to
throw exceptions if certain metadata wasn't provided that no other
formatter required. Its legacy also means we have this silly convention
of using empty-string rather than boolean true, annoying restrictions on
keys (leading to things that should be hashes being arrays of key-value
object instead), '*' used as a key all over the place, and so on.
So, changes here:
* ApiResult is no longer an ApiBase or a ContextSource.
* Wherever sensible, ApiResult provides a static method working on an
arrayref and a non-static method working on internal data.
* Metadata is now always added to ApiResult's internal data structure.
Formatters are responsible for stripping it if necessary. "raw mode"
is deprecated.
* New metadata to replace the '*' key, solve the array() => '[]' vs '{}'
question, and so on.
* New class for formatting warnings and errors using i18n messages, and
support for multiple errors and a more machine-readable format for
warnings. For the moment, though, the actual output will not be changing
yet (see T47843 for future plans).
* New formatversion parameter for format=json and format=php, to select
between BC mode and the modern output.
* In BC mode, booleans will be converted to empty-string presence style;
modules currently returning booleans will need to use
ApiResult::META_BC_BOOLS to preserve their current output.
Actual changes to the API modules' output (e.g. actually returning
booleans for the new formatversion) beyond the use of
ApiResult::setContentValue() are left for a future change.
Bug: T76728
Bug: T57371
Bug: T33629
Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2014-12-03 22:14:22 +00:00
|
|
|
ApiResult::setContentValue( $entry, 'title', $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 ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$result = [];
|
2010-01-23 15:25:14 +00:00
|
|
|
foreach ( $headItems as $tag => $content ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$entry = [];
|
2010-01-16 13:07:58 +00:00
|
|
|
$entry['tag'] = $tag;
|
API: Overhaul ApiResult, make format=xml not throw, and add json formatversion
ApiResult was a mess: some methods could only be used with an array
reference instead of manipulating the stored data, methods that had both
array-ref and internal-data versions had names that didn't at all
correspond, some methods that worked on an array reference were
annoyingly non-static, and then the whole mess with setIndexedTagName.
ApiFormatXml is also entirely annoying to deal with, as it liked to
throw exceptions if certain metadata wasn't provided that no other
formatter required. Its legacy also means we have this silly convention
of using empty-string rather than boolean true, annoying restrictions on
keys (leading to things that should be hashes being arrays of key-value
object instead), '*' used as a key all over the place, and so on.
So, changes here:
* ApiResult is no longer an ApiBase or a ContextSource.
* Wherever sensible, ApiResult provides a static method working on an
arrayref and a non-static method working on internal data.
* Metadata is now always added to ApiResult's internal data structure.
Formatters are responsible for stripping it if necessary. "raw mode"
is deprecated.
* New metadata to replace the '*' key, solve the array() => '[]' vs '{}'
question, and so on.
* New class for formatting warnings and errors using i18n messages, and
support for multiple errors and a more machine-readable format for
warnings. For the moment, though, the actual output will not be changing
yet (see T47843 for future plans).
* New formatversion parameter for format=json and format=php, to select
between BC mode and the modern output.
* In BC mode, booleans will be converted to empty-string presence style;
modules currently returning booleans will need to use
ApiResult::META_BC_BOOLS to preserve their current output.
Actual changes to the API modules' output (e.g. actually returning
booleans for the new formatversion) beyond the use of
ApiResult::setContentValue() are left for a future change.
Bug: T76728
Bug: T57371
Bug: T33629
Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2014-12-03 22:14:22 +00:00
|
|
|
ApiResult::setContentValue( $entry, 'content', $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;
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-24 16:35:23 +00:00
|
|
|
private function formatCss( $css ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$result = [];
|
2010-05-24 16:35:23 +00:00
|
|
|
foreach ( $css as $file => $link ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$entry = [];
|
2010-05-24 16:35:23 +00:00
|
|
|
$entry['file'] = $file;
|
API: Overhaul ApiResult, make format=xml not throw, and add json formatversion
ApiResult was a mess: some methods could only be used with an array
reference instead of manipulating the stored data, methods that had both
array-ref and internal-data versions had names that didn't at all
correspond, some methods that worked on an array reference were
annoyingly non-static, and then the whole mess with setIndexedTagName.
ApiFormatXml is also entirely annoying to deal with, as it liked to
throw exceptions if certain metadata wasn't provided that no other
formatter required. Its legacy also means we have this silly convention
of using empty-string rather than boolean true, annoying restrictions on
keys (leading to things that should be hashes being arrays of key-value
object instead), '*' used as a key all over the place, and so on.
So, changes here:
* ApiResult is no longer an ApiBase or a ContextSource.
* Wherever sensible, ApiResult provides a static method working on an
arrayref and a non-static method working on internal data.
* Metadata is now always added to ApiResult's internal data structure.
Formatters are responsible for stripping it if necessary. "raw mode"
is deprecated.
* New metadata to replace the '*' key, solve the array() => '[]' vs '{}'
question, and so on.
* New class for formatting warnings and errors using i18n messages, and
support for multiple errors and a more machine-readable format for
warnings. For the moment, though, the actual output will not be changing
yet (see T47843 for future plans).
* New formatversion parameter for format=json and format=php, to select
between BC mode and the modern output.
* In BC mode, booleans will be converted to empty-string presence style;
modules currently returning booleans will need to use
ApiResult::META_BC_BOOLS to preserve their current output.
Actual changes to the API modules' output (e.g. actually returning
booleans for the new formatversion) beyond the use of
ApiResult::setContentValue() are left for a future change.
Bug: T76728
Bug: T57371
Bug: T33629
Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2014-12-03 22:14:22 +00:00
|
|
|
ApiResult::setContentValue( $entry, 'link', $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 ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$result = [];
|
2014-02-04 19:16:59 +00:00
|
|
|
|
|
|
|
|
foreach ( $limitReportData as $name => $value ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$entry = [];
|
2014-02-04 19:16:59 +00:00
|
|
|
$entry['name'] = $name;
|
|
|
|
|
if ( !is_array( $value ) ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$value = [ $value ];
|
2014-02-04 19:16:59 +00:00
|
|
|
}
|
2015-01-16 19:00:07 +00:00
|
|
|
ApiResult::setIndexedTagNameRecursive( $value, 'param' );
|
2014-02-04 19:16:59 +00:00
|
|
|
$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] ) ) {
|
API: Overhaul ApiResult, make format=xml not throw, and add json formatversion
ApiResult was a mess: some methods could only be used with an array
reference instead of manipulating the stored data, methods that had both
array-ref and internal-data versions had names that didn't at all
correspond, some methods that worked on an array reference were
annoyingly non-static, and then the whole mess with setIndexedTagName.
ApiFormatXml is also entirely annoying to deal with, as it liked to
throw exceptions if certain metadata wasn't provided that no other
formatter required. Its legacy also means we have this silly convention
of using empty-string rather than boolean true, annoying restrictions on
keys (leading to things that should be hashes being arrays of key-value
object instead), '*' used as a key all over the place, and so on.
So, changes here:
* ApiResult is no longer an ApiBase or a ContextSource.
* Wherever sensible, ApiResult provides a static method working on an
arrayref and a non-static method working on internal data.
* Metadata is now always added to ApiResult's internal data structure.
Formatters are responsible for stripping it if necessary. "raw mode"
is deprecated.
* New metadata to replace the '*' key, solve the array() => '[]' vs '{}'
question, and so on.
* New class for formatting warnings and errors using i18n messages, and
support for multiple errors and a more machine-readable format for
warnings. For the moment, though, the actual output will not be changing
yet (see T47843 for future plans).
* New formatversion parameter for format=json and format=php, to select
between BC mode and the modern output.
* In BC mode, booleans will be converted to empty-string presence style;
modules currently returning booleans will need to use
ApiResult::META_BC_BOOLS to preserve their current output.
Actual changes to the API modules' output (e.g. actually returning
booleans for the new formatversion) beyond the use of
ApiResult::setContentValue() are left for a future change.
Bug: T76728
Bug: T57371
Bug: T33629
Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2014-12-03 22:14:22 +00:00
|
|
|
ApiResult::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() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
2013-06-19 14:53:57 +00:00
|
|
|
'title' => null,
|
2016-02-17 09:09:32 +00:00
|
|
|
'text' => [
|
2015-05-07 16:39:55 +00:00
|
|
|
ApiBase::PARAM_TYPE => 'text',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2010-01-31 17:45:51 +00:00
|
|
|
'summary' => null,
|
2008-01-29 14:47:27 +00:00
|
|
|
'page' => null,
|
2016-02-17 09:09:32 +00:00
|
|
|
'pageid' => [
|
2011-04-04 20:51:41 +00:00
|
|
|
ApiBase::PARAM_TYPE => 'integer',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2008-10-24 12:28:14 +00:00
|
|
|
'redirects' => false,
|
2016-02-17 09:09:32 +00:00
|
|
|
'oldid' => [
|
2011-04-04 20:51:41 +00:00
|
|
|
ApiBase::PARAM_TYPE => 'integer',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'prop' => [
|
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,
|
2016-02-17 09:09:32 +00:00
|
|
|
ApiBase::PARAM_TYPE => [
|
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',
|
2015-01-23 23:27:11 +00:00
|
|
|
'jsconfigvars',
|
|
|
|
|
'encodedjsconfigvars',
|
Implement page status indicators
Page status indicators are icons (or short text snippets) usually
displayed in the top-right corner of the page, outside of the main
content. Basically, <indicator name="foo">[[File:Foo.svg|20px]]</indicator>
may be used on a page to place the icon in the indicator area. They
are also known as top icons, page icons, heading icons or title icons.
I found the discussion on bug 23796 highly illuminating. I suggest
that everyone read it before suggesting different design choices.
I spent some time with a thesaurus pondering the name. "Emblems" and
"badges" were also considered, but the former has a much more limited
meaning and the latter is already taken by Wikidata, with a similar
but subtly different feature set. I am not aware of any naming
conflicts ;) besides new talk page message "indicator" (used by core
and Echo in some documents) and OOjs UI indicators (tiny icons like
the arrow on a dropdown form element), which shouldn't be confusing.
Potential use cases include:
* "Lock" indicators for page protection levels
* Featured/good article indicators
* Redirect shortcuts display ("WP:VPT")
* Links to help/manual for special pages
* Coordinates?… or globe icon for inline pop-up maps
Design features:
* Skin-customizable. Skins can fully control where and how indicators
are shown, or may just do <?php echo $this->getIndicators(); ?> to
output the default structure. By default they are not shown at all.
* Extension-customizable. Extensions can call ParserOutput::addIndicator()
to insert an indicator from one of the numerous parser hooks.
* Wiki-customizable. In addition to just using the parser functions,
on-wiki styles and scripts can use the provided classes and ids
(.mw-indicator, #mw-indicator-<name>) to customize their display.
Design limitations:
* Every indicator must have a unique identifier (name). It's not
possible to create arrays, or to have several indicators with the
same name. In case of duplicates, the latest occurrence of the
parser function wins.
* Indicators are displayed ordered by their names (and not occurrence
order). This ensures consistency across pages and provides a simple
means of ordering or grouping them.
* Indicators are not stored, tracked or accessible outside of
ParserOutput (in particular they're not in the page_props table).
They are intended to merely reflect the content or metadata that is
already present on the page, and not be data themselves. If you ever
think you need to list pages with a given status indicator, instead
figure out what it means and use the appropriate tracking category,
special page report, already existing page_prop, or other means.
Corresponding patch in Vector: I90a8ae15ac8275d084ea5f47b6b2684d5e6c7412.
I'll implement support in the other three skins included in the tarball
and document it on mediawiki.org after this is merged.
Bug: 23796
Change-Id: I2389ff9a5332a2b1d033eb75f0946e5241cfaaf4
2014-09-24 10:44:16 +00:00
|
|
|
'indicators',
|
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',
|
2015-06-05 09:22:17 +00:00
|
|
|
'parsetree',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
ApiBase::PARAM_HELP_MSG_PER_VALUE => [
|
|
|
|
|
'parsetree' => [ 'apihelp-parse-paramvalue-prop-parsetree', CONTENT_MODEL_WIKITEXT ],
|
|
|
|
|
],
|
|
|
|
|
],
|
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
|
|
|
'section' => null,
|
2016-02-17 09:09:32 +00:00
|
|
|
'sectiontitle' => [
|
2015-03-10 21:27:01 +00:00
|
|
|
ApiBase::PARAM_TYPE => 'string',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'disablepp' => [
|
2015-08-24 05:05:09 +00:00
|
|
|
ApiBase::PARAM_DFLT => false,
|
|
|
|
|
ApiBase::PARAM_DEPRECATED => true,
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2015-08-24 05:05:09 +00:00
|
|
|
'disablelimitreport' => false,
|
2014-06-21 06:09:18 +00:00
|
|
|
'disableeditsection' => false,
|
2015-08-24 05:05:09 +00:00
|
|
|
'disabletidy' => false,
|
2016-02-17 09:09:32 +00:00
|
|
|
'generatexml' => [
|
2014-09-18 17:38:23 +00:00
|
|
|
ApiBase::PARAM_DFLT => false,
|
2016-02-17 09:09:32 +00:00
|
|
|
ApiBase::PARAM_HELP_MSG => [
|
2014-09-18 17:38:23 +00:00
|
|
|
'apihelp-parse-param-generatexml', CONTENT_MODEL_WIKITEXT
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2015-06-05 09:22:17 +00:00
|
|
|
ApiBase::PARAM_DEPRECATED => true,
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
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,
|
2016-02-17 09:09:32 +00:00
|
|
|
'contentformat' => [
|
2012-08-21 14:15:12 +00:00
|
|
|
ApiBase::PARAM_TYPE => ContentHandler::getAllContentFormats(),
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'contentmodel' => [
|
2012-08-21 14:15:12 +00:00
|
|
|
ApiBase::PARAM_TYPE => ContentHandler::getContentModels(),
|
2016-02-17 09:09:32 +00:00
|
|
|
]
|
|
|
|
|
];
|
2007-12-01 13:37:02 +00:00
|
|
|
}
|
|
|
|
|
|
2014-10-28 17:17:02 +00:00
|
|
|
protected function getExamplesMessages() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
2014-09-18 17:38:23 +00:00
|
|
|
'action=parse&page=Project:Sandbox'
|
|
|
|
|
=> 'apihelp-parse-example-page',
|
|
|
|
|
'action=parse&text={{Project:Sandbox}}&contentmodel=wikitext'
|
|
|
|
|
=> 'apihelp-parse-example-text',
|
|
|
|
|
'action=parse&text={{PAGENAME}}&title=Test'
|
|
|
|
|
=> 'apihelp-parse-example-texttitle',
|
|
|
|
|
'action=parse&summary=Some+[[link]]&prop='
|
|
|
|
|
=> 'apihelp-parse-example-summary',
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
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
|
|
|
}
|