public function execute()
 {
     $params = $this->extractRequestParams();
     // TODO: this prevents doing [[Category:Foo||bar||baz]], must document.
     $rawParams = explode('|', $params['query']);
     $queryString = '';
     $printouts = array();
     SMWQueryProcessor::processFunctionParams($rawParams, $queryString, $this->parameters, $printouts);
     $queryResult = $this->getQueryResult($this->getQuery($queryString, $printouts));
     $this->addQueryResult($queryResult);
 }
Beispiel #2
0
 public function execute()
 {
     $params = $this->extractRequestParams();
     $this->requireParameters($params, array('query'));
     $rawParams = explode('|', $params['query']);
     $queryString = '';
     $printouts = array();
     SMWQueryProcessor::processFunctionParams($rawParams, $queryString, $this->parameters, $printouts);
     $queryResult = $this->getQueryResult($this->getQuery($queryString, $printouts));
     $this->addQueryResult($queryResult);
 }
 public function updateData(SMWSemanticData $data, $store)
 {
     //get list of properties which are set by this article
     //todo: think about only querying for modified properties
     $properties = $data->getProperties();
     foreach ($properties as $name => $property) {
         //ignore internal properties
         if (!$property->isUserDefined() || $name == QRC_HQID_LABEL) {
             unset($properties[$name]);
         }
     }
     //determine differences between the new and the original semantic data
     global $wgTitle;
     if ($wgTitle) {
         $originalData = $store->getSemanticData($wgTitle);
         foreach ($originalData->getProperties() as $oName => $oProperty) {
             if (array_key_exists($oName, $properties)) {
                 $oValues = $originalData->getPropertyValues($oProperty);
                 $values = $data->getPropertyValues($properties[$oName]);
                 if (count($oValues) == count($values)) {
                     $oWikiValues = array();
                     foreach ($oValues as $key => $value) {
                         $oWikiValues[$value->getWikiValue()] = true;
                     }
                     $wikiValues = array();
                     foreach ($values as $key => $value) {
                         $wikiValues[$value->getWikiValue()] = true;
                     }
                     $unset = true;
                     foreach (array_keys($values) as $value) {
                         if (!array_key_exists($value, $oWikiValues)) {
                             $unset = false;
                             break;
                         }
                     }
                     if ($unset) {
                         unset($properties[$oName]);
                     }
                 }
                 //echo('<pre>'.print_r($oProperty, true).'</pre>');
                 //echo('<pre>'.print_r(, true).'</pre>');
             } else {
                 if ($oProperty->isUserDefined() && $name != QRC_HQID_LABEL) {
                     $properties[$oName] = $oProperty;
                 }
             }
         }
     }
     //deal with categories and determine which queries to update
     $categories = array();
     global $wgParser;
     if ($wgParser && $wgParser->getOutput() && $wgTitle) {
         $categories = $wgParser->getOutput()->getCategories();
         $originalCategories = $wgTitle->getParentCategories();
         //echo('<pre>'.print_r($originalCategories, true).'</pre>');
         foreach (array_keys($originalCategories) as $category) {
             $category = substr($category, strpos($category, ':') + 1);
             if (array_key_exists($category, $categories)) {
                 unset($categories[$category]);
             } else {
                 $categories[$category] = true;
             }
         }
     }
     //echo('<pre>'.print_r(array_keys($categories), true).'</pre>');
     //echo('<pre>'.print_r(array_keys($properties), true).'</pre>');
     if (count($properties) > 0 || count($categories) > 0) {
         //query for all articles that use a query which depends on one of the properties
         $queryString = SMWQRCQueryManagementHandler::getInstance()->getSearchQueriesAffectedByDataModification(array_keys($properties), array_keys($categories));
         SMWQueryProcessor::processFunctionParams(array($queryString), $queryString, $params, $printouts);
         $query = SMWQueryProcessor::createQuery($queryString, $params);
         $queryResults = $this->getQueryResult($query, true, false)->getResults();
         //get query ids which have to be invalidated
         $queryIds = array();
         foreach ($queryResults as $queryResult) {
             $semanticData = $store->getSemanticData($queryResult);
             $invalidatePC = false;
             $tQueryIds = SMWQRCQueryManagementHandler::getInstance()->getIdsOfQueriesUsingProperty($semanticData, $properties);
             if (count($tQueryIds) > 0) {
                 $invalidatePC = true;
             }
             $queryIds = array_merge($queryIds, $tQueryIds);
             $tQueryIds = SMWQRCQueryManagementHandler::getInstance()->getIdsOfQueriesUsingCategory($semanticData, $categories);
             if (count($tQueryIds) > 0) {
                 $invalidatePC = true;
             }
             $queryIds = array_merge($queryIds, $tQueryIds);
             global $invalidateParserCache, $showInvalidatedCacheEntries;
             if ($invalidatePC && $invalidateParserCache && !$showInvalidatedCacheEntries) {
                 $title = $queryResult->getTitle();
                 $title->invalidateCache();
             }
         }
         $qrcStore = SMWQRCStore::getInstance()->getDB();
         $qrcStore->invalidateQueryData($queryIds);
     }
     return $store->doUpdateData($data);
 }
Beispiel #4
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__);
 }
	static function smwfProcessInlineQueryParserFunctionGTP( &$parser ) {
		global $smwgQEnabled, $smwgIQRunningNumber;
		if ( $smwgQEnabled ) {
			$smwgIQRunningNumber++;
			$rawparams = func_get_args();
			array_shift( $rawparams ); // we already know the $parser ...

			SMWQueryProcessor::processFunctionParams( $rawparams, &$querystring, &$params, &$printouts );
			self::prequery( $params, $printouts, $label, $wom_id );

			$query  = SMWQueryProcessor::createQuery(
					$querystring,
					$params,
					SMWQueryProcessor::INLINE_QUERY,
					SMW_OUTPUT_WIKI,
					$printouts
				);
			$res = smwfGetStore()->getQueryResult( $query );

			while ( $row = $res->getNext() ) {
				$firstcol = true;
				foreach ( $row as $field ) {
					$object = $field->getNextObject();
					$text = $object->getWikiValue();
					self::$queryProps[$wom_id][$label][] = $text;

					// get the first column only
					break;
				}
			}
		}
		return '';
	}
 /**
  * This code rather hacky since there are many ways to call that special page, the most involved of
  * which is the way that this page calls itself when data is submitted via the form (since the shape
  * of the parameters then is governed by the UI structure, as opposed to being governed by reason).
  *
  * TODO: most of this can probably be killed now we are using Validator
  *
  * @param string $p
  */
 protected function extractQueryParameters($p)
 {
     global $wgRequest, $smwgQMaxInlineLimit;
     // First make all inputs into a simple parameter list that can again be parsed into components later.
     if ($wgRequest->getCheck('q')) {
         // called by own Special, ignore full param string in that case
         $query_val = $wgRequest->getVal('p');
         if (!empty($query_val)) {
             // p is used for any additional parameters in certain links.
             $rawparams = SMWInfolink::decodeParameters($query_val, false);
         } else {
             $query_values = $wgRequest->getArray('p');
             if (is_array($query_values)) {
                 foreach ($query_values as $key => $val) {
                     if (empty($val)) {
                         unset($query_values[$key]);
                     }
                 }
             }
             // p is used for any additional parameters in certain links.
             $rawparams = SMWInfolink::decodeParameters($query_values, false);
         }
     } else {
         // called from wiki, get all parameters
         $rawparams = SMWInfolink::decodeParameters($p, true);
     }
     // Check for q= query string, used whenever this special page calls itself (via submit or plain link):
     $this->m_querystring = $wgRequest->getText('q');
     if ($this->m_querystring !== '') {
         $rawparams[] = $this->m_querystring;
     }
     // Check for param strings in po (printouts), appears in some links and in submits:
     $paramstring = $wgRequest->getText('po');
     if ($paramstring !== '') {
         // parameters from HTML input fields
         $ps = explode("\n", $paramstring);
         // params separated by newlines here (compatible with text-input for printouts)
         foreach ($ps as $param) {
             // add initial ? if omitted (all params considered as printouts)
             $param = trim($param);
             if ($param !== '' && $param[0] != '?') {
                 $param = '?' . $param;
             }
             $rawparams[] = $param;
         }
     }
     // Now parse parameters and rebuilt the param strings for URLs.
     SMWQueryProcessor::processFunctionParams($rawparams, $this->m_querystring, $this->m_params, $this->m_printouts);
     // Try to complete undefined parameter values from dedicated URL params.
     if (!array_key_exists('format', $this->m_params)) {
         $this->m_params['format'] = 'broadtable';
     }
     if (!array_key_exists('order', $this->m_params)) {
         $order_values = $wgRequest->getArray('order');
         if (is_array($order_values)) {
             $this->m_params['order'] = '';
             foreach ($order_values as $order_value) {
                 if ($order_value === '') {
                     $order_value = 'ASC';
                 }
                 $this->m_params['order'] .= ($this->m_params['order'] !== '' ? ',' : '') . $order_value;
             }
         }
     }
     $this->m_num_sort_values = 0;
     if (!array_key_exists('sort', $this->m_params)) {
         $sort_values = $wgRequest->getArray('sort');
         if (is_array($sort_values)) {
             $this->m_params['sort'] = implode(',', $sort_values);
             $this->m_num_sort_values = count($sort_values);
         }
     }
     if (!array_key_exists('offset', $this->m_params)) {
         $this->m_params['offset'] = $wgRequest->getVal('offset');
         if ($this->m_params['offset'] === '') {
             $this->m_params['offset'] = 0;
         }
     }
     if (!array_key_exists('limit', $this->m_params)) {
         $this->m_params['limit'] = $wgRequest->getVal('limit');
         if ($this->m_params['limit'] === '') {
             $this->m_params['limit'] = $this->m_params['format'] == 'rss' ? 10 : 20;
             // Standard limit for RSS.
         }
     }
     $this->m_params['limit'] = min($this->m_params['limit'], $smwgQMaxInlineLimit);
     $this->m_editquery = $wgRequest->getVal('eq') == 'yes' || $this->m_querystring === '';
 }
 protected function extractQueryParameters($p)
 {
     // This code rather hacky since there are many ways to call that special page, the most involved of
     // which is the way that this page calls itself when data is submitted via the form (since the shape
     // of the parameters then is governed by the UI structure, as opposed to being governed by reason).
     global $wgRequest, $smwgIP;
     // First make all inputs into a simple parameter list that can again be parsed into components later.
     if ($wgRequest->getCheck('q')) {
         // called by own Special, ignore full param string in that case
         $rawparams = SMWInfolink::decodeParameters($wgRequest->getVal('p'), false);
         // p is used for any additional parameters in certain links
     } else {
         // called from wiki, get all parameters
         $rawparams = SMWInfolink::decodeParameters($p, true);
     }
     // Check for q= query string, used whenever this special page calls itself (via submit or plain link):
     $this->m_querystring = $wgRequest->getText('q');
     if ($this->m_querystring != '') {
         $rawparams[] = $this->m_querystring;
     }
     // Check for param strings in po (printouts), appears in some links and in submits:
     $paramstring = $wgRequest->getText('po');
     if ($paramstring != '') {
         // parameters from HTML input fields
         $ps = explode("\n", $paramstring);
         // params separated by newlines here (compatible with text-input for printouts)
         foreach ($ps as $param) {
             // add initial ? if omitted (all params considered as printouts)
             $param = trim($param);
             if ($param != '' && $param[0] != '?') {
                 $param = '?' . $param;
             }
             $rawparams[] = $param;
         }
     }
     // Now parse parameters and rebuilt the param strings for URLs
     include_once "{$smwgIP}/includes/SMW_QueryProcessor.php";
     SMWQueryProcessor::processFunctionParams($rawparams, $this->m_querystring, $this->m_params, $this->m_printouts);
     // Try to complete undefined parameter values from dedicated URL params
     if (!array_key_exists('format', $this->m_params)) {
         if (array_key_exists('rss', $this->m_params)) {
             // backwards compatibility (SMW<=1.1 used this)
             $this->m_params['format'] = 'rss';
         } else {
             // default
             $this->m_params['format'] = 'broadtable';
         }
     }
     $sortcount = $wgRequest->getVal('sc');
     if (!is_numeric($sortcount)) {
         $sortcount = 0;
     }
     if (!array_key_exists('order', $this->m_params)) {
         $this->m_params['order'] = $wgRequest->getVal('order');
         // basic ordering parameter (, separated)
         for ($i = 0; $i < $sortcount; $i++) {
             if ($this->m_params['order'] != '') {
                 $this->m_params['order'] .= ',';
             }
             $value = $wgRequest->getVal('order' . $i);
             $value = $value == '' ? 'ASC' : $value;
             $this->m_params['order'] .= $value;
         }
     }
     if (!array_key_exists('sort', $this->m_params)) {
         $this->m_params['sort'] = $wgRequest->getText('sort');
         // basic sorting parameter (, separated)
         for ($i = 0; $i < $sortcount; $i++) {
             if ($this->m_params['sort'] != '' || $i > 0) {
                 // admit empty sort strings here
                 $this->m_params['sort'] .= ',';
             }
             $this->m_params['sort'] .= $wgRequest->getText('sort' . $i);
         }
     }
     // Find implicit ordering for RSS -- needed for downwards compatibility with SMW <=1.1
     if ($this->m_params['format'] == 'rss' && $this->m_params['sort'] == '' && $sortcount == 0) {
         foreach ($this->m_printouts as $printout) {
             if (strtolower($printout->getLabel()) == "date" && $printout->getTypeID() == "_dat") {
                 $this->m_params['sort'] = $printout->getTitle()->getText();
                 $this->m_params['order'] = 'DESC';
             }
         }
     }
     if (!array_key_exists('offset', $this->m_params)) {
         $this->m_params['offset'] = $wgRequest->getVal('offset');
         if ($this->m_params['offset'] == '') {
             $this->m_params['offset'] = 0;
         }
     }
     if (!array_key_exists('limit', $this->m_params)) {
         $this->m_params['limit'] = $wgRequest->getVal('limit');
         if ($this->m_params['limit'] == '') {
             $this->m_params['limit'] = $this->m_params['format'] == 'rss' ? 10 : 20;
             // standard limit for RSS
         }
     }
     $this->m_editquery = $wgRequest->getVal('eq') != '' || '' == $this->m_querystring;
 }
	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 );
			}
		}
	}
Beispiel #9
0
 /**
  *
  * @param <String> $query (e.g. [[ChangeSet:+]][[inPullFeed::Pullfeed:xxxxx]])
  * @param <String> $paramstring Printout parameters (e.g. ?hasPatch?changeSetID)
  * @return <Object> SMWQueryResult object
  */
 public static function getSemanticQuery($query, $paramstring = '')
 {
     $printouts = array();
     $rawparams = array();
     $params = array('format' => ' ', 'sort' => ' ', 'offset' => 0);
     $rawparams[] = $query;
     if ($paramstring != '') {
         $ps = explode("\n", $paramstring);
         foreach ($ps as $param) {
             $param = trim($param);
             if ($param != '' && $param[0] != '?') {
                 $param = '?' . $param;
             }
             $rawparams[] = $param;
         }
     }
     SMWQueryProcessor::processFunctionParams($rawparams, $query, $params, $printouts);
     $queryobj = SMWQueryProcessor::createQuery($query, $params, SMWQueryProcessor::SPECIAL_PAGE, '', $printouts);
     $queryobj->setLimit(5000);
     $res = smwfGetStore()->getQueryResult($queryobj);
     if (!$res instanceof SMWQueryResult) {
         return false;
     }
     return $res;
 }
Beispiel #10
0
 /**
  * Answers a ASK query.
  *
  * @param string $rawQuery
  * @return SPARQL XML string
  */
 function answerASK($rawquery, $format = "xml")
 {
     // add desired query printer (SPARQL-XML)
     if (property_exists('SMWQueryProcessor', 'formats')) {
         // registration up to SMW 1.2.*
         SMWQueryProcessor::$formats['xml'] = 'SMWXMLResultPrinter';
         // overwrite SMW printer
     } else {
         // registration since SMW 1.3.*
         global $smwgResultFormats;
         $smwgResultFormats['xml'] = 'SMWXMLResultPrinter';
     }
     // add query as first rawparam
     $paramPos = strpos($rawquery, "|");
     $rawparams[] = $paramPos === false ? $rawquery : substr($rawquery, 0, $paramPos);
     if ($paramPos !== false) {
         // add other params
         $ps = explode("|", substr($rawquery, $paramPos + 1));
         foreach ($ps as $param) {
             $param = trim($param);
             $rawparams[] = $param;
         }
     }
     // parse params and answer query
     SMWQueryProcessor::processFunctionParams($rawparams, $querystring, $params, $printouts);
     $params['format'] = $format;
     return SMWQueryProcessor::getResultFromQueryString($querystring, $params, $printouts, SMW_OUTPUT_FILE);
 }
Beispiel #11
0
 /**
  * Format and output report results using the given information plus
  * OutputPage
  *
  * @param OutputPage $out OutputPage to print to
  * @param Skin $skin User skin to use
  * @param Database $dbr Database (read) connection to use
  * @param int $res Result pointer
  * @param int $num Number of available result rows
  * @param int $offset Paging offset
  */
 protected function outputResults($out, $skin, $dbr, $res, $num, $offset)
 {
     global $wgContLang;
     $all_display_params = SDUtils::getDisplayParamsForCategory($this->category);
     $querystring = null;
     $printouts = $params = array();
     // only one set of params is handled for now
     if (count($all_display_params) > 0) {
         $display_params = array_map('trim', $all_display_params[0]);
         SMWQueryProcessor::processFunctionParams($display_params, $querystring, $params, $printouts);
     }
     if (!empty($querystring)) {
         $query = SMWQueryProcessor::createQuery($querystring, $params);
     } else {
         $query = new SMWQuery();
     }
     if (!array_key_exists('format', $params)) {
         $params['format'] = 'category';
     }
     if (array_key_exists('mainlabel', $params)) {
         $mainlabel = $params['mainlabel'];
     } else {
         $mainlabel = '';
     }
     $r = $this->addSemanticResultWrapper($dbr, $res, $num, $query, $mainlabel, $printouts);
     $printer = SMWQueryProcessor::getResultPrinter($params['format'], SMWQueryProcessor::SPECIAL_PAGE, $r);
     if (version_compare(SMW_VERSION, '1.6.1', '>')) {
         SMWQueryProcessor::addThisPrintout($printouts, $params);
         $params = SMWQueryProcessor::getProcessedParams($params, $printouts);
     }
     $prresult = $printer->getResult($r, $params, SMW_OUTPUT_HTML);
     $prtext = is_array($prresult) ? $prresult[0] : $prresult;
     SMWOutputs::commitToOutputPage($out);
     // Crappy hack to get the contents of SMWOutputs::$mHeadItems,
     // which may have been set in the result printer, and dump into
     // headItems of $out.
     // How else can we do this?
     global $wgParser;
     SMWOutputs::commitToParser($wgParser);
     if (!is_null($wgParser->mOutput)) {
         // getHeadItems() was added in MW 1.16
         if (method_exists($wgParser->getOutput(), 'getHeadItems')) {
             $headItems = $wgParser->getOutput()->getHeadItems();
         } else {
             $headItems = $wgParser->getOutput()->mHeadItems;
         }
         foreach ($headItems as $key => $item) {
             $out->addHeadItem($key, $item);
         }
         // Force one more parser function, so links appear.
         $wgParser->replaceLinkHolders($prtext);
     }
     $html = array();
     $html[] = $prtext;
     if (!$this->listoutput) {
         $html[] = $this->closeList();
     }
     $html = $this->listoutput ? $wgContLang->listToText($html) : implode('', $html);
     $out->addHTML($html);
 }
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' );
	}
}
Beispiel #13
0
 private static function runASKQuery($rawquery, $column, $userInput)
 {
     global $smwgResultFormats, $smwgHaloIP;
     require_once "{$smwgHaloIP}/includes/queryprinters/SMW_QP_XML.php";
     $smwgResultFormats['xml'] = 'SMWXMLResultPrinter';
     // add query as first rawparam
     $rawparams[] = $rawquery;
     if ($column != "_var0") {
         $rawparams[] = "?{$column}";
     }
     // parse params and answer query
     SMWQueryProcessor::processFunctionParams($rawparams, $querystring, $params, $printouts);
     $params['format'] = "xml";
     //$params['limit'] = SMW_AC_MAX_RESULTS;
     if ($column != "_var0") {
         $params['sort'] = $column;
     }
     $querystring = str_replace("{{USERINPUT}}", $userInput, $querystring);
     return SMWQueryProcessor::getResultFromQueryString($querystring, $params, $printouts, SMW_OUTPUT_FILE);
 }
 private function getNecessaryTermImports()
 {
     require_once "SMW_TermImportDefinitionValidator.php";
     $log = SGAGardeningIssuesAccess::getGardeningIssuesAccess();
     SMWQueryProcessor::processFunctionParams(array("[[TermImport:+]] [[Category:TermImport]]"), $querystring, $params, $printouts);
     $queryResult = explode("|", SMWQueryProcessor::getResultFromQueryString($querystring, $params, $printouts, SMW_OUTPUT_WIKI));
     unset($queryResult[0]);
     $necessaryTermImports = array();
     foreach ($queryResult as $tiArticleName) {
         $tiArticleName = substr($tiArticleName, 0, strpos($tiArticleName, "]]"));
         $xmlString = smwf_om_GetWikiText('TermImport:' . $tiArticleName);
         $start = strpos($xmlString, "<ImportSettings>");
         $end = strpos($xmlString, "</ImportSettings>") + 17 - $start;
         $xmlString = substr($xmlString, $start, $end);
         SMWQueryProcessor::processFunctionParams(array("[[belongsToTermImport::TermImport:" . $tiArticleName . "]]", "?hasImportDate", "limit=1", "sort=hasImportDate", "order=descending", "format=list", "mainlabel=-", "searchlabel="), $querystring, $params, $printouts);
         $queryResult = SMWQueryProcessor::getResultFromQueryString($querystring, $params, $printouts, SMW_OUTPUT_WIKI);
         // timestamp creation depends on property type (page or date)
         $queryResult = trim(substr($queryResult, strpos($queryResult, "]]") + 2));
         if (strpos($queryResult, "[[:") === 0) {
             //type page
             $queryResult = trim(substr($queryResult, strpos($queryResult, "|") + 1));
             $queryResult = trim(substr($queryResult, 0, strpos($queryResult, "]")));
         } else {
             //type date
             $queryResult = trim(substr($queryResult, 0, strpos($queryResult, "[")));
         }
         $timestamp = strtotime($queryResult);
         $tiDV = new SMWTermImportDefinitionValidator($xmlString);
         if (!$tiDV->validate()) {
             echo "\nThe Term Import definition of " . $tiArticleName . " is invalid.\n";
             $title = Title::newFromText("TermImport:" . $tiArticleName);
             $log->addGardeningIssueAboutArticle($this->id, SMW_GARDISSUE_UPDATE_FAILURE, $title);
             continue;
         }
         $simpleXMLElement = new SimpleXMLElement($xmlString);
         $maxAge = $simpleXMLElement->xpath("//UpdatePolicy/maxAge/@value");
         //echo("\ntimestamp: ".$imestamp);
         if ($maxAge != "") {
             if ($timestamp == 0 || wfTime() - $timestamp - $maxAge[0]->value * 60 > 0) {
                 echo "\nRun this term import: " . $tiArticleName;
                 $necessaryTermImports[$tiArticleName] = $xmlString;
             }
         } else {
             $title = Title::newFromText("TermImport:" . $tiArticleName);
             $log->addGardeningIssueAboutArticle($this->id, SMW_GARDISSUE_UPDATE_NOT_NECESSARY, $title);
         }
     }
     return $necessaryTermImports;
 }
Beispiel #15
0
 /**
  * #ask itself.
  * Delegate the treatments to SMWQueryProcessor
  *
  * @var SMWQueryProcessor
  * @param <type> $m_querystring
  * @param <type> $props
  * @return <type>
  */
 private function ask($m_querystring, $props = array(), $limit = null, $offset = 0)
 {
     $rawparams = array();
     if ($m_querystring != '') {
         $rawparams[] = $m_querystring;
     }
     foreach ($props as $prop) {
         $prop = trim($prop);
         if ($prop != '' && $prop != '?') {
             if ($prop[0] != '?') {
                 $prop = '?' . $prop;
             }
             $rawparams[] = $prop;
         }
     }
     $m_params = array();
     $m_printouts = array();
     SMWQueryProcessor::processFunctionParams($rawparams, $m_querystring, $m_params, $m_printouts);
     $m_params['offset'] = $offset;
     if (!is_null($limit)) {
         $m_params['limit'] = $limit;
     }
     $queryobj = SMWQueryProcessor::createQuery($m_querystring, $m_params, SMWQueryProcessor::SPECIAL_PAGE, null, $m_printouts);
     return smwfGetStore()->getQueryResult($queryobj);
 }
Beispiel #16
0
 /**
  * returns an array of pages that are result of the semantic query
  * @param $rawQueryString string - the query string like [[Category:Trees]][[age::>1000]]
  * @return array of SMWDIWikiPage objects representing the result
  */
 public static function getAllPagesForQuery($rawQuery)
 {
     $rawQueryArray = array($rawQuery);
     SMWQueryProcessor::processFunctionParams($rawQueryArray, $queryString, $processedParams, $printouts);
     SMWQueryProcessor::addThisPrintout($printouts, $processedParams);
     $processedParams = SMWQueryProcessor::getProcessedParams($processedParams, $printouts);
     $queryObj = SMWQueryProcessor::createQuery($queryString, $processedParams, SMWQueryProcessor::SPECIAL_PAGE, '', $printouts);
     $res = smwfGetStore()->getQueryResult($queryObj);
     $pages = $res->getResults();
     return $pages;
 }
 /**
  * this methods constructs the special page webservice repository
  *
  */
 public function execute($par)
 {
     global $wgRequest, $wgOut;
     $wgOut->setPageTitle("Data Import Repository");
     $webTestDebug = $wgRequest->getVal('webTestDebug');
     if (!is_null($webTestDebug)) {
         $webTestDebug = true;
     }
     global $wgCookiePrefix;
     global $wgArticlePath;
     $gardeningURL = Title::makeTitleSafe(NS_SPECIAL, "Gardening")->getFullURL();
     $allowed = false;
     global $wgUser;
     $user = $wgUser;
     if ($user != null) {
         $groupsOfUser = $user->getGroups();
         foreach ($groupsOfUser as $key => $group) {
             if ($group == SMW_WS_SYSOP) {
                 $allowed = true;
             }
         }
     }
     $html = "";
     $html .= "<table id=\"menue\" class=\"TabContainer\"><tr>";
     $html .= "<td id=\"web-service-tab\" class=\"ActiveTab\" onclick=\"webServiceRepSpecial.displayWebServiceTab()\">Web Service definitions</td>";
     $html .= "<td></td>";
     $html .= "<td id=\"term-import-tab\" class=\"InactiveTab\" onclick=\"webServiceRepSpecial.displayTermImportTab()\" onmouseover=\"webServiceRepSpecial.highlightTab(event)\">Term Import definitions</td>";
     $html .= "<td></td></tr></table>";
     global $smwgDIIP;
     // handle web service repository
     require_once $smwgDIIP . '/specials/WebServices/SMW_WSStorage.php';
     $webServices = WSStorage::getDatabase()->getWebServices();
     ksort($webServices);
     $html .= "<span id=\"web-service-tab-content\">";
     $html .= "<h2><span class=\"mw-headline\">" . wfMsg('smw_wwsr_intro') . "</span></h2>";
     $html .= "<p>" . wfMsg('smw_wwsr_rep_intro') . "</p>";
     $html .= '<p><a href="' . Title::makeTitleSafe(NS_SPECIAL, "DefineWebService")->getFullURL() . '">' . wfMsg('smw_wwsr_rep_create_link') . '</a></p>';
     if ($allowed) {
         $html .= "<table id=\"webservicetable\" class=\"smwtable\"><tr><th>" . wfMsg('smw_wwsr_name') . "</th><th>" . wfMsg('smw_wwsr_lastupdate') . "</th><th style=\"text-align: center\">" . wfMsg('smw_wwsr_update_manual') . "</th><th style=\"text-align: center\">" . wfMsg('smw_wwsr_rep_edit') . "</th><th style=\"text-align: center\">" . wfMsg('smw_wwsr_delete') . "</th><th style=\"text-align: center\">" . wfMsg('smw_wwsr_confirm') . "</th></tr>";
     } else {
         $html .= "<table id=\"webservicetable\" class=\"smwtable\"><tr><th>" . wfMsg('smw_wwsr_name') . "</th><th>" . wfMsg('smw_wwsr_lastupdate') . "</th><th style=\"text-align: center\">" . wfMsg('smw_wwsr_rep_edit') . "</th></tr>";
     }
     foreach ($webServices as $ws) {
         $title = Title::newFromID($ws->getArticleID());
         if (!is_null($title)) {
             $wsUrl = $title->getFullURL();
             $wsName = substr($ws->getName(), 11, strlen($ws->getName()));
             $html .= "<tr id=\"ws-row-" . $ws->getArticleID() . "\"><td><a href=\"" . $wsUrl . "\">" . $wsName . "</a></td>";
             $cacheResults = WSStorage::getDatabase()->getResultsFromCache($ws->getArticleID());
             $oldestUpdate = "";
             if (count($cacheResults) > 0) {
                 $oldestUpdate = $cacheResults[0]["lastUpdate"];
                 if (strlen($oldestUpdate) > 0) {
                     $oldestUpdate = wfTimestamp(TS_DB, $oldestUpdate);
                 }
             }
             $latestUpdate = "";
             if (sizeof($cacheResults) > 1) {
                 $latestUpdate = $cacheResults[sizeof($cacheResults) - 1]["lastUpdate"];
                 if (strlen($latestUpdate) > 0) {
                     $latestUpdate = wfTimestamp(TS_DB, $cacheResults[sizeof($cacheResults) - 1]["lastUpdate"]);
                     if (strlen($oldestUpdate) > 0) {
                         $latestUpdate = " - " . $latestUpdate;
                     }
                 }
             }
             $html .= "<td>" . $oldestUpdate . $latestUpdate . "</td>";
             if ($allowed) {
                 $wsUpdateBot = new WSUpdateBot();
                 $html .= "<td style=\"text-align: center\"><button id=\"update" . $ws->getArticleID() . "\" type=\"button\" name=\"update\" onclick=\"webServiceRepSpecial.updateCache('" . $wsUpdateBot->getBotID() . "', 'WS_WSID=" . $ws->getArticleID() . "')\" alt=\"" . wfMsg('smw_wwsr_update') . "\" title=\"" . wfMsg('smw_wwsr_update_tooltip') . "\">" . wfMsg('smw_wwsr_update') . "</button>";
                 $html .= "<div id=\"updating" . $ws->getArticleID() . "\" style=\"display: none; text-align: center\"><a href=\"" . $gardeningURL . "\">" . wfMsg('smw_wwsr_updating') . "</a></div></td>";
             }
             global $wgArticlePath;
             if (strpos($wgArticlePath, "?") > 0) {
                 $url = Title::makeTitleSafe(NS_SPECIAL, "DefineWebService")->getFullURL() . "&wwsdId=" . $ws->getArticleID();
             } else {
                 $url = Title::makeTitleSafe(NS_SPECIAL, "DefineWebService")->getFullURL() . "?wwsdId=" . $ws->getArticleID();
             }
             $html .= "<td style=\"text-align: center\"><button id=\"edit" . $ws->getArticleID() . "\" type=\"button\" name=\"edit\" onclick=\"window.location.href = '" . $url . "';\" alt=\"" . wfMsg('smw_wwsr_rep_edit') . "\" title=\"" . wfMsg('smw_wwsr_rep_edit_tooltip') . "\">" . wfMsg('smw_wwsr_rep_edit') . "</button>";
             if ($allowed) {
                 $html .= "<td style=\"text-align: center\">  <button type=\"button\"  onclick=\"webServiceRepSpecial.deleteWWSD(" . $ws->getArticleID() . ")\" alt=\"" . wfMsg('smw_wwsr_delete') . "\" title=\"" . wfMsg('smw_wwsr_delete_tooltip') . "\">" . wfMsg('smw_wwsr_delete') . "</button></td>";
             }
             if ($allowed) {
                 if ($ws->getConfirmationStatus() != "true") {
                     $html .= "<td style=\"text-align: center\" id=\"confirmText" . $ws->getArticleID() . "\">  <button type=\"button\" id=\"confirmButton" . $ws->getArticleID() . "\" onclick=\"webServiceRepSpecial.confirmWWSD(" . $ws->getArticleID() . ")\" alt=\"" . wfMsg('smw_wwsr_confirm') . "\" title=\"" . wfMsg('smw_wwsr_confirm_tooltip') . "\">" . wfMsg('smw_wwsr_confirm') . "</button></td></tr>";
                 } else {
                     $html .= "<td style=\"text-align: center\" alt=\"" . wfMsg('smw_wwsr_confirm') . "\" title=\"" . wfMsg('smw_wwsr_confirm_tooltip') . "\">" . wfMsg('smw_wwsr_confirmed') . "</td></tr>";
                 }
             } else {
                 $html .= "</tr>";
             }
         }
     }
     $html .= "</table>";
     $html .= "</span>";
     //Term Import definition tab
     $html .= "<span id=\"term-import-tab-content\" style=\"display: none\">";
     $html .= "<h2><span class=\"mw-headline\">" . wfMsg('smw_tir_intro') . "</span></h2>";
     $html .= "<p>" . wfMsg('smw_tir_rep_intro') . "</p>";
     $html .= '<p><a href="' . Title::makeTitleSafe(NS_SPECIAL, "TermImport")->getFullURL() . '">' . wfMsg('smw_tir_rep_create_link') . '</a></p>';
     if ($allowed) {
         $html .= "<table id=\"termimporttable\" width=\"100%\" class=\"smwtable\"><tr><th>" . wfMsg('smw_wwsr_name') . "</th><th>" . wfMsg('smw_wwsr_lastupdate') . "</th><th style=\"text-align: center\">" . wfMsg('smw_wwsr_update_manual') . "</th><th style=\"text-align: center\">" . wfMsg('smw_wwsr_rep_edit') . "</th><th style=\"text-align: center\">" . wfMsg('smw_wwsr_delete') . "</th></tr>";
     } else {
         $html .= "<table id=\"termimporttable\" width=\"100%\" class=\"smwtable\"><tr><th>" . wfMsg('smw_wwsr_name') . "</th><th>" . wfMsg('smw_wwsr_lastupdate') . "</th></tr>";
     }
     $log = SGAGardeningIssuesAccess::getGardeningIssuesAccess();
     SMWQueryProcessor::processFunctionParams(array("[[Category:TermImport]]"), $querystring, $params, $printouts);
     $queryResult = explode("|", SMWQueryProcessor::getResultFromQueryString($querystring, $params, $printouts, SMW_OUTPUT_WIKI));
     unset($queryResult[0]);
     foreach ($queryResult as $tiArticleName) {
         $tiArticleName = substr($tiArticleName, 0, strpos($tiArticleName, "]]"));
         $html .= "<tr id=\"ti-row-" . $tiArticleName . "\">";
         $tiUrl = Title::newFromText("TermImport:" . $tiArticleName)->getFullURL();
         $html .= "<td><a href=\"" . $tiUrl . "\">" . $tiArticleName . "</a></td>";
         SMWQueryProcessor::processFunctionParams(array("[[belongsToTermImport::TermImport:" . $tiArticleName . "]]", "?hasImportDate", "limit=1", "sort=hasImportDate", "order=descending", "format=list", "mainlabel=-"), $querystring, $params, $printouts);
         $queryResult = SMWQueryProcessor::getResultFromQueryString($querystring, $params, $printouts, SMW_OUTPUT_WIKI);
         // timestamp creation depends on property type (page or date)
         $queryResult = trim(substr($queryResult, strpos($queryResult, "]]") + 2));
         if (strpos($queryResult, "[[:") === 0) {
             //type page
             $queryResult = trim(substr($queryResult, strpos($queryResult, "|") + 1));
             $queryResult = trim(substr($queryResult, 0, strpos($queryResult, "]")));
         } else {
             //type date
             $queryResult = trim(substr($queryResult, 0, strpos($queryResult, "[")));
         }
         $html .= "<td>" . $queryResult . "</td>";
         if ($allowed) {
             $tiUpdateBot = new TermImportUpdateBot();
             $html .= "<td style=\"text-align: center\"><button id=\"update-ti-" . $tiArticleName . "\" \r\n\t\t\t\t\ttype=\"button\" name=\"update-ti\" \r\n\t\t\t\t\tonclick=\"webServiceRepSpecial.updateTermImport('" . $tiArticleName . "')\" alt=\"" . wfMsg('smw_wwsr_update') . "\" title=\"" . wfMsg('smw_wwsr_update_tooltip_ti') . "\">" . wfMsg('smw_wwsr_update') . "</button>";
             $html .= "<div id=\"updating-ti-" . $tiArticleName . "\" style=\"display: none; text-align: center\"><a href=\"" . $gardeningURL . "\">" . wfMsg('smw_wwsr_updating') . "</a></div></td>";
             global $wgArticlePath;
             if (strpos($wgArticlePath, "?") > 0) {
                 $url = Title::makeTitleSafe(NS_SPECIAL, "TermImport")->getFullURL() . "&tiname=" . $tiArticleName;
             } else {
                 $url = Title::makeTitleSafe(NS_SPECIAL, "TermImport")->getFullURL() . "?tiname=" . $tiArticleName;
             }
             $html .= "<td style=\"text-align: center\"><button id=\"edit" . $tiArticleName . "\" type=\"button\" name=\"edit\" onclick=\"window.location.href = '" . $url . "';\" alt=\"" . wfMsg('smw_wwsr_rep_edit') . "\" title=\"" . wfMsg('smw_wwsr_rep_edit_tooltip_ti') . "\">" . wfMsg('smw_wwsr_rep_edit') . "</button></td>";
             $html .= "<td style=\"text-align: center\"><button type=\"button\" name=\"delete\" onclick=\"webServiceRepSpecial.deleteTermImport('" . $tiArticleName . "')\" alt=\"" . wfMsg('smw_wwsr_delete') . "\" title=\"" . wfMsg('smw_wwsr_rep_delete_tooltip_ti') . "\">" . wfMsg('smw_wwsr_delete') . "</button></td>";
         }
         $html .= "</tr>";
     }
     $html .= "</table>";
     $html .= "</span>";
     $wgOut->addHTML($html);
 }
Beispiel #18
0
 /**
  * Processes the QueryString, Params, and PrintOuts.
  *
  * @todo Combine this method with execute() or remove it altogether.
  */
 public function extractParameters($p)
 {
     if ($this->context == self::SPECIAL_PAGE) {
         // assume setParams(), setPintouts and setQueryString have been called
         $rawParams = array_merge($this->parameters, array($this->queryString), $this->printOutStrings);
     } else {
         // context is WIKI_LINK
         $rawParams = SMWInfolink::decodeParameters($p, true);
         // calling setParams to fill in missing parameters
         $this->setParams($rawParams);
         $rawParams = $this->parameters;
     }
     SMWQueryProcessor::processFunctionParams($rawParams, $this->queryString, $this->parameters, $this->printOuts);
 }
Beispiel #19
0
function smwf_qi_QIAccess($method, $params)
{
    $p_array = explode(",", $params);
    global $smwgQEnabled;
    if ($method == "getPropertyInformation") {
        return qiGetPropertyInformation($p_array[0]);
    } else {
        if ($method == "getPropertyTypes") {
            $p_array = func_get_args();
            $types = "<propertyTypes>";
            for ($i = 1; $i < count($p_array); $i++) {
                $types .= qiGetPropertyInformation($p_array[$i]);
            }
            $types .= "</propertyTypes>";
            return $types;
        } else {
            if ($method == "getNumericTypes") {
                $numtypes = array();
                $types = SMWDataValueFactory::getKnownTypeLabels();
                foreach ($types as $v) {
                    $id = SMWDataValueFactory::findTypeID($v);
                    if (SMWDataValueFactory::newTypeIDValue($id)->isNumeric()) {
                        array_push($numtypes, strtolower($v));
                    }
                }
                return implode(",", $numtypes);
            } else {
                if ($method == "getQueryResult") {
                    $result = "null";
                    if ($smwgQEnabled) {
                        // read fix parameters from QI GUI
                        $params = count($p_array) > 1 ? explode("|", $p_array[1]) : array();
                        $fixparams = array();
                        foreach ($params as $p) {
                            if (strlen($p) > 0 && strpos($p, "=") !== false) {
                                list($key, $value) = explode("=", $p);
                                $fixparams[trim($key)] = str_replace('%2C', ',', $value);
                            }
                        }
                        // indicate that it comes from an ajax call
                        $fixparams['ajaxCall'] = true;
                        // fix bug 10812: if query string contains a ,
                        $p_array[0] = str_replace('%2C', ',', $p_array[0]);
                        // read query with printouts and (possibly) other parameters like sort, order, limit, etc...
                        $pos = strpos($p_array[0], "|?");
                        if ($pos > 0) {
                            $rawparams[] = trim(substr($p_array[0], 0, $pos));
                            $ps = explode("|?", trim(substr($p_array[0], $pos + 2)));
                            foreach ($ps as $param) {
                                $rawparams[] = "?" . trim($param);
                            }
                        } else {
                            $ps = preg_split('/[^\\|]{1}\\|{1}(?!\\|)/s', $p_array[0]);
                            if (count($ps) > 1) {
                                // last char of query condition is missing (matched with [^\|]{1}) therefore copy from original
                                $rawparams[] = trim(substr($p_array[0], 0, strlen($ps[0]) + 1));
                                array_shift($ps);
                                // remove the query condition
                                // add other params for formating etc.
                                foreach ($ps as $param) {
                                    $rawparams[] = trim($param);
                                }
                            } else {
                                $rawparams[] = trim($p_array[0]);
                            }
                        }
                        $rawparams = array_merge($rawparams, $fixparams);
                        // set some default values, if params are not set
                        if (!in_array('reasoner', array_keys($fixparams))) {
                            $fixparams['reasoner'] = 'ask';
                        }
                        if (!in_array('format', array_keys($fixparams))) {
                            $fixparams['format'] = 'table';
                        }
                        // use SMW classes or TSC classes and parse params and answer query
                        if ($fixparams['reasoner'] == 'ask') {
                            SMWQueryProcessor::processFunctionParams($rawparams, $querystring, $params, $printouts);
                        } else {
                            if ($fixparams['reasoner'] == 'sparql') {
                                SMWSPARQLQueryProcessor::processFunctionParams($rawparams, $querystring, $params, $printouts);
                            }
                        }
                        // check if there is any result and if it corresponds to the selected format
                        $mainlabel = isset($rawparams['mainlabel']) && $rawparams['mainlabel'] == '-';
                        $invalidRes = smwf_qi_CheckValidResult($printouts, $fixparams['format'], $mainlabel);
                        if ($invalidRes != 0) {
                            return wfMsg('smw_qi_printout_err' . $invalidRes);
                        }
                        // quickfix: unset conflicting params for maps
                        if (in_array($fixparams['format'], array("map", "googlemaps2", "openlayers", "yahoomaps"))) {
                            if (isset($params['reasoner'])) {
                                unset($params['reasoner']);
                            }
                            if (isset($params['ajaxcall'])) {
                                unset($params['ajaxcall']);
                            }
                            if (isset($params['merge'])) {
                                unset($params['merge']);
                            }
                        }
                        // answer query using the SMW classes or TSC classes
                        if ($fixparams['reasoner'] == 'ask') {
                            $result = SMWQueryProcessor::getResultFromQueryString($querystring, $params, $printouts, SMW_OUTPUT_WIKI);
                        } else {
                            if ($fixparams['reasoner'] == 'sparql') {
                                $result = SMWSPARQLQueryProcessor::getResultFromQueryString($querystring, $params, $printouts, SMW_OUTPUT_WIKI);
                            }
                        }
                        // check for empty result
                        if (is_array($result) && trim($result[0]) == '' || trim($result == '')) {
                            return wfMsg('smw_qi_printout_err4');
                        }
                        switch ($fixparams['format']) {
                            case 'timeline':
                            case 'exhibit':
                            case 'eventline':
                                return $result;
                                break;
                            case 'gallery':
                            case 'googlepie':
                            case 'googlebar':
                            case 'ofc-pie':
                            case 'ofc-bar':
                            case 'ofc-bar_3d':
                            case 'ofc-line':
                            case 'ofc-scatterline':
                                return is_array($result) ? $result[0] : $result;
                                break;
                            case 'map':
                            case 'googlemaps2':
                            case 'openlayers':
                            case 'yahoomaps':
                                return wfMsg('smw_qi_printout_notavailable');
                            default:
                        }
                        $result = parseWikiText($result);
                        // add target="_new" for all links
                        $pattern = "|<a|i";
                        $result = preg_replace($pattern, '<a target="_new"', $result);
                        return $result;
                    }
                } else {
                    if ($method == "getQueryResultForDownload") {
                        $result = "null";
                        if ($smwgQEnabled) {
                            $params = array('format' => $p_array[1], 'link' => $p_array[2], 'intro' => $p_array[3], 'sort' => $p_array[4], 'limit' => $p_array[5], 'mainlabel' => $p_array[6], 'order' => $p_array[7], 'default' => $p_array[8], 'headers' => $p_array[9]);
                            $result = applyQueryHighlighting($p_array[0], $params);
                            // add target="_new" for all links
                            $pattern = "|<a|i";
                            $result = preg_replace($pattern, '<a target="_new"', $result);
                        }
                        if ($result != "null" && $result != "") {
                            global $request_query;
                            $request_query = true;
                        }
                        return $result;
                    } else {
                        if ($method == "getSupportedParameters") {
                            global $smwgResultFormats;
                            wfLoadExtensionMessages('SemanticMediaWiki');
                            $format = $p_array[0];
                            if (array_key_exists($format, $smwgResultFormats)) {
                                $formatclass = $smwgResultFormats[$format];
                            } else {
                                $formatclass = "SMWListResultPrinter";
                            }
                            // fix for missing parameter order
                            $order_missing = true;
                            $intro_missing = true;
                            $outro_missing = true;
                            $qp = new $formatclass($format, false);
                            $params = $qp->getParameters();
                            // repair some misplaced parameters
                            for ($i = 0; $i < count($params); $i++) {
                                switch ($params[$i]['name']) {
                                    case "order":
                                        $order_missing = false;
                                        break;
                                    case "template":
                                        if ($format != "template") {
                                            array_splice($params, $i, 1);
                                        }
                                        break;
                                    case "intro":
                                        if (substr($format, 0, 4) != "ofc-") {
                                            $intro_missing = false;
                                        }
                                        break;
                                    case "outro":
                                        if (substr($format, 0, 4) != "ofc-") {
                                            $outro_missing = false;
                                        }
                                        break;
                                    case "headers":
                                        if ($format != "table" && $format != "broadtable") {
                                            array_splice($params, $i, 1);
                                        }
                                        break;
                                }
                            }
                            if ($order_missing) {
                                $params[] = array('name' => 'order', 'type' => 'enumeration', 'description' => wfMsg('smw_qi_tt_order'), 'values' => array('ascending', 'descending'));
                            }
                            if ($intro_missing) {
                                $params[] = array('name' => 'intro', 'type' => 'string', 'description' => wfMsg('smw_qi_tt_intro'));
                            }
                            if ($outro_missing) {
                                $params[] = array('name' => 'outro', 'type' => 'string', 'description' => wfMsg('smw_qi_tt_outro'));
                            }
                            $jsonEnc = new Services_JSON();
                            return $jsonEnc->encode($params);
                        } else {
                            return "false";
                        }
                    }
                }
            }
        }
    }
}