예제 #1
0
 /**
  * Returns all watchlist groups.
  *
  * @since 0.1
  *
  * @return array of SWLGroup
  */
 public static function getAll()
 {
     if (self::$groups === false) {
         self::$groups = array();
         $dbr = wfGetDB(DB_SLAVE);
         $groups = $dbr->select('swl_groups', array('group_id', 'group_name', 'group_categories', 'group_namespaces', 'group_properties', 'group_concepts'));
         foreach ($groups as $group) {
             self::$groups[] = SWLGroup::newFromDBResult($group);
         }
     }
     return self::$groups;
 }
 /**
  * Main method.
  * 
  * @since 0.1
  * 
  * @param string $arg
  */
 public function execute($arg)
 {
     global $wgOut, $wgUser, $wgRequest;
     $this->setHeaders();
     $this->outputHeader();
     // If the user is authorized, display the page, if not, show an error.
     if (!$this->userCanExecute($wgUser)) {
         $this->displayRestrictionError();
         return;
     }
     $groupsHtml = array();
     foreach (SWLGroups::getAll() as $group) {
         $groupsHtml[] = $this->getGroupHtml($group);
     }
     $wgOut->addHTML('<div id="swl-groups">' . implode('', $groupsHtml) . '</div>');
     $wgOut->addHTML(Html::rawElement('fieldset', array(), Html::element('legend', array(), wfMsg('swl-group-add-new-group')) . Html::element('span', array(), wfMsg('swl-group-name')) . '&nbsp;' . Html::element('input', array('type' => 'text', 'value' => '', 'id' => 'swl-add-group-name')) . '&nbsp;' . Html::element('input', array('type' => 'button', 'value' => wfMsg('swl-group-add-group'), 'id' => 'swl-add-group-button'))));
     $wgOut->addHTML(Html::element('input', array('type' => 'button', 'value' => wfMsg('swl-group-save-all'), 'id' => 'swl-save-all')));
     $wgOut->addModules('ext.swl.watchlistconditions');
 }
 /**
  * Main method.
  *
  * @since 0.1
  *
  * @param string $arg
  */
 public function execute($arg)
 {
     global $wgOut, $wgUser;
     $this->setHeaders();
     $this->outputHeader();
     // If the user is authorized, display the page, if not, show an error.
     if (!$this->userCanExecute($wgUser)) {
         $this->displayRestrictionError();
         return;
     }
     $wgOut->addHTML('<strong><p class="saveMessage" style=" display:none;width: 100px; alight:center;text-align:center; background: #f9f9aa; border: 1px solid #dd9">' . $this->msg('swl-group-saved')->text() . '</p></strong>');
     $groupsHtml = array();
     foreach (SWLGroups::getAll() as $group) {
         $groupsHtml[] = $this->getGroupHtml($group);
     }
     $wgOut->addHTML('<div id="swl-groups">' . implode('', $groupsHtml) . '</div>');
     $wgOut->addHTML("<p>" . Html::element('input', array('type' => 'button', 'value' => $this->msg('swl-group-add-group')->text(), 'id' => 'swl-add-group-button')) . "</p>\n");
     $wgOut->addHTML("<p>" . Html::element('input', array('type' => 'button', 'value' => $this->msg('swl-group-save')->text(), 'id' => 'swl-save-all')) . "</p>\n");
     $wgOut->addModules('ext.swl.watchlistconditions');
 }
 /**
  * Handle the updateDataBefore 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 $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;
 }
    /**
     * Adds the preferences of Semantic Watchlist to the list of available ones.
     * 
     * @since 0.1
     * 
     * @param User $user
     * @param array $preferences
     * 
     * @return true
     */
	public static function onGetPreferences( User $user, array &$preferences ) {
		$groups = SWLGroups::getAll();
		
		// Only show the email notification preference when email notifications are enabled.
		if ( $GLOBALS['egSWLEnableEmailNotify'] ) {
			$preferences['swl_email'] = array(
				'type' => 'toggle',
				'label-message' => 'swl-prefs-emailnofity',
				'section' => 'swl/swlglobal',
			);	
		}
		
		// Only show the top link preference when it's enabled.
		if ( $GLOBALS['egSWLEnableTopLink'] ) {
			$preferences['swl_watchlisttoplink'] = array(
				'type' => 'toggle',
				'label-message' => 'swl-prefs-watchlisttoplink',
				'section' => 'swl/swlglobal',
			);	
		}
		
		foreach ( $groups as /* SWLGroup */ $group ) {
			if ( count( $group->getProperties() ) == 0 ) {
				continue;
			}
			
			switch ( true ) {
				case count( $group->getCategories() ) > 0 :
					$type = 'category';
					$name = $group->getCategories();
					$name = $name[0];
					break;
				case count( $group->getNamespaces() ) > 0 :
					$type = 'namespace';
					$name = $group->getNamespaces();
					$name = $name[0] == 0 ? wfMsg( 'main' ) : MWNamespace::getCanonicalName( $name[0] );
					break;
				case count( $group->getConcepts() ) > 0 :
					$type = 'concept';
					$name = $group->getConcepts();
					$name = $name[0];
					break;
			}
			
			$properties = $group->getProperties();
			
			foreach ( $properties as &$property ) {
				$property = "''$property''";
			}
			
			$preferences['swl_watchgroup_' . $group->getId()] = array(
				'type' => 'toggle',
				'label' => wfMsgExt(
					"swl-prefs-$type-label",
					'parseinline',
					$group->getName(),
					count( $group->getProperties() ),
					$GLOBALS['wgLang']->listToText( $properties ),
					$name
				),
				'section' => 'swl/swlgroup',
			);
		}

		return true;
	}   
 protected function getAllSwlGroups()
 {
     return \SWLGroups::getAll();
 }