コード例 #1
0
ファイル: SMW_SpecialAsk.php プロジェクト: Tjorriemorrie/app
 /**
  * Generates the Search Box UI
  *
  * @param string $printoutstring
  * @param string $urltail
  *
  * @return string
  */
 protected function getInputForm($printoutstring, $urltail)
 {
     global $wgScript;
     $result = '';
     if ($this->m_editquery) {
         $result .= Html::openElement('form', array('action' => $wgScript, 'name' => 'ask', 'method' => 'get'));
         $result .= Html::hidden('title', $this->getTitle()->getPrefixedDBKey());
         // Table for main query and printouts.
         $result .= '<table style="width: 100%;"><tr><th>' . wfMessage('smw_ask_queryhead')->text() . "</th>\n<th>" . wfMessage('smw_ask_printhead')->text() . "<br />\n" . '<span style="font-weight: normal;">' . wfMessage('smw_ask_printdesc')->text() . '</span>' . "</th></tr>\n" . '<tr><td style="padding-right: 7px;"><textarea name="q" cols="20" rows="6">' . htmlspecialchars($this->m_querystring) . "</textarea></td>\n" . '<td style="padding-left: 7px;"><textarea id = "add_property" name="po" cols="20" rows="6">' . htmlspecialchars($printoutstring) . '</textarea></td></tr></table>' . "\n";
         // Format selection
         $result .= self::getFormatSelection($this->m_params);
         // @TODO
         // Sorting inputs
         if ($GLOBALS['smwgQSortingSupport']) {
             $result .= '<fieldset class="smw-ask-sorting"><legend>' . wfMessage('smw-ask-sorting')->escaped() . "</legend>\n";
             $result .= self::getSortingOption($this->m_params);
             $result .= "</fieldset>\n";
         }
         // Other options fieldset
         $result .= '<fieldset class="smw-ask-options smwExpandedFieldset"><legend>' . wfMessage('smw_ask_otheroptions')->escaped() . "</legend>\n";
         // Info text for when the fieldset is collapsed
         $result .= Html::element('div', array('class' => 'collapsed-info', 'style' => 'display:none;'), wfMessage('smw-ask-otheroptions-collapsed-info')->text());
         // Individual options
         $result .= "<div id=\"other_options\">" . $this->showFormatOptions($this->m_params['format'], $this->m_params) . "</div>";
         $result .= "</fieldset>\n";
         $urltail = str_replace('&eq=yes', '', $urltail) . '&eq=no';
         // FIXME: doing it wrong, srysly
         // Submit
         $result .= '<br /><input type="submit" value="' . wfMessage('smw_ask_submit')->text() . '"/>' . '<input type="hidden" name="eq" value="yes"/>' . Html::element('a', array('href' => SpecialPage::getSafeTitleFor('Ask')->getLocalURL($urltail), 'rel' => 'nofollow'), wfMessage('smw_ask_hidequery')->text()) . ' | ' . SMWAskPage::getEmbedToggle() . ' | <a href="' . htmlspecialchars(wfMessage('smw_ask_doculink')->text()) . '">' . wfMessage('smw_ask_help')->text() . '</a>' . "\n</form>";
     } else {
         // if $this->m_editquery == false
         $urltail = str_replace('&eq=no', '', $urltail) . '&eq=yes';
         $result .= '<p>' . Html::element('a', array('href' => SpecialPage::getSafeTitleFor('Ask')->getLocalURL($urltail), 'rel' => 'nofollow'), wfMessage('smw_ask_editquery')->text()) . '| ' . SMWAskPage::getEmbedToggle() . '</p>';
     }
     //show|hide inline embed code
     $result .= '<div id="inlinequeryembed" style="display: none"><div id="inlinequeryembedinstruct">' . wfMessage('smw_ask_embed_instr')->text() . '</div><textarea id="inlinequeryembedarea" readonly="yes" cols="20" rows="6" onclick="this.select()">' . '{{#ask:' . htmlspecialchars($this->m_querystring) . "\n";
     foreach ($this->m_printouts as $printout) {
         $result .= '|' . $printout->getSerialisation() . "\n";
     }
     // Find parameters
     foreach ($this->params as $param) {
         if (!$param->wasSetToDefault()) {
             $result .= '|' . htmlspecialchars($param->getName()) . '=';
             // e.g. sorting returns with an array
             $result .= $param->getDefinition()->isList() ? implode($param->getDefinition()->getDelimiter(), $param->getValue()) . "\n" : $param->getValue() . "\n";
         }
     }
     $result .= '}}</textarea></div><br />';
     return $result;
 }
コード例 #2
0
	function get_ask_feed() {
		global $wgSitename, $wgTitle, $wgRequest;
		// check for semantic wiki:
		if ( !defined( 'SMW_VERSION' ) ) {
			return false;
		}
		// bootstrap off of SMWAskPage:
		$SMWAskPage = new SMWAskPage();
		$SMWAskPage->extractQueryParameters( $wgRequest->getVal( 'q' ) );

		// print 'query string: ' . $SMWAskPage->m_querystring . "\n<br />";
		// print 'm_params: ' . print_r($SMWAskPage->m_params) . "\n<br />";
		// print 'print outs: ' .print_r($SMWAskPage->m_printouts) . "\n<br />";
		// set up the feed:
		$this->feed = new mvRSSFeed(
		$wgSitename . ' - ' . wfMsg( 'mediasearch' ) . ' : ' . strip_tags( $SMWAskPage->m_querystring ), // title
		strip_tags( $SMWAskPage->m_querystring ), // description
		$wgTitle->getFullUrl() // link
		);
		$this->feed->outHeader();

		$queryobj = SMWQueryProcessor::createQuery( $SMWAskPage->m_querystring, $SMWAskPage->m_params, false, '', $SMWAskPage->m_printouts );
		$res = smwfGetStore()->getQueryResult( $queryobj );
		$row = $res->getNext();
		while ( $row !== false ) {
			$wikititle = $row[0]->getNextObject();
			$this->feed->outPutItem( $wikititle->getTitle() );
			$row = $res->getNext();
		}
		$this->feed->outFooter();
	}
コード例 #3
0
	/**
	 * Generates the Search Box UI
	 *
	 * @param string $printoutstring
	 * @param string $urltail
	 *
	 * @return string
	 */
	protected function getInputForm( $printoutstring, $urltail ) {
		global $smwgQSortingSupport, $smwgResultFormats;

		$result = '';

		if ( $this->m_editquery ) {
			$spectitle = $this->getTitleFor( 'Ask' );
			$result .= '<form name="ask" action="' . htmlspecialchars( $spectitle->getLocalURL() ) . '" method="get">' . "\n" .
				'<input type="hidden" name="title" value="' . $spectitle->getPrefixedText() . '"/>';

			// Table for main query and printouts.
			$result .= '<table style="width: 100%; "><tr><th>' . wfMsg( 'smw_ask_queryhead' ) . "</th>\n<th>" . wfMsg( 'smw_ask_printhead' ) . "<br />\n" .
				'<span style="font-weight: normal;">' . wfMsg( 'smw_ask_printdesc' ) . '</span>' . "</th></tr>\n" .
				'<tr><td style="padding-right: 7px;"><textarea name="q" cols="20" rows="6">' . htmlspecialchars( $this->m_querystring ) . "</textarea></td>\n" .
				'<td style="padding-left: 7px;"><textarea id = "add_property" name="po" cols="20" rows="6">' . htmlspecialchars( $printoutstring ) . '</textarea></td></tr></table>' . "\n";
// @TODO
			// sorting inputs
			if ( $smwgQSortingSupport ) {
				if ( ! array_key_exists( 'sort', $this->m_params ) || ! array_key_exists( 'order', $this->m_params ) ) {
					$orders = array(); // do not even show one sort input here
				} else {
					$sorts = explode( ',', $this->m_params['sort'] );
					$orders = explode( ',', $this->m_params['order'] );
					reset( $sorts );
				}

				foreach ( $orders as $i => $order ) {
					$result .=  "<div id=\"sort_div_$i\">" . wfMsg( 'smw_ask_sortby' ) . ' <input type="text" name="sort[' . $i . ']" value="' .
						    htmlspecialchars( $sorts[$i] ) . "\" size=\"35\"/>\n" . '<select name="order[' . $i . ']"><option ';

					if ( $order == 'ASC' ) $result .= 'selected="selected" ';
					$result .=  'value="ASC">' . wfMsg( 'smw_ask_ascorder' ) . '</option><option ';
					if ( $order == 'DESC' ) $result .= 'selected="selected" ';

					$result .=  'value="DESC">' . wfMsg( 'smw_ask_descorder' ) . "</option></select>\n";
					$result .= '[<a href="javascript:removeInstance(\'sort_div_' . $i . '\')">' . wfMsg( 'delete' ) . '</a>]' . "\n";
					$result .= "</div>\n";
				}

				$result .=  '<div id="sorting_starter" style="display: none">' . wfMsg( 'smw_ask_sortby' ) . ' <input type="text" name="sort_num" size="35" />' . "\n";
				$result .= ' <select name="order_num">' . "\n";
				$result .= '	<option value="ASC">' . wfMsg( 'smw_ask_ascorder' ) . "</option>\n";
				$result .= '	<option value="DESC">' . wfMsg( 'smw_ask_descorder' ) . "</option>\n</select>\n";
				$result .= "</div>\n";
				$result .= '<div id="sorting_main"></div>' . "\n";
				$result .= '<a href="javascript:addInstance(\'sorting_starter\', \'sorting_main\')">' . wfMsg( 'smw_add_sortcondition' ) . '</a>' . "\n";
			}

			$printer = SMWQueryProcessor::getResultPrinter( 'broadtable', SMWQueryProcessor::SPECIAL_PAGE );
			$url = SpecialPage::getSafeTitleFor( 'Ask' )->getLocalURL( "showformatoptions=' + this.value + '" );

			foreach ( $this->m_params as $param => $value ) {
				if ( $param !== 'format' ) {
					$url .= '&params[' . Xml::escapeJsString( $param ) . ']=' . Xml::escapeJsString( $value );
				}
			}

			$result .= "<br /><br />\n<p>" . wfMsg( 'smw_ask_format_as' ) . ' <input type="hidden" name="eq" value="yes"/>' . "\n" .
				'<select id="formatSelector" name="p[format]" onChange="JavaScript:updateOtherOptions(\'' . $url . '\')">' . "\n" .
				'	<option value="broadtable"' . ( $this->m_params['format'] == 'broadtable' ? ' selected' : '' ) . '>' .
				$printer->getName() . ' (' . wfMsg( 'smw_ask_defaultformat' ) . ')</option>' . "\n";

			$formats = array();

			foreach ( array_keys( $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 . '"' . ( $this->m_params['format'] == $format ? ' selected' : '' ) . '>' . $name . "</option>\n";
			}

			$result .= "</select></p>\n";
			$result .= '<fieldset><legend>' . wfMsg( 'smw_ask_otheroptions' ) . "</legend>\n";
			$result .= "<div id=\"other_options\">" . $this->showFormatOptions( $this->m_params['format'], $this->m_params ) . "</div>";
			$result .= "</fieldset>\n";
			$urltail = str_replace( '&eq=yes', '', $urltail ) . '&eq=no'; // FIXME: doing it wrong, srysly

			$result .= '<br /><input type="submit" value="' . wfMsg( 'smw_ask_submit' ) . '"/>' .
				'<input type="hidden" name="eq" value="yes"/>' .
					Html::element(
						'a',
						array(
							'href' => SpecialPage::getSafeTitleFor( 'Ask' )->getLocalURL( $urltail ),
							'rel' => 'nofollow'
						),
						wfMsg( 'smw_ask_hidequery' )
					) .
					'| ' . SMWAskPage::getEmbedToggle() .
					'| <a href="' . htmlspecialchars( wfMsg( 'smw_ask_doculink' ) ) . '">' . wfMsg( 'smw_ask_help' ) . '</a>' .
				"\n</form>";
		} else { // if $this->m_editquery == false
			$urltail = str_replace( '&eq=no', '', $urltail ) . '&eq=yes';
			$result .= '<p>' .
				Html::element(
					'a',
					array(
						'href' => SpecialPage::getSafeTitleFor( 'Ask' )->getLocalURL( $urltail ),
						'rel' => 'nofollow'
					),
					wfMsg( 'smw_ask_editquery' )
				) .
				'| ' . SMWAskPage::getEmbedToggle() .
				'</p>';
		}
	//show|hide inline embed code
		$result .= '<div id="inlinequeryembed" style="display: none"><div id="inlinequeryembedinstruct">' . wfMsg( 'smw_ask_embed_instr' ) . '</div><textarea id="inlinequeryembedarea" readonly="yes" cols="20" rows="6" onclick="this.select()">' .
			'{{#ask:' . htmlspecialchars( $this->m_querystring ) . "\n";

		foreach ( $this->m_printouts as $printout ) {
			$result .= '|' . $printout->getSerialisation() . "\n";
		}

		foreach ( $this->m_params as $param_name => $param_value ) {
			$result .= '|' . htmlspecialchars( $param_name ) . '=' . htmlspecialchars( $param_value ) . "\n";
		}

		$result .= '}}</textarea></div><br />';

		return $result;
	}