コード例 #1
0
ファイル: SNM_Initialize.php プロジェクト: Tjorriemorrie/app
function smwfNMInitializeTables()
{
    global $smwgNMIP;
    require_once $smwgNMIP . '/includes/SMW_NMStorage.php';
    NMStorage::getDatabase()->setup(true);
    return true;
}
コード例 #2
0
ファイル: SMW_NMStorage.php プロジェクト: Tjorriemorrie/app
 /**
  * Returns the single instance of this class.
  *
  * @return NMStorage
  * 		The single instance of this class.
  */
 public static function getInstance()
 {
     if (!isset(self::$mInstance)) {
         $c = __CLASS__;
         self::$mInstance = new $c();
     }
     return self::$mInstance;
 }
コード例 #3
0
	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 );
			}
		}
	}
コード例 #4
0
ファイル: SMWNotifyMe.php プロジェクト: Tjorriemorrie/app
 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__);
 }
コード例 #5
0
$wgRequestTime = microtime(true);
/** */
# Abort if called from a web server
if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
    print "This script must be run from the command line\n";
    exit;
}
if (version_compare(PHP_VERSION, '5.0.0') < 0) {
    print "Sorry! This version of MediaWiki requires PHP 5; you are running " . PHP_VERSION . ".\n\n" . "If you are sure you already have PHP 5 installed, it may be " . "installed\n" . "in a different path from PHP 4. Check with your system administrator.\n";
    die(-1);
}
// include commandLine script which provides some basic
// methodes for maintenance scripts
$mediaWikiLocation = dirname(__FILE__) . '/../../../..';
require_once "{$mediaWikiLocation}/maintenance/commandLine.inc";
global $smwgNMIP;
require_once $smwgNMIP . '/includes/SMW_NMStorage.php';
$sStore = NMStorage::getDatabase();
$msgs = $sStore->getUnmailedNMMessages();
foreach ($msgs as $msg) {
    // send notifications by mail
    if ($msg['user_id'] == null) {
        continue;
    }
    $user_info = $sStore->getUserInfo($msg['user_id']);
    $user = User::newFromRow($user_info);
    if ($user_info->user_email != '' && $user->getGlobalPreference('enotifyme')) {
        $name = $user_info->user_real_name == '' ? $user_info->user_name : $user_info->user_real_name;
        UserMailer::send(new MailAddress($user_info->user_email, $name), new MailAddress($wgEmergencyContact, 'Admin'), wfMsg('smw_nm_hint_mail_title', $msg['title'], $wgSitename), wfMsg('smw_nm_hint_mail_body_html', $name, $msg['notify']), new MailAddress($wgEmergencyContact, 'Admin'), 'text/html; charset=UTF-8');
    }
}