jenkins-bot has submitted this change and it was merged. Change subject: Migrated DYK box from DYK extension and added msg. ......................................................................
Migrated DYK box from DYK extension and added msg. No Siebrands were harmed in the making of this commit. Change-Id: I91cca7d8ef230860ba2971f285a2b5b9c767cd7b --- M EducationProgram.i18n.php M EducationProgram.php A includes/DYKBox.php M includes/specials/SpecialMyCourses.php A resources/ep.dyk.css 5 files changed, 217 insertions(+), 5 deletions(-) Approvals: Reedy: Looks good to me, approved jenkins-bot: Verified diff --git a/EducationProgram.i18n.php b/EducationProgram.i18n.php index 68191aa..6380555 100644 --- a/EducationProgram.i18n.php +++ b/EducationProgram.i18n.php @@ -29,6 +29,7 @@ 'ep-move-error' => 'You are not allowed to move articles in or out of the education namespaces.', 'ep-student-view-profile' => 'student profile', 'ep-err-failed-to-save' => 'Something went wrong - your changes have not been saved.', + 'ep-didyouknow-header' => 'Did you know ... ?', // Tabs 'ep-tab-view' => 'Read', @@ -843,6 +844,7 @@ 'educationprogram-desc' => '{{desc|name=Education Program|url=http://www.mediawiki.org/wiki/Extension:Education_Program}}', 'ep-item-summary' => 'Table column header. {{Identical|Summary}}', + 'ep-didyouknow-header' => 'Message displayed as a header in the did you know box', 'ep-toplink' => 'Text of a link the the top menu (next to "My preferences")', 'ep-org-course-delete-comment' => 'Success message. Parameters: * $1 is an institution name, diff --git a/EducationProgram.php b/EducationProgram.php index 54ee1bb..e528d00 100644 --- a/EducationProgram.php +++ b/EducationProgram.php @@ -147,6 +147,7 @@ $wgAutoloadClasses['EducationProgram\Students'] = $dir . '/includes/tables/Students.php'; // includes +$wgAutoloadClasses['EducationProgram\DYKBox'] = $dir . '/includes/DYKBox.php'; $wgAutoloadClasses['EducationProgram\LogFormatter'] = $dir . '/includes/LogFormatter.php'; $wgAutoloadClasses['EducationProgram\RoleChangeFormatter'] = $dir . '/includes/LogFormatter.php'; $wgAutoloadClasses['EducationProgram\ArticleFormatter'] = $dir . '/includes/LogFormatter.php'; @@ -679,6 +680,12 @@ ), ); +$wgResourceModules['ep.dyk'] = $moduleTemplate + array( + 'styles' => array( + 'ep.dyk.css', + ), +); + unset( $moduleTemplate ); $egEPSettings = array(); diff --git a/includes/DYKBox.php b/includes/DYKBox.php new file mode 100644 index 0000000..158e5b6 --- /dev/null +++ b/includes/DYKBox.php @@ -0,0 +1,180 @@ +<?php + +namespace EducationProgram; +use IContextSource; +use Html; +use WikiPage; +use Title; +use TextContent; + +/** + * Class representing a did you know box. + * + * @since 0.3 + * + * @file + * @ingroup EducationProgram + * + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < jeroended...@gmail.com > + */ +class DYKBox extends \ContextSource { + + protected $mainCategory; + protected $specificCategory; + + /** + * Constructor. + * + * @since 0.3 + * + * @param string $mainCategory + * @param string|bool $specificCategory + * @param IContextSource|null $context + */ + public function __construct( $mainCategory, $specificCategory = false, IContextSource $context = null ) { + if ( !is_null( $context ) ) { + $this->setContext( $context ); + } + + $this->mainCategory = $mainCategory; + $this->specificCategory = $specificCategory; + } + + /** + * Returns the HTML for the did you know box. + * + * @since 0.3 + * + * @return string + */ + public function getHTML() { + $html = '<h4 class="didyouknow-header">'; + $html .= $this->msg( 'ep-didyouknow-header' )->escaped(); + $html .= '</h4>'; + + $title = $this->getArticleTitle(); + + if ( $title === false ) { + return ''; + } + else { + $html .= $this->getOutput()->parse( $this->getArticleContent( $title ) ); + } + + $html = Html::rawElement( + 'div', + array( 'class' => 'didyouknow' ), + $html + ); + + return $html; + } + + /** + * Returns the resource modules needed by the did you know box. + * + * @since 0.3 + * + * @return array + */ + public static function getModules() { + return array( + 'ep.dyk' + ); + } + + /** + * Displays the did you know box. + * + * @since 0.3 + */ + public function display() { + $this->getOutput()->addHTML( $this->getHTML() ); + $this->getOutput()->addModules( self::getModules() ); + } + + /** + * Returns the content for the article with provided title. + * + * @since 0.3 + * + * @param Title $title + * + * @return string + */ + protected function getArticleContent( Title $title ) { + $wikiPage = WikiPage::newFromID( $title->getArticleID() ); + + if ( $wikiPage === null ) { + return ''; + } + + $content = $wikiPage->getContent(); + + if ( $content === null || !( $content instanceof TextContent ) ) { + return ''; + } + + return $content->getNativeData(); + } + + /** + * Returns the title for the article to get content from or false if there is none. + * + * @since 0.3 + * + * @return Title|bool + */ + protected function getArticleTitle() { + $pageName = false; + + if ( $this->specificCategory !== false ) { + $pageName = $this->getPageFromCategory( $this->specificCategory ); + } + + if ( $pageName === false ) { + $pageName = $this->getPageFromCategory( $this->mainCategory ); + } + + return $pageName === false ? false : Title::newFromText( $pageName ); + } + + /** + * Gets a random page from a category. + * Note that the random function becomes inefficient for large result sets, + * so this should only be used for small categories. + * + * NOTE: this is only usable for small categories since the query becomes + * expensive for big categories. So do not use for categories with potentially + * hundreds of pages or more. + * + * @since 0.3 + * + * @param string $categoryName + * + * @return string|bool + */ + protected function getPageFromCategory( $categoryName ) { + global $wgContLang; + + $dbr = wfGetDB( DB_SLAVE ); + $res = $dbr->selectRow( + array( 'page', 'categorylinks' ), + array( 'page_namespace', 'page_title' ), + array( + 'cl_from=page_id', + 'cl_to' => Title::newFromText( $categoryName, NS_CATEGORY )->getDBkey() + ), + __METHOD__, + array( 'ORDER BY' => 'RAND()' ) + ); + + if ( $res !== false ) { + $res = $wgContLang->getNsText( $res->page_namespace ) . ':' . $res->page_title; + } + + return $res; + } + +} diff --git a/includes/specials/SpecialMyCourses.php b/includes/specials/SpecialMyCourses.php index d2f146e..df52565 100644 --- a/includes/specials/SpecialMyCourses.php +++ b/includes/specials/SpecialMyCourses.php @@ -49,9 +49,7 @@ $this->startCache( 60 ); - if ( defined( 'DYK_VERSION' ) ) { - $this->displayDidYouKnow(); - } + $this->displayDidYouKnow(); if ( $this->courses === array() ) { $this->getOutput()->addWikiMsg( 'ep-dashboard-enroll-first' ); @@ -120,7 +118,7 @@ } } - $box = new \DYKBox( + $box = new DYKBox( Settings::get( 'dykCategory' ), $specificCategory, $context @@ -131,7 +129,7 @@ array( $this->getContext(), $this->courses ) ); - $this->getOutput()->addModules( \DYKBox::getModules() ); + $this->getOutput()->addModules( DYKBox::getModules() ); } /** diff --git a/resources/ep.dyk.css b/resources/ep.dyk.css new file mode 100644 index 0000000..55b966e --- /dev/null +++ b/resources/ep.dyk.css @@ -0,0 +1,25 @@ +/** + * CSS for the Education Program MediaWiki extension. + * @see https://www.mediawiki.org/wiki/Extension:Education_Program + * + * @licence GNU GPL v2+ + * @author Jeroen De Dauw <jeroendedauw at gmail dot com> + */ + +div.didyouknow { + background-color: #EDEFF5; + border-bottom: 1px solid #D2D9E6; + width: 300px; + position: static; + float: right; +} + +h4.didyouknow-header { + padding: 5px 15px 4px; + border-bottom: 1px solid #A2A9B6; + border-top: 1px solid #A2A9B6; +} + +div.didyouknow > p { + padding: 5px 25px 4px; +} -- To view, visit https://gerrit.wikimedia.org/r/43488 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I91cca7d8ef230860ba2971f285a2b5b9c767cd7b Gerrit-PatchSet: 6 Gerrit-Project: mediawiki/extensions/EducationProgram Gerrit-Branch: master Gerrit-Owner: Jeroen De Dauw <jeroended...@gmail.com> Gerrit-Reviewer: CSteipp <cste...@wikimedia.org> Gerrit-Reviewer: Isarra <zhoris...@gmail.com> Gerrit-Reviewer: Jeroen De Dauw <jeroended...@gmail.com> Gerrit-Reviewer: Ragesoss <rages...@gmail.com> Gerrit-Reviewer: Reedy <re...@wikimedia.org> Gerrit-Reviewer: Siebrand <siebr...@wikimedia.org> Gerrit-Reviewer: jenkins-bot _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits