Ejemplo n.º 1
0
 /**
  * Run job
  * @return boolean success
  */
 function run()
 {
     wfProfileIn('SMWNMRefreshJob::run (SMW)');
     SMWNotifyProcessor::refreshNotifyMe();
     wfProfileOut('SMWNMRefreshJob::run (SMW)');
     return true;
 }
	public function notifyUsers() {
		global $wgSitename, $wgSMTP, $wgEmergencyContact, $wgEnotifyMeJob;
		$sStore = NMStorage::getDatabase();

		$nm_send_jobs = array();
		$id = 0;

		if ( count( $this->m_notifyHtmlMsgs ) > 0 ) {
			$notifications = $sStore->getNotifyMe( array_keys( $this->m_notifyHtmlMsgs ) );
		}
		$html_style = '';
		// <style>
		// table.smwtable{background-color: #EEEEFF;}
		// table.smwtable th{background-color: #EEEEFF;text-align: left;}
		// table.smwtable td{background-color: #FFFFFF;padding: 1px;padding-left: 5px;padding-right: 5px;text-align: left;vertical-align: top;}
		// table.smwtable tr.smwfooter td{font-size: 90%;line-height: 1;background-color: #EEEEFF;padding: 0px;padding-left: 5px;padding-right: 5px;text-align: right;vertical-align: top;}
		// </style>';
		$html_showall = array();
		foreach ( $this->m_notifyHtmlMsgs as $notify_id => $msg ) {
			$html_msg = $html_style;
			$showing_all = false;
			if ( isset( $notifications[$notify_id] ) && $notifications[$notify_id]['show_all'] ) {
				SMWQueryProcessor::processFunctionParams( SMWNotifyProcessor::getQueryRawParams( $notifications[$notify_id]['query'] ), $querystring, $params, $printouts );

				$format = 'auto';
				if ( array_key_exists( 'format', $params ) ) {
					$format = strtolower( trim( $params['format'] ) );
					global $smwgResultFormats;
					if ( !array_key_exists( $format, $smwgResultFormats ) ) {
						$format = 'auto';
					}
				}
				$query  = SMWQueryProcessor::createQuery( $querystring, $params, SMWQueryProcessor::INLINE_QUERY, $format, $printouts );
				$res = smwfGetStore()->getQueryResult( $query );
				$printer = SMWQueryProcessor::getResultPrinter( $format, SMWQueryProcessor::INLINE_QUERY, $res );
				$result = $printer->getResult( $res, $params, SMW_OUTPUT_HTML );
				// FIXME: hardcode switch to full url
				global $wgScriptPath, $wgServer;
				$result = str_replace ( $wgScriptPath, $wgServer . $wgScriptPath, $result );
				$html_msg .= $result . '<br/>';
				$html_showall[$notify_id] = array ( 'name' => $notifications[$notify_id]['name'], 'html' => $result );

				$showing_all = true;
				$link = $res->getQueryLink()->getURL();
			}
			global $smwgNMHideDiffWhenShowAll;
			if ( !( $smwgNMHideDiffWhenShowAll && $showing_all ) ) {
				$html_msg .= wfMsg( 'smw_nm_hint_notification_html', $this->m_notifyHtmlMsgs[$notify_id] );
				if ( isset( $this->m_notifyHtmlPropMsgs[$notify_id] ) ) {
					$html_msg .= wfMsg( 'smw_nm_hint_nmtable_html', $this->m_notifyHtmlPropMsgs[$notify_id] );
				}
			}
			if ( $showing_all ) {
				$id = $sStore->addNotifyRSS( 'nid', $notify_id, "All current items, " . date( 'Y-m-d H:i:s', time() ), $this->applyStyle( $html_msg ), $link );
			} else {
				$id = $sStore->addNotifyRSS( 'nid', $notify_id, $this->m_title->getText(), $this->applyStyle( $html_msg ) );
			}
		}
		foreach ( $this->m_userMsgs as $user_id => $msg ) {
			// generate RSS items
			$html_msg = $html_style;
			foreach ( array_unique( $this->m_userNMs[$user_id] ) as $showall_nid ) {
				if ( isset( $html_showall[$showall_nid] ) ) {
					$html_msg .= wfMsg( 'smw_nm_hint_item_html', $html_showall[$showall_nid]['name'], $html_showall[$showall_nid]['html'] );
				}
			}

			$html_msg .= wfMsg( 'smw_nm_hint_notification_html', $this->m_userHtmlNMMsgs[$user_id] );
			if ( isset( $this->m_userHtmlPropMsgs[$user_id] ) ) {
				$html_msg .= wfMsg( 'smw_nm_hint_nmtable_html', $this->m_userHtmlPropMsgs[$user_id] );
			}

			global $wgNMReportModifier, $wgUser;
			if ( $wgNMReportModifier ) {
				$userText = $wgUser->getName();
				if ( $wgUser->getId() == 0 ) {
					$page = SpecialPage::getTitleFor( 'Contributions', $userText );
				} else {
					$page = Title::makeTitle( NS_USER, $userText );
				}
				$l = '<a href="' . $page->getFullUrl() . '">' . htmlspecialchars( $userText ) . '</a>';
				$html_msg .= wfMsg( 'smw_nm_hint_modifier_html', $l );
				$msg .= wfMsg( 'smw_nm_hint_modifier', $wgUser->getName() );
			}

			$id = $sStore->addNotifyRSS( 'uid', $user_id, $this->m_title->getText(), $this->applyStyle( $html_msg ) );

			if ( $wgEnotifyMeJob ) {
				// send notifications by mail
				$user_info = $sStore->getUserInfo( $user_id );
				$user = User::newFromRow( $user_info );
				if ( ( $user_info->user_email != '' ) && $user->getOption( 'enotifyme' ) ) {
					$name = ( ( $user_info->user_real_name == '' ) ? $user_info->user_name:$user_info->user_real_name );

					$params = array( 'to' => new MailAddress( $user_info->user_email, $name ),
						'from' => new MailAddress( $wgEmergencyContact, 'Admin' ),
						'subj' => wfMsg( 'smw_nm_hint_mail_title', $this->m_title->getText(), $wgSitename ),
						'body' => wfMsg( 'smw_nm_hint_mail_body', $name, $msg ),
						'replyto' => new MailAddress( $wgEmergencyContact, 'Admin' ) );

					$nm_send_jobs[] = new SMW_NMSendMailJob( $this->m_title, $params );
				}
			}
		}

		if ( $wgEnotifyMeJob ) {
			if ( count( $nm_send_jobs ) ) {
				Job :: batchInsert( $nm_send_jobs );
			}
		} else {
			global $phpInterpreter;
			if ( !isset( $phpInterpreter ) ) {
				// if $phpInterpreter is not set, assume it is in search path
				// if not, starting of bot will FAIL!
				$phpInterpreter = "php";
			}
			// copy from SMW_GardeningBot.php
			ob_start();
			phpinfo();
			$info = ob_get_contents();
			ob_end_clean();
			// Get Systemstring
			preg_match( '!\nSystem(.*?)\n!is', strip_tags( $info ), $ma );
			// Check if it consists 'windows' as string
			preg_match( '/[Ww]indows/', $ma[1], $os );
			global $smwgNMIP ;
			if ( $os[0] == '' && $os[0] == null ) {

				// FIXME: $runCommand must allow whitespaces in paths too
				$runCommand = "$phpInterpreter -q $smwgNMIP/specials/SMWNotifyMe/SMW_NMSendMailAsync.php";
				// TODO: test async code for linux.
				// low prio
				$nullResult = `$runCommand > /dev/null &`;
			}
			else // windowze
			{
				$runCommand = "\"\"$phpInterpreter\" -q \"$smwgNMIP/specials/SMWNotifyMe/SMW_NMSendMailAsync.php\"\"";
				$wshShell = new COM( "WScript.Shell" );
				$runCommand = "cmd /C " . $runCommand;

				$oExec = $wshShell->Run( $runCommand, 7, false );
			}
		}
	}
Ejemplo n.º 3
0
 function rcDoOutputFeed(&$feed, $type, $id, $limit)
 {
     wfProfileIn(__METHOD__);
     $feed->outHeader();
     if ($type == "nid") {
         $dbr = wfGetDB(DB_SLAVE);
         $showall = $dbr->selectField('smw_nm_query', 'show_all', array('notify_id' => $id), 'NotifyMeRSS');
         if ($showall) {
             $query = $dbr->selectField('smw_nm_query', 'query', array('notify_id' => $id), 'NotifyMeRSS');
             SMWQueryProcessor::processFunctionParams(SMWNotifyProcessor::getQueryRawParams($query), $querystring, $params, $printouts);
             $query = SMWQueryProcessor::createQuery($querystring, $params, SMWQueryProcessor::INLINE_QUERY, 'auto', $printouts);
             $res = smwfGetStore()->getQueryResult($query);
             $items = array();
             $labels = array();
             foreach ($res->getPrintRequests() as $pr) {
                 $labels[] = $pr->getText(SMW_OUTPUT_WIKI);
             }
             $row = $res->getNext();
             $linker = new Linker();
             while ($row !== false) {
                 $wikipage = $row[0]->getNextObject();
                 // get the object
                 $a = new Article($wikipage->getTitle());
                 $description = "<table style=\"width: 60em; font-size: 90%; border: 1px solid #aaaaaa; background-color: #f9f9f9; color: black; margin-bottom: 0.5em; margin-left: 1em; padding: 0.2em; clear: right; text-align:left;\"><tr><th style=\"text-align: center; background-color:#ccccff;\" colspan=\"2\"><big>" . $wikipage->getText() . "</big></th></tr>";
                 $idx = 0;
                 foreach ($row as $field) {
                     $description .= "<tr><td>" . $labels[$idx] . "</td><td>";
                     $first_value = true;
                     while (($object = $field->getNextObject()) !== false) {
                         if ($first_value) {
                             $first_value = false;
                         } else {
                             $description .= ', ';
                         }
                         $description .= $object->getShortText(SMW_OUTPUT_HTML, $linker);
                     }
                     $description .= "</td></tr>";
                     $idx++;
                 }
                 $description .= "</table>";
                 $items[] = array('title' => $wikipage->getText(), 'notify' => $description, 'timestamp' => $a->getTimestamp());
                 $row = $res->getNext();
             }
         } else {
             $items = NMStorage::getDatabase()->getNotifyRSS($type, $id, $limit);
         }
     } else {
         $items = NMStorage::getDatabase()->getNotifyRSS($type, $id, $limit);
     }
     foreach ($items as $i) {
         if (isset($i['link']) && $i['link']) {
             $item = new FeedItem($i['title'], $i['notify'], $i['link'], $i['timestamp']);
         } else {
             $title = Title::makeTitle(NS_MAIN, $i['title']);
             $talkpage = $title->getTalkPage();
             $item = new FeedItem($title->getPrefixedText(), $i['notify'], $title->getFullURL(), $i['timestamp'], "", $talkpage->getFullURL());
         }
         $feed->outItem($item);
     }
     $feed->outFooter();
     wfProfileOut(__METHOD__);
 }
	public function getPossibleQuery( $info ) {
		$cnt = count( $info );
		if ( $cnt == 0 ) {
			return null;
		}
		$fname = 'NotifyMe::getPossibleQuery';
		wfProfileIn( $fname );

		$first = true;
		foreach ( $info as $key => $value ) {
			if ( $first ) {
				$first = false;
			} else {
				$cond .= "OR ";
			}
			$i = SMWNotifyProcessor::getInfoFromId( $key );
			$cond .= "(smw_id=$i[attr_id] AND type=$i[type]) ";
		}

		$db = wfGetDB( DB_SLAVE );
		$result = array( 0 => array(), 1 => array() );
		extract( $db->tableNames( 'smw_nm_query', 'smw_nm_relations' ) );
		$res = $db->query( "SELECT q.notify_id, q.name, q.user_id, q.delegate, q.nm_sql, q.nm_hierarchy, c1.subquery FROM (" .
			"SELECT count(*) cnt, notify_id, subquery FROM $smw_nm_relations " .
					"WHERE $cond GROUP BY notify_id, subquery" .
			") c1 INNER JOIN (" .
				"SELECT count(*) cnt, notify_id, subquery FROM $smw_nm_relations " .
					"WHERE type<>1 GROUP BY notify_id, subquery" .
			") c2 ON c1.notify_id=c2.notify_id AND c1.subquery=c2.subquery AND c1.cnt=c2.cnt " .
			"LEFT JOIN $smw_nm_query q ON q.notify_id = c1.notify_id WHERE c1.cnt<=$cnt", $fname );
		if ( $db->numRows( $res ) > 0 ) {
			while ( $row = $db->fetchObject( $res ) ) {
				$ds = explode( ',', $row->delegate );
				$uids = array();
				foreach ( $ds as $delegate ) {
					$u = User::newFromName( trim( $delegate ) );
					if ( $u == null ) continue;
					$id = $u->getId();
					if ( $id > 0 ) {
						$uids[] = $id;
					}
				}
				if ( count( $uids ) == 0 ) {
					$uids[] = $row->user_id;
				}
				$result[$row->subquery > 0 ? 1:0][$row->notify_id] = array( 'user_ids' => $uids, 'name' => $row->name, 'sql' => $row->nm_sql, 'hierarchy' => $row->nm_hierarchy );
			}
		}
		$db->freeResult( $res );
		wfProfileOut( $fname );
		return $result;
	}
Ejemplo n.º 5
0
function smwfNMUndeleteHook(&$title, $create)
{
    SMWNotifyProcessor::articleSavedComplete($title);
    return true;
    // always return true, in order not to stop MW's hook processing!
}
function smwf_nm_NotifyAccess( $method, $params ) {
	$p_array = explode( ",", $params );
	global $smwgQEnabled;

	$result = "Query disabled.";
	if ( $method == "updateMail" ) {
		global $wgUser;
		$wgUser->setOption( 'enotifyme', $params );
		$wgUser->saveSettings();
		return wfMsg( 'smw_nm_ajax_mailupdate' );
	}
	elseif ( $method == "addNotify" ) {
		if ( $smwgQEnabled ) {
			$result = SMWNotifyProcessor::addNotify( str_replace( '&amp;', '&', str_replace( '&comma;', ',', $p_array[0] ) ),
				str_replace( '&amp;', '&', str_replace( '&comma;', ',', $p_array[3] ) ),
				$p_array[1], $p_array[2], implode( ",", array_slice( $p_array, 4 ) ) );
		}
		return $result;
	}
	elseif ( $method == "getQueryResult" ) {
		if ( $smwgQEnabled ) {
			$params .= '
| format=table
| link=all';

			// parse params and answer query
			SMWQueryProcessor::processFunctionParams( SMWNotifyProcessor::getQueryRawParams( $params ), $querystring, $params, $printouts );

			$result = SMWQueryProcessor::getResultFromQueryString( $querystring, $params, $printouts, SMW_OUTPUT_WIKI );
			switch ( $params->format ) {
				case 'timeline':
					return $result;
					break;
				case 'eventline':
					return $result;
					break;
				case 'googlepie':
					return $result[0];
					break;
				case 'googlebar':
					return $result[0];
					break;
				case 'exhibit':
					return $result;
					break;
				default:
			}
			global $wgParser;

		   	if ( ( $wgParser->getTitle() instanceof Title ) && ( $wgParser->getOptions() instanceof ParserOptions ) ) {
				$result = $wgParser->recursiveTagParse( $result );
			} else {
				global $wgTitle;
				$popt = new ParserOptions();
				$popt->setEditSection( false );
				$pout = $wgParser->parse( $result . '__NOTOC__', $wgTitle, $popt );
				// / NOTE: as of MW 1.14SVN, there is apparently no better way to hide the TOC
				SMWOutputs::requireFromParserOutput( $pout );
				$result = $pout->getText();
			}

			// add target="_new" for all links
			$pattern = "|<a|i";
			$result = preg_replace( $pattern, '<a target="_new"', $result );
		}
		return $result;
	}
	elseif ( $method == "updateStates" ) {
		if ( $smwgQEnabled ) {
			$result = SMWNotifyProcessor::updateStates( $p_array );
		}
		return $result;
	}
	elseif ( $method == "updateReportAll" ) {
		if ( $smwgQEnabled ) {
			$result = SMWNotifyProcessor::updateReportAll( $p_array );
		}
		return $result;
	}
	elseif ( $method == "updateShowAll" ) {
		if ( $smwgQEnabled ) {
			$result = SMWNotifyProcessor::updateShowAll( $p_array );
		}
		return $result;
	}
	elseif ( $method == "updateDelegates" ) {
		if ( $smwgQEnabled ) {
			$result = SMWNotifyProcessor::updateDelegates( explode( "|", $params ) );
		}
		return $result;
	}
	elseif ( $method == "delNotify" ) {
		if ( $smwgQEnabled ) {
			$result = SMWNotifyProcessor::delNotify( $p_array );
		}
		return $result;
	}
	else {
		return wfMsg( 'smw_nm_ajax_fail' );
	}
}