/**
	 * Construct a new DefinedMeaningModel for a particular DM.
	 * You need to call loadRecord() to load the actual data.
	 *
	 * @param Integer         the database ID of the DM 
	 * @param ViewInformation optional
	 * @param DataSet	  where to look for the DM by default
         */
	public function __construct( $definedMeaningId, $viewInformation = null, DataSet $dc = null ) {

		if ( !$definedMeaningId ) throw new Exception( "DM needs at least a DMID!" );
		$this->setId( $definedMeaningId );
		if ( is_null( $viewInformation ) ) {
			$viewInformation = new ViewInformation();
			$viewInformation->queryTransactionInformation = new QueryLatestTransactionInformation();
		}
		$this->viewInformation = $viewInformation;
		if ( is_null( $dc ) ) {
			$dc = wdGetDataSetContext();
		}
		$this->dataset = $dc;
	}
	/**
	 * Purpose: Add custom tabs
	 *
	 * When editing in read-only data-set, if you have the copy permission, you can
	 * make a copy into the designated community dataset and edit the data there.
	 * This is accessible through an 'edit copy' tab which is added below.
	 *
	 * @param $skin Skin as passed by MW
	 * @param $tabs as passed by MW
	 */
	public static function onSkinTemplateTabs( $skin, $content_actions ) {
		global $wgUser, $wgCommunity_dc, $wdShowEditCopy, $wdHandlerClasses;

		$title = $skin->getTitle();

		if ( !self::isWikidataNs( $title ) ) {
			return true;
		}

		$ns = $title->getNamespace();
		$editChanged = false;
		$dc = wdGetDataSetContext();

		if ( $wdHandlerClasses[ $ns ] == 'DefinedMeaning' ) {

			# Hackishly determine which DMID we're on by looking at the page title component
			$tt = $title->getText();
			$rpos1 = strrpos( $tt, '(' );
			$rpos2 = strrpos( $tt, ')' );
			$dmid = ( $rpos1 && $rpos2 ) ? substr( $tt, $rpos1 + 1, $rpos2 - $rpos1 - 1 ) : 0;
			if ( $dmid ) {
				$copyTitle = SpecialPage::getTitleFor( 'Copy' );
				if ( $dc != $wgCommunity_dc && $wdShowEditCopy ) {
					$editChanged = true;
					$content_actions['edit'] = array(
						'class' => false,
						'text' => wfMsg( 'ow_nstab_edit_copy' ),
						'href' => $copyTitle->getLocalUrl( "action=copy&dmid=$dmid&dc1=$dc&dc2=$wgCommunity_dc" )
					);
				}
				$content_actions['nstab-definedmeaning'] = array(
					 'class' => 'selected',
					 'text' => wfMsg( 'ow_nstab_definedmeaning' ),
					 'href' => $title->getLocalUrl( "dataset=$dc" )
				);
			}
		}

		// Prevent move tab being shown.
		unset( $content_actions['move'] );

		// Add context dataset (old hooks 'GetEditLinkTrail' and 'GetHistoryLinkTrail')
		if ( !$editChanged && $content_actions['edit'] != null ) {
			$content_actions['edit']['href'] = wfAppendQuery( $content_actions['edit']['href'], "dataset=$dc" );
		}

		$content_actions['history']['href'] = wfAppendQuery( $content_actions['history']['href'], "dataset=$dc" );

		return true;
	}
Пример #3
0
function spellingAsURL( $spelling, $lang = 0 ) {
	global $wdDefaultViewDataSet;

	$title = Title::makeTitle( NS_EXPRESSION, $spelling );
	$query = array() ;

	$dc = wdGetDataSetContext();
	if ( $dc != $wdDefaultViewDataSet ) {
		$query['dataset'] = $dc ;
	}
	if ( $lang != 0 ) {
		$query['explang'] = $lang ;
	}

	return $title->getLocalURL( $query ) ;
}
Пример #4
0
	function searchText( $text ) {
		$dc = wdGetDataSetContext();
		$dbr = wfGetDB( DB_SLAVE );
		
		$sql = "SELECT INSTR(LCASE({$dc}_expression.spelling), LCASE(" . $dbr->addQuotes( "$text" ) . ")) as position, {$dc}_syntrans.defined_meaning_id AS defined_meaning_id, {$dc}_expression.spelling AS spelling, {$dc}_expression.language_id AS language_id " .
				"FROM {$dc}_expression, {$dc}_syntrans " .
	            "WHERE {$dc}_expression.expression_id={$dc}_syntrans.expression_id AND {$dc}_syntrans.identical_meaning=1 " .
	            " AND " . getLatestTransactionRestriction( "{$dc}_syntrans" ) .
	            " AND " . getLatestTransactionRestriction( "{$dc}_expression" ) .
				" AND spelling LIKE " . $dbr->addQuotes( "%$text%" ) .
				" ORDER BY position ASC, {$dc}_expression.spelling ASC limit 100";
		
		$queryResult = $dbr->query( $sql );
		list( $recordSet, $editor ) = getSearchResultAsRecordSet( $queryResult );
//		return $sql;
		return $editor->view( new IdStack( "expression" ), $recordSet );
	}
Пример #5
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;
	}
	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 ) );
	}
	/** 
	 * Creates sidebar HTML for indicating concepts which exist
	 * in multiple datasets, and providing a link to add new
	 * mappings.
	 *
	 * Potential refactor candidate!
	*/
	protected function getConceptPanel() {
		global $wgTitle, $wgUser, $wdShowCopyPanel;
		$active = true; # wrong place, but hey
		$dmId = $this->getDefinedMeaningId();
		$dc = wdGetDataSetContext();
		$ow_conceptpanel = wfMsgSc( "concept_panel" );

		$html = "<div class=\"dataset-panel\">"; ;
		$html .= "<table border=\"0\"><tr><th class=\"dataset-panel-heading\">$ow_conceptpanel</th></tr>";
		$sk = $wgUser->getSkin();
		$meanings = getDefinedMeaningDataAssociatedByConcept( $dmId, $dc );
		if ( $meanings ) {
			foreach ( $meanings as $dm ) {
				$dataset = $dm->getDataset();
				$active = ( $dataset->getPrefix() == $dc->getPrefix() );
				$name = $dataset->fetchName();
				$prefix = $dataset->getPrefix();
	
				$class = $active ? 'dataset-panel-active' : 'dataset-panel-inactive';
				$slot = $active ? "$name" : $sk->makeLinkObj( $dm->getTitleObject(), $name, "dataset=$prefix" );
				$html .= "<tr><td class=\"$class\">$slot</td></tr>";
			}
		} else {
				$name = $dc->fetchName();
				$html .= "<tr><td class=\"dataset-panel-active\">$name</td></tr>";
		}
		$cmtitle = Title::newFromText( "Special:ConceptMapping" );
		$titleText = $wgTitle->getPrefixedURL();
		$cmlink = $sk->makeLinkObj( $cmtitle, "<small>" . wfMsgSc( "add_concept_link" ) . "</small>", "set_$dc=$dmId&suppressWarnings=true" );
		$html .= "<tr><td>$cmlink</td></tr>\n";
		if ( $wdShowCopyPanel ) {
			$html .= "<tr><td>" . $this->getCopyPanel() . "<td><tr>";
		}
		$html .= "</table>\n";
		$html .= "</div>\n";
		return $html;
	}
Пример #8
0
	public function __construct( $definedMeaningId ) {
		$dc = wdGetDataSetContext();
		$dbr = wfGetDB( DB_SLAVE );

		global
			$wgDefaultClassMids, $dataSet;

		$queryResult = $dbr->query(
			SelectLatestDistinct(
				array(
					$dataSet->classAttributes->attributeMid,
					$dataSet->classAttributes->attributeType,
					$dataSet->bootstrappedDefinedMeanings->name
				),
				array( $dataSet->classAttributes, $dataSet->bootstrappedDefinedMeanings ),
				array(
					equals( $dataSet->classAttributes->levelMid, $dataSet->bootstrappedDefinedMeanings->definedMeaningId ),
					sqlOr(
						in( $dataSet->classAttributes->classMid,
							selectLatest(
								array( $dataSet->classMemberships->classMid ),
								array( $dataSet->classMemberships ),
								array( equals( $dataSet->classMemberships->classMemberMid, $definedMeaningId ) )
							)
						),
						inArray( $dataSet->classAttributes->classMid, $wgDefaultClassMids )
					)
				)
			)
		);

		$this->classAttributes = array();
		
		while ( $row = $dbr->fetchRow( $queryResult ) ) {
			$classAttribute = new ClassAttribute();
			$classAttribute->attributeId = $row[0];
			$classAttribute->type = $row[1];
			$classAttribute->levelName = $row[2];
			
			$this->classAttributes[] = $classAttribute;
		}
	}
Пример #9
0
 function searchExternalIdentifiers($text, $collectionId)
 {
     $dc = wdGetDataSetContext();
     $dbr = wfGetDB(DB_SLAVE);
     $sql = "SELECT " . $this->getPositionSelectColumn($text, "{$dc}_collection_contents.internal_member_id") . " {$dc}_collection_contents.member_mid AS member_mid, {$dc}_collection_contents.internal_member_id AS external_identifier, {$dc}_collection.collection_mid AS collection_mid " . "FROM {$dc}_collection_contents, {$dc}_collection ";
     $sql .= "WHERE {$dc}_collection.collection_id={$dc}_collection_contents.collection_id " . " AND " . getLatestTransactionRestriction("{$dc}_collection") . " AND " . getLatestTransactionRestriction("{$dc}_collection_contents") . $this->getSpellingRestriction($text, "{$dc}_collection_contents.internal_member_id");
     if ($collectionId > 0) {
         $sql .= " AND {$dc}_collection.collection_id={$collectionId} ";
     }
     $sql .= " ORDER BY " . $this->getSpellingOrderBy($text) . "{$dc}_collection_contents.internal_member_id ASC limit 100";
     $queryResult = $dbr->query($sql);
     $recordSet = $this->getExternalIdentifiersSearchResultAsRecordSet($queryResult);
     $editor = $this->getExternalIdentifiersSearchResultEditor();
     return $editor->view(new IdStack("external-identifiers"), $recordSet);
 }
Пример #10
0
/**
 *
 * Returns HTML for an autocompleted form field.
 *
 * @param String unique identifier for this form field
 * @param String type of query to run
 * @param Integer Default value
 * @param String How default value will be shown
 * @param Array Override column titles
 * @param DataSet Override standard dataset
 *
*/
function getSuggest( $name, $query, $parameters = array(), $value = 0, $label = '', $displayLabelColumns = array( 0 ), DataSet $dc = null ) {
	global
		$wgScriptPath, $wgLang;

	if ( is_null( $dc ) ) {
		$dc = wdGetDataSetContext();
	}
	if ( $label == "" )
		$label = '&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;';
	
	$result =
		'<span class="suggest">' .
			'<input type="hidden" id="' . $name . '-suggest-query" value="' . $query . '"/>' .
			'<input type="hidden" id="' . $name . '-suggest-offset" value="0"/>' .
			'<input type="hidden" id="' . $name . '-suggest-label-columns" value="' . implode( ', ', $displayLabelColumns ) . '"/>' .
			'<input type="hidden" id="' . $name . '" name="' . $name . '" value="' . $value . '"/>' .
			'<input type="hidden" id="' . $name . '-suggest-dataset" value="' . $dc . '"/>';

	foreach ( $parameters as $parameter => $parameterValue )
		$result .=
			'<input type="hidden" id="' . $name . '-suggest-parameter-' . $parameter . '" name="' . $parameter . '" value="' . $parameterValue . '"/>';

	$result .=
			'<a id="' . $name . '-suggest-link" class="suggest-link" onclick="suggestLinkClicked(event, this);" title="' . wfMsgSc( "SuggestHint" ) . '">' . $label . '</a>' .
		'</span>';
	
	if ( $wgLang->isRTL() )
		$result .=
        '<div class="suggest-drop-down" style="position: relative"><div id="' . $name . '-suggest-div" style="position: absolute; right: 0px; top: 0px; border: 1px solid #000000; display: none; background-color: white; padding: 4px">' .
        	'<div><table>' .
        		'<tr>' .
        			'<td><input type="text" id="' . $name . '-suggest-text" autocomplete="off" onkeyup="suggestTextChanged(this)" style="width: 300px"></input></td>' .
        			'<td><a id="' . $name . '-suggest-clear" href="javascript:void(0)" onclick="suggestClearClicked(event, this)">' . wfMsg( 'ow_suggest_clear' ) . '</a></td>' .
        			'<td style="white-space: nowrap"><a id="' . $name . '-suggest-previous" href="javascript:void(0)" class="suggest-previous" onclick="suggestPreviousClicked(event, this)"><img src="' . $wgScriptPath . '/extensions/Wikidata/Images/ArrowRight.png" alt="' . wfMsg( 'ow_suggest_previous' ) . '"/> ' . wfMsg( 'ow_suggest_previous' ) . '</a></td>' .
        			'<td style="white-space: nowrap"><a id="' . $name . '-suggest-next" href="javascript:void(0)" class="suggest-next" onclick="suggestNextClicked(event, this)">' . wfMsg( 'ow_suggest_next' ) . ' <img src="' . $wgScriptPath . '/extensions/Wikidata/Images/ArrowLeft.png" alt="' . wfMsg( 'ow_suggest_next' ) . '"/></a></td>' .
        			'<td><a id="' . $name . '-suggest-close" href="javascript:void(0)" onclick="suggestCloseClicked(event, this)">[X]</a></td>' .
        		'</tr>' .
        	'</table></div>' .
        	'<div><table id="' . $name . '-suggest-table"><tr><td></td></tr></table></div>' .
        '</div></div>';
	else
		$result .=
        '<div class="suggest-drop-down" style="position: relative"><div id="' . $name . '-suggest-div" style="position: absolute; left: 0px; top: 0px; border: 1px solid #000000; display: none; background-color: white; padding: 4px">' .
        	'<div><table>' .
        		'<tr>' .
        			'<td><input type="text" id="' . $name . '-suggest-text" autocomplete="off" onkeyup="suggestTextChanged(this)" style="width: 300px"></input></td>' .
        			'<td><a id="' . $name . '-suggest-clear" href="javascript:void(0)" onclick="suggestClearClicked(event, this)">' . wfMsg( 'ow_suggest_clear' ) . '</a></td>' .
        			'<td style="white-space: nowrap"><a id="' . $name . '-suggest-previous" href="javascript:void(0)" class="suggest-previous" onclick="suggestPreviousClicked(event, this)"><img src="' . $wgScriptPath . '/extensions/Wikidata/Images/ArrowLeft.png" alt="' . wfMsg( 'ow_suggest_previous' ) . '"/> ' . wfMsg( 'ow_suggest_previous' ) . '</a></td>' .
        			'<td style="white-space: nowrap"><a id="' . $name . '-suggest-next" href="javascript:void(0)" class="suggest-next" onclick="suggestNextClicked(event, this)">' . wfMsg( 'ow_suggest_next' ) . ' <img src="' . $wgScriptPath . '/extensions/Wikidata/Images/ArrowRight.png" alt="' . wfMsg( 'ow_suggest_next' ) . '"/></a></td>' .
        			'<td><a id="' . $name . '-suggest-close" href="javascript:void(0)" onclick="suggestCloseClicked(event, this)">[X]</a></td>' .
        		'</tr>' .
        	'</table></div>' .
        	'<div><table id="' . $name . '-suggest-table"><tr><td></td></tr></table></div>' .
        '</div></div>';
	
	return $result;
}
function getSynonymAndTranslationRecordSet( $definedMeaningId, ViewInformation $viewInformation ) {
	global $dataSet;

	$o = OmegaWikiAttributes::getInstance();
	$dc = wdGetDataSetContext();

	$restrictions = array( "defined_meaning_id=$definedMeaningId" );
	if ( $viewInformation->filterLanguageId != 0 )
		$restrictions[] =
			"expression_id IN (" .
				"SELECT expressions.expression_id" .
				" FROM {$dc}_expression AS expressions" .
				" WHERE expressions.expression_id=expression_id" .
				" AND language_id=" . $viewInformation->filterLanguageId .
				" AND expressions.remove_transaction_id IS NULL " .
			")";
	
	$recordSet = queryRecordSet(
		$o->synonymsTranslationsStructure->getStructureType(),
		$viewInformation->queryTransactionInformation,
		$o->syntransId,
		new TableColumnsToAttributesMapping(
			new TableColumnsToAttribute( array( 'syntrans_sid' ), $o->syntransId ),
			new TableColumnsToAttribute( array( 'expression_id' ), $o->expression ),
			new TableColumnsToAttribute( array( 'identical_meaning' ), $o->identicalMeaning )
		),
		$dataSet->syntrans,
		$restrictions
	);
	
	if ( $viewInformation->filterLanguageId == 0 )
		expandExpressionReferencesInRecordSet( $recordSet, array( $o->expression ) );
	else
		expandExpressionSpellingsInRecordSet( $recordSet, array( $o->expression ) );

	expandObjectAttributesAttribute( $recordSet, $o->objectAttributes, $o->syntransId, $viewInformation );
	return $recordSet;
}
Пример #12
0
	/**
	 * @return true if permission to edit, false if not
	**/
	public function edit() {
		global $wgOut, $wgRequest, $wgUser;

		$wgOut->enableClientCache( false );

		if ( $wgUser->isBlockedFrom( $this->getTitle(), false ) ) {
			$wgOut->blockedPage() ;
			return false;                                                 
		}

		$dc = wdGetDataSetContext();
		if ( !$wgUser->isAllowed( 'editwikidata-' . $dc ) ) {
			$wgOut->addWikiText( wfMsgSc( "noedit", $dc->fetchName() ) );
			$wgOut->setPageTitle( wfMsgSc( "noedit_title" ) );
			return false;
		}

		if ( $wgRequest->getText( 'save' ) != '' )
			$this->saveWithinTransaction();

		$viewInformation = new ViewInformation();
		$viewInformation->filterLanguageId = $this->filterLanguageId;
		$viewInformation->showRecordLifeSpan = false;
		$viewInformation->queryTransactionInformation = new QueryLatestTransactionInformation();
		$viewInformation->viewOrEdit = "edit";
		$viewInformation->setPropertyToColumnFilters( $this->propertyToColumnFilters );
		
		$this->viewInformation = $viewInformation;
		
		initializeOmegaWikiAttributes( $this->viewInformation );
		initializeObjectAttributeEditors( $this->viewInformation );

		return true;
	}
Пример #13
0
	function execute( $par ) {
		require_once( 'languages.php' );
		require_once( 'Transaction.php' );
		global $wgOut, $wgLang, $wgRequest, $wgOptionAttribute;

		$wgOut->disable();

		$dc = wdGetDataSetContext();
		$optionAttribute = $wgRequest->getVal( $wgOptionAttribute );
		$attributeObject = $wgRequest->getVal( 'attribute-object' );
		$lang_code = $wgLang->getCode();

		$dbr = wfGetDB( DB_SLAVE );
		$sql = 'SELECT language_id' .
				" FROM {$dc}_syntrans" .
				" JOIN {$dc}_expression ON {$dc}_expression.expression_id = {$dc}_syntrans.expression_id" .
				" WHERE {$dc}_syntrans.syntrans_sid = " . $attributeObject .
				' AND ' . getLatestTransactionRestriction( "{$dc}_syntrans" ) .
				' AND ' . getLatestTransactionRestriction( "{$dc}_expression" );
		$lang_res = $dbr->query( $sql );
		$objectLanguage = $dbr->fetchObject( $lang_res )->language_id;
		// language is not always defined, for example for a DM Option Attribute
		if ( ! $objectLanguage ) $objectLanguage = 0 ;

		$sql = "SELECT {$dc}_option_attribute_options.option_id,{$dc}_option_attribute_options.option_mid" .
				" FROM {$dc}_option_attribute_options" .
				" WHERE {$dc}_option_attribute_options.attribute_id = " . $optionAttribute .
				" AND ({$dc}_option_attribute_options.language_id = " . $objectLanguage .
				" OR {$dc}_option_attribute_options.language_id = 0)" .
				' AND ' . getLatestTransactionRestriction( "{$dc}_option_attribute_options" ) ;
		$options_res = $dbr->query( $sql );

		$optionsString = '';
		$optionsArray = array() ;
		while ( $options_row = $dbr->fetchObject( $options_res ) ) {
			/* Use a simpler query if the user's language is English. */
			if ( $lang_code == 'en' || !( $lang_id = getLanguageIdForCode( $lang_code ) ) ) {
				$sql = "SELECT {$dc}_expression.spelling" .
						" FROM {$dc}_syntrans" .
						" JOIN {$dc}_expression ON {$dc}_expression.expression_id = {$dc}_syntrans.expression_id" .
						" WHERE {$dc}_syntrans.defined_meaning_id = " . $options_row->option_mid .
						" AND {$dc}_expression.language_id = " . getLanguageIdForCode( 'en' ) .
						' AND ' . getLatestTransactionRestriction( "{$dc}_syntrans" ) .
						' AND ' . getLatestTransactionRestriction( "{$dc}_expression" );
			}
			/* Fall back on English in cases where an option name is not present in the
				user's preferred language. */
			else {
				/* XXX: This setup is really hacked together. It NEEDS to be improved. */
				$sql = "SELECT {$dc}_expression.spelling" .
						" FROM {$dc}_syntrans" .
						" JOIN {$dc}_expression ON {$dc}_expression.expression_id = {$dc}_syntrans.expression_id" .
						" WHERE {$dc}_syntrans.defined_meaning_id = " . $options_row->option_mid .
						" AND {$dc}_expression.language_id = " . $lang_id .
						' AND ' . getLatestTransactionRestriction( "{$dc}_syntrans" ) .
						' AND ' . getLatestTransactionRestriction( "{$dc}_expression" );
				$res = $dbr->query( $sql );
				if ( !$dbr->fetchObject( $res )->spelling )
					$sql = "SELECT {$dc}_expression.spelling" .
							" FROM {$dc}_syntrans" .
							" JOIN {$dc}_expression ON {$dc}_expression.expression_id = {$dc}_syntrans.expression_id" .
							" WHERE {$dc}_syntrans.defined_meaning_id = " . $options_row->option_mid .
							" AND {$dc}_expression.language_id = " . getLanguageIdForCode( 'en' ) .
							' AND ' . getLatestTransactionRestriction( "{$dc}_syntrans" ) .
							' AND ' . getLatestTransactionRestriction( "{$dc}_expression" );
			}

			$spelling_res = $dbr->query( $sql );
			$spelling_row = $dbr->fetchObject( $spelling_res );

			$optionsArray[$options_row->option_id] = $spelling_row->spelling ;
		}

		asort( $optionsArray ) ;
		foreach ($optionsArray as $option_id => $spelling ) {
			if ( $optionsString != '' ) $optionsString .= "\n";
			$optionsString .= $option_id . ';' . $spelling ;
		}

	echo $optionsString;
	}
Пример #14
0
function getTransactionRecord( $transactionId ) {

	$o = OmegaWikiAttributes::getInstance();
	
	$dc = wdGetDataSetContext();
	$result = new ArrayRecord( $o->transactionStructure );
	$result->transactionId = $transactionId;
	
	if ( $transactionId > 0 ) {
		$dbr = wfGetDB( DB_SLAVE );
		$queryResult = $dbr->query( "SELECT user_id, user_ip, timestamp, comment FROM {$dc}_transactions WHERE transaction_id=$transactionId" );
		
		if ( $transaction = $dbr->fetchObject( $queryResult ) ) {
			$result->user = getUserLabel( $transaction->user_id, $transaction->user_ip );
			if ( $result->user == null ) $result->user = "******" . $transaction->user_id . " not found" ;
			$result->timestamp = $transaction->timestamp;
			$result->summary = $transaction->comment;
		}
	}
	else {
		if ( $transactionId != null )
			$result->user = "******";
		else
			$result->user = "";
				
		$result->timestamp = "";
		$result->summary = "";
	}

	return $result;
}
function bootStrappedDefinedMeanings( $dc ) {
	global
		$definedMeaningMeaningName, $definitionMeaningName,
		$relationMeaningName, $synTransMeaningName,
		$annotationMeaningName, $wgCommandLineMode;

	$wgCommandLineMode = true;

	$dbr = wfGetDB( DB_MASTER );
	
	$dbr->query( "DROP TABLE IF EXISTS `{$dc}_bootstrapped_defined_meanings`;" );

	$dbr->query( "CREATE TABLE `{$dc}_bootstrapped_defined_meanings` (
			`name` VARCHAR(255) NOT NULL ,
			`defined_meaning_id` INT NOT NULL);" );


	$userId = getUserId( 'Root' );
	if ( $userId == - 1 ) {
		echo "root user undefined\n";
		return;
	}

	setUser( $userId );

	setDefaultDC( $dc );
	
	$rdc = wdGetDataSetContext();

	startNewTransaction( $userId, 0, "Script bootstrap class attribute meanings", $dc );

	$languageId = 85;
	$collectionId = bootstrapCollection( "Class attribute levels", $languageId, "LEVL" );
	$meanings = array();
	$meanings[$definedMeaningMeaningName] = bootstrapDefinedMeaning( $definedMeaningMeaningName, $languageId, "The combination of an expression and definition in one language defining a concept." );
	$meanings[$definitionMeaningName] = bootstrapDefinedMeaning( $definitionMeaningName, $languageId, "A paraphrase describing a concept." );
	$meanings[$synTransMeaningName] = bootstrapDefinedMeaning( $synTransMeaningName, $languageId, "A translation or a synonym that is equal or near equal to the concept defined by the defined meaning." );
	$meanings[$relationMeaningName] = bootstrapDefinedMeaning( $relationMeaningName, $languageId, "The association of two defined meanings through a specific relation type." );
	$meanings[$annotationMeaningName] = bootstrapDefinedMeaning( $annotationMeaningName, $languageId, "Characteristic information of a concept." );

	foreach ( $meanings as $internalName => $meaningId ) {
		addDefinedMeaningToCollection( $meaningId, $collectionId, $internalName );
	
		$dbr->query( "INSERT INTO `{$dc}_bootstrapped_defined_meanings` (name, defined_meaning_id) " .
				"VALUES (" . $dbr->addQuotes( $internalName ) . ", " . $meaningId . ")" );
	}

	$timestamp = wfTimestampNow();
	$dbr->query( "INSERT INTO {$dc}_script_log (time, script_name, comment) " .
		    "VALUES (" . $timestamp . "," . $dbr->addQuotes( '23 - Bootstrap class attribute meanings.php' ) .  "," . $dbr->addQuotes( 'create bootstrap class attribute meanings' ) . ")" );
	
}
	private function getSQLForCollection( $language ) {
		$dc = wdGetDataSetContext();
		$dbr = wfGetDB( DB_SLAVE );
		$userlang = ' ( SELECT language_id FROM language WHERE wikimedia_key = ' . $dbr->addQuotes( $language ) . ' LIMIT 1 ) ';

		$sql = "SELECT collection_id, spelling " .
			" FROM {$dc}_expression exp, {$dc}_collection col, {$dc}_syntrans synt, {$dc}_defined_meaning dm " .
			" WHERE exp.expression_id=synt.expression_id " .
			" AND synt.defined_meaning_id=col.collection_mid " .
			" AND dm.defined_meaning_id = synt.defined_meaning_id " ;
//			" AND synt.identical_meaning=1" .

		// fallback is English
		$sql .= " AND ( exp.language_id=$userlang " ;
		if ( $userlang != 85 ) {
			$sql .= ' OR ( ' .
				' language_id=85 ' .
				" AND NOT EXISTS ( SELECT * FROM {$dc}_syntrans synt2, {$dc}_expression exp2 WHERE synt2.defined_meaning_id = synt.defined_meaning_id AND exp2.expression_id = synt2.expression_id AND exp2.language_id=$userlang AND synt2.remove_transaction_id IS NULL LIMIT 1 ) ) " ;
		}
		$sql .= ' ) ' ;

		$sql .= " AND " . getLatestTransactionRestriction( "synt" ) .
			" AND " . getLatestTransactionRestriction( "exp" ) .
			" AND " . getLatestTransactionRestriction( "col" ) .
			" AND " . getLatestTransactionRestriction( "dm" );

		return $sql;
	}
function getTranslatedContentFromHistory( $translatedContentId, $languageId, $addTransactionId ) {

	$dc = wdGetDataSetContext();
	$dbr = wfGetDB( DB_SLAVE );
	$queryResult = $dbr->query(
		"SELECT text_text " .
		" FROM {$dc}_translated_content, {$dc}_text " .
		" WHERE {$dc}_translated_content.translated_content_id=$translatedContentId " .
		" AND {$dc}_translated_content.text_id={$dc}_text.text_id " .
		" AND {$dc}_translated_content.add_transaction_id=$addTransactionId" );
		
	$row = $dbr->fetchObject( $queryResult );
	
	return $row->text_text;
}
		$prefixedIdentifier = $this->dataSetPrefix . "_" . $identifier;
		
		if ( isset( $this->tableLookupMap[$prefixedIdentifier] ) ) {
			return $this->tableLookupMap[$prefixedIdentifier];
		} else {
			return null;
		}
	}
}

global
	$dataSet;

require_once( "Wikidata.php" );

$dataSet = new WikiDataSet( wdGetDataSetContext() );

function genericSelect( $selectCommand, array $expressions, array $tables, array $restrictions ) {
	$result = $selectCommand . " " . $expressions[0]->toExpression();
	
	for ( $i = 1; $i < count( $expressions ); $i++ ) {
		$result .= ", " . $expressions[$i]->toExpression();
	}
	if ( count( $tables ) > 0 ) {
		$result .= " FROM " . $tables[0]->getIdentifier();
		
		for ( $i = 1; $i < count( $tables ); $i++ ) {
			$result .= ", " . $tables[$i]->getIdentifier();
		}
	}
	
Пример #19
0
	protected function resolveSyntrans( $objectId ) {
		$dc = wdGetDataSetContext();
		$dbr = wfGetDB( DB_SLAVE );
		$queryResult = $dbr->query(
			"SELECT spelling, defined_meaning_id" .
			" FROM {$dc}_syntrans, {$dc}_expression" .
			" WHERE syntrans_sid=$objectId" .
			" AND {$dc}_syntrans.expression_id={$dc}_expression.expression_id"
		);

		if ( $syntrans = $dbr->fetchObject( $queryResult ) )
			return
				 definedMeaningAsLink( $syntrans->defined_meaning_id ) . " > " . spellingAsLink( $syntrans->spelling );
		else
			return "Syntrans " . $objectId;
	}