function getSearchResultAsRecordSet( $queryResult ) {

	$o = OmegaWikiAttributes::getInstance();
	global
		$definedMeaningReferenceType,
		$wgDefinedMeaning;

	$dbr = wfGetDB( DB_SLAVE );
	$spellingAttribute = new Attribute( "found-word", "Found word", "short-text" );
	$languageAttribute = new Attribute( "language", "Language", "language" );
	
	$expressionStructure = new Structure( $spellingAttribute, $languageAttribute );
	$expressionAttribute = new Attribute( "expression", "Expression", $expressionStructure );
	
	$definedMeaningAttribute = new Attribute( $wgDefinedMeaning, "Defined meaning", $definedMeaningReferenceType );
	$definitionAttribute = new Attribute( "definition", "Definition", "definition" );
	
	$meaningStructure = new Structure( $definedMeaningAttribute, $definitionAttribute );
	$meaningAttribute = new Attribute( "meaning", "Meaning", $meaningStructure );

	$recordSet = new ArrayRecordSet( new Structure( $o->definedMeaningId, $expressionAttribute, $meaningAttribute ), new Structure( $o->definedMeaningId ) );
	
	while ( $row = $dbr->fetchObject( $queryResult ) ) {
		$expressionRecord = new ArrayRecord( $expressionStructure );
		$expressionRecord->setAttributeValue( $spellingAttribute, $row->spelling );
		$expressionRecord->setAttributeValue( $languageAttribute, $row->language_id );
		
		$meaningRecord = new ArrayRecord( $meaningStructure );
		$meaningRecord->setAttributeValue( $definedMeaningAttribute, getDefinedMeaningReferenceRecord( $row->defined_meaning_id ) );
		$meaningRecord->setAttributeValue( $definitionAttribute, getDefinedMeaningDefinition( $row->defined_meaning_id ) );

		$recordSet->addRecord( array( $row->defined_meaning_id, $expressionRecord, $meaningRecord ) );
	}

	$expressionEditor = new RecordTableCellEditor( $expressionAttribute );
	$expressionEditor->addEditor( new SpellingEditor( $spellingAttribute, new SimplePermissionController( false ), false ) );
	$expressionEditor->addEditor( new LanguageEditor( $languageAttribute, new SimplePermissionController( false ), false ) );

	$meaningEditor = new RecordTableCellEditor( $meaningAttribute );
	$meaningEditor->addEditor( new DefinedMeaningReferenceEditor( $definedMeaningAttribute, new SimplePermissionController( false ), false ) );
	$meaningEditor->addEditor( new TextEditor( $definitionAttribute, new SimplePermissionController( false ), false, true, 75 ) );

	$editor = createTableViewer( null );
	$editor->addEditor( $expressionEditor );
	$editor->addEditor( $meaningEditor );

	return array( $recordSet, $editor );
}
	private function getTransactionAsRecordSet( $queryResult ) {

		$o = OmegaWikiAttributes::getInstance();

		$dbr = wfGetDB( DB_SLAVE );

		$userAttribute = new Attribute( "user", wfMsg( 'ow_User' ), "short-text" );
		$timestampAttribute = new Attribute( "timestamp", wfMsg( 'ow_Time' ), "timestamp" );
		$summaryAttribute = new Attribute( "summary", wfMsg( 'ow_transaction_summary' ), "short-text" );

		$recordSet = new ArrayRecordSet( new Structure( $o->id, $userAttribute, $timestampAttribute, $summaryAttribute ), new Structure( $o->id ) );

		while ( $row = $dbr->fetchObject( $queryResult ) )
			$recordSet->addRecord( array( $row->transaction_id, getUserLabel( $row->user_id, $row->user_ip ), $row->time, $row->comment ) );

		$editor = createSuggestionsTableViewer( null );
		$editor->addEditor( createShortTextViewer( $timestampAttribute ) );
		$editor->addEditor( createShortTextViewer( $o->id ) );
		$editor->addEditor( createShortTextViewer( $userAttribute ) );
		$editor->addEditor( createShortTextViewer( $summaryAttribute ) );

		return array( $recordSet, $editor );
	}
	protected function showExpressionsNeedingTranslation( $sourceLanguageId, $destinationLanguageId, $collectionId ) {

		$o = OmegaWikiAttributes::getInstance();

		$dc = wdGetDataSetContext();
		require_once( "Transaction.php" );
		require_once( "OmegaWikiAttributes.php" );
		require_once( "RecordSet.php" );
		require_once( "Editor.php" );
		require_once( "WikiDataAPI.php" );

		$dbr = wfGetDB( DB_SLAVE );

		$sqlcount = 'SELECT COUNT(*)' .
			" FROM ({$dc}_syntrans source_syntrans, {$dc}_expression source_expression)";

		if ( $collectionId != '' )
			$sqlcount .= " JOIN {$dc}_collection_contents ON source_syntrans.defined_meaning_id = member_mid";

		$sqlcount .= ' WHERE source_syntrans.expression_id = source_expression.expression_id';

		if ( $sourceLanguageId != '' )
			$sqlcount .= ' AND source_expression.language_id = ' . $sourceLanguageId;
		if ( $collectionId != '' )
			$sqlcount .= " AND {$dc}_collection_contents.collection_id = " . $collectionId .
				' AND ' . getLatestTransactionRestriction( "{$dc}_collection_contents" );

		$sqlcount .= ' AND NOT EXISTS (' .
			" SELECT * FROM {$dc}_syntrans destination_syntrans, {$dc}_expression destination_expression" .
			' WHERE destination_syntrans.expression_id = destination_expression.expression_id AND destination_expression.language_id = ' . $destinationLanguageId .
			' AND source_syntrans.defined_meaning_id = destination_syntrans.defined_meaning_id' .
			' AND ' . getLatestTransactionRestriction( 'destination_syntrans' ) .
			' AND ' . getLatestTransactionRestriction( 'destination_expression' ) .
			')' .
			' AND ' . getLatestTransactionRestriction( 'source_syntrans' ) .
			' AND ' . getLatestTransactionRestriction( 'source_expression' ) ;

		$queryResultCount_r = mysql_query( $sqlcount );
		$queryResultCount_a = mysql_fetch_row( $queryResultCount_r );
		$queryResultCount = $queryResultCount_a[0];
		$nbshown = min ( 100, $queryResultCount ) ;


		$sql = 'SELECT source_expression.expression_id AS source_expression_id, source_expression.language_id AS source_language_id, source_expression.spelling AS source_spelling, source_syntrans.defined_meaning_id AS source_defined_meaning_id' .
			" FROM ({$dc}_syntrans source_syntrans, {$dc}_expression source_expression)";

		if ( $collectionId != '' )
			$sql .= " JOIN {$dc}_collection_contents ON source_syntrans.defined_meaning_id = member_mid";

		$sql .= ' WHERE source_syntrans.expression_id = source_expression.expression_id';

		if ( $sourceLanguageId != '' )
			$sql .= ' AND source_expression.language_id = ' . $sourceLanguageId;
		if ( $collectionId != '' )
			$sql .= " AND {$dc}_collection_contents.collection_id = " . $collectionId .
				' AND ' . getLatestTransactionRestriction( "{$dc}_collection_contents" );

		$sql .= ' AND NOT EXISTS (' .
			" SELECT * FROM {$dc}_syntrans destination_syntrans, {$dc}_expression destination_expression" .
			' WHERE destination_syntrans.expression_id = destination_expression.expression_id AND destination_expression.language_id = ' . $destinationLanguageId .
			' AND source_syntrans.defined_meaning_id = destination_syntrans.defined_meaning_id' .
			' AND ' . getLatestTransactionRestriction( 'destination_syntrans' ) .
			' AND ' . getLatestTransactionRestriction( 'destination_expression' ) .
			')' .
			' AND ' . getLatestTransactionRestriction( 'source_syntrans' ) .
			' AND ' . getLatestTransactionRestriction( 'source_expression' ) ;

		if ( $queryResultCount > 100 ) {
			$startnumber = rand ( 0 , $queryResultCount - 100 ) ;
			$sql .= " LIMIT $startnumber,100";
		} else {
			$sql .= ' LIMIT 100';
		}

		$queryResult = $dbr->query( $sql );


		$definitionAttribute = new Attribute( "definition", wfMsg( "ow_Definition" ), "definition" );

		$recordSet = new ArrayRecordSet( new Structure( $o->definedMeaningId, $o->expressionId, $o->expression, $definitionAttribute ), new Structure( $o->definedMeaningId, $o->expressionId ) );

		while ( $row = $dbr->fetchObject( $queryResult ) ) {
			$expressionRecord = new ArrayRecord( $o->expressionStructure );
			$expressionRecord->language = $row->source_language_id;
			$spellingAsLink = definedMeaningReferenceAsLink( $row->source_defined_meaning_id, $row->source_spelling, $row->source_spelling );
			$expressionRecord->spelling = $spellingAsLink ;

			$definition = getDefinedMeaningDefinitionForLanguage( $row->source_defined_meaning_id, $row->source_language_id ) ;
			if ( $definition == "" ) {
				$definition = getDefinedMeaningDefinition( $row->source_defined_meaning_id ) ;
			}

			$recordSet->addRecord( array( $row->source_defined_meaning_id, $row->source_expression_id, $expressionRecord, $definition ) );
		}

		$expressionEditor = new RecordTableCellEditor( $o->expression );
		$expressionEditor->addEditor( new LanguageEditor( $o->language, new SimplePermissionController( false ), false ) );
		$expressionEditor->addEditor( new ShortTextNoEscapeEditor( $o->spelling, new SimplePermissionController( false ), false ) );

		$editor = new RecordSetTableEditor( null, new SimplePermissionController( false ), new ShowEditFieldChecker( true ), new AllowAddController( false ), false, false, null );
		$editor->addEditor( $expressionEditor );
		$editor->addEditor( new TextEditor( $definitionAttribute, new SimplePermissionController( false ), false, true, 75 ) );

		global $wgOut;

		$wgOut->addHTML( "Showing $nbshown out of $queryResultCount" ) ;
		$wgOut->addHTML( $editor->view( new IdStack( "expression" ), $recordSet ) );
	}
 function getWordsSearchResultAsRecordSet($queryResult)
 {
     $o = OmegaWikiAttributes::getInstance();
     $dbr = wfGetDB(DB_SLAVE);
     $recordSet = new ArrayRecordSet(new Structure($o->definedMeaningId, $this->expressionAttribute, $this->meaningAttribute), new Structure($o->definedMeaningId));
     while ($row = $dbr->fetchObject($queryResult)) {
         $expressionRecord = new ArrayRecord($this->expressionStructure);
         $expressionRecord->setAttributeValue($this->spellingAttribute, $row->spelling);
         $expressionRecord->setAttributeValue($this->languageAttribute, $row->language_id);
         $meaningRecord = new ArrayRecord($this->meaningStructure);
         $meaningRecord->setAttributeValue($this->definedMeaningAttribute, getDefinedMeaningReferenceRecord($row->defined_meaning_id));
         $meaningRecord->setAttributeValue($this->definitionAttribute, getDefinedMeaningDefinition($row->defined_meaning_id));
         $recordSet->addRecord(array($row->defined_meaning_id, $expressionRecord, $meaningRecord));
     }
     return $recordSet;
 }
function getExpressionsRecordSet( $spelling, ViewInformation $viewInformation, $dc = null ) {
	$dc = wdGetDataSetContext( $dc );
	$o = OmegaWikiAttributes::getInstance();

	$dbr = wfGetDB( DB_SLAVE );
	$sql =
		"SELECT expression_id, language_id " .
		" FROM {$dc}_expression" .
		" WHERE spelling=BINARY " . $dbr->addQuotes( $spelling ) .
		" AND {$dc}_expression.remove_transaction_id IS NULL " ;

	// needed because expression.remove_transaction_id is not updated automatically
	$sql .= " AND EXISTS (" .
		"SELECT * " .
		" FROM {$dc}_syntrans " .
		" WHERE {$dc}_syntrans.expression_id={$dc}_expression.expression_id" .
		" AND {$dc}_syntrans.remove_transaction_id IS NULL " .
		")";


	if ( $viewInformation->expressionLanguageId != 0 ) {
		// display the expression in that language
		$sql .= " AND language_id=" . $viewInformation->expressionLanguageId ;
	} else {
		// no language is given: display in any language that comes first
		$sql .= " LIMIT 1";
	}

	$queryResult = $dbr->query( $sql );
	
	$result = new ArrayRecordSet( $o->expressionsStructure, new Structure( "expression-id", $o->expressionId ) );
	$languageStructure = new Structure( "language", $o->language );

	foreach ( $queryResult as $expression ) {
		$expressionRecord = new ArrayRecord( $languageStructure );
		$expressionRecord->language = $expression->language_id;

		$result->addRecord( array(
			$expression->expression_id,
			$expressionRecord,
			getExpressionMeaningsRecord( $expression->expression_id, $viewInformation )
		) );
	}

	return $result;
}
	public function getAddValues( IdStack $idPath ) {
		$addStructure = $this->getAddStructure();

		if ( count( $addStructure->getAttributes() ) > 0 ) {
			$relations = array();

			$value_array_array = array(array());

			foreach ( $this->getEditors() as $editor ) {
				if ( $attribute = $editor->getAddAttribute() ) {
					$idPath->pushAttribute( $attribute );

					$addValues = $editor->getAddValues( $idPath );
					$i = 0;
					foreach ( $addValues as $value ) {
						$value_array_array[$i][] = $value ;
						$i++;
					}

					$idPath->popAttribute();
				}
			}

			foreach ( $value_array_array as $value_array ) {
				$relation = new ArrayRecordSet( $addStructure, $addStructure ) ;  // TODO Determine real key
				$relation->addRecord( $value_array );
				$relations[] = $relation ;
			}

			return $relations ;
		}
		else
			return null;
	}