/** * Handles group notification. * * @since 0.1 * * @param SWLGroup $group * @param array $userIDs * @param SMWChangeSet $changes * * @return true */ public static function onGroupNotify(SWLGroup $group, array $userIDs, SWLChangeSet $changes) { global $egSWLMailPerChange, $egSWLMaxMails; foreach ($userIDs as $userID) { $user = User::newFromId($userID); if ($user->getOption('swl_email', false)) { if ($user->getName() != $changes->getEdit()->getUser()->getName() || $GLOBALS['egSWLEnableSelfNotify']) { if (!method_exists('Sanitizer', 'validateEmail') || Sanitizer::validateEmail($user->getEmail())) { $lastNotify = $user->getOption('swl_last_notify'); $lastWatch = $user->getOption('swl_last_watch'); if (is_null($lastNotify) || is_null($lastWatch) || $lastNotify < $lastWatch) { $mailCount = $user->getOption('swl_mail_count', 0); if ($egSWLMailPerChange || $mailCount < $egSWLMaxMails) { SWLEmailer::notifyUser($group, $user, $changes, $egSWLMailPerChange); $user->setOption('swl_last_notify', wfTimestampNow()); $user->setOption('swl_mail_count', $mailCount + 1); $user->saveSettings(); } } } } } } return true; }
/** * Creates and returns the HTML representatation of the change set. * * @since 0.1 * * @param SWLChangeSet $changeSet * * @return string */ protected static function getChangeListHTML(SWLChangeSet $changeSet) { $propertyHTML = array(); foreach ($changeSet->getAllProperties() as $property) { $propertyHTML[] = self::getPropertyHTML($property, $changeSet->getAllPropertyChanges($property)); } return implode('', $propertyHTML); }
/** * Creates and returns the HTML representatation of the change set. * * @since 0.1 * * @param SWLChangeSet $changeSet * @param SWLGroup $group * * @return string */ protected static function getChangeListHTML(SWLChangeSet $changeSet, SWLGroup $group) { $propertyHTML = array(); $customTexts = new SWLCustomTexts($group); foreach ($changeSet->getAllProperties() as $property) { $propertyHTML[] = self::getPropertyHTML($property, $changeSet->getAllPropertyChanges($property), $customTexts); } return implode('', $propertyHTML); }
/** * Handle the onDataChanged hook of SMW >1.6, which gets called * every time the value of a propery changes somewhere. * * @since 0.1 * * @param SMWStore $store * @param SMWChangeSet $changes * * @return true */ public static function onDataUpdate( SMWStore $store, SMWSemanticData $newData ) { $subject = $newData->getSubject(); $oldData = $store->getSemanticData( $subject ); $title = Title::makeTitle( $subject->getNamespace(), $subject->getDBkey() ); $groups = SWLGroups::getMatchingWatchGroups( $title ); $edit = false; foreach ( $groups as /* SWLGroup */ $group ) { $changeSet = SWLChangeSet::newFromSemanticData( $oldData, $newData, $group->getProperties() ); if ( $changeSet->hasUserDefinedProperties() ) { if ( $edit === false ) { $edit = new SWLEdit( $title->getArticleID(), $GLOBALS['wgUser']->getName(), wfTimestampNow() ); $edit->writeToDB(); } $changeSet->setEdit( $edit ); $setId = $changeSet->writeToStore( $groups, $edit->getId() ); if ( $setId != 0 ) { $group->notifyWatchingUsers( $changeSet ); } } } return true; }
/** * Retrieve the specil words from the database. */ public function execute() { // Get the requests parameters. $params = $this->extractRequestParams(); if (!(isset($params['userid']) xor isset($params['groupids']))) { $this->dieUsage(wfMsgExt('swl-err-userid-xor-groupids'), 'userid-xor-groupids'); } $isUserFilter = isset($params['userid']); $filter = $isUserFilter ? $params['userid'] : $params['groupids']; $this->setupChangeSetQuery($filter, $isUserFilter, $params['limit'], $params['continue']); $sets = $this->select(__METHOD__); $count = 0; $resultSets = array(); foreach ($sets as $set) { if (++$count > $params['limit']) { // We've reached the one extra which shows that // there are additional pages to be had. Stop here... $this->setContinueEnumParameter('continue', $set->edit_time . '-' . $set->spe_set_id); break; } $resultSets[] = SWLChangeSet::newFromDBResult($set); } if ($params['merge']) { $this->mergeSets($resultSets); } foreach ($resultSets as &$set) { $set = $set->toArray(); foreach ($set['changes'] as $propName => $changes) { $this->getResult()->setIndexedTagName($set['changes'][$propName], 'change'); } } $this->getResult()->setIndexedTagName($resultSets, 'set'); $this->getResult()->addValue(null, 'sets', $resultSets); }
/** * Merges in the changes of another change set. * Duplicate changes are detected and only kept as a single change. * This is usefull for merging sets with (possibly overlapping) changes belonging to a single edit. * * @since 0.1 * * @param SWLChangeSet $set */ public function mergeInChangeSet(SWLChangeSet $set) { foreach ($set->getAllProperties() as $property) { foreach ($set->getChanges()->getPropertyChanges($property) as $change) { if (!$this->hasChange($property, $change)) { $this->addChange($property, $change); } } foreach ($set->getInsertions()->getPropertyValues($property) as $dataItem) { if (!$this->hasInsertion($property, $dataItem)) { $this->addInsertion($property, $dataItem); } } foreach ($set->getDeletions()->getPropertyValues($property) as $dataItem) { if (!$this->hasInsertion($property, $dataItem)) { $this->addDeletion($property, $dataItem); } } } }
/** * Gets the HTML for a single change set (edit). * * @since 0.1 * * @param SWLChangeSet $changeSet * * @return string */ protected function getChangeSetHTML( SWLChangeSet $changeSet ) { global $wgLang; $edit = $changeSet->getEdit(); $html = ''; $html .= '<li>'; $html .= '<p>' . $wgLang->time( $edit->getTime(), true ) . ' ' . Html::element( 'a', array( 'href' => $edit->getTitle()->getLocalURL() ), $edit->getTitle()->getText() ) . ' (' . Html::element( 'a', array( 'href' => $edit->getTitle()->getLocalURL( 'action=history' ) ), wfMsg( 'hist' ) ) . ') . . ' . Html::element( 'a', array( 'href' => $edit->getUser()->getUserPage()->getLocalURL() ), $edit->getUser()->getName() ) . ' (' . Html::element( 'a', array( 'href' => $edit->getUser()->getTalkPage()->getLocalURL() ), wfMsg( 'talkpagelinktext' ) ) . ' | ' . ( $edit->getUser()->isAnon() ? '' : Html::element( 'a', array( 'href' => SpecialPage::getTitleFor( 'Contributions', $edit->getUser()->getName() )->getLocalURL() ), wfMsg( 'contribslink' ) ) . ' | ' ) . Html::element( 'a', array( 'href' => SpecialPage::getTitleFor( 'Block', $edit->getUser()->getName() )->getLocalURL() ), wfMsg( 'blocklink' ) ) . ')' . ( $edit->getTime() > $this->lastViewed ? ' [NEW]' : '' ) . '</p>' ; $propertyHTML= array(); foreach ( $changeSet->getAllProperties() as /* SMWDIProperty */ $property ) { $propertyHTML[] = $this->getPropertyHTML( $property, $changeSet->getAllPropertyChanges( $property ) ); } $html .= implode( '', $propertyHTML ); $html .= '</li>'; return $html; }
/** * Gets all the watching users and passes them, together with the specified * changes and the group object itself, to the SWLGroupNotify hook. * * @since 0.1 * * @param SMWChangeSet $changes */ public function notifyWatchingUsers(SWLChangeSet $changes) { $users = $this->getWatchingUsers(); if ($changes->hasChanges(true)) { wfRunHooks('SWLGroupNotify', array($this, $users, $changes)); } }