/** * Read and interpret the given parameters. * * @since 1.8 * @param string $query from the web request as given by MW */ protected function processParameters($query) { global $wgRequest; // get the GET parameters $params = SMWInfolink::decodeParameters($query, false); reset($params); $inputPropertyString = $wgRequest->getText('property', current($params)); $inputValueString = $wgRequest->getText('value', next($params)); $inputValueString = str_replace(' ', ' ', $inputValueString); $inputValueString = str_replace(' ', ' ', $inputValueString); $this->property = SMWPropertyValue::makeUserProperty($inputPropertyString); if (!$this->property->isValid()) { $this->propertystring = $inputPropertyString; $this->value = null; $this->valuestring = $inputValueString; } else { $this->propertystring = $this->property->getWikiValue(); $this->value = SMWDataValueFactory::newPropertyObjectValue($this->property->getDataItem(), $inputValueString); $this->valuestring = $this->value->isValid() ? $this->value->getWikiValue() : $inputValueString; } $limitString = $wgRequest->getVal('limit'); if (is_numeric($limitString)) { $this->limit = intval($limitString); } else { $this->limit = 20; } $offsetString = $wgRequest->getVal('offset'); if (is_numeric($offsetString)) { $this->offset = intval($offsetString); } else { $this->offset = 0; } }
/** * Main entry point for Special Pages * * @param[in] $query string Given by MediaWiki */ public function execute($query) { global $wgRequest, $wgOut, $smwgBrowseShowAll; $this->setHeaders(); // get the GET parameters $this->articletext = $wgRequest->getVal('article'); // no GET parameters? Then try the URL if (is_null($this->articletext)) { $params = SMWInfolink::decodeParameters($query, false); reset($params); $this->articletext = current($params); } $this->subject = SMWDataValueFactory::newTypeIDValue('_wpg', $this->articletext); $offsettext = $wgRequest->getVal('offset'); $this->offset = is_null($offsettext) ? 0 : intval($offsettext); $dir = $wgRequest->getVal('dir'); if ($smwgBrowseShowAll) { $this->showoutgoing = true; $this->showincoming = true; } if ($dir === 'both' || $dir === 'in') { $this->showincoming = true; } if ($dir === 'in') { $this->showoutgoing = false; } if ($dir === 'out') { $this->showincoming = false; } $wgOut->addHTML($this->displayBrowse()); SMWOutputs::commitToOutputPage($wgOut); // make sure locally collected output data is pushed to the output! }
/** * Main entry point for Special Pages. Gets all required parameters. * * @param[in] $query string Given by MediaWiki */ public function execute( $query ) { global $wgRequest, $wgOut; $this->setHeaders(); // get the GET parameters $this->propertystring = $wgRequest->getText( 'property' ); $this->valuestring = $wgRequest->getText( 'value' ); $params = SMWInfolink::decodeParameters( $query, false ); reset( $params ); // no GET parameters? Then try the URL if ( $this->propertystring === '' ) $this->propertystring = current( $params ); if ( $this->valuestring === '' ) $this->valuestring = next( $params ); $this->valuestring = str_replace( ' ', ' ', $this->valuestring ); $this->valuestring = str_replace( ' ', ' ', $this->valuestring ); $this->property = SMWPropertyValue::makeUserProperty( $this->propertystring ); if ( !$this->property->isValid() ) { $this->propertystring = ''; } else { $this->propertystring = $this->property->getWikiValue(); $this->value = SMWDataValueFactory::newPropertyObjectValue( $this->property->getDataItem(), $this->valuestring ); if ( $this->value->isValid() ) { $this->valuestring = $this->value->getWikiValue(); } else { $this->value = null; } } $limitstring = $wgRequest->getVal( 'limit' ); if ( is_numeric( $limitstring ) ) { $this->limit = intval( $limitstring ); } $offsetstring = $wgRequest->getVal( 'offset' ); if ( is_numeric( $offsetstring ) ) { $this->offset = intval( $offsetstring ); } $wgOut->addHTML( $this->displaySearchByProperty() ); $wgOut->addHTML( $this->queryForm() ); SMWOutputs::commitToOutputPage( $wgOut ); // make sure locally collected output data is pushed to the output! }
public function execute($param) { global $wgOut; $params = SMWInfolink::decodeParameters($param, false); $typeLabel = reset($params); if ($typeLabel == false) { $wgOut->setPageTitle(wfMessage('types')->text()); $html = $this->getTypesList(); } else { $typeName = str_replace('_', ' ', $typeLabel); $wgOut->setPageTitle($typeName); // Maybe add a better message for this $html = $this->getTypeProperties($typeLabel); } $wgOut->addHTML($html); SMWOutputs::commitToOutputPage($wgOut); }
/** * 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); }
/** * 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. list($this->m_querystring, $this->m_params, $this->m_printouts) = SMWQueryProcessor::getComponentsFromFunctionParams($rawparams, false); // 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; }
/** * A method which decodes form data sent through form-elements generated * by its complement, getFormatSelectBox(). UIs may overload both to * change form parameters. * * @param WebRequest $wgRequest * @return array */ protected function processFormatSelectBox(WebRequest $wgRequest) { $queryVal = $wgRequest->getVal('p'); if (!empty($queryVal)) { $params = SMWInfolink::decodeParameters($queryVal, false); } else { $queryValues = $wgRequest->getArray('p'); if (is_array($queryValues)) { foreach ($queryValues as $key => $val) { if (empty($val)) { unset($queryValues[$key]); } } } // p is used for any additional parameters in certain links. $params = SMWInfolink::decodeParameters($queryValues, false); } return $params; }
/** * Displays a value, including all relevant links (browse and search by property) * * @param[in] $property SMWPropertyValue The property this value is linked to the subject with * @param[in] $value SMWDataValue The actual value * @param[in] $incoming bool If this is an incoming or outgoing link * * @return string HTML with the link to the article, browse, and search pages */ private function displayValue( SMWPropertyValue $property, SMWDataValue $dataValue, $incoming ) { $linker = smwfGetLinker(); $html = $dataValue->getLongHTMLText( $linker ); // TODO: How to I trigger autoload if extends? SMWInfolink::decodeParameters(); if ( $dataValue->getTypeID() == '_wpg' ) { $html .= " " . SWBInfolink::newBrowsingLink( '+', $dataValue->getLongWikiText() )->getHTML( $linker ); } elseif ( $incoming && $property->isVisible() ) { $html .= " " . SWBInfolink::newInversePropertySearchLink( '+', $dataValue->getTitle(), $property->getDataItem()->getLabel(), 'smwsearch' )->getHTML( $linker ); } else { $html .= $dataValue->getInfolinkText( SMW_OUTPUT_HTML, $linker ); } return $html; }