Tweichart has submitted this change and it was merged. Change subject: Shoutbox Trigger + Counter ......................................................................
Shoutbox Trigger + Counter * added a sup counter element to the shoutbox tab to display the shouts beeing made in the shoutbox * added 4 new hooks before/after update/archive * changed getShouts API to return total amount of shouts * added new method to get all shouts for a single article id * added new icon to statebar to display the number of shouts * some cc Change-Id: Iabd571f95874a18f17c6ee5c0bfaab9de5fc5653 --- M ShoutBox/ShoutBox.class.php M ShoutBox/resources/bluespice.shoutBox.css M ShoutBox/resources/bluespice.shoutBox.js A ShoutBox/resources/images/icon-shoutbox.png 4 files changed, 232 insertions(+), 156 deletions(-) Approvals: Smuggli: Checked; Looks good to me, but someone else must approve Tweichart: Verified; Looks good to me, approved diff --git a/ShoutBox/ShoutBox.class.php b/ShoutBox/ShoutBox.class.php index 2b785b6..d28246d 100644 --- a/ShoutBox/ShoutBox.class.php +++ b/ShoutBox/ShoutBox.class.php @@ -1,4 +1,5 @@ <?php + /** * Shoutbox extension for BlueSpice * @@ -31,7 +32,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU Public License v2 or later * @filesource */ - /* Changelog * v1.20.0 * - MediaWiki I18N @@ -73,35 +73,36 @@ * Constructor of ShoutBox class */ public function __construct() { - wfProfileIn( 'BS::'.__METHOD__ ); + wfProfileIn( 'BS::' . __METHOD__ ); // Base settings $this->mExtensionFile = __FILE__; $this->mExtensionType = EXTTYPE::PARSERHOOK; - $this->mInfo = array( - EXTINFO::NAME => 'ShoutBox', + $this->mInfo = array( + EXTINFO::NAME => 'ShoutBox', EXTINFO::DESCRIPTION => 'Adds a parser function for embedding your own shoutbox.', - EXTINFO::AUTHOR => 'Karl Waldmannstetter, Markus Glaser', - EXTINFO::VERSION => 'default', - EXTINFO::STATUS => 'default', - EXTINFO::PACKAGE => 'default', - EXTINFO::URL => 'http://www.hallowelt.biz', - EXTINFO::DEPS => array( 'bluespice' => '2.22.0' ) + EXTINFO::AUTHOR => 'Karl Waldmannstetter, Markus Glaser', + EXTINFO::VERSION => 'default', + EXTINFO::STATUS => 'default', + EXTINFO::PACKAGE => 'default', + EXTINFO::URL => 'http://www.hallowelt.biz', + EXTINFO::DEPS => array( 'bluespice' => '2.22.0' ) ); $this->mExtensionKey = 'MW::ShoutBox'; - wfProfileOut( 'BS::'.__METHOD__ ); + wfProfileOut( 'BS::' . __METHOD__ ); } /** * Initialization of ShoutBox extension */ protected function initExt() { - wfProfileIn( 'BS::'.__METHOD__ ); + wfProfileIn( 'BS::' . __METHOD__ ); // Hooks $this->setHook( 'SkinTemplateOutputPageBeforeExec' ); $this->setHook( 'BeforePageDisplay' ); $this->setHook( 'BSInsertMagicAjaxGetData' ); + $this->setHook( 'BSStateBarBeforeTopViewAdd', 'onStateBarBeforeTopViewAdd' ); // Permissions $this->mCore->registerPermission( 'readshoutbox' ); @@ -110,15 +111,15 @@ $this->mCore->registerBehaviorSwitch( 'bs_noshoutbox' ); - BsConfig::registerVar('MW::ShoutBox::ShowShoutBoxByNamespace', array(0), BsConfig::LEVEL_PRIVATE|BsConfig::TYPE_ARRAY_INT, 'multiselectplusadd' ); - BsConfig::registerVar('MW::ShoutBox::CommitTimeInterval', 15, BsConfig::LEVEL_PUBLIC|BsConfig::TYPE_INT, 'bs-shoutbox-pref-committimeinterval', 'int' ); - BsConfig::registerVar('MW::ShoutBox::NumberOfShouts', 5, BsConfig::LEVEL_PUBLIC|BsConfig::TYPE_INT, 'bs-shoutbox-pref-numberofshouts', 'int' ); - BsConfig::registerVar('MW::ShoutBox::ShowAge', true, BsConfig::LEVEL_PUBLIC|BsConfig::TYPE_BOOL, 'bs-shoutbox-pref-showage', 'toggle' ); - BsConfig::registerVar('MW::ShoutBox::ShowUser', true, BsConfig::LEVEL_PUBLIC|BsConfig::TYPE_BOOL, 'bs-shoutbox-pref-showuser', 'toggle' ); - BsConfig::registerVar('MW::ShoutBox::Show', true, BsConfig::LEVEL_PUBLIC|BsConfig::TYPE_BOOL, 'bs-shoutbox-pref-show', 'toggle' ); - BsConfig::registerVar('MW::ShoutBox::AllowArchive', true, BsConfig::LEVEL_PUBLIC|BsConfig::TYPE_BOOL, 'bs-shoutbox-pref-allowarchive', 'toggle' ); - BsConfig::registerVar('MW::ShoutBox::MaxMessageLength', 255, BsConfig::LEVEL_PUBLIC|BsConfig::TYPE_INT, 'bs-shoutbox-pref-maxmessagelength', 'int' ); - wfProfileOut( 'BS::'.__METHOD__ ); + BsConfig::registerVar( 'MW::ShoutBox::ShowShoutBoxByNamespace', array( 0 ), BsConfig::LEVEL_PRIVATE | BsConfig::TYPE_ARRAY_INT, 'multiselectplusadd' ); + BsConfig::registerVar( 'MW::ShoutBox::CommitTimeInterval', 15, BsConfig::LEVEL_PUBLIC | BsConfig::TYPE_INT, 'bs-shoutbox-pref-committimeinterval', 'int' ); + BsConfig::registerVar( 'MW::ShoutBox::NumberOfShouts', 5, BsConfig::LEVEL_PUBLIC | BsConfig::TYPE_INT, 'bs-shoutbox-pref-numberofshouts', 'int' ); + BsConfig::registerVar( 'MW::ShoutBox::ShowAge', true, BsConfig::LEVEL_PUBLIC | BsConfig::TYPE_BOOL, 'bs-shoutbox-pref-showage', 'toggle' ); + BsConfig::registerVar( 'MW::ShoutBox::ShowUser', true, BsConfig::LEVEL_PUBLIC | BsConfig::TYPE_BOOL, 'bs-shoutbox-pref-showuser', 'toggle' ); + BsConfig::registerVar( 'MW::ShoutBox::Show', true, BsConfig::LEVEL_PUBLIC | BsConfig::TYPE_BOOL, 'bs-shoutbox-pref-show', 'toggle' ); + BsConfig::registerVar( 'MW::ShoutBox::AllowArchive', true, BsConfig::LEVEL_PUBLIC | BsConfig::TYPE_BOOL, 'bs-shoutbox-pref-allowarchive', 'toggle' ); + BsConfig::registerVar( 'MW::ShoutBox::MaxMessageLength', 255, BsConfig::LEVEL_PUBLIC | BsConfig::TYPE_INT, 'bs-shoutbox-pref-maxmessagelength', 'int' ); + wfProfileOut( 'BS::' . __METHOD__ ); } /** @@ -131,32 +132,32 @@ $sDir = __DIR__ . DS; if ( $wgDBtype == 'mysql' ) { - $wgExtNewTables[] = array( 'bs_shoutbox', $sDir . 'db/mysql/ShoutBox.sql' ); + $wgExtNewTables[] = array( 'bs_shoutbox', $sDir . 'db/mysql/ShoutBox.sql' ); $wgExtNewIndexes[] = array( 'bs_shoutbox', 'sb_page_id', $sDir . 'db/mysql/ShoutBox.patch.sb_page_id.index.sql' ); - $wgExtNewFields[] = array( 'bs_shoutbox', 'sb_user_id', $sDir . 'db/mysql/ShoutBox.patch.sb_user_id.sql' ); - $wgExtNewFields[] = array( 'bs_shoutbox', 'sb_archived', $sDir . 'db/mysql/ShoutBox.patch.sb_archived.sql' ); + $wgExtNewFields[] = array( 'bs_shoutbox', 'sb_user_id', $sDir . 'db/mysql/ShoutBox.patch.sb_user_id.sql' ); + $wgExtNewFields[] = array( 'bs_shoutbox', 'sb_archived', $sDir . 'db/mysql/ShoutBox.patch.sb_archived.sql' ); //TODO: also do this for oracle and postgres - $wgExtNewFields[] = array( 'bs_shoutbox', 'sb_title', $sDir . 'db/mysql/ShoutBox.patch.sb_title.sql' ); - $wgExtNewFields[] = array( 'bs_shoutbox', 'sb_touched', $sDir . 'db/mysql/ShoutBox.patch.sb_touched.sql' ); - $wgExtNewFields[] = array( 'bs_shoutbox', 'sb_parent_id', $sDir . 'db/mysql/ShoutBox.patch.sb_parent_id.sql' ); + $wgExtNewFields[] = array( 'bs_shoutbox', 'sb_title', $sDir . 'db/mysql/ShoutBox.patch.sb_title.sql' ); + $wgExtNewFields[] = array( 'bs_shoutbox', 'sb_touched', $sDir . 'db/mysql/ShoutBox.patch.sb_touched.sql' ); + $wgExtNewFields[] = array( 'bs_shoutbox', 'sb_parent_id', $sDir . 'db/mysql/ShoutBox.patch.sb_parent_id.sql' ); } elseif ( $wgDBtype == 'postgres' ) { - $wgExtNewTables[] = array( 'bs_shoutbox', $sDir . 'db/postgres/ShoutBox.pg.sql' ); + $wgExtNewTables[] = array( 'bs_shoutbox', $sDir . 'db/postgres/ShoutBox.pg.sql' ); $wgExtNewFields[] = array( 'bs_shoutbox', 'sb_archived', $sDir . 'db/postgres/ShoutBox.patch.sb_archived.pg.sql' ); /* - $wgExtNewIndexes[] = array( 'bs_shoutbox', 'sb_page_id', $sDir . 'db/postgres/ShoutBox.patch.sb_page_id.index.pg.sql' ); - $wgExtNewFields[] = array( 'bs_shoutbox', 'sb_user_id', $sDir . 'db/postgres/ShoutBox.patch.sb_user_id.pg.sql' ); - */ + $wgExtNewIndexes[] = array( 'bs_shoutbox', 'sb_page_id', $sDir . 'db/postgres/ShoutBox.patch.sb_page_id.index.pg.sql' ); + $wgExtNewFields[] = array( 'bs_shoutbox', 'sb_user_id', $sDir . 'db/postgres/ShoutBox.patch.sb_user_id.pg.sql' ); + */ } elseif ( $wgDBtype == 'oracle' ) { - $wgExtNewTables[] = array( 'bs_shoutbox', $sDir . 'db/oracle/ShoutBox.oci.sql' ); + $wgExtNewTables[] = array( 'bs_shoutbox', $sDir . 'db/oracle/ShoutBox.oci.sql' ); $dbr = wfGetDB( DB_SLAVE ); - if ( !$dbr->fieldExists('bs_shoutbox', 'sb_archived') && $dbr->tableExists('bs_shoutbox') ) { + if ( !$dbr->fieldExists( 'bs_shoutbox', 'sb_archived' ) && $dbr->tableExists( 'bs_shoutbox' ) ) { #$wgExtNewFields[] = array( 'bs_shoutbox', 'sb_archived', $sDir . 'db/oracle/ShoutBox.patch.sb_archived.oci.sql' ); } $wgExtNewIndexes[] = array( 'bs_shoutbox', 'sb_page_id', $sDir . 'db/oracle/ShoutBox.patch.sb_page_id.index.oci.sql' ); /* - $wgExtNewFields[] = array( 'bs_shoutbox', 'sb_user_id', $sDir . 'db/oracle/ShoutBox.patch.sb_user_id.oci.sql' ); - */ + $wgExtNewFields[] = array( 'bs_shoutbox', 'sb_user_id', $sDir . 'db/oracle/ShoutBox.patch.sb_user_id.oci.sql' ); + */ } return true; } @@ -168,10 +169,11 @@ * @return always true to keep hook running */ public function onBSInsertMagicAjaxGetData( &$oResponse, $type ) { - if( $type != 'switches' ) return true; + if ( $type != 'switches' ) + return true; $oResponse->result[] = array( - 'id' => 'bs:shoutbox', + 'id' => 'bs:shoutbox', 'type' => 'switch', 'name' => 'NOSHOUTBOX', 'desc' => wfMessage( 'bs-shoutbox-switch-description' )->plain(), @@ -188,24 +190,33 @@ * @return boolean */ public function onBeforePageDisplay( $oOutputPage, $oSkinTemplate ) { - if ( BsConfig::get( 'MW::ShoutBox::Show' ) === false ) return true; + if ( BsConfig::get( 'MW::ShoutBox::Show' ) === false ) + return true; $oTitle = $oOutputPage->getTitle(); - if( $oOutputPage->isPrintable() ) return true; + if ( $oOutputPage->isPrintable() ) + return true; - if( is_object( $oTitle ) && $oTitle->exists() == false ) return true; - if( !$oTitle->userCan( 'readshoutbox' ) ) return true; - if( $this->getRequest()->getVal( 'action', 'view' ) != 'view' ) return true; - if( $oTitle->isSpecialPage() ) return true; - if( !$oTitle->userCan( 'read' ) ) return true; + if ( is_object( $oTitle ) && $oTitle->exists() == false ) + return true; + if ( !$oTitle->userCan( 'readshoutbox' ) ) + return true; + if ( $this->getRequest()->getVal( 'action', 'view' ) != 'view' ) + return true; + if ( $oTitle->isSpecialPage() ) + return true; + if ( !$oTitle->userCan( 'read' ) ) + return true; $aNamespacesToDisplayShoutBox = BsConfig::get( 'MW::ShoutBox::ShowShoutBoxByNamespace' ); - if( !in_array( $oTitle->getNsText(), $aNamespacesToDisplayShoutBox ) ) return true; + if ( !in_array( $oTitle->getNsText(), $aNamespacesToDisplayShoutBox ) ) + return true; $vNoShoutbox = BsArticleHelper::getInstance( $oTitle )->getPageProp( 'bs_noshoutbox' ); - if( $vNoShoutbox === '' ) return true; + if ( $vNoShoutbox === '' ) + return true; - $oOutputPage->addModuleStyles('ext.bluespice.shoutbox.styles'); - $oOutputPage->addModules('ext.bluespice.shoutbox'); + $oOutputPage->addModuleStyles( 'ext.bluespice.shoutbox.styles' ); + $oOutputPage->addModules( 'ext.bluespice.shoutbox' ); BsExtensionManager::setContext( 'MW::ShoutboxShow' ); return true; @@ -232,8 +243,8 @@ $tpl->data['bs_dataAfterContent']['bs-shoutbox'] = array( 'position' => 30, - 'label' => wfMessage('bs-shoutbox-title')->text(), - 'content' => $oShoutBoxView ->execute() + 'label' => wfMessage( 'bs-shoutbox-title' )->text(), + 'content' => $oShoutBoxView->execute() ); return true; } @@ -245,26 +256,29 @@ * @return bool allow other hooked methods to be executed. Always true */ public static function getShouts( $iArticleId, $iLimit ) { - if ( BsCore::checkAccessAdmission( 'readshoutbox' ) === false ) return ""; + if ( BsCore::checkAccessAdmission( 'readshoutbox' ) === false ) + return ""; // do not allow negative page ids and pages that have 0 as id (e.g. special pages) - if ( $iArticleId <= 0 ) return true; + if ( $iArticleId <= 0 ) + return true; $sKey = BsCacheHelper::getCacheKey( 'BlueSpice', 'ShoutBox', $iArticleId ); $aData = BsCacheHelper::get( $sKey ); - if( $aData !== false ) { - wfDebugLog( 'BsMemcached', __CLASS__.': Fetching shouts from cache'); + if ( $aData !== false ) { + wfDebugLog( 'BsMemcached', __CLASS__ . ': Fetching shouts from cache' ); $sOutput = $aData; } else { - wfDebugLog( 'BsMemcached', __CLASS__.': Fetching shouts from DB'); - if ( $iLimit <= 0 ) $iLimit = BsConfig::get('MW::ShoutBox::NumberOfShouts'); + wfDebugLog( 'BsMemcached', __CLASS__ . ': Fetching shouts from DB' ); + if ( $iLimit <= 0 ) + $iLimit = BsConfig::get( 'MW::ShoutBox::NumberOfShouts' ); $sOutput = ''; //return false on hook handler to break here - $aTables = array('bs_shoutbox'); - $aFields = array('*'); + $aTables = array( 'bs_shoutbox' ); + $aFields = array( '*' ); $aConditions = array( 'sb_page_id' => $iArticleId, 'sb_archived' => '0', @@ -282,45 +296,66 @@ $dbr = wfGetDB( DB_SLAVE ); $res = $dbr->select( - $aTables, - $aFields, - $aConditions, - __METHOD__, - $aOptions + $aTables, $aFields, $aConditions, __METHOD__, $aOptions ); $oShoutBoxMessageListView = new ViewShoutBoxMessageList(); - if( $dbr->numRows( $res ) > $iLimit ) { - $oShoutBoxMessageListView->setMoreLimit( $iLimit + BsConfig::get('MW::ShoutBox::NumberOfShouts') ); + if ( $dbr->numRows( $res ) > $iLimit ) { + $oShoutBoxMessageListView->setMoreLimit( $iLimit + BsConfig::get( 'MW::ShoutBox::NumberOfShouts' ) ); } - $bShowAge = BsConfig::get( 'MW::ShoutBox::ShowAge' ); + $bShowAge = BsConfig::get( 'MW::ShoutBox::ShowAge' ); $bShowUser = BsConfig::get( 'MW::ShoutBox::ShowUser' ); $iCount = 0; - while( $row = $dbr->fetchRow( $res ) ) { + while ( $row = $dbr->fetchRow( $res ) ) { $oUser = User::newFromId( $row['sb_user_id'] ); $oProfile = BsCore::getInstance()->getUserMiniProfile( $oUser ); $oShoutBoxMessageView = new ViewShoutBoxMessage(); - if ( $bShowAge ) $oShoutBoxMessageView->setDate( BsFormatConverter::mwTimestampToAgeString( $row[ 'sb_timestamp' ], true ) ); - if ( $bShowUser ) $oShoutBoxMessageView->setUsername( $row[ 'sb_user_name' ] ); + if ( $bShowAge ) + $oShoutBoxMessageView->setDate( BsFormatConverter::mwTimestampToAgeString( $row['sb_timestamp'], true ) ); + if ( $bShowUser ) + $oShoutBoxMessageView->setUsername( $row['sb_user_name'] ); $oShoutBoxMessageView->setUser( $oUser ); $oShoutBoxMessageView->setMiniProfile( $oProfile ); - $oShoutBoxMessageView->setMessage( $row[ 'sb_message' ] ); - $oShoutBoxMessageView->setShoutID( $row[ 'sb_id' ] ); + $oShoutBoxMessageView->setMessage( $row['sb_message'] ); + $oShoutBoxMessageView->setShoutID( $row['sb_id'] ); $oShoutBoxMessageListView->addItem( $oShoutBoxMessageView ); // Since we have one more shout than iLimit, we need to count :) $iCount++; - if ( $iCount >= $iLimit ) break; + if ( $iCount >= $iLimit ) + break; } $sOutput .= $oShoutBoxMessageListView->execute(); + $iTotelShouts = self::getTotalShouts( $iArticleId ); + $sOutput .= "<div id='bs-sb-count-all' style='display:none'>" . $iTotelShouts . "</div>"; BsCacheHelper::set( $sKey, $sOutput ); $dbr->freeResult( $res ); } return $sOutput; + } + + /** + * Returns total number of shouts for the article id + * @param int $iArticleId + * @return int number of shouts + */ + public static function getTotalShouts( $iArticleId = 0 ) { + $aTables = array( 'bs_shoutbox' ); + $aFields = array( 'sb_id' ); + $aConditions = array( + 'sb_page_id' => $iArticleId, + 'sb_archived' => '0', + 'sb_parent_id' => '0', + 'sb_title' => '', + ); + $dbr = wfGetDB( DB_SLAVE ); + $res = $dbr->select( $aTables, $aFields, $aConditions, __METHOD__ ); + $iTotelShouts = $res !== false ? $dbr->numRows( $res ) : 0; + return $iTotelShouts; } /** @@ -330,11 +365,11 @@ * @return bool allow other hooked methods to be executed */ public static function insertShout( $iArticleId, $sMessage ) { - if ( BsCore::checkAccessAdmission( 'readshoutbox' ) === false - || BsCore::checkAccessAdmission( 'writeshoutbox' ) === false ) return true; + if ( BsCore::checkAccessAdmission( 'readshoutbox' ) === false || BsCore::checkAccessAdmission( 'writeshoutbox' ) === false ) + return true; $oRequest = RequestContext::getMain()->getRequest(); - $oUser = RequestContext::getMain()->getUser(); + $oUser = RequestContext::getMain()->getUser(); // prevent spam by enforcing a interval between two commits $iCommitTimeInterval = BsConfig::get( 'MW::ShoutBox::CommitTimeInterval' ); @@ -342,12 +377,12 @@ $vLastCommit = $oRequest->getSessionData( 'MW::ShoutBox::lastCommit' ); if ( is_numeric( $vLastCommit ) && $vLastCommit + $iCommitTimeInterval > $iCurrentCommit ) { - return json_encode(array('success' => false, 'msg' => 'bs-shoutbox-too-early')); + return json_encode( array( 'success' => false, 'msg' => 'bs-shoutbox-too-early' ) ); } $oRequest->setSessionData( 'MW::ShoutBox::lastCommit', $iCurrentCommit ); - $sNick = BsCore::getUserDisplayName( $oUser ); - $iUserId = $oUser->getId(); + $sNick = BsCore::getUserDisplayName( $oUser ); + $iUserId = $oUser->getId(); $sTimestamp = wfTimestampNow(); if ( strlen( $sMessage ) > BsConfig::get( 'MW::ShoutBox::MaxMessageLength' ) ) { @@ -355,25 +390,25 @@ } // TODO MRG (08.09.10 01:57): error message - if ( $iArticleId <= 0 ) return false; + if ( $iArticleId <= 0 ) + return false; $dbw = wfGetDB( DB_MASTER ); $dbw->insert( - 'bs_shoutbox', - array( - 'sb_page_id' => $iArticleId, - 'sb_user_id' => $iUserId, - 'sb_user_name' => $sNick, - 'sb_message' => $sMessage, - 'sb_timestamp' => $sTimestamp, - 'sb_archived' => '0' - ) + 'bs_shoutbox', array( + 'sb_page_id' => $iArticleId, + 'sb_user_id' => $iUserId, + 'sb_user_name' => $sNick, + 'sb_message' => $sMessage, + 'sb_timestamp' => $sTimestamp, + 'sb_archived' => '0' + ) ); // TODO RBV (21.10.10 17:21): Send error / success to client. wfRunHooks( 'BSShoutBoxAfterInsertShout', array( $iArticleId, $iUserId, $sNick, $sMessage, $sTimestamp ) ); self::invalidateShoutBoxCache( $iArticleId ); - return json_encode(array('success' => true, 'msg' => self::getShouts( $iArticleId, 0 ))); + return json_encode( array( 'success' => true, 'msg' => self::getShouts( $iArticleId, 0 ) ) ); } /** @@ -382,20 +417,16 @@ * @param string $sOutput success state of database action * @return bool allow other hooked methods to be executed */ - public static function archiveShout( $iShoutId, $iArticleId ){ - if ( BsCore::checkAccessAdmission( 'readshoutbox' ) === false - || BsCore::checkAccessAdmission( 'writeshoutbox' ) === false ) return true; + public static function archiveShout( $iShoutId, $iArticleId ) { + if ( BsCore::checkAccessAdmission( 'readshoutbox' ) === false || BsCore::checkAccessAdmission( 'writeshoutbox' ) === false ) + return true; global $wgUser; $iUserId = $wgUser->getId(); $dbw = wfGetDB( DB_MASTER ); $res = $dbw->select( - 'bs_shoutbox', - 'sb_user_id', - array( 'sb_id' => $iShoutId ), - __METHOD__, - array('LIMIT' => '1') + 'bs_shoutbox', 'sb_user_id', array( 'sb_id' => $iShoutId ), __METHOD__, array( 'LIMIT' => '1' ) ); $row = $dbw->fetchRow( $res ); @@ -408,19 +439,41 @@ } } $res = $dbw->update( - 'bs_shoutbox', - array( 'sb_archived' => '1' ), - array( 'sb_id' => $iShoutId ) + 'bs_shoutbox', array( 'sb_archived' => '1' ), array( 'sb_id' => $iShoutId ) ); - self::invalidateShoutBoxCache( (int)$iArticleId ); + self::invalidateShoutBoxCache( (int) $iArticleId ); $sResponse = $res == true ? 'bs-shoutbox-archive-success' : 'bs-shoutbox-archive-failure'; $sOutput = wfMessage( $sResponse )->plain(); return $sOutput; } public static function invalidateShoutBoxCache( $iArticleId ) { - BsCacheHelper::invalidateCache( BsCacheHelper::getCacheKey( 'BlueSpice', 'ShoutBox', $iArticleId ) ); + BsCacheHelper::invalidateCache( BsCacheHelper::getCacheKey( 'BlueSpice', 'ShoutBox', $iArticleId ) ); + } + + /** + * Ads Shoutbox icon with number of shouts to the statebar + * @global String $wgScriptPath + * @param StateBar $oStateBar + * @param array $aTopViews + * @param User $oUser + * @param Title $oTitle + * @return boolean + */ + public function onStateBarBeforeTopViewAdd( $oStateBar, &$aTopViews, $oUser, $oTitle ) { + $oShoutboxView = new ViewStateBarTopElement(); + $iTotalShouts = self::getTotalShouts( $oTitle->getArticleID() ); + if ( !is_object( $this->getTitle() ) || $iTotalShouts == 0 ) { + return true; + } + global $wgScriptPath; + $oShoutboxView->setKey( 'Shoutbox' ); + $oShoutboxView->setIconSrc( $wgScriptPath . '/extensions/BlueSpiceExtensions/ShoutBox/resources/images/icon-shoutbox.png' ); + $oShoutboxView->setIconAlt( wfMessage( 'bs-shoutbox-title' )->plain() ); + $oShoutboxView->setText( self::getTotalShouts( $oTitle->getArticleID() ) ); + $aTopViews['statebartopshoutbox'] = $oShoutboxView; + return true; } } diff --git a/ShoutBox/resources/bluespice.shoutBox.css b/ShoutBox/resources/bluespice.shoutBox.css index 2e038e4..c5308b1 100644 --- a/ShoutBox/resources/bluespice.shoutBox.css +++ b/ShoutBox/resources/bluespice.shoutBox.css @@ -108,4 +108,8 @@ margin-right:10px; font-size:10px; color:#999999; +} + +.bs-sb-tab-counter{ + margin-left: 5px; } \ No newline at end of file diff --git a/ShoutBox/resources/bluespice.shoutBox.js b/ShoutBox/resources/bluespice.shoutBox.js index 500d622..2da022b 100644 --- a/ShoutBox/resources/bluespice.shoutBox.js +++ b/ShoutBox/resources/bluespice.shoutBox.js @@ -60,40 +60,55 @@ */ characterCounter: null, /** + * Reference to the jQuery Tab + * @var jQuery + */ + shoutboxTab: null, + /** + * Sup Element for the ShoutboxTab + * @var jQuery + */ + shoutboxTabCounter: null, + /** * Load and display a current list of shouts from server * @param sblimit int Maximum number of shouts before more link is displayed */ - updateShoutbox: function(sblimit) { + updateShoutbox: function( sblimit ) { if ( typeof sblimit == 'undefined' ) sblimit = 0; + $( document ).trigger( "onBsShoutboxBeforeUpdated", [ BsShoutBox ] ); BsShoutBox.ajaxLoader.fadeIn(); this.msgList.load( - bs.util.getAjaxDispatcherUrl( 'ShoutBox::getShouts', [ wgArticleId, sblimit ] ), - function( data ) { - BsShoutBox.msgList.slideDown(); - BsShoutBox.btnSend.blur().removeAttr( 'disabled' ); //reactivate the send button - BsShoutBox.textField.val( BsShoutBox.defaultMessage ); - BsShoutBox.textField.blur().removeAttr( 'disabled' ); - BsShoutBox.ajaxLoader.fadeOut(); - BsShoutBox.characterCounter.text( mw.message( 'bs-shoutbox-charactersleft', BsShoutBox.textField.attr( 'maxlength' ) ).text() ); - } + bs.util.getAjaxDispatcherUrl( 'ShoutBox::getShouts', [ wgArticleId, sblimit ] ), + function( data ) { + BsShoutBox.msgList.slideDown(); + BsShoutBox.btnSend.blur().removeAttr( 'disabled' ); //reactivate the send button + BsShoutBox.textField.val( BsShoutBox.defaultMessage ); + BsShoutBox.textField.blur().removeAttr( 'disabled' ); + BsShoutBox.ajaxLoader.fadeOut(); + BsShoutBox.characterCounter.text( mw.message( 'bs-shoutbox-charactersleft', BsShoutBox.textField.attr( 'maxlength' ) ).text() ); + BsShoutBox.shoutboxTabCounter.text( $( "#bs-sb-count-all" ).text() ); + $( document ).trigger( "onBsShoutboxAfterUpdated", [ BsShoutBox ] ); + } ); }, archiveEntry: function( iShoutID ) { $( "#bs-sb-error" ).empty(); + $( document ).trigger( "onBsShoutboxBeforeArchived", [ BsShoutBox ] ); BsShoutBox.ajaxLoader.fadeIn(); $.post( - bs.util.getAjaxDispatcherUrl( 'ShoutBox::archiveShout', [ iShoutID, wgArticleId ] ), - function( data ) { - BsShoutBox.updateShoutbox(); - $("#bs-sb-error").html(data).fadeIn().delay("1500").fadeOut(); - } + bs.util.getAjaxDispatcherUrl( 'ShoutBox::archiveShout', [ iShoutID, wgArticleId ] ), + function( data ) { + BsShoutBox.updateShoutbox(); + $( "#bs-sb-error" ).html( data ).fadeIn().delay( "1500" ).fadeOut(); + $( document ).trigger( "onBsShoutboxAfterArchived", [ BsShoutBox ] ); + } ); } }; -mw.loader.using('ext.bluespice', function() { +mw.loader.using( 'ext.bluespice', function() { $( "#bs-sb-content" ).before( $( "<div id='bs-sb-error'></div>" ) ); BsShoutBox.textField = $( "#bs-sb-message" ); BsShoutBox.btnSend = $( "#bs-sb-send" ); @@ -101,75 +116,79 @@ BsShoutBox.ajaxLoader = $( "#bs-sb-loading" ); BsShoutBox.defaultMessage = BsShoutBox.textField.val(); BsShoutBox.characterCounter = $( '#bs-sb-charactercounter' ); + BsShoutBox.shoutboxTab = $( "#bs-data-after-content-tabs a[href='#bs-shoutbox']" ); + BsShoutBox.shoutboxTabCounter = $( "<sup class='bs-sb-tab-counter'>" ); + if ( typeof ( BsShoutBox.shoutboxTab ) !== "undefined" ) + BsShoutBox.shoutboxTab.after( BsShoutBox.shoutboxTabCounter ); BsShoutBox.updateShoutbox(); //HTML5 like placeholder effect. BsShoutBox.textField - .focus(function() { - if ($(this).val() == BsShoutBox.defaultMessage) - $(this).val(''); + .focus( function() { + if ( $( this ).val() == BsShoutBox.defaultMessage ) + $( this ).val( '' ); } - ).blur(function() { - if ($(this).val() == '') { - $(this).val(BsShoutBox.defaultMessage); + ).blur( function() { + if ( $( this ).val() == '' ) { + $( this ).val( BsShoutBox.defaultMessage ); } - }); + } ); - BsShoutBox.textField.bind("input propertychange", function (e) { + BsShoutBox.textField.bind( "input propertychange", function( e ) { var currCharLen = $( this ).attr( 'maxlength' ) - $( this ).val().length; BsShoutBox.characterCounter.text( mw.message( 'bs-shoutbox-charactersleft', currCharLen ).text() ); - }); + } ); $( "#bs-sb-form" ).submit( function() { var sMessage = BsShoutBox.textField.val(); if ( sMessage == '' || sMessage == BsShoutBox.defaultMessage ) { bs.util.alert( - 'bs-shoutbox-alert', - { - textMsg: 'bs-shoutbox-entermessage' - } + 'bs-shoutbox-alert', + { + textMsg: 'bs-shoutbox-entermessage' + } ); return false; } //we deactivate submit button while sending - BsShoutBox.btnSend.blur().attr('disabled', 'disabled'); - BsShoutBox.textField.blur().attr('disabled', 'disabled'); + BsShoutBox.btnSend.blur().attr( 'disabled', 'disabled' ); + BsShoutBox.textField.blur().attr( 'disabled', 'disabled' ); $.post( - bs.util.getAjaxDispatcherUrl( 'ShoutBox::insertShout', [ wgArticleId, sMessage ] ), - function( data ) { - var responseObj = $.parseJSON( data ); - if ( responseObj.success === false ) { - bs.util.alert( - 'bs-shoutbox-alert', - { - textMsg: responseObj.msg - } - ); + bs.util.getAjaxDispatcherUrl( 'ShoutBox::insertShout', [ wgArticleId, sMessage ] ), + function( data ) { + var responseObj = $.parseJSON( data ); + if ( responseObj.success === false ) { + bs.util.alert( + 'bs-shoutbox-alert', + { + textMsg: responseObj.msg + } + ); + } + BsShoutBox.updateShoutbox(); } - BsShoutBox.updateShoutbox(); - } ); //we prevent the refresh of the page after submitting the form return false; - }); + } ); - $(document).on( 'click', '.bs-sb-archive', function() { - var iShoutID = $(this).parent().attr('id'); + $( document ).on( 'click', '.bs-sb-archive', function() { + var iShoutID = $( this ).parent().attr( 'id' ); bs.util.confirm( - 'bs-shoutbox-confirm', - { - titleMsg: 'bs-shoutbox-confirm-title', - textMsg: 'bs-shoutbox-confirm-text' - }, + 'bs-shoutbox-confirm', + { + titleMsg: 'bs-shoutbox-confirm-title', + textMsg: 'bs-shoutbox-confirm-text' + }, { ok: function() { BsShoutBox.archiveEntry( iShoutID.replace( /bs-sb-/, "" ) ); } - }); - }); -}); \ No newline at end of file + } ); + } ); +} ); \ No newline at end of file diff --git a/ShoutBox/resources/images/icon-shoutbox.png b/ShoutBox/resources/images/icon-shoutbox.png new file mode 100644 index 0000000..83ed862 --- /dev/null +++ b/ShoutBox/resources/images/icon-shoutbox.png Binary files differ -- To view, visit https://gerrit.wikimedia.org/r/151818 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Iabd571f95874a18f17c6ee5c0bfaab9de5fc5653 Gerrit-PatchSet: 4 Gerrit-Project: mediawiki/extensions/BlueSpiceExtensions Gerrit-Branch: master Gerrit-Owner: Tweichart <[email protected]> Gerrit-Reviewer: Mglaser <[email protected]> Gerrit-Reviewer: Pigpen <[email protected]> Gerrit-Reviewer: Pwirth <[email protected]> Gerrit-Reviewer: Robert Vogel <[email protected]> Gerrit-Reviewer: Smuggli <[email protected]> Gerrit-Reviewer: Tweichart <[email protected]> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
