jenkins-bot has submitted this change and it was merged. Change subject: Add content type: fixed-html ......................................................................
Add content type: fixed-html API is drawing a lot on view-* APIs, both for displaying content & editing content (we're now directly using the html output in VE) We need to be able to request 2 kinds of HTML: the one including our ContentFixer adjustments (for output) & the one for VE, where we need the original content. This patch adds a 'fixed-html' content type. 'html' will from now be the original, unfixed, html - the way VE needs it & we store it. 'fixed-html' is what we'll output, where ContentFixers are applied. Bug: T90681 Change-Id: I3506c60790b03bf368a24d0964a81bda593c6aaf --- M includes/Api/ApiFlowViewHeader.php M includes/Api/ApiFlowViewPost.php M includes/Api/ApiFlowViewTopicSummary.php M includes/Block/Header.php M includes/Block/Topic.php M includes/Block/TopicSummary.php M includes/Formatter/RevisionFormatter.php M includes/TemplateHelper.php M includes/Templating.php M modules/editor/editors/ext.flow.editors.none.js M modules/editor/editors/visualeditor/ext.flow.editors.visualeditor.js M modules/engine/misc/flow-handlebars.js 12 files changed, 33 insertions(+), 25 deletions(-) Approvals: EBernhardson: Looks good to me, approved jenkins-bot: Verified diff --git a/includes/Api/ApiFlowViewHeader.php b/includes/Api/ApiFlowViewHeader.php index 01aa15d..231beef 100644 --- a/includes/Api/ApiFlowViewHeader.php +++ b/includes/Api/ApiFlowViewHeader.php @@ -26,7 +26,7 @@ return array( 'format' => array( - ApiBase::PARAM_TYPE => array( 'html', 'wikitext' ), + ApiBase::PARAM_TYPE => array( 'html', 'wikitext', 'fixed-html' ), ApiBase::PARAM_DFLT => $wgFlowContentFormat, ), 'revId' => null, diff --git a/includes/Api/ApiFlowViewPost.php b/includes/Api/ApiFlowViewPost.php index 7b68b56..fe56fbc 100644 --- a/includes/Api/ApiFlowViewPost.php +++ b/includes/Api/ApiFlowViewPost.php @@ -30,7 +30,7 @@ ApiBase::PARAM_REQUIRED => true, ), 'format' => array( - ApiBase::PARAM_TYPE => array( 'html', 'wikitext' ), + ApiBase::PARAM_TYPE => array( 'html', 'wikitext', 'fixed-html' ), ApiBase::PARAM_DFLT => $wgFlowContentFormat, ), 'contentFormat' => array( diff --git a/includes/Api/ApiFlowViewTopicSummary.php b/includes/Api/ApiFlowViewTopicSummary.php index fc93ae7..d41abcc 100644 --- a/includes/Api/ApiFlowViewTopicSummary.php +++ b/includes/Api/ApiFlowViewTopicSummary.php @@ -26,7 +26,7 @@ return array( 'format' => array( - ApiBase::PARAM_TYPE => array( 'html', 'wikitext' ), + ApiBase::PARAM_TYPE => array( 'html', 'wikitext', 'fixed-html' ), ApiBase::PARAM_DFLT => $wgFlowContentFormat, ), 'revId' => null, diff --git a/includes/Block/Header.php b/includes/Block/Header.php index 951d479..af3796e 100644 --- a/includes/Block/Header.php +++ b/includes/Block/Header.php @@ -195,7 +195,7 @@ switch ( $this->action ) { case 'view': - $format = isset( $options['format'] ) ? $options['format'] : 'html'; + $format = isset( $options['format'] ) ? $options['format'] : 'fixed-html'; $output += $this->renderRevisionApi( $format ); break; @@ -213,7 +213,7 @@ if ( isset( $options['revId'] ) && $options['revId'] ) { $output += $this->renderSingleViewApi( $options['revId'] ); } else { - $format = isset( $options['format'] ) ? $options['format'] : 'html'; + $format = isset( $options['format'] ) ? $options['format'] : 'fixed-html'; $output += $this->renderRevisionApi( $format ); } break; diff --git a/includes/Block/Topic.php b/includes/Block/Topic.php index fcf70c3..730378d 100644 --- a/includes/Block/Topic.php +++ b/includes/Block/Topic.php @@ -589,7 +589,7 @@ protected function renderTopicApi( array $options, $workflowId = '' ) { $serializer = Container::get( 'formatter.topic' ); - $format = isset( $options['format'] ) ? $options['format'] : 'html'; + $format = isset( $options['format'] ) ? $options['format'] : 'fixed-html'; $serializer->setContentFormat( $format ); if ( !$workflowId ) { @@ -629,7 +629,7 @@ throw new FlowException( 'No posts can exist for non-existent topic' ); } - $format = isset( $options['format'] ) ? $options['format'] : 'html'; + $format = isset( $options['format'] ) ? $options['format'] : 'fixed-html'; $serializer = $this->getRevisionFormatter( $format ); if ( !$postId ) { @@ -686,7 +686,7 @@ } /** - * @param string $format Content format (html|wikitext) + * @param string $format Content format (html|wikitext|html-fixed|plaintext) * @return RevisionFormatter */ protected function getRevisionFormatter( $format ) { @@ -721,7 +721,7 @@ protected function processHistoryResult( /* TopicHistoryQuery|PostHistoryQuery */ $query, UUID $uuid, $options ) { global $wgRequest; - $format = isset( $options['format'] ) ? $options['format'] : 'html'; + $format = isset( $options['format'] ) ? $options['format'] : 'fixed-html'; $serializer = $this->getRevisionFormatter( $format ); $serializer->setIncludeHistoryProperties( true ); diff --git a/includes/Block/TopicSummary.php b/includes/Block/TopicSummary.php index 8d0114b..2dfa0a5 100644 --- a/includes/Block/TopicSummary.php +++ b/includes/Block/TopicSummary.php @@ -258,7 +258,7 @@ $formatter = Container::get( 'formatter.revisionview' ); $output['revision'] = $formatter->formatApi( $row, $this->context ); } else { - $format = isset( $options['format'] ) ? $options['format'] : 'html'; + $format = isset( $options['format'] ) ? $options['format'] : 'fixed-html'; $output += $this->renderNewestTopicSummary( $format ); } break; diff --git a/includes/Formatter/RevisionFormatter.php b/includes/Formatter/RevisionFormatter.php index 5d33d1c..3ff60fe 100644 --- a/includes/Formatter/RevisionFormatter.php +++ b/includes/Formatter/RevisionFormatter.php @@ -66,12 +66,12 @@ /** * @var string[] */ - protected $allowedContentFormats = array( 'html', 'wikitext' ); + protected $allowedContentFormats = array( 'html', 'wikitext', 'fixed-html', 'plaintext' ); /** * @var string Default content format for revision output */ - protected $contentFormat = 'html'; + protected $contentFormat = 'fixed-html'; /** * @var array Map from alphadeicmal revision id to content format ovverride @@ -868,7 +868,7 @@ * Parsoid roundtrip is needed then (and if it *is*, it'll already * be needed to render Flow discussions, so this is manageable) */ - $content = $this->templating->getContent( $revision, 'html' ); + $content = $this->templating->getContent( $revision, 'fixed-html' ); // strip html tags and decode to plaintext $content = Utils::htmlToPlaintext( $content, 140, $ctx->getLanguage() ); return Message::plaintextParam( $content ); @@ -935,7 +935,7 @@ if ( $post->isTopicTitle() ) { return Message::plaintextParam( $this->templating->getContent( $post, 'wikitext' ) ); } else { - return Message::rawParam( $this->templating->getContent( $post, 'html' ) ); + return Message::rawParam( $this->templating->getContent( $post, 'fixed-html' ) ); } case 'bundle-count': diff --git a/includes/TemplateHelper.php b/includes/TemplateHelper.php index 79b0af7..63bfb84 100644 --- a/includes/TemplateHelper.php +++ b/includes/TemplateHelper.php @@ -730,7 +730,7 @@ throw new WrongNumberArgumentsException( $args, 'two' ); } list( $contentType, $content ) = $args; - return $contentType === 'html' ? self::html( $content ) : $content; + return in_array( $contentType, array( 'html', 'fixed-html' ) ) ? self::html( $content ) : $content; } /** diff --git a/includes/Templating.php b/includes/Templating.php index 3393dad..cae993d 100644 --- a/includes/Templating.php +++ b/includes/Templating.php @@ -2,6 +2,7 @@ namespace Flow; +use Flow\Exception\InvalidInputException; use Flow\Repository\UserNameBatch; use Flow\Exception\FlowException; use Flow\Model\AbstractRevision; @@ -111,15 +112,16 @@ * required permissions to view the full content). Otherwise, in normal * cases, the full content will be returned. * - * The content-type of the return value varys on the $format parameter. + * The content-type of the return value varies on the $format parameter. * Further processing in the final output stage must escape all formats * other than the default 'html'. * * @param AbstractRevision $revision Revision to display content for - * @param string[optional] $format Format to output content in (html|wikitext) + * @param string[optional] $format Format to output content in (fixed-html|html|wikitext|plaintext) * @return string HTML if requested, otherwise plain text + * @throws InvalidInputException */ - public function getContent( AbstractRevision $revision, $format = 'html' ) { + public function getContent( AbstractRevision $revision, $format = 'fixed-html' ) { $allowed = $this->permissions->isAllowed( $revision, 'view' ); // Posts require view access to the topic title as well if ( $allowed && $revision instanceof PostRevision && !$revision->isTopicTitle() ) { @@ -130,8 +132,8 @@ } if ( $allowed ) { - // html format - if ( $format === 'html' ) { + // fixed html format + if ( $format === 'fixed-html' ) { // Parsoid doesn't render redlinks & doesn't strip bad images try { $content = $this->contentFixer->getContent( $revision ); @@ -142,8 +144,14 @@ $content = wfMessage( 'flow-stub-post-content' )->parse(); } // all other formats - } else { + } elseif ( in_array( $format, array( 'html', 'plaintext', 'wikitext' ) ) ) { + if ( $format === 'plaintext' ) { + $format = 'wikitext'; + } + $content = $revision->getContent( $format ); + } else { + throw new InvalidInputException( 'Invalid format: ' . $format ); } return $content; @@ -180,7 +188,7 @@ $message = wfMessage( 'flow-error-other' ); } - if ( $format === 'html' ) { + if ( in_array( $format, array( 'fixed-html', 'html' ) ) ) { return $message->escaped(); } else { return $message->text(); diff --git a/modules/editor/editors/ext.flow.editors.none.js b/modules/editor/editors/ext.flow.editors.none.js index c869943..4e92e26 100644 --- a/modules/editor/editors/ext.flow.editors.none.js +++ b/modules/editor/editors/ext.flow.editors.none.js @@ -33,7 +33,7 @@ // Static properties /** - * Type of content to use (html or wikitext) + * Type of content to use * * @var string */ diff --git a/modules/editor/editors/visualeditor/ext.flow.editors.visualeditor.js b/modules/editor/editors/visualeditor/ext.flow.editors.visualeditor.js index 91eb1a1..661cb06 100644 --- a/modules/editor/editors/visualeditor/ext.flow.editors.visualeditor.js +++ b/modules/editor/editors/visualeditor/ext.flow.editors.visualeditor.js @@ -169,7 +169,7 @@ // Static fields /** - * Type of content to use (html or wikitext) + * Type of content to use * * @var {string} */ diff --git a/modules/engine/misc/flow-handlebars.js b/modules/engine/misc/flow-handlebars.js index b3f2192..68aa637 100644 --- a/modules/engine/misc/flow-handlebars.js +++ b/modules/engine/misc/flow-handlebars.js @@ -466,7 +466,7 @@ * @return {string} */ FlowHandlebars.prototype.escapeContent = function ( contentType, content ) { - if ( contentType === 'html' ) { + if ( contentType === 'html' || contentType === 'fixed-html' ) { return FlowHandlebars.prototype.html( content ); } return content; -- To view, visit https://gerrit.wikimedia.org/r/202339 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I3506c60790b03bf368a24d0964a81bda593c6aaf Gerrit-PatchSet: 5 Gerrit-Project: mediawiki/extensions/Flow Gerrit-Branch: master Gerrit-Owner: Matthias Mullie <mmul...@wikimedia.org> Gerrit-Reviewer: EBernhardson <ebernhard...@wikimedia.org> Gerrit-Reviewer: Legoktm <legoktm.wikipe...@gmail.com> Gerrit-Reviewer: Matthias Mullie <mmul...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits