function execute( $par ) {
		global $wgOut, $wgRequest;

		require_once( "forms.php" );
		require_once( "type.php" );
		require_once( "OmegaWikiAttributes.php" );
		require_once( "ViewInformation.php" );

		initializeOmegaWikiAttributes( new ViewInformation() );
		$wgOut->setPageTitle( wfMsg( 'ow_needs_xlation_title' ) );

		$destinationLanguageId = array_key_exists( 'to-lang', $_GET ) ? $_GET['to-lang']:'';
		$collectionId = array_key_exists( 'collection', $_GET ) ? $_GET['collection'] : '';
		$sourceLanguageId = array_key_exists( 'from-lang', $_GET ) ? $_GET['from-lang'] : '';
                                                                
		$wgOut->addHTML( getOptionPanel(
			array(
				wfMsg( 'ow_needs_xlation_dest_lang' ) => getSuggest( 'to-lang', 'language', array(), $destinationLanguageId, languageIdAsText( $destinationLanguageId ) ),
				wfMsg( 'ow_needs_xlation_source_lang' ) => getSuggest( 'from-lang', 'language', array(), $sourceLanguageId, languageIdAsText( $sourceLanguageId ) ),
				wfMsg( 'ow_Collection_colon' ) => getSuggest( 'collection', 'collection', array(), $collectionId, collectionIdAsText( $collectionId ) )
			)
		) );

		if ( $destinationLanguageId == '' )
			$wgOut->addHTML( '<p>' . wfMsg( 'ow_needs_xlation_no_dest_lang' ) . '</p>' );
		else
			$this->showExpressionsNeedingTranslation( $sourceLanguageId, $destinationLanguageId, $collectionId );
	}
	function execute( $par ) {

		global $wgOut, $wgUser, $wgRequest;

		$wgOut->setPageTitle( 'Add Collection' );

		if ( !$wgUser->isAllowed( 'addcollection' ) ) {
			$wgOut->addHTML( 'You do not have permission to add a collection.' );
			return false;
		}

		$dbr = wfGetDB( DB_MASTER );

		if ( $wgRequest->getText( 'collection' ) ) {
			require_once( 'WikiDataAPI.php' );
			require_once( 'Transaction.php' );

			$dc = $wgRequest->getText( 'dataset' );
			$collectionName = $wgRequest->getText( 'collection' );
			startNewTransaction( $wgUser->getID(), wfGetIP(), 'Add collection ' . $collectionName );
			bootstrapCollection( $collectionName, $wgRequest->getText( 'language' ), $wgRequest->getText( 'type' ), $dc );
			$wgOut->addHTML( wfMsg( 'ow_collection_added', $collectionName ) . "<br />" );
		}
		$datasets = wdGetDatasets();
		$datasetarray[''] = wfMsgSc( "none_selected" );
		foreach ( $datasets as $datasetid => $dataset ) {
			$datasetarray[$datasetid] = $dataset->fetchName();
		}

		$wgOut->addHTML( getOptionPanel(
			array(
				'Collection name:' => getTextBox( 'collection' ),
				'Language of name:' => getSuggest( 'language', 'language' ),
				'Collection type:' => getSelect( 'type', array( '' => 'None', 'RELT' => 'RELT', 'LEVL' => 'LEVL', 'CLAS' => 'CLAS', 'MAPP' => 'MAPP' ) ),
				'Dataset:' => getSelect( 'dataset', $datasetarray )
			),
			'', array( 'create' => wfMsg( 'ow_create' ) )
		) );
	}
	function execute( $par ) {

		global $wgOut, $wgUser, $wgRequest;

		if ( !$wgUser->isAllowed( 'exporttsv' ) ) {
			$wgOut->addHTML( wfMsg( 'ow_exporttsv_not_allowed' ) );
			return false;
		}
		
		$dbr = wfGetDB( DB_SLAVE );
		$dc = wdGetDataSetcontext();
		
		if ( $wgRequest->getText( 'collection' ) && $wgRequest->getText( 'languages' ) ) {
			// render the tsv file

			require_once( 'WikiDataAPI.php' );
			require_once( 'Transaction.php' );
			// get the collection to export. Cut off the 'cid' part that we added
			// to make the keys strings rather than numbers in the array sent to the form.
			$collectionId = substr( $wgRequest->getText( 'collection' ), 3 );
			// get the languages requested, turn into an array, trim for spaces.
			$isoCodes = explode( ',', $wgRequest->getText( 'languages' ) );
			for ( $i = 0; $i < count( $isoCodes ); $i++ ) {
				$isoCodes[$i] = trim( $isoCodes[$i] );
				if ( !getLanguageIdForIso639_3( $isoCodes[$i] ) ) {
					$wgOut->setPageTitle( wfMsg( 'ow_exporttsv_export_failed' ) );
					$wgOut->addHTML( wfMsg( 'ow_impexptsv_unknown_lang', $isoCodes[$i] ) );
					return false;
				}
			}
			
			$wgOut->disable();
			
			$languages = $this->getLanguages( $isoCodes );
			$isoLookup = $this->createIsoLookup( $languages );
			$downloadFileName = $this->createFileName( $isoCodes );
			
			// Force the browser into a download
			header( 'Content-Type: text/tab-separated-values;charset=utf-8' );
			header( 'Content-Disposition: attachment; filename="' . $downloadFileName . '"' ); // attachment

			// separator character used.
			$sc = "\t";
			
			echo( pack( 'CCC', 0xef, 0xbb, 0xbf ) );
			// start the first row: column names
			echo( 'defined meaning id' . $sc . 'defining expression' );
			foreach ( $isoCodes as $isoCode ) {
				echo( $sc . 'definition_' . $isoCode . $sc . 'translations_' . $isoCode );
			}
			echo( "\r\n" );
			
			// get all the defined meanings in the collection
			$query = "SELECT dm.defined_meaning_id, exp.spelling ";
			$query .= "FROM {$dc}_collection_contents col, {$dc}_defined_meaning dm, {$dc}_expression exp ";
			$query .= "WHERE col.collection_id=" . $collectionId . " ";
			$query .= "AND col.member_mid=dm.defined_meaning_id ";
			$query .= "AND dm.expression_id = exp.expression_id ";
			$query .= "AND " . getLatestTransactionRestriction( "col" );
			$query .= "AND " . getLatestTransactionRestriction( "dm" );
			$query .= "AND " . getLatestTransactionRestriction( "exp" );
			$query .= "ORDER BY exp.spelling";
			
			// wfDebug($query."\n");					

			$queryResult = $dbr->query( $query );
			while ( $row = $dbr->fetchRow( $queryResult ) ) {
				$dm_id = $row['defined_meaning_id'];
				// echo the defined meaning id and the defining expression
				echo( $dm_id );
				echo( "\t" . $row['spelling'] );
				
				// First we'll fill an associative array with the definitions and
				// translations. Then we'll use the isoCodes array to put them in the
				// proper order.

				// the associative array holding the definitions and translations
				$data = array();
				
				// ****************************
				// query to get the definitions
				// ****************************
				$qry = 'SELECT txt.text_text, trans.language_id ';
				$qry .= "FROM {$dc}_text txt, {$dc}_translated_content trans, {$dc}_defined_meaning dm ";
				$qry .= 'WHERE txt.text_id = trans.text_id ';
				$qry .= 'AND trans.translated_content_id = dm.meaning_text_tcid ';
				$qry .= "AND dm.defined_meaning_id = $dm_id ";
				$qry .= 'AND trans.language_id IN (';
				for ( $i = 0; $i < count( $languages ); $i++ ) {
					$language = $languages[$i];
					if ( $i > 0 )
						$qry .= ",";
					$qry .= $language['language_id'];
				}
				$qry .= ') AND ' . getLatestTransactionRestriction( 'trans' );
				$qry .= 'AND ' . getLatestTransactionRestriction( 'dm' );
				
				// wfDebug($qry."\n"); // uncomment this if you accept having 1700+ queries in the log

				$definitions = $dbr->query( $qry );
				while ( $row = $dbr->fetchRow( $definitions ) ) {
					// $key becomes something like def_eng
					$key = 'def_' . $isoLookup['id' . $row['language_id']];
					$data[$key] = $row['text_text'];
				}
				$dbr->freeResult( $definitions );
				
				// *****************************
				// query to get the translations
				// *****************************
				$qry = "SELECT exp.spelling, exp.language_id ";
				$qry .= "FROM {$dc}_expression exp ";
				$qry .= "INNER JOIN {$dc}_syntrans trans ON exp.expression_id=trans.expression_id ";
				$qry .= "WHERE trans.defined_meaning_id=$dm_id ";
				$qry .= "AND " . getLatestTransactionRestriction( "exp" );
				$qry .= "AND " . getLatestTransactionRestriction( "trans" );
				
				// wfDebug($qry."\n"); // uncomment this if you accept having 1700+ queries in the log

				$translations = $dbr->query( $qry );
				while ( $row = $dbr->fetchRow( $translations ) ) {
					// qry gets all languages, we filter them here. Saves an order 
					// of magnitude execution time.
					if ( isset( $isoLookup['id' . $row['language_id']] ) ) {
						// $key becomes something like trans_eng
						$key = 'trans_' . $isoLookup['id' . $row['language_id']];
						if ( !isset( $data[$key] ) )
							$data[$key] = $row['spelling'];
						else
							$data[$key] = $data[$key] . '|' . $row['spelling'];
					}
				}
				$dbr->freeResult( $translations );
				
										
				
				// now that we have everything, output the row.
				foreach ( $isoCodes as $isoCode ) {
					// if statements save a bunch of notices in the log about
					// undefined indices.	
					echo( "\t" );
					if ( isset( $data['def_' . $isoCode] ) )
						echo( $this->escapeDelimitedValue( $data['def_' . $isoCode] ) );
					echo( "\t" );
					if ( isset( $data['trans_' . $isoCode] ) )
						echo( $data['trans_' . $isoCode] );
				}
				echo( "\r\n" );
			}
			
			
		}
		else {
			
			// Get the collections
			$colQuery = "SELECT col.collection_id, exp.spelling " .
						"FROM {$dc}_collection col INNER JOIN {$dc}_defined_meaning dm ON col.collection_mid=dm.defined_meaning_id " .
						"INNER JOIN {$dc}_expression exp ON dm.expression_id=exp.expression_id " .
						"WHERE " . getLatestTransactionRestriction( 'col' );
			
			$collections = array();
			$colResults = $dbr->query( $colQuery );
			while ( $row = $dbr->fetchRow( $colResults ) ) {
				$collections['cid' . $row['collection_id']] = $row['spelling'];
			}
								
			// render the page
			$wgOut->setPageTitle( wfMsg( 'ow_exporttsv_title' ) );
			$wgOut->addHTML( wfMsg( 'ow_exporttsv_header' ) );
			
			$wgOut->addHTML( getOptionPanel(
				array(
					wfMsg( 'ow_Collection_colon' ) => getSelect( 'collection', $collections, 'cid376322' ),
					wfMsg( 'ow_exporttsv_languages' ) => getTextBox( 'languages', 'ita, eng, deu, fra, cat' ),
				),
				'', array( 'create' => wfMsg( 'ow_create' ) )
			) );
		}

	}
 function search($searchText)
 {
     global $wgOut, $wgRequest, $wgFilterLanguageId, $wgSearchWithinWordsDefaultValue, $wgSearchWithinExternalIdentifiersDefaultValue, $wgShowSearchWithinExternalIdentifiersOption, $wgShowSearchWithinWordsOption;
     $collectionId = $wgRequest->getInt("collection");
     $languageId = $wgRequest->getInt("language");
     $withinWords = $wgRequest->getBool("within-words");
     $withinExternalIdentifiers = $wgRequest->getBool("within-external-identifiers");
     if (!$withinWords && !$withinExternalIdentifiers) {
         $withinWords = $wgSearchWithinWordsDefaultValue;
         $withinExternalIdentifiers = $wgSearchWithinExternalIdentifiersDefaultValue;
     }
     $languageName = languageIdAsText($languageId);
     $options = array();
     $options[wfMsg('datasearch_search_text')] = getTextBox('search-text', $searchText);
     if ($wgFilterLanguageId == 0) {
         $options[wfMsg('datasearch_language')] = getSuggest('language', "language", array(), $languageId, $languageName);
     } else {
         $languageId = $wgFilterLanguageId;
     }
     $options[wfMsg('ow_Collection_colon')] = getSuggest('collection', 'collection', array(), $collectionId, collectionIdAsText($collectionId));
     if ($wgShowSearchWithinWordsOption) {
         $options[wfMsg('datasearch_within_words')] = getCheckBox('within-words', $withinWords);
     } else {
         $withinWords = $wgSearchWithinWordsDefaultValue;
     }
     if ($wgShowSearchWithinExternalIdentifiersOption) {
         $options[wfMsg('datasearch_within_ext_ids')] = getCheckBox('within-external-identifiers', $withinExternalIdentifiers);
     } else {
         $withinExternalIdentifiers = $wgSearchWithinExternalIdentifiersDefaultValue;
     }
     $wgOut->addHTML(getOptionPanel($options));
     if ($withinWords) {
         if ($languageId != 0 && $languageName != "") {
             $wgOut->addHTML('<h1>' . wfMsg('datasearch_match_words_lang', $languageName, $searchText) . '</h1>');
         } else {
             $wgOut->addHTML('<h1>' . wfMsg('datasearch_match_words', $searchText) . '</h1>');
         }
         $resultCount = $this->searchWordsCount($searchText, $collectionId, $languageId);
         $wgOut->addHTML('<p>' . wfMsgExt('datasearch_showing_only', 'parsemag', 100, $resultCount) . '</p>');
         $wgOut->addHTML($this->searchWords($searchText, $collectionId, $languageId));
     }
     if ($withinExternalIdentifiers) {
         $wgOut->addHTML('<h1>' . wfMsg('datasearch_match_ext_ids', $searchText) . '</i></h1>');
         $wgOut->addHTML('<p>' . wfMsgExt('datasearch_showing_only', 'parsemag', 100) . '</p>');
         $wgOut->addHTML($this->searchExternalIdentifiers($searchText, $collectionId));
     }
 }
function getFilterOptionsPanel( $fromTransactionId, $transactionCount, $userName, $showRollBackOptions ) {
	$countOptions = array();
	
	for ( $i = 1; $i <= 20; $i++ )
		$countOptions[$i] = $i;
	
	return getOptionPanel(
		array(
			wfMsg( 'ow_transaction_from_transaction' ) =>
				getSuggest(
					'from-transaction',
					'transaction',
					array(),
					$fromTransactionId,
					getTransactionLabel( $fromTransactionId ),
					array( 0, 2, 3 )
				),
			wfMsg( 'ow_transaction_count' ) =>
				getSelect( 'transaction-count',
					$countOptions,
					$transactionCount
				),
			wfMsg( 'ow_transaction_user' ) => getTextBox( 'user-name', $userName ),
			wfMsg( 'ow_transaction_show_rollback' ) => getCheckBox( 'show-roll-back-options', $showRollBackOptions )
		)
	);
}
	public function history() {
		global
			$wgOut, $wgTitle, $wgRequest;
			
		$wgOut->enableClientCache( false );

		$title = $wgTitle->getPrefixedText();

		if ( !$this->showClassicPageTitles )
			$title = $this->getTitle();

		$wgOut->setPageTitle( wfMsgSc( "history", $title ) );

		# Plain filter for the lifespan info about each record
		if ( isset( $_GET['show'] ) ) {
			$this->showRecordLifeSpan = isset( $_GET["show-record-life-span"] );
			$this->transaction = (int) $_GET["transaction"];
		}
		else {
			$this->showRecordLifeSpan = true;
			$this->transaction = 0;
		}
		
		# Up to which transaction to view the data
		if ( $this->transaction == 0 )
			$this->queryTransactionInformation = new QueryHistoryTransactionInformation();
		else
			$this->queryTransactionInformation = new QueryAtTransactionInformation( $this->transaction, $this->showRecordLifeSpan );
			
		$transactionId = $wgRequest->getInt( 'transaction' );

		$wgOut->addHTML( getOptionPanel(
			array(
				wfMsg( 'ow_history_transaction' ) => getSuggest( 'transaction', 'transaction', array(), $transactionId, getTransactionLabel( $transactionId ), array( 0, 2, 3 ) ),
				wfMsg( 'ow_history_show_life_span' ) => getCheckBox( 'show-record-life-span', $this->showRecordLifeSpan )
			),
			'history'
		) );

		$viewInformation = new ViewInformation();
		$viewInformation->filterLanguageId = $this->filterLanguageId;
		$viewInformation->showRecordLifeSpan = $this->showRecordLifeSpan;
		$viewInformation->queryTransactionInformation = $this->queryTransactionInformation;
		$viewInformation->setPropertyToColumnFilters( $this->propertyToColumnFilters );
		
		$this->viewInformation = $viewInformation;

		initializeOmegaWikiAttributes( $this->viewInformation );
		initializeObjectAttributeEditors( $viewInformation );
	}
	protected function ui() {

		global $wgOut, $wgRequest, $wgLang, $wgDefinedMeaning;
		$lang = $wgLang->getCode();
		require_once( "forms.php" );
		$wgOut->addHTML( wfMsgSc( "conceptmapping_uitext" ) );
		$sets = wdGetDataSets();
		$options = array();
		$html = "";
		$mappings = array();
		$rq = array();

		foreach ( $sets as $key => $setObject ) {
			$set = $setObject->getPrefix();
			$rq[$set] = $wgRequest->getText( "set_" . $set );
			$rq[$set] = trim( $rq[$set] );
			$rq[$set] = (int)$rq[$set];
			if ( $rq[$set] ) {
				$dmModel = new DefinedMeaningModel( $rq[$set], null, $setObject );
				$defaultSel = $dmModel->getSyntransByLanguageCode( $lang );
				$options[$setObject->fetchName()] = getSuggest( "set_$set", $wgDefinedMeaning, array(), $rq[$set], $defaultSel, array( 0 ), $setObject );
			} else {
				$options[$setObject->fetchName()] = getSuggest( "set_$set", $wgDefinedMeaning, array(), null, null, array( 0 ), $setObject );
			}

		}
		$wgOut->addHTML( getOptionPanel( $options ) );
		$noerror = $wgRequest->getText( "suppressWarnings" );

		foreach ( $sets as $key => $setObject ) {
			$set = $setObject->getPrefix();
			if ( !$rq[$set] ) {
				$wgOut->addHTML( ' <span style="color:yellow">[' . wfMsgSc( "dm_not_present" ) . ']</span>' );
			} else  {
				$dmModel = new DefinedMeaningModel( $rq[$set], null, $setObject );
				$dmModel->checkExistence();
				if ( $dmModel->exists() ) {
					$id = $dmModel->getId();
					$title = $dmModel->getTitleText();
				} else {
					$id = null;
					$title = null;
				}
				if ( !$noerror ) {
					$wgOut->addHTML( "$key: " . $rq[$set] . " ($title)" );
				}
				if ( $id != null ) {
					$mappings[$key] = $id;
					if ( !$noerror ) {
						$wgOut->addHTML( ' <span style="color:green">[' . wfMsgSc( "dm_OK" ) . ']</span>' );
					}
				} else {
					if ( !$noerror ) {
						$wgOut->addHTML( ' <span style="color:red">[' . wfMsgSc( "dm_not_found" ) . ']</span>' );
					}
				}
			}
			$wgOut->addHTML( "<br />\n" );
		}
		if ( sizeOf( $mappings ) > 1 ) {
			createConceptMapping( $mappings );
			$wgOut->addHTML( wfMsgSc( "mapping_successful" ) );
		} else {
			$wgOut->addHTML( wfMsgSc( "mapping_unsuccessful" ) );
		}

	}