diff options
Diffstat (limited to 'CommentStreams/includes/CommentStreamsHooks.php')
-rw-r--r-- | CommentStreams/includes/CommentStreamsHooks.php | 81 |
1 files changed, 57 insertions, 24 deletions
diff --git a/CommentStreams/includes/CommentStreamsHooks.php b/CommentStreams/includes/CommentStreamsHooks.php index 6bfcf99a..38afb6d3 100644 --- a/CommentStreams/includes/CommentStreamsHooks.php +++ b/CommentStreams/includes/CommentStreamsHooks.php @@ -21,6 +21,24 @@ * DEALINGS IN THE SOFTWARE. */ +namespace MediaWiki\Extension\CommentStreams; + +use Article; +use DatabaseUpdater; +use MediaWiki; +use OutputPage; +use Parser; +use PPFrame; +use SearchResult; +use Skin; +use SMW\DIWikiPage; +use SpecialSearch; +use Status; +use Title; +use User; +use WebRequest; +use WikiPage; + class CommentStreamsHooks { /** @@ -92,16 +110,16 @@ class CommentStreamsHooks { } $wikipage = new WikiPage( $title ); $comment = Comment::newFromWikiPage( $wikipage ); - if ( !is_null( $comment ) ) { + if ( $comment !== null ) { $commentTitle = $comment->getCommentTitle(); - if ( !is_null( $commentTitle ) ) { + if ( $commentTitle !== null ) { $output->setPageTitle( $commentTitle ); } $associatedTitle = Title::newFromId( $comment->getAssociatedId() ); - if ( !is_null( $associatedTitle ) ) { + if ( $associatedTitle !== null ) { $values = []; if ( class_exists( 'PageProps' ) ) { - $values = PageProps::getInstance()->getProperties( $associatedTitle, + $values = \PageProps::getInstance()->getProperties( $associatedTitle, 'displaytitle' ); } if ( array_key_exists( $comment->getAssociatedId(), $values ) ) { @@ -117,7 +135,11 @@ class CommentStreamsHooks { wfMessage( 'commentstreams-error-comment-on-deleted-page' )->text(); $output->addHTML( '<p class="error">' . $message . '</p>' ); } - $output->addWikitext( $comment->getHTML() ); + if ( method_exists( 'OutputPage', 'addWikiTextAsInterface' ) ) { + $output->addWikiTextAsInterface( $comment->getHTML() ); + } else { + $output->addWikiText( $comment->getHTML() ); + } } return false; } @@ -213,11 +235,11 @@ class CommentStreamsHooks { */ public static function onParserSetup( Parser $parser ) { $parser->setHook( 'comment-streams', - 'CommentStreamsHooks::enableCommentStreams' ); + 'MediaWiki\Extension\CommentStreams\CommentStreamsHooks::enableCommentStreams' ); $parser->setHook( 'no-comment-streams', - 'CommentStreamsHooks::disableCommentStreams' ); + 'MediaWiki\Extension\CommentStreams\CommentStreamsHooks::disableCommentStreams' ); $parser->setHook( 'comment-streams-initially-collapsed', - 'CommentStreamsHooks::initiallyCollapseCommentStreams' ); + 'MediaWiki\Extension\CommentStreams\CommentStreamsHooks::initiallyCollapseCommentStreams' ); return true; } @@ -233,7 +255,7 @@ class CommentStreamsHooks { */ public static function enableCommentStreams( $input, array $args, Parser $parser, PPFrame $frame ) { - $parser->disableCache(); + $parser->getOutput()->updateCacheExpiry( 0 ); $cs = CommentStreams::singleton(); $cs->enableCommentsOnPage(); if ( isset( $args['location'] ) && $args['location'] === 'footer' ) { @@ -256,7 +278,7 @@ class CommentStreamsHooks { */ public static function disableCommentStreams( $input, array $args, Parser $parser, PPFrame $frame ) { - $parser->disableCache(); + $parser->getOutput()->updateCacheExpiry( 0 ); $cs = CommentStreams::singleton(); $cs->disableCommentsOnPage(); return ""; @@ -274,7 +296,7 @@ class CommentStreamsHooks { */ public static function initiallyCollapseCommentStreams( $input, array $args, Parser $parser, PPFrame $frame ) { - $parser->disableCache(); + $parser->getOutput()->updateCacheExpiry( 0 ); $cs = CommentStreams::singleton(); $cs->initiallyCollapseCommentsOnPage(); return ""; @@ -312,9 +334,9 @@ class CommentStreamsHooks { public static function showSearchHitTitle( Title &$title, &$text, SearchResult $result, array $terms, SpecialSearch $page ) { $comment = Comment::newFromWikiPage( WikiPage::factory( $title ) ); - if ( !is_null( $comment ) ) { + if ( $comment !== null ) { $t = Title::newFromId( $comment->getAssociatedId() ); - if ( !is_null( $t ) ) { + if ( $t !== null ) { $title = $t; } } @@ -322,9 +344,21 @@ class CommentStreamsHooks { } /** + * Implements SMW::Settings::BeforeInitializationComplete callback. + * See https://github.com/SemanticMediaWiki/SemanticMediaWiki/blob/master/docs/technical/hooks/hook.settings.beforeinitializationcomplete.md + * Defines CommentStreams namespace constants. + * + * @param array &$configuration An array of the configuration options + */ + public static function onSMWInitialization( array &$configuration ) { + $namespace = $GLOBALS['wgCommentStreamsNamespaceIndex']; + $configuration['smwgNamespacesWithSemanticLinks'][$namespace] = true; + } + + /** * Implements extension registration callback. * See https://www.mediawiki.org/wiki/Manual:Extension_registration#Customizing_registration - * Defines CommentStreams namespace constants. + * Sets configuration constants. * */ public static function onRegistration() { @@ -332,7 +366,6 @@ class CommentStreamsHooks { define( 'NS_COMMENTSTREAMS_TALK', $GLOBALS['wgCommentStreamsNamespaceIndex'] + 1 ); $GLOBALS['wgNamespacesToBeSearchedDefault'][NS_COMMENTSTREAMS] = true; - $GLOBALS['smwgNamespacesWithSemanticLinks'][NS_COMMENTSTREAMS] = true; $found = false; foreach ( $GLOBALS['wgGroupPermissions'] as $groupperms ) { if ( isset( $groupperms['cs-comment'] ) ) { @@ -392,40 +425,40 @@ class CommentStreamsHooks { */ public static function updateData( $store, $semanticData ) { $subject = $semanticData->getSubject(); - if ( !is_null( $subject ) && !is_null( $subject->getTitle() ) && + if ( $subject !== null && $subject->getTitle() !== null && $subject->getTitle()->getNamespace() === NS_COMMENTSTREAMS ) { $page_id = $subject->getTitle()->getArticleID( Title::GAID_FOR_UPDATE ); $wikipage = WikiPage::newFromId( $page_id ); $comment = Comment::newFromWikiPage( $wikipage ); - if ( is_null( $comment ) ) { + if ( $comment === null ) { return true; } $assoc_page_id = $comment->getAssociatedId(); - if ( !is_null( $assoc_page_id ) ) { + if ( $assoc_page_id !== null ) { $assoc_wikipage = WikiPage::newFromId( $assoc_page_id ); - if ( !is_null( $assoc_wikipage ) ) { + if ( $assoc_wikipage !== null ) { $propertyDI = new SMW\DIProperty( '___CS_ASSOCPG' ); $dataItem = - SMW\DIWikiPage::newFromTitle( $assoc_wikipage->getTitle() ); + DIWikiPage::newFromTitle( $assoc_wikipage->getTitle() ); $semanticData->addPropertyObjectValue( $propertyDI, $dataItem ); } } $parent_page_id = $comment->getParentId(); - if ( !is_null( $parent_page_id ) ) { + if ( $parent_page_id !== null ) { $parent_wikipage = WikiPage::newFromId( $parent_page_id ); - if ( !is_null( $parent_wikipage ) ) { + if ( $parent_wikipage !== null ) { $propertyDI = new SMW\DIProperty( '___CS_REPLYTO' ); $dataItem = - SMW\DIWikiPage::newFromTitle( $parent_wikipage->getTitle() ); + DIWikiPage::newFromTitle( $parent_wikipage->getTitle() ); $semanticData->addPropertyObjectValue( $propertyDI, $dataItem ); } } $commentTitle = $comment->getCommentTitle(); - if ( !is_null( $commentTitle ) ) { + if ( $commentTitle !== null ) { $propertyDI = new SMW\DIProperty( '___CS_TITLE' ); $dataItem = new SMWDIBlob( $comment->getCommentTitle() ); $semanticData->addPropertyObjectValue( $propertyDI, $dataItem ); |