/** * @see ItemParameterManipulation::doManipulation * * @since 1.6.2 */ public function doManipulation(&$value, Parameter $parameter, array &$parameters) { // Make sure the format value is valid. $value = self::getValidFormatName($value); // Add the formats parameters to the parameter list. $queryPrinter = SMWQueryProcessor::getResultPrinter($value); $parameters = array_merge($parameters, $queryPrinter->getValidatorParameters()); }
function execute($p) { global $wgOut, $wgRequest, $smwgQEnabled, $smwgRSSEnabled, $smwgMW_1_14; wfProfileIn('doSpecialAskTSC (SMWHalo)'); $this->extractQueryParameters($p); $format = $this->getResultFormat($this->m_params); $query = SMWSPARQLQueryProcessor::createQuery($this->m_querystring, $this->m_params, SMWQueryProcessor::SPECIAL_PAGE, $format, $this->m_printouts); $res = smwfGetStore()->getQueryResult($query); $printer = SMWQueryProcessor::getResultPrinter($format, SMWQueryProcessor::SPECIAL_PAGE, $res); $result_mime = $printer->getMimeType($res); if ($result_mime == false) { if ($res->getCount() > 0) { $result = '<div style="text-align: center;">'; $result .= '</div>' . $printer->getResult($res, $this->m_params, SMW_OUTPUT_HTML); $result .= '<div style="text-align: center;"></div>'; } else { $result = '<div style="text-align: center;">' . wfMsg('smw_result_noresults') . '</div>'; } } else { // make a stand-alone file $result = $printer->getResult($res, $this->m_params, SMW_OUTPUT_FILE); $result_name = $printer->getFileName($res); // only fetch that after initialising the parameters } if ($result_mime == false) { if ($this->m_querystring) { $wgOut->setHTMLtitle($this->m_querystring); } else { $wgOut->setHTMLtitle(wfMsg('ask')); } $wgOut->addHTML($result); } else { $wgOut->disable(); header("Content-type: {$result_mime}; charset=UTF-8"); if ($result_name !== false) { header("Content-Disposition: attachment; filename={$result_name}"); } print $result; } wfProfileOut('doSpecialAskTSC (SMWHalo)'); }
/** * Returns the definitions of all parameters supported by the specified format. * * @since 1.8 * * @param string $format * * @return array of IParamDefinition */ public static function getFormatParameters($format) { SMWParamFormat::resolveFormatAliases($format); if (array_key_exists($format, $GLOBALS['smwgResultFormats'])) { return ParamDefinition::getCleanDefinitions(SMWQueryProcessor::getResultPrinter($format)->getParamDefinitions(SMWQueryProcessor::getParameters())); } else { return array(); } }
/** * Returns the results in HTML, or in case of exports, a link to the * result. * * This method can only be called after execute() has been called. * * @return string of all the HTML generated */ public function getHTMLResult() { $result = ''; $res = $this->queryResult; $printer = SMWQueryProcessor::getResultPrinter($this->parameters['format'], SMWQueryProcessor::SPECIAL_PAGE); if ($res->getCount() > 0) { $queryResult = $printer->getResult($res, $this->params, SMW_OUTPUT_HTML); if (is_array($queryResult)) { $result .= $queryResult[0]; } else { $result .= $queryResult; } } else { $result = wfMsg('smw_result_noresults'); } return $result; }
/** * @param string $format * * @return array of IParamDefinition */ protected function getFormatParameters($format) { if (array_key_exists($format, $GLOBALS['smwgResultFormats'])) { return ParamDefinition::getCleanDefinitions(SMWQueryProcessor::getResultPrinter($format)->getParamDefinitions(SMWQueryProcessor::getParameters())); } else { return array(); } }
/** * Build the format drop down * * @param array * * @return string */ protected static function getFormatSelection($params) { $result = ''; $printer = SMWQueryProcessor::getResultPrinter('broadtable', SMWQueryProcessor::SPECIAL_PAGE); $url = SpecialPage::getSafeTitleFor('Ask')->getLocalURL('showformatoptions=this.value'); foreach ($params as $param => $value) { if ($param !== 'format') { $url .= '¶ms[' . rawurlencode($param) . ']=' . rawurlencode($value); } } $result .= '<br /><span style=vertical-align:middle;">' . wfMessage('smw_ask_format_as')->text() . ' <input type="hidden" name="eq" value="yes"/>' . "\n" . Html::openElement('select', array('id' => 'formatSelector', 'name' => 'p[format]', 'data-url' => $url)) . "\n" . ' <option value="broadtable"' . ($params['format'] == 'broadtable' ? ' selected' : '') . '>' . $printer->getName() . ' (' . wfMessage('smw_ask_defaultformat')->text() . ')</option>' . "\n"; $formats = array(); foreach (array_keys($GLOBALS['smwgResultFormats']) as $format) { // Special formats "count" and "debug" currently not supported. if ($format != 'broadtable' && $format != 'count' && $format != 'debug') { $printer = SMWQueryProcessor::getResultPrinter($format, SMWQueryProcessor::SPECIAL_PAGE); $formats[$format] = $printer->getName(); } } natcasesort($formats); foreach ($formats as $format => $name) { $result .= ' <option value="' . $format . '"' . ($params['format'] == $format ? ' selected' : '') . '>' . $name . "</option>\n"; } $result .= "</select></span>\n"; return $result; }
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 ); } } }
/** * Formats the parameter value to it's final result. * * @since 1.8 * * @param mixed $value * @param IParam $param * @param IParamDefinition[] $definitions * @param IParam[] $params * * @return mixed */ protected function formatValue($value, IParam $param, array &$definitions, array $params) { $value = parent::formatValue($value, $param, $definitions, $params); // Make sure the format value is valid. $value = self::getValidFormatName($value); // Add the formats parameters to the parameter list. $queryPrinter = SMWQueryProcessor::getResultPrinter($value); $definitions = $queryPrinter->getParamDefinitions($definitions); return $value; }
protected function getFormatParameters($format) { if (array_key_exists($format, $GLOBALS['smwgResultFormats'])) { return SMWQueryProcessor::getResultPrinter($format)->getValidatorParameters(); } else { return array(); } }
protected function makeHTMLResult() { global $wgOut; $result = ''; $result_mime = false; // output in MW Special page as usual // build parameter strings for URLs, based on current settings $urltail = '&q=' . urlencode($this->m_querystring); $tmp_parray = array(); foreach ($this->m_params as $key => $value) { if (!in_array($key, array('sort', 'order', 'limit', 'offset', 'title'))) { $tmp_parray[$key] = $value; } } $urltail .= '&p=' . urlencode(SMWInfolink::encodeParameters($tmp_parray)); $printoutstring = ''; foreach ($this->m_printouts as $printout) { $printoutstring .= $printout->getSerialisation() . "\n"; } if ('' != $printoutstring) { $urltail .= '&po=' . urlencode($printoutstring); } if ('' != $this->m_params['sort']) { $urltail .= '&sort=' . $this->m_params['sort']; } if ('' != $this->m_params['order']) { $urltail .= '&order=' . $this->m_params['order']; } if ($this->m_querystring != '') { $queryobj = SMWQueryProcessor::createQuery($this->m_querystring, $this->m_params, false, '', $this->m_printouts); $queryobj->querymode = SMWQuery::MODE_INSTANCES; ///TODO: Somewhat hacky (just as the query mode computation in SMWQueryProcessor::createQuery!) $res = smwfGetStore()->getQueryResult($queryobj); $printer = SMWQueryProcessor::getResultPrinter($this->m_params['format'], false, $res); $result_mime = $printer->getMimeType($res); if ($result_mime == false) { $navigation = $this->getNavigationBar($res, $urltail); $result = '<div style="text-align: center;">' . $navigation; $result .= '</div>' . $printer->getResult($res, $this->m_params, SMW_OUTPUT_HTML); $result .= '<div style="text-align: center;">' . $navigation . '</div>'; } else { // make a stand-alone file $result = $printer->getResult($res, $this->m_params, SMW_OUTPUT_FILE); } } if ($result_mime == false) { if ($this->m_querystring) { $wgOut->setHTMLtitle($this->m_querystring); } else { $wgOut->setHTMLtitle(wfMsg('ask')); } $result = $this->getInputForm($printoutstring, 'offset=' . $this->m_params['offset'] . '&limit=' . $this->m_params['limit'] . $urltail) . $result; $wgOut->addHTML($result); } else { $wgOut->disable(); header("Content-type: {$result_mime}; charset=UTF-8"); print $result; } }
/** * Creates form elements for choosing the result-format and their * associated format. * * The drop-down list and the format options are returned seperately as * elements of an array.Use in conjunction with processFormatOptions() to * supply formats options using ajax. Also, use its complement * processFormatSelectBox() to decode form data sent by these elements. * UI's may overload these methods to change behaviour or form * parameters. * * @param string $defaultFormat The default format which remains selected in the form * @return array The first element contains the format selector, while the second contains the Format options */ protected function getFormatSelectBoxSep($defaultFormat = 'broadtable') { global $smwgResultFormats; SMWOutputs::requireResource('jquery'); // checking argument $defFormat = 'broadtable'; if (array_key_exists($defaultFormat, $smwgResultFormats)) { $defFormat = $defaultFormat; } $printer = SMWQueryProcessor::getResultPrinter($defFormat, SMWQueryProcessor::SPECIAL_PAGE); $url = $this->getTitle()->getLocalURL("showformatoptions=' + this.value + '"); foreach ($this->uiCore->getParameters() as $param => $value) { if ($param !== 'format') { $url .= '¶ms[' . Xml::escapeJsString($param) . ']=' . Xml::escapeJsString($value); } } // @todo FIXME: i18n: Hard coded parentheses. $result[0] = "\n" . '<select id="formatSelector" name="p[format]" onChange="JavaScript:updateOtherOptions(\'' . $url . '\')">' . "\n" . '<option value="' . $defFormat . '">' . $printer->getName() . ' (' . wfMessage('smw_ask_defaultformat')->text() . ')</option>' . "\n"; $formats = array(); foreach (array_keys($smwgResultFormats) as $format) { // Special formats "count" and "debug" currently not supported. if ($format != $defFormat && $format != 'count' && $format != 'debug') { $printer = SMWQueryProcessor::getResultPrinter($format, SMWQueryProcessor::SPECIAL_PAGE); $formats[$format] = $printer->getName(); } } natcasesort($formats); $params = $this->uiCore->getParameters(); foreach ($formats as $format => $name) { $result[0] .= '<option value="' . $format . '"' . ($params['format'] == $format ? ' selected' : '') . '>' . $name . "</option>\n"; } $result[0] .= "</select>"; $result[0] .= "\n"; $result[] .= '<div id="other_options"> ' . $this->showFormatOptions($params['format'], $params) . ' </div>'; // BEGIN: add javascript for updating formating options by ajax $javascript = <<<END <script type="text/javascript"> function updateOtherOptions(strURL) { \tjQuery.ajax({ url: strURL, context: document.body, success: function(data){ \t\tjQuery("#other_options").html(data); \t}}); } </script> END; SMWOutputs::requireScript('smwUpdateOptionsQueryUI', $javascript); // END: add javascript for updating formating options by ajax return $result; }
/** * 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); }
private static function formatWSResultWithSMWQPs($wsResults, $configArgs, $wsParameters, $wsReturnValues, $smwQueryMode) { //do sorting $wsResults = self::sortWSResult($wsResults, $configArgs); //deal with limit and offset list($wsResults, $furtherResults) = self::formatWithLimitAndOffset($wsResults, $configArgs); $format = array_key_exists('format', $configArgs) ? $configArgs['format'] : ''; //todo: create print requests array for constructor below $printRequests = array(); $queryResults = array(); $typeIds = array(); //get Type ids $numTypeFormats = array('sum' => true, 'min' => true, 'max' => true, 'average' => true); foreach ($wsResults as $columnLabel => $values) { if (array_key_exists(strtolower($format), $numTypeFormats)) { $typeIds[$columnLabel] = '_num'; } else { $typeIds[$columnLabel] = '_txt'; } } //create print requests foreach ($wsReturnValues as $id => $label) { $id = ucfirst(substr($id, strpos($id, '.') + 1)); if (!$label) { $label = $id; } $printRequests[$id] = new SMWPrintRequest(SMWPrintRequest::PRINT_THIS, $label, $id); } //transpose ws result foreach ($wsResults as $columnLabel => $values) { foreach ($values as $key => $value) { $queryResultColumnValues = array(); $resultInstance = SMWDataValueFactory::newTypeIDValue('_wpg'); $title = Title::newFromText(wfMsg('smw_ob_invalidtitle'), ''); $resultInstance->setValues($title->getDBkey(), $title->getNamespace(), $title->getArticleID(), false, '', $title->getFragment()); $dataValue = SMWDataValueFactory::newTypeIDValue($typeIds[$columnLabel]); $dataValue->setUserValue($value); $queryResultColumnValues[] = $dataValue; //this is necessary, because one can edit with the properties //parameter of the LDConnector additional columns if (!array_key_exists(ucfirst($columnLabel), $printRequests)) { $printRequests[ucfirst($columnLabel)] = new SMWPrintRequest(SMWPrintRequest::PRINT_THIS, $columnLabel, ucfirst($columnLabel)); } $queryResultColumnValues = new SMWWSResultArray($resultInstance, $printRequests[ucfirst($columnLabel)], $queryResultColumnValues); @($queryResults[$key][$columnLabel] = $queryResultColumnValues); } } //translate ws call to SMW ask query $queryParams = array(); foreach ($wsParameters as $param => $value) { $queryParams['_' . $param] = $value; } foreach ($configArgs as $param => $value) { $queryParams[$param] = $value; } $queryParams['source'] = 'webservice'; $queryParams['webservice'] = $configArgs['webservice']; //create query object $query = SMWQueryProcessor::createQuery('[[dummy]]', $queryParams, SMWQueryProcessor::INLINE_QUERY, $format, $printRequests); $query->params = $queryParams; //create query result object $queryResult = new SMWWSQueryResult($printRequests, $query, $queryResults, new SMWWSSMWStore(), $furtherResults); //deal with count mode if ($format == 'count') { return count($queryResults); } //return the query result object if this is called by special:ask if ($smwQueryMode) { return $queryResult; } $printer = SMWQueryProcessor::getResultPrinter($format, SMWQueryProcessor::INLINE_QUERY); $result = $printer->getResult($queryResult, $configArgs, SMW_OUTPUT_WIKI); return $result; }
/** * Display a form section showing the options for a given format, * based on the getParameters() value for that format's query printer. * * @param string $format * @param array $paramValues The current values for the parameters (name => value) * * @return string */ protected function showFormatOptions( $format, array $paramValues ) { $printer = SMWQueryProcessor::getResultPrinter( $format, SMWQueryProcessor::SPECIAL_PAGE ); $params = SMWQueryProcessor::getParameters(); if ( method_exists( $printer, 'getValidatorParameters' ) ) { $params = array_merge( $params, $printer->getValidatorParameters() ); } $optionsHtml = array(); foreach ( $params as $param ) { // Ignore the format parameter, as we got a special control in the GUI for it already. if ( $param->getName() == 'format' ) { continue; } $currentValue = array_key_exists( $param->getName(), $paramValues ) ? $paramValues[$param->getName()] : false; $optionsHtml[] = Html::rawElement( 'div', array( 'style' => 'width: 30%; padding: 5px; float: left;' ), htmlspecialchars( $param->getName() ) . ': ' . $this->showFormatOption( $param, $currentValue ) . '<br />' . Html::element( 'em', array(), $param->getDescription() ) ); } for ( $i = 0, $n = count( $optionsHtml ); $i < $n; $i++ ) { if ( $i % 3 == 2 || $i == $n - 1 ) { $optionsHtml[$i] .= "<div style=\"clear: both\";></div>\n"; } } $i = 0; $rowHtml = ''; $resultHtml = ''; while ( $option = array_shift( $optionsHtml ) ) { $rowHtml .= $option; $i++; $resultHtml .= Html::rawElement( 'div', array( 'style' => 'background: ' . ( $i % 6 == 0 ? 'white' : '#dddddd' ) . ';' ), $rowHtml ); $rowHtml = ''; } return $resultHtml; }
protected function makeHTMLResult() { $this->checkIfThisIsAWSCALL(); global $wgOut, $smwgAutocompleteInSpecialAsk; $delete_msg = wfMsg('delete'); // Javascript code for the dynamic parts of the page $javascript_text = <<<END <script type="text/javascript"> jQuery.noConflict(); function xmlhttpPost(strURL) { \tjQuery.ajax({ url: strURL, data: getquerystring(), context: document.body, success: function(data){ \t\tdocument.getElementById("other_options").innerHTML = data; \t}}); } function getquerystring() { \tvar format_selector = document.getElementById('formatSelector'); \treturn format_selector.value; } // code for handling adding and removing the "sort" inputs var num_elements = {$this->m_num_sort_values}; function addInstance(starter_div_id, main_div_id) { \tvar starter_div = document.getElementById(starter_div_id); \tvar main_div = document.getElementById(main_div_id); \t//Create the new instance \tvar new_div = starter_div.cloneNode(true); \tvar div_id = 'sort_div_' + num_elements; \tnew_div.className = 'multipleTemplate'; \tnew_div.id = div_id; \tnew_div.style.display = 'block'; \tvar children = new_div.getElementsByTagName('*'); \tvar x; \tfor (x = 0; x < children.length; x++) { \t\tif (children[x].name) \t\t\tchildren[x].name = children[x].name.replace(/_num/, '[' + num_elements + ']'); \t} \t//Create 'delete' link \tvar remove_button = document.createElement('span'); \tremove_button.innerHTML = '[<a href="javascript:removeInstance(\\'sort_div_' + num_elements + '\\')">{$delete_msg}</a>]'; \tnew_div.appendChild(remove_button); \t//Add the new instance \tmain_div.appendChild(new_div); \tnum_elements++; } function removeInstance(div_id) { \tvar olddiv = document.getElementById(div_id); \tvar parent = olddiv.parentNode; \tparent.removeChild(olddiv); } </script> END; $wgOut->addScript($javascript_text); if ($smwgAutocompleteInSpecialAsk) { self::addAutocompletionJavascriptAndCSS(); } $result = ''; $result_mime = false; // output in MW Special page as usual // build parameter strings for URLs, based on current settings $urltail = '&q=' . urlencode($this->m_querystring); $tmp_parray = array(); foreach ($this->m_params as $key => $value) { if (!in_array($key, array('sort', 'order', 'limit', 'offset', 'title'))) { $tmp_parray[$key] = $value; } } $urltail .= '&p=' . urlencode(SMWInfolink::encodeParameters($tmp_parray)); $printoutstring = ''; foreach ($this->m_printouts as $printout) { $printoutstring .= $printout->getSerialisation() . "\n"; } if ($printoutstring != '') { $urltail .= '&po=' . urlencode($printoutstring); } if (array_key_exists('sort', $this->m_params)) { $urltail .= '&sort=' . $this->m_params['sort']; } if (array_key_exists('order', $this->m_params)) { $urltail .= '&order=' . $this->m_params['order']; } if ($this->m_querystring != '') { $queryobj = SMWQueryProcessor::createQuery($this->m_querystring, $this->m_params, SMWQueryProcessor::SPECIAL_PAGE, $this->m_params['format'], $this->m_printouts); $queryobj->params = $this->m_params; $store = $this->getStore(); $res = $store->getQueryResult($queryobj); // try to be smart for rss/ical if no description/title is given and we have a concept query: if ($this->m_params['format'] == 'rss') { $desckey = 'rssdescription'; $titlekey = 'rsstitle'; } elseif ($this->m_params['format'] == 'icalendar') { $desckey = 'icalendardescription'; $titlekey = 'icalendartitle'; } else { $desckey = false; } if ($desckey && $queryobj->getDescription() instanceof SMWConceptDescription && (!isset($this->m_params[$desckey]) || !isset($this->m_params[$titlekey]))) { $concept = $queryobj->getDescription()->getConcept(); if (!isset($this->m_params[$titlekey])) { $this->m_params[$titlekey] = $concept->getText(); } if (!isset($this->m_params[$desckey])) { $dv = end(smwfGetStore()->getPropertyValues(SMWWikiPageValue::makePageFromTitle($concept), SMWPropertyValue::makeProperty('_CONC'))); if ($dv instanceof SMWConceptValue) { $this->m_params[$desckey] = $dv->getDocu(); } } } $printer = SMWQueryProcessor::getResultPrinter($this->m_params['format'], SMWQueryProcessor::SPECIAL_PAGE); $result_mime = $printer->getMimeType($res); global $wgRequest; $hidequery = $wgRequest->getVal('eq') == 'no'; // if it's an export format (like CSV, JSON, etc.), // don't actually export the data if 'eq' is set to // either 'yes' or 'no' in the query string - just // show the link instead if ($this->m_editquery || $hidequery) { $result_mime = false; } if ($result_mime == false) { if ($res->getCount() > 0) { if ($this->m_editquery) { $urltail .= '&eq=yes'; } if ($hidequery) { $urltail .= '&eq=no'; } $navigation = $this->getNavigationBar($res, $urltail); $result .= '<div style="text-align: center;">' . "\n" . $navigation . "\n</div>\n"; $query_result = $printer->getResult($res, $this->m_params, SMW_OUTPUT_HTML); if (is_array($query_result)) { $result .= $query_result[0]; } else { $result .= $query_result; } $result .= '<div style="text-align: center;">' . "\n" . $navigation . "\n</div>\n"; } else { $result = '<div style="text-align: center;">' . wfMsg('smw_result_noresults') . '</div>'; } } else { // make a stand-alone file $result = $printer->getResult($res, $this->m_params, SMW_OUTPUT_FILE); $result_name = $printer->getFileName($res); // only fetch that after initialising the parameters } } if ($result_mime == false) { if ($this->m_querystring) { $wgOut->setHTMLtitle($this->m_querystring); } else { $wgOut->setHTMLtitle(wfMsg('ask')); } $result = $this->getInputForm($printoutstring, 'offset=' . $this->m_params['offset'] . '&limit=' . $this->m_params['limit'] . $urltail) . $result; $result = $this->postProcessHTML($result); $wgOut->addHTML($result); } else { $wgOut->disable(); header("Content-type: {$result_mime}; charset=UTF-8"); if ($result_name !== false) { header("content-disposition: attachment; filename={$result_name}"); } print $result; } }