$tsz += $att[$i]['att_size']; $sz = $Fichier->file_size_format($att[$i]['att_size'], 2); if (getAttDisplayMode($att[$i]['att_type'], 'A') == ATT_DSP_LINK) { // This mime-type can't be displayed inline echo '<input type="hidden" name="inline_att[' . $id . ']" value="0" />'; $inline_box = '--'; } else { $inline_box = getListBox("inline_att[{$id}]", $inline_list, $att[$i]["inline"]); } if ($Mmod) { $visu = "<td align=\"center\">" . getCheckBox("visible_att[]", $id, $att[$i]["visible"] == 1 ? $id : -1, "") . "</td>"; $visible_list .= $id . ','; } $att_table .= ' <tr> <td>' . getCheckBox("del_att[]", $id, 0, "") . '</td> <td>' . $att[$i]['att_name'] . '</td> <td>' . $att[$i]['att_type'] . '</td> <td align="center">' . $sz . '</td> <td align="center">' . $inline_box . '</td> ' . $visu . ' </tr>'; } // $total_sz = $Fichier->Pretty_Size($tsz); $total_sz = $Fichier->file_size_format($tsz, 1); echo '<input type="hidden" name="visible_list" value="' . $visible_list . '">'; $att_inline_button = '<input type="button" class="btn btn-outline-primary btn-sm" value="' . upload_translate("Adapter") . '" onclick="InlineType(this.form);" />'; if ($Mmod) { $visu_button = '<input type="button" class="btn btn-outline-primary btn-sm" value="' . upload_translate("Adapter") . '" onclick="visibleFile(this.form);" />'; } if ($ibid = theme_image("upload/arrow.gif")) {
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 ) ) ); }
function getInputFieldForType( $name, $type, $value ) { global $wgDefinedMeaning; switch( $type ) { case "language": return getLanguageSelect( $name ); case "spelling": return getTextBox( $name, $value ); case "boolean": return getCheckBox( $name, $value ); case "$wgDefinedMeaning": case "defining-expression": return getSuggest( $name, $wgDefinedMeaning ); case "relation-type": return getSuggest( $name, "relation-type" ); case "attribute": return getSuggest( $name, "attribute" ); case "collection": return getSuggest( $name, "collection" ); case "short-text": return getTextBox( $name, $value ); case "text": return getTextArea( $name, $value ); } }
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 ); }
function execute( $par ) { global $wgOut, $wgUser, $wgRequest; $wgOut->setPageTitle( wfMsg( 'ow_importtsv_title1' ) ); if ( !$wgUser->isAllowed( 'importtsv' ) ) { $wgOut->addHTML( wfMsg( 'ow_importtsv_not_allowed' ) ); return false; } $dbr = wfGetDB( DB_MASTER ); $dc = wdGetDataSetcontext(); $wgOut->setPageTitle( wfMsg( 'ow_importtsv_importing' ) ); setlocale( LC_ALL, 'en_US.UTF-8' ); if ( $wgRequest->getFileName( 'tsvfile' ) ) { // ***************** // process tsv // ***************** require_once( 'WikiDataAPI.php' ); require_once( 'Transaction.php' ); $testRun = $wgRequest->getCheck( 'testrun' ); // lets do some tests first. Is this even a tsv file? // It is _very_ important that the file is utf-8 encoded. // also, this is a good time to determine the max line length for the // fgetcsv function. $file = fopen( $wgRequest->getFileTempname( 'tsvfile' ), 'r' ); $myLine = ""; $maxLineLength = 0; while ( $myLine = fgets( $file ) ) { if ( !preg_match( '/./u', $myLine ) ) { $wgOut->setPageTitle( wfMsg( 'ow_importtsv_import_failed' ) ); $wgOut->addHTML( wfMsg( 'ow_importtsv_not_utf8' ) ); return false; } $maxLineLength = max( $maxLineLength, strlen( $myLine ) + 2 ); } // start from the beginning again. Check if the column names are valid rewind( $file ); $columns = fgetcsv( $file, $maxLineLength, "\t" ); // somehow testing for $columns[0] fails sometimes. Byte Order Mark? if ( !$columns || count( $columns ) <= 2 || $columns[1] != "defining expression" ) { $wgOut->setPageTitle( wfMsg( 'ow_importtsv_import_failed' ) ); $wgOut->addHTML( wfMsg( 'ow_importtsv_not_tsv' ) ); return false; } for ( $i = 2; $i < count( $columns ); $i++ ) { $columnName = $columns[$i]; $baseName = substr( $columnName, 0, strrpos( $columnName, '_' ) ); if ( $baseName == "definition" || $baseName == "translations" ) { $langCode = substr( $columnName, strrpos( $columnName, '_' ) + 1 ); if ( !getLanguageIdForIso639_3( $langCode ) ) { $wgOut->setPageTitle( wfMsg( 'ow_importtsv_import_failed' ) ); $wgOut->addHTML( wfMsg( 'ow_impexptsv_unknown_lang', $langCode ) ); return false; } } else { // column name does not start with definition or translations. $wgOut->setPageTitle( wfMsg( 'ow_importtsv_import_failed' ) ); $wgOut->addHTML( wfMsg( 'ow_importtsv_bad_columns', $columnName ) ); return false; } } // // All tests passed. lets get started // if ( $testRun ) { $wgOut->setPageTitle( wfMsg( 'ow_importtsv_test_run_title' ) ); } else { $wgOut->setPageTitle( wfMsg( 'ow_importtsv_importing' ) ); } startNewTransaction( $wgUser->getID(), wfGetIP(), "Bulk import via Special:ImportTSV", $dc ); # this string shouldn't be localized because it will be stored in the db $row = ""; $line = 1; // actually 2, 1 was the header, but increased at the start of while $definitions = 0; // definitions added $translations = 0; // translations added while ( $row = fgetcsv( $file, $maxLineLength, "\t" ) ) { $line++; $dmid = $row[0]; $exp = $row[1]; // find the defined meaning record $qry = "SELECT dm.meaning_text_tcid, exp.spelling "; $qry .= "FROM {$dc}_defined_meaning dm INNER JOIN {$dc}_expression exp ON dm.expression_id=exp.expression_id "; $qry .= "WHERE dm.defined_meaning_id=$dmid "; $qry .= "AND " . getLatestTransactionRestriction( 'dm' ); $qry .= "AND " . getLatestTransactionRestriction( 'exp' ); $dmResult = $dbr->query( $qry ); $dmRecord = null; // perfomr some tests if ( $dmRecord = $dbr->fetchRow( $dmResult ) ) { if ( $dmRecord['spelling'] != $exp ) { $wgOut->addHTML( "Skipped line $line: defined meaning id $dmid does not match defining expression. Should be '{$dmRecord['spelling']}', found '$exp'.<br />" ); continue; } } else { $wgOut->addHTML( "Skipped line $line: unknown defined meaning id $dmid. The id may have been altered in the imported file, or the defined meaning or defining expression was removed from the database.<br />" ); continue; } // all is well. Get the translated content id $tcid = $dmRecord['meaning_text_tcid']; for ( $columnIndex = 2; $columnIndex < count( $columns ); $columnIndex++ ) { // Google docs removes empty columns at the end of a row, // so if column index is higher than the length of the row, we can break // and move on to the next defined meaning. if ( columnIndex >= count( $row ) ) { break; } $columnValue = $row[$columnIndex]; if ( !$columnValue ) { continue; } $columnName = $columns[$columnIndex]; $langCode = substr( $columnName, strrpos( $columnName, '_' ) + 1 ); $langId = getLanguageIdForIso639_3( $langCode ); if ( strpos( $columnName, 'definition' ) === 0 ) { if ( !translatedTextExists( $tcid, $langId ) ) { if ( $testRun ) { $wgOut->addHTML( "Would add definition for $exp ($dmid) in $langCode: $columnValue.<br />" ); } else { addTranslatedText( $tcid, $langId, $columnValue ); $wgOut->addHTML( "Added definition for $exp ($dmid) in $langCode: $columnValue.<br />" ); $definitions++; } } } if ( strpos( $columnName, 'translation' ) === 0 ) { $spellings = explode( '|', $columnValue ); foreach ( $spellings as $spelling ) { $spelling = trim( $spelling ); $expression = findExpression( $spelling, $langId ); if ( !$expression ) { // expression does not exist if ( $testRun ) { $wgOut->addHTML( "Would add translation for $exp ($dmid) in $langCode: $spelling. Would also add new page.<br />" ); } else { $expression = createExpression( $spelling, $langId ); $expression->bindToDefinedMeaning( $dmid, 1 ); // not nescesary to check page exists, createPage does that. $title = getPageTitle( $spelling ); createPage( 16, $title ); $wgOut->addHTML( "Added translation for $exp ($dmid) in $langCode: $spelling. Also added new page.<br />" ); $translations++; } } else { // expression exists, but may not be bound to this defined meaning. if ( !$expression->isBoundToDefinedMeaning( $dmid ) ) { if ( $testRun ) { $wgOut->addHTML( "Would add translation for $exp ($dmid) in $langCode: $spelling.<br />" ); } else { $expression->bindToDefinedMeaning( $dmid, 1 ); $wgOut->addHTML( "Added translation for $exp ($dmid) in $langCode: $spelling.<br />" ); $translations++; } } } } } } } if ( $definitions == 0 && $translations == 0 ) { $wgOut->addHTML( "<br />" ); if ( $testRun ) { $wgOut->addHTML( wfMsg( 'ow_importtsv_nothing_added_test' ) ); } else { $wgOut->addHTML( wfMsg( 'ow_importtsv_nothing_added' ) ); } $wgOut->addHTML( "<br />" ); } else { $wgOut->addHTML( "<br />" . wfMsgExt( 'ow_importtsv_results', 'parsemag', $definitions, $translations ) . "<br />" ); } } else { // render the page $wgOut->setPageTitle( wfMsg( 'ow_importtsv_title2' ) ); $wgOut->addHTML( wfMsg( 'ow_importtsv_header' ) ); $wgOut->addHTML( getOptionPanelForFileUpload( array( wfMsg( 'ow_importtsv_file' ) => getFileField( 'tsvfile' ), wfMsg( 'ow_importtsv_test_run' ) => getCheckBox( 'testrun', true ) ) ) ); } }
public function add( IdStack $idPath ) { if ( $this->isAddField ) return getCheckBox( $this->addId( $idPath->getId() ), $this->defaultValue ); else return ""; }