static function create( $actual_val, $filter_time_period = null ) {
		$fv = new SDFilterValue();
		$fv->text = $actual_val;

		if ( $fv->text == ' none' )
			$fv->is_none = true;
		if ( $fv->text == ' other' )
			$fv->is_other = true;
		// set other fields, if it's a date or number range
		if ( $filter_time_period != null ) {
			if ( $filter_time_period == wfMsg( 'sd_filter_month' ) ) {
				list( $month_str, $year ) = explode( ' ', $fv->text );
				$fv->month = SDUtils::stringToMonth( $month_str );
				$fv->year = $year;
			} else {
				$fv->year = $fv->text;
			}
		} else {
			if ( $fv->text == '' ) {
				// do nothing
			} elseif ( $fv->text { 0 } == '<' ) {
				$possible_number = str_replace( ',', '', trim( substr( $fv->text, 1 ) ) );
				if ( is_numeric( $possible_number ) ) {
					$fv->upper_limit = $possible_number;
					$fv->is_numeric = true;
				}
			} elseif ( $fv->text { 0 } == '>' ) {
				$possible_number = str_replace( ',', '', trim( substr( $fv->text, 1 ) ) );
				if ( is_numeric( $possible_number ) ) {
					$fv->lower_limit = $possible_number;
					$fv->is_numeric = true;
				}
			} else {
				$elements = explode( '-', $fv->text );
				if ( count( $elements ) == 2 ) {
					$first_elem = str_replace( ',', '', trim( $elements[0] ) );
					$second_elem = str_replace( ',', '', trim( $elements[1] ) );
					if ( is_numeric( $first_elem ) && is_numeric( $second_elem ) ) {
						$fv->lower_limit = $first_elem;
						$fv->upper_limit = $second_elem;
						$fv->is_numeric = true;
					}
				}
			}
		}
		return $fv;
	}
 static function create($actual_val, $filter = null)
 {
     $fv = new SDFilterValue();
     $fv->text = str_replace('_', ' ', $actual_val);
     if ($fv->text == ' none') {
         $fv->is_none = true;
     } elseif ($fv->text == ' other') {
         $fv->is_other = true;
     }
     // set other fields, if it's a date or number range
     if ($filter != null && $filter->property_type == 'date') {
         // @TODO - this should ideally be handled via query
         // string arrays - and this code merged in with
         // date-range handling - instead of just doing string
         // parsing on one string.
         if (strpos($fv->text, ' - ') > 0) {
             // If there's a dash, assume it's a year range
             $years = explode(' - ', $fv->text);
             $fv->year = $years[0];
             $fv->end_year = $years[1];
             $fv->time_period = 'year range';
         } else {
             $date_parts = explode(' ', $fv->text);
             if (count($date_parts) == 3) {
                 list($month_str, $day_str, $year) = explode(' ', $fv->text);
                 $fv->month = SDUtils::stringToMonth($month_str);
                 $fv->day = str_replace(',', '', $day_str);
                 $fv->year = $year;
                 $fv->time_period = 'day';
             } elseif (count($date_parts) == 2) {
                 list($month_str, $year) = explode(' ', $fv->text);
                 $fv->month = SDUtils::stringToMonth($month_str);
                 $fv->year = $year;
                 $fv->time_period = 'month';
             } else {
                 $fv->month = null;
                 $fv->year = $fv->text;
                 $fv->time_period = 'year';
             }
         }
     } else {
         if ($fv->text == '') {
             // do nothing
         } elseif ($fv->text[0] == '<') {
             $possible_number = str_replace(',', '', trim(substr($fv->text, 1)));
             if (is_numeric($possible_number)) {
                 $fv->upper_limit = $possible_number;
                 $fv->is_numeric = true;
             }
         } elseif ($fv->text[0] == '>') {
             $possible_number = str_replace(',', '', trim(substr($fv->text, 1)));
             if (is_numeric($possible_number)) {
                 $fv->lower_limit = $possible_number;
                 $fv->is_numeric = true;
             }
         } else {
             $elements = explode('-', $fv->text);
             if (count($elements) == 2) {
                 $first_elem = str_replace(',', '', trim($elements[0]));
                 $second_elem = str_replace(',', '', trim($elements[1]));
                 if (is_numeric($first_elem) && is_numeric($second_elem)) {
                     $fv->lower_limit = $first_elem;
                     $fv->upper_limit = $second_elem;
                     $fv->is_numeric = true;
                 }
             }
         }
     }
     return $fv;
 }
Ejemplo n.º 3
0
 /**
  * Returns the HTML for setting the filter options, for the
  * Semantic Drilldown section in Page Schemas' "edit schema" page
  */
 public static function getFieldEditingHTML($psField)
 {
     //$require_filter_label = wfMessage( 'sd_createfilter_requirefilter' )->text();
     $filter_array = array();
     $hasExistingValues = false;
     if (!is_null($psField)) {
         $filter_array = $psField->getObject('semanticdrilldown_Filter');
         if (!is_null($filter_array)) {
             $hasExistingValues = true;
         }
     }
     $filterName = PageSchemas::getValueFromObject($filter_array, 'name');
     $selectedCategory = PageSchemas::getValueFromObject($filter_array, 'ValuesFromCategory');
     $fromCategoryAttrs = array();
     if (!is_null($selectedCategory)) {
         $fromCategoryAttrs['checked'] = true;
     }
     // Have the first radiobutton ("Use all values of this
     // property for the filter") checked if none of the other
     // options have been selected - unlike the others, there's
     // no XML to define this option.
     $usePropertyValuesAttr = array();
     if (empty($selectedCategory)) {
         $usePropertyValuesAttr['checked'] = true;
     }
     $html_text = '<div class="editSchemaMinorFields">' . "\n";
     $html_text .= '<p>' . wfMessage('ps-optional-name')->text() . ' ';
     $html_text .= Html::input('sd_filter_name_num', $filterName, 'text', array('size' => 25)) . "</p>\n";
     $html_text .= wfMessage('sd-pageschemas-values')->text() . ":\n";
     $html_text .= Html::input('sd_values_source_num', 'property', 'radio', $usePropertyValuesAttr) . ' ';
     $html_text .= wfMessage('sd_createfilter_usepropertyvalues')->text() . "\n";
     $html_text .= Html::input('sd_values_source_num', 'category', 'radio', $fromCategoryAttrs) . "\n";
     $html_text .= "\t" . wfMessage('sd_createfilter_usecategoryvalues')->text() . "\n";
     $categories = SDUtils::getTopLevelCategories();
     $categoriesHTML = "";
     foreach ($categories as $category) {
         $categoryOptionAttrs = array();
         $category = str_replace('_', ' ', $category);
         if ($category == $selectedCategory) {
             $categoryOptionAttrs['selected'] = true;
         }
         $categoriesHTML .= "\t" . Html::element('option', $categoryOptionAttrs, $category) . "\n";
     }
     $html_text .= "\t" . Html::rawElement('select', array('id' => 'category_dropdown', 'name' => 'sd_category_name_num'), "\n" . $categoriesHTML) . "\n";
     $html_text .= "\t</p>\n";
     $html_text .= "\t</div>\n";
     return array($html_text, $hasExistingValues);
 }
Ejemplo n.º 4
0
 static function getCategoryChildren($category_name, $get_categories, $levels)
 {
     if ($levels == 0) {
         return array();
     }
     $pages = array();
     $subcategories = array();
     $dbr = wfGetDB(DB_SLAVE);
     extract($dbr->tableNames('page', 'categorylinks'));
     $cat_ns = NS_CATEGORY;
     $query_category = str_replace(' ', '_', $category_name);
     $sql = "SELECT p.page_title, p.page_namespace FROM {$categorylinks} cl\n\tJOIN {$page} p on cl.cl_from = p.page_id\n\tWHERE cl.cl_to = {$dbr->addQuotes($query_category)}\n";
     if ($get_categories) {
         $sql .= "AND p.page_namespace = {$cat_ns}\n";
     }
     $sql .= "ORDER BY cl.cl_sortkey";
     $res = $dbr->query($sql);
     while ($row = $dbr->fetchRow($res)) {
         if ($get_categories) {
             $subcategories[] = $row[0];
             $pages[] = $row[0];
         } else {
             if ($row[1] == $cat_ns) {
                 $subcategories[] = $row[0];
             } else {
                 $pages[] = $row[0];
             }
         }
     }
     $dbr->freeResult($res);
     foreach ($subcategories as $subcategory) {
         $pages = array_merge($pages, SDUtils::getCategoryChildren($subcategory, $get_categories, $levels - 1));
     }
     return $pages;
 }
Ejemplo n.º 5
0
	/**
	 * Gets an array of the possible time period values (e.g., years,
	 * years and months) for this filter, and, for each one,
	 * the number of pages that match that time period.
	 */
	function getTimePeriodValues() {
		$possible_dates = array();
		$property_value = $this->escaped_property;
		$dbr = wfGetDB( DB_SLAVE );
		if ( $this->time_period == wfMsg( 'sd_filter_month' ) ) {
			$fields = "YEAR(value_xsd), MONTH(value_xsd)";
		} else {
			$fields = "YEAR(value_xsd)";
		}
		$smw_attributes = $dbr->tableName( 'smw_atts2' );
		$smw_ids = $dbr->tableName( 'smw_ids' );
		$sql = <<<END
	SELECT $fields, count(*)
	FROM semantic_drilldown_values sdv 
	JOIN $smw_attributes a ON sdv.id = a.s_id
	JOIN $smw_ids p_ids ON a.p_id = p_ids.smw_id
	WHERE p_ids.smw_title = '$property_value'
	GROUP BY $fields
	ORDER BY $fields

END;
		$res = $dbr->query( $sql );
		while ( $row = $dbr->fetchRow( $res ) ) {
			if ( $this->time_period == wfMsg( 'sd_filter_month' ) ) {
				global $sdgMonthValues;
				$date_string = SDUtils::monthToString( $row[1] ) . " " . $row[0];
				$possible_dates[$date_string] = $row[2];
			} else {
				$date_string = $row[0];
				$possible_dates[$date_string] = $row[1];
			}
		}
		$dbr->freeResult( $res );
		return $possible_dates;
	}
	/**
	 * Returns the HTML for setting the filter options, for the
	 * Semantic Drilldown section in Page Schemas' "edit schema" page
	 */
	public static function getFieldEditingHTML( $psField ){
		//$require_filter_label = wfMsg( 'sd_createfilter_requirefilter' );

		$filter_array = array();
		$hasExistingValues = false;
		if ( !is_null( $psField ) ) {
			$filter_array = $psField->getObject( 'semanticdrilldown_Filter' );
			if ( !is_null( $filter_array ) ) {
				$hasExistingValues = true;
			}
		}

		$filterName = PageSchemas::getValueFromObject( $filter_array, 'name' );
		$selectedCategory = PageSchemas::getValueFromObject( $filter_array, 'ValuesFromCategory' );
		$fromCategoryAttrs = array();
		if ( !is_null( $selectedCategory ) ) {
			$fromCategoryAttrs['checked'] = true;
		}
		$dateRangesAttrs = array();
		$year_value = wfMsgForContent( 'sd_filter_year' );
		$yearOptionAttrs = array( 'value' => $year_value );
		$month_value = wfMsgForContent( 'sd_filter_month' );
		$monthOptionAttrs = array( 'value' => $month_value );
		$filterTimePeriod = PageSchemas::getValueFromObject( $filter_array, 'TimePeriod' );
		if ( !is_null( $filterTimePeriod ) ) {
			$dateRangesAttrs['checked'] = true;
			if ( $filterTimePeriod == $year_value ) {
				$yearOptionAttrs['selected'] = true;
			} else {
				$monthOptionAttrs['selected'] = true;
			}
		}
		$manualSourceAttrs = array();
		$filterValuesAttrs = array( 'size' => 40 );
		$values_array = PageSchemas::getValueFromObject( $filter_array, 'Values' );
		if ( !is_null( $values_array ) ) {
			$manualSourceAttrs['checked'] = true;
			$filterValuesStr = implode( ', ', $values_array );
		} else {
			$filterValuesStr = '';
		}
		// Have the first radiobutton ("Use all values of this
		// property for the filter") checked if none of the other
		// options have been selected - unlike the others, there's
		// no XML to define this option.
		$usePropertyValuesAttr = array();
		if ( empty( $selectedCategory ) && empty( $filterTimePeriod ) && empty( $filterValuesStr ) ) {
			$usePropertyValuesAttr['checked'] = true;
		}

		// The "input type" field.
		$combo_box_value = wfMsgForContent( 'sd_filter_combobox' );
		$date_range_value = wfMsgForContent( 'sd_filter_daterange' );
		$valuesListAttrs = array( 'value' => '' );
		$comboBoxAttrs = array( 'value' => $combo_box_value );
		$dateRangeAttrs = array( 'value' => $date_range_value );
		$input_type_val = PageSchemas::getValueFromObject( $filter_array, 'InputType' );
		if ( $input_type_val == $combo_box_value ) {
			$comboBoxAttrs['selected'] = true;
		} elseif ( $input_type_val == $date_range_value ) {
			$dateRangeAttrs['selected'] = true;
		} else {
			$valuesListAttrs['selected'] = true;
		}

		$html_text = '<p>' . wfMsg( 'ps-optional-name' ) . ' ';
		$html_text .= Html::input( 'sd_filter_name_num', $filterName, 'text', array( 'size' => 25 ) ) . "</p>\n";
		$html_text .= '<fieldset><legend>' . wfMsg( 'sd-pageschemas-values' ) . '</legend>' . "\n";
		$html_text .= '<p>' . Html::input( 'sd_values_source_num', 'property', 'radio', $usePropertyValuesAttr ) . ' ';
		$html_text .= wfMsg( 'sd_createfilter_usepropertyvalues' ) . "</p>\n";
		$html_text .= "\t<p>\n";
		$html_text .= Html::input( 'sd_values_source_num', 'category', 'radio', $fromCategoryAttrs ) . "\n";
		$html_text .= "\t" . wfMsg( 'sd_createfilter_usecategoryvalues' ) . "\n";
		$categories = SDUtils::getTopLevelCategories();
		$categoriesHTML = "";
		foreach ( $categories as $category ) {
			$categoryOptionAttrs = array();
			$category = str_replace( '_', ' ', $category );
			if ( $category == $selectedCategory) {
				$categoryOptionAttrs['selected'] = true;
			}
			$categoriesHTML .= "\t" . Html::element( 'option', $categoryOptionAttrs, $category ) . "\n";
		}
		$html_text .= "\t" . Html::rawElement( 'select', array( 'id' => 'category_dropdown', 'name' => 'sd_category_name_num' ), "\n" . $categoriesHTML ) . "\n";
		$html_text .= "\t</p>\n";

		$html_text .= "\t<p>\n";
		$html_text .= "\t" . Html::input( 'sd_values_source_num', 'dates', 'radio', $dateRangesAttrs ) . "\n";
		$html_text .= "\t" . wfMsg( 'sd_createfilter_usedatevalues' ) . "\n";
		$dateRangeDropdown = Html::element( 'option', $yearOptionAttrs, wfMsg( 'sd_filter_year' ) ) . "\n";
		$dateRangeDropdown .= Html::element( 'option', $monthOptionAttrs, wfMsg( 'sd_filter_month' ) ) . "\n";
		$html_text .= Html::rawElement( 'select', array( 'name' => 'sd_time_period_num', 'id' => 'time_period_dropdown' ), "\n" . $dateRangeDropdown ) . "\n";
		$html_text .= "</p>\n<p>\n";
		$html_text .= "\t" . Html::input( 'sd_values_source_num', 'manual', 'radio', $manualSourceAttrs ) . "\n";
		$html_text .= "\t" . wfMsg( 'sd_createfilter_entervalues' ) . "\n";
		$html_text .= "\t" . Html::input( 'sd_filter_values_num', $filterValuesStr, 'text', $filterValuesAttrs ) . "\n";
		$html_text .= "\t</p>\n";
		$html_text .= "</fieldset>\n";

		$html_text .= '<p>' . wfMsg( 'sd_createfilter_inputtype' ) . "\n";
		$inputTypeOptionsHTML = "\t" . Html::element( 'option', $valuesListAttrs, wfMsg( 'sd_createfilter_listofvalues' ) ) . "\n";
		$inputTypeOptionsHTML .= "\t" . Html::element( 'option', $comboBoxAttrs, wfMsg( 'sd_filter_combobox' ) ) . "\n";
		$inputTypeOptionsHTML .= "\t" . Html::element( 'option', $dateRangeAttrs, wfMsg( 'sd_filter_daterange' ) ) . "\n";
		$html_text .= Html::rawElement( 'select', array( 'name' => 'sd_input_type_num', 'id' => 'input_type_dropdown' ), $inputTypeOptionsHTML ) . "\n";
		$html_text .= "</p>\n";

		return array( $html_text, $hasExistingValues );
	}
Ejemplo n.º 7
0
 /**
  * Gets an array of all values that the property belonging to this
  * filter has, for pages in the passed-in category.
  */
 function getAllOrValues($category)
 {
     $possible_values = array();
     $property_value = $this->filter->escaped_property;
     $dbr = wfGetDB(DB_SLAVE, 'smw');
     $property_table_name = $dbr->tableName($this->filter->getTableName());
     if ($this->filter->property_type != 'date') {
         $value_field = $this->filter->getValueField();
     } else {
         // Is this necessary?
         $date_field = $this->filter->getDateField();
         if ($this->filter->getTimePeriod() == 'month') {
             $value_field = "YEAR({$date_field}), MONTH({$date_field})";
         } elseif ($this->filter->getTimePeriod() == 'day') {
             $value_field = "YEAR({$date_field}), MONTH({$date_field}), DAYOFMONTH({$date_field})";
         } elseif ($this->filter->getTimePeriod() == 'year') {
             $value_field = "YEAR({$date_field})";
         } else {
             // if ( $this->filter->getTimePeriod() == 'year range' ) {
             $value_field = "YEAR({$date_field})";
         }
     }
     $smwIDs = $dbr->tableName(SDUtils::getIDsTableName());
     $smwCategoryInstances = $dbr->tableName(SDUtils::getCategoryInstancesTableName());
     $cat_ns = NS_CATEGORY;
     $sql = "\tSELECT {$value_field}\n\tFROM {$property_table_name} p\n\tJOIN {$smwIDs} p_ids ON p.p_id = p_ids.smw_id\n";
     if ($this->filter->property_type === 'page') {
         $sql .= "       JOIN {$smwIDs} o_ids ON p.o_id = o_ids.smw_id\n";
     }
     $sql .= "\tJOIN {$smwCategoryInstances} insts ON p.s_id = insts.s_id\n\tJOIN {$smwIDs} cat_ids ON insts.o_id = cat_ids.smw_id\n\tWHERE p_ids.smw_title = '{$property_value}'\n\tAND cat_ids.smw_namespace = {$cat_ns}\n\tAND cat_ids.smw_title = {$dbr->addQuotes($category)}\n\tGROUP BY {$value_field}\n\tORDER BY {$value_field}";
     $res = $dbr->query($sql);
     while ($row = $dbr->fetchRow($res)) {
         if ($this->filter->property_type == 'date' && $this->filter->getTimePeriod() == 'month') {
             $value_string = SDUtils::monthToString($row[1]) . " " . $row[0];
         } else {
             // why is trim() necessary here???
             $value_string = str_replace('_', ' ', trim($row[0]));
         }
         $possible_values[] = $value_string;
     }
     $dbr->freeResult($res);
     return $possible_values;
 }
	function execute( $query ) {
		global $wgOut, $wgRequest;

		$this->setHeaders();

		// Cycle through the query values, setting the appropriate
		// local variables
		$filter_name = $wgRequest->getVal( 'filter_name' );
		$values_source = $wgRequest->getVal( 'values_source' );
		$property_name = $wgRequest->getVal( 'property_name' );
		$category_name = $wgRequest->getVal( 'category_name' );
		$time_period = $wgRequest->getVal( 'time_period' );
		$filter_values = $wgRequest->getVal( 'filter_values' );
		$input_type = $wgRequest->getVal( 'input_type' );
		$required_filter = $wgRequest->getVal( 'required_filter' );
		$filter_label = $wgRequest->getVal( 'filter_label' );

		$save_button_text = wfMsg( 'savearticle' );
		$preview_button_text = wfMsg( 'preview' );
		$filter_name_error_str = '';
		$save_page = $wgRequest->getCheck( 'wpSave' );
		$preview_page = $wgRequest->getCheck( 'wpPreview' );
		if ( $save_page || $preview_page ) {
			# validate filter name
			if ( $filter_name == '' ) {
				$filter_name_error_str = wfMsg( 'sd_blank_error' );
			} else {
				# redirect to wiki interface
				$namespace = SD_NS_FILTER;
				$title = Title::newFromText( $filter_name, $namespace );
				$full_text = self::createFilterText( $property_name, $values_source, $category_name, $time_period, $filter_values, $input_type, $required_filter, $filter_label );
				// HTML-encode
				$full_text = str_replace( '"', '&quot;', $full_text );
				$text = SDUtils::printRedirectForm( $title, $full_text, "", $save_page, $preview_page, false, false, false );
				$wgOut->addHTML( $text );
				return;
			}
		}

		// Set 'title' as hidden field, in case there's no URL niceness
		global $wgContLang;
		$mw_namespace_labels = $wgContLang->getNamespaces();
		$special_namespace = $mw_namespace_labels[NS_SPECIAL];
		$name_label = wfMsg( 'sd_createfilter_name' );
		$property_label = wfMsg( 'sd_createfilter_property' );
		$label_label = wfMsg( 'sd_createfilter_label' );
		$text = <<<END
	<form action="" method="post">
	<input type="hidden" name="title" value="$special_namespace:CreateFilter">
	<p>$name_label <input size="25" name="filter_name" value="">
	<span style="color: red;">$filter_name_error_str</span></p>
	<p>$property_label
	<select id="property_dropdown" name="property_name">

END;
		$all_properties = SDUtils::getSemanticProperties();
		foreach ( $all_properties as $property_name ) {
			$text .= "	<option>$property_name</option>\n";
		}

		$values_from_property_label = wfMsg( 'sd_createfilter_usepropertyvalues' );
		$values_from_category_label = wfMsg( 'sd_createfilter_usecategoryvalues' );
		$date_values_label = wfMsg( 'sd_createfilter_usedatevalues' );
		$enter_values_label = wfMsg( 'sd_createfilter_entervalues' );
		// Need both label and value, in case user's language is
		// different from wiki's
		$year_label = wfMsg( 'sd_filter_year' );
		$year_value = wfMsgForContent( 'sd_filter_year' );
		$month_label = wfMsg( 'sd_filter_month' );
		$month_value = wfMsgForContent( 'sd_filter_month' );
		$input_type_label = wfMsg( 'sd_createfilter_inputtype' );
		$values_list_label = wfMsg( 'sd_createfilter_listofvalues' );
		// same as for time values
		$combo_box_label = wfMsg( 'sd_filter_combobox' );
		$combo_box_value = wfMsgForContent( 'sd_filter_combobox' );
		$date_range_label = wfMsg( 'sd_filter_daterange' );
		$date_range_value = wfMsgForContent( 'sd_filter_daterange' );
		$require_filter_label = wfMsg( 'sd_createfilter_requirefilter' );
		$text .= <<<END
	</select>
	</p>
	<p><input type="radio" name="values_source" checked value="property">
	$values_from_property_label
	</p>
	<p><input type="radio" name="values_source" value="category">
	$values_from_category_label
	<select id="category_dropdown" name="category_name">

END;
		$categories = SDUtils::getCategoriesForBrowsing();
		foreach ( $categories as $category ) {
			$category = str_replace( '_', ' ', $category );
			$text .= "	<option>$category</option>\n";
		}
		$text .= <<<END
	</select>
	</p>
	<p><input type="radio" name="values_source" value="dates">
	$date_values_label
	<select id="time_period_dropdown" name="time_period">
	<option value="$year_value">$year_label</option>
	<option value="$month_value">$month_label</option>
	</select>
	</p>
	<p><input type="radio" name="values_source" value="manual">
	$enter_values_label <input size="40" name="filter_values" value="">
	</p>
	<p>$input_type_label
	<select id="input_type_dropdown" name="input_type">
	<option value="">$values_list_label</option>
	<option value="$combo_box_value">$combo_box_label</option>
	<option value="$date_range_value">$date_range_label</option>
	</select>
	</p>
	<p>$require_filter_label
	<select id="required_filter_dropdown" name="required_filter">
	<option />

END;
		$filters = SDUtils::getFilters();
		foreach ( $filters as $filter ) {
			$filter = str_replace( '_', ' ', $filter );
			$text .= "	<option>$filter</option>\n";
		}
		$text .= <<<END
	</select>
	</p>
	<p>$label_label <input size="25" name="filter_label" value=""></p>
	<div class="editButtons">
	<p>
	<input type="submit" id="wpSave" name="wpSave" value="$save_button_text">
	<input type="submit" id="wpPreview" name="wpPreview" value="$preview_button_text"></p>
	</div>

END;

		$text .= "	</form>\n";

		$wgOut->addHTML( $text );
	}
Ejemplo n.º 9
0
 /**
  * Gets an array of all values that the property belonging to this
  * filter has, for pages in the passed-in category.
  */
 function getAllOrValues($category)
 {
     $possible_values = array();
     $property_value = $this->filter->escaped_property;
     $dbr = wfGetDB(DB_SLAVE, 'smw');
     if ($this->filter->is_relation) {
         $property_table_name = $dbr->tableName('smw_rels2');
         $property_table_nickname = "r";
         $value_field = 'o_ids.smw_title';
     } else {
         $property_table_name = $dbr->tableName('smw_atts2');
         $property_table_nickname = "a";
         $value_field = 'value_xsd';
     }
     if ($this->filter->time_period != null) {
         if ($this->filter->time_period == wfMsg('sd_filter_month')) {
             $value_field = "YEAR(value_xsd), MONTH(value_xsd)";
         } else {
             $value_field = "YEAR(value_xsd)";
         }
     }
     $smw_insts = $dbr->tableName('smw_inst2');
     $smw_ids = $dbr->tableName('smw_ids');
     $cat_ns = NS_CATEGORY;
     $sql = "\tSELECT {$value_field}\n\tFROM {$property_table_name} {$property_table_nickname}\n\tJOIN {$smw_ids} p_ids ON {$property_table_nickname}.p_id = p_ids.smw_id\n";
     if ($this->filter->is_relation) {
         $sql .= "       JOIN {$smw_ids} o_ids ON {$property_table_nickname}.o_id = o_ids.smw_id\n";
     }
     $sql .= "\tJOIN {$smw_insts} insts ON {$property_table_nickname}.s_id = insts.s_id\n\tJOIN {$smw_ids} cat_ids ON insts.o_id = cat_ids.smw_id\n\tWHERE p_ids.smw_title = '{$property_value}'\n\tAND cat_ids.smw_namespace = {$cat_ns}\n\tAND cat_ids.smw_title = '{$category}'\n\tGROUP BY {$value_field}\n\tORDER BY {$value_field}";
     $res = $dbr->query($sql);
     while ($row = $dbr->fetchRow($res)) {
         if ($this->filter->time_period == wfMsg('sd_filter_month')) {
             $value_string = SDUtils::monthToString($row[1]) . " " . $row[0];
         } else {
             // why is trim() necessary here???
             $value_string = str_replace('_', ' ', trim($row[0]));
         }
         $possible_values[] = $value_string;
     }
     $dbr->freeResult($res);
     return $possible_values;
 }
Ejemplo n.º 10
0
    /**
     * Creates a temporary database table, semantic_drilldown_filter_values,
     * that holds every value held by any page in the wiki that matches
     * the property associated with this filter. This table is useful
     * both for speeding up later queries (at least, that's the hope)
     * and for getting the set of 'None' values.
     */
    function createTempTable()
    {
        $dbr = wfGetDB(DB_SLAVE, 'smw');
        $smw_ids = $dbr->tableName(SDUtils::getIDsTableName());
        $valuesTable = $dbr->tableName($this->getTableName());
        $value_field = $this->getValueField();
        $property_field = 'p_id';
        $query_property = $this->escaped_property;
        $sql = <<<END
\tCREATE TEMPORARY TABLE semantic_drilldown_filter_values
\tAS SELECT s_id AS id, {$value_field} AS value
\tFROM {$valuesTable}
\tJOIN {$smw_ids} p_ids ON {$valuesTable}.p_id = p_ids.smw_id

END;
        if ($this->property_type === 'page') {
            $sql .= "\tJOIN {$smw_ids} o_ids ON {$valuesTable}.o_id = o_ids.smw_id\n";
        }
        $sql .= "\tWHERE p_ids.smw_title = '{$query_property}'";
        $dbr->query($sql);
    }
Ejemplo n.º 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);
 }
Ejemplo n.º 12
0
 function addSemanticResultWrapper($dbr, $res, $num, $query, $mainlabel, $printouts)
 {
     $qr = array();
     $count = 0;
     $store = SDUtils::getSMWStore();
     while ($count < $num && ($row = $dbr->fetchObject($res))) {
         $count++;
         $qr[] = new SMWDIWikiPage($row->t, $row->ns, '');
         if (method_exists($store, 'cacheSMWPageID')) {
             $store->cacheSMWPageID($row->id, $row->t, $row->ns, $row->iw, '');
         }
     }
     if ($dbr->fetchObject($res)) {
         $count++;
     }
     $dbr->freeResult($res);
     $printrequest = new SMWPrintRequest(SMWPrintRequest::PRINT_THIS, $mainlabel);
     $main_printout = array();
     $main_printout[$printrequest->getHash()] = $printrequest;
     $printouts = array_merge($main_printout, $printouts);
     return new SMWQueryResult($printouts, $query, $qr, $store, $count > $num);
 }