public function __construct( Attribute $attribute, $propertyCaption, $valueCaption, ViewInformation $viewInformation, $levelName, AttributeIDFilter $attributeIDFilter ) {
		parent::__construct( new RecordUnorderedListEditor( $attribute, 5 ) );
		
		$this->levelName = $levelName;
		$this->attributeIDFilter = $attributeIDFilter;
		$this->showPropertyColumn = !$attributeIDFilter->leavesOnlyOneOption();
		
		$this->recordSetTableEditor = new RecordSetTableEditor(
			$attribute,
			new SimplePermissionController( false ),
			new ShowEditFieldChecker( true ),
			new AllowAddController( false ),
			false,
			false,
			null
		);
		
		$this->propertyAttribute = new Attribute( "property", $propertyCaption, "short-text" );
		$this->valueAttribute = new Attribute( "value", $valueCaption, "short-text" );
		
		foreach ( $viewInformation->getPropertyToColumnFilters() as $propertyToColumnFilter )
			$this->recordSetTableEditor->addEditor( new DummyViewer( $propertyToColumnFilter->getAttribute() ) );

		$o = OmegaWikiAttributes::getInstance();
			
		$this->recordSetTableEditor->addEditor( new DummyViewer( $o->objectAttributes ) );
		addTableMetadataEditors( $this->recordSetTableEditor, $viewInformation );
	}
Ejemplo n.º 2
0
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 );
}
Ejemplo n.º 3
0
	public function convert( $record ) {
		$dc = wdGetDataSetContext();


		$o = OmegaWikiAttributes::getInstance();
		
		$dbr = wfGetDB( DB_SLAVE );
		$expressionId = $record->getAttributeValue( $this->attribute );
		$queryResult = $dbr->query( "SELECT language_id, spelling from {$dc}_expression WHERE expression_id=$expressionId" .
									" AND " . getLatestTransactionRestriction( "{$dc}_expression" ) );
		$expression = $dbr->fetchObject( $queryResult );

		$expressionRecord = new ArrayRecord( new Structure( $o->language, $o->spelling ) );
		$expressionRecord->language = $expression->language_id;
		$expressionRecord->spelling = $expression->spelling;

		$result = new ArrayRecord( $this->structure );
		$result->expression = $expressionRecord;
	
		return $result;
	}
	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 );
	}
Ejemplo n.º 5
0
	public function setVersioningAttributes( Record $record, $row ) {

		$o = OmegaWikiAttributes::getInstance();
			
		if ( $this->addAttributes )
			$record->recordLifeSpan = getRecordLifeSpanTuple( $row['add_transaction_id'], $row['remove_transaction_id'] );
	}
	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 ) );
	}
	protected function getIdStack( $definedMeaningId ) {

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

		$definedMeaningIdStructure = new Structure( $o->definedMeaningId );
		$definedMeaningIdRecord = new ArrayRecord( $definedMeaningIdStructure, $definedMeaningIdStructure );
		$definedMeaningIdRecord->definedMeaningId = $definedMeaningId;
		
		$idStack = new IdStack( $wgDefinedMeaning );
		$idStack->pushKey( $definedMeaningIdRecord );
		
		return $idStack;
	}
Ejemplo n.º 8
0
 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;
 }
Ejemplo n.º 9
0
	/**
	 * Look up the correct attribute using omegaWikiAttributes
	 * and set its value
 	 */
	public function __set( $attributeName, $value ) {
		$o = OmegaWikiAttributes::getInstance();
		return $this->setAttributeValue( $o->$attributeName, $value );
	}
function rollBackCollectionMemberships( $idStack, $collectionMemberships ) {

	$o = OmegaWikiAttributes::getInstance();
	
	$collectionMembershipsKeyStructure = $collectionMemberships->getKey();
	
	for ( $i = 0; $i < $collectionMemberships->getRecordCount(); $i++ ) {
		$collectionMembershipRecord = $collectionMemberships->getRecord( $i );

		$collectionId = $collectionMembershipRecord->collectionId;
		$collectionMemberId = $collectionMembershipRecord->collectionMemberId;
		$isLatest = $collectionMembershipRecord->isLatest;

		if ( $isLatest ) {
			$idStack->pushKey( simpleRecord( $collectionMembershipsKeyStructure, array( $collectionId, $collectionMemberId ) ) );
			
			rollBackCollectionMembership(
				getRollBackAction( $idStack, $o->rollBack ),
				$collectionId,
				$collectionMemberId,
				$collectionMembershipRecord->sourceIdentifier,
				$collectionMembershipRecord->operation
			);
				
			$idStack->popKey();
		}
	}
}
function getDefiningExpressionRecord( $definedMeaningId ) {

		$o = OmegaWikiAttributes::getInstance();

		$definingExpression = definingExpressionRow( $definedMeaningId );
		$definingExpressionRecord = new ArrayRecord( $o->definedMeaningCompleteDefiningExpression->type );
		$definingExpressionRecord->expressionId = $definingExpression[0];
		$definingExpressionRecord->definedMeaningDefiningExpression = $definingExpression[1];
		$definingExpressionRecord->language = $definingExpression[2];
		return $definingExpressionRecord;
}
/**
 *
 * This file models the structure of the OmegaWiki database in a
 * database-independent fashion. To do so, it follows a simplified
 * relational model, consisting of Attribute objects which are hierarchically
 * grouped together using Structure objects. See Attribute.php for details.
 *
 * The actual data is stored in Records, grouped together as RecordSets.
 * See Record.php and RecordSet.php for details.
 *
 * OmegawikiAttributes2.php was running out of date already, so
 * merging here.
 *
 * TODO:
 * - Records and RecordSets are currently capable of storing most (not all)
 * data, but can't actually commit them to the database again. To achieve
 * proper separation of architectural layers, the Records should learn
 * to talk directly with the DB layer.
 # - This is not a pure singleton, because it relies on the existence of
 #   of viewInformation, and a message cache. We now defer lookups in these
 #   to as late as possible, to make sure these items are actually initialized.
 */
function initializeOmegaWikiAttributes( ViewInformation $viewInformation ) {
	$init_and_discard_this = OmegaWikiAttributes::getInstance( $viewInformation );
}