Hoo man has uploaded a new change for review. https://gerrit.wikimedia.org/r/311227
Change subject: Content handler demo ...................................................................... Content handler demo Change-Id: I2f76e022e2379e7a9ee4654c7212f0701cb9d83e --- M extension.json A includes/VideoLinkContent.php A includes/VideoLinkHandler.php 3 files changed, 113 insertions(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MOOC refs/changes/27/311227/1 diff --git a/extension.json b/extension.json index 06a68a9..63cfca4 100644 --- a/extension.json +++ b/extension.json @@ -16,7 +16,9 @@ "HTMLGenerator": "includes/rendering/HTMLGenerator.php", "MoocItemRenderer": "includes/rendering/MoocItemRenderer.php", "MoocStructureProvider": "includes/MoocStructureProvider.php", - "SpecialHelloWorld": "specials/SpecialHelloWorld.php" + "SpecialHelloWorld": "specials/SpecialHelloWorld.php", + "VideoLinkContent": "includes/VideoLinkContent.php", + "VideoLinkHandler": "includes/VideoLinkHandler.php" }, "config": { "MOOCEnableFoo": true @@ -58,5 +60,8 @@ "SpecialPages": { "HelloWorld": "SpecialHelloWorld" }, + "ContentHandlers": { + "videolink": "VideoLinkHandler" + }, "manifest_version": 1 } diff --git a/includes/VideoLinkContent.php b/includes/VideoLinkContent.php new file mode 100644 index 0000000..3ed7460 --- /dev/null +++ b/includes/VideoLinkContent.php @@ -0,0 +1,65 @@ +<?php +/** + * JSON Content Model + * + * @file + * + * @author Ori Livneh <o...@wikimedia.org> + * @author Kunal Mehta <lego...@gmail.com> + */ + +/** + * Represents the content of a JSON content. + * @since 1.24 + */ +class VideoLinkContent extends TextContent { + + /** + * @since 1.25 + * @var Status + */ + protected $jsonParse; + + /** + * @param string $text JSON + */ + public function __construct( $text, $modelId = 'videolink' ) { + parent::__construct( $text, $modelId ); + } + + /** + * @return bool Whether content is valid. + */ + public function isValid() { + return true; + } + + /** + * Set the HTML and add the appropriate styles. + * + * @param Title $title + * @param int $revId + * @param ParserOptions $options + * @param bool $generateHtml + * @param ParserOutput $output + */ + protected function fillParserOutput( Title $title, $revId, + ParserOptions $options, $generateHtml, ParserOutput &$output + ) { + $json = $this->getNativeData(); + $data = (array)json_decode( $json ); + + $parserConfig = array( 'class' => 'Parser' ); + $parser = new Parser( $parserConfig ); + $pout = $parser->parse( '== Video: "' . $data['name'] . '" ==' . PHP_EOL . '[[File:' . $data['file'] . ']]', $title, $options, Parser::OT_HTML ); + // FIXME: WikiPage::doEditContent generates parser output before validation. + // As such, native data may be invalid (though output is discarded later in that case). + if ( $generateHtml && $this->isValid() ) { + $output->setText( $pout->getText() ); + $output->addImage( $data['file'] ); + } else { + $output->setText( '' ); + } + } + +} diff --git a/includes/VideoLinkHandler.php b/includes/VideoLinkHandler.php new file mode 100644 index 0000000..3762ebd --- /dev/null +++ b/includes/VideoLinkHandler.php @@ -0,0 +1,42 @@ +<?php +/** + * 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/gpl.html + * + * @file + */ + +/** + * Content handler for JSON. + * + * @author Ori Livneh <o...@wikimedia.org> + * @author Kunal Mehta <lego...@gmail.com> + * + * @since 1.24 + * @ingroup Content + */ +class VideoLinkHandler extends CodeContentHandler { + + public function __construct( $modelId = 'videolink' ) { + parent::__construct( $modelId, [ 'videolink' ] ); + } + + /** + * @return string + */ + protected function getContentClass() { + return VideoLinkContent::class; + } +} -- To view, visit https://gerrit.wikimedia.org/r/311227 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I2f76e022e2379e7a9ee4654c7212f0701cb9d83e Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/MOOC Gerrit-Branch: master Gerrit-Owner: Hoo man <h...@online.de> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits