function getLangNames( $code ) { $dbr = wfGetDB( DB_SLAVE ); $names = array(); $sql = getSQLForLanguageNames( $code ); $lang_res = $dbr->query( $sql ); while ( $lang_row = $dbr->fetchObject( $lang_res ) ) $names[$lang_row->row_id] = $lang_row->language_name; return $names; }
function execute( $par ) { global $wgOut, $wgLang, $wgRequest, $IP, $wgDefinedMeaning, $wgDefinedMeaningAttributes, $wgOptionAttribute, $wgLinkAttribute; $wgOut->disable(); require_once( "$IP/includes/Setup.php" ); require_once( "Attribute.php" ); require_once( "WikiDataBootstrappedMeanings.php" ); require_once( "RecordSet.php" ); require_once( "Editor.php" ); require_once( "HTMLtable.php" ); require_once( "Transaction.php" ); require_once( "OmegaWikiEditors.php" ); require_once( "Utilities.php" ); require_once( "Wikidata.php" ); require_once( "WikiDataTables.php" ); require_once( "WikiDataGlobals.php" ); $o = OmegaWikiAttributes::getInstance(); $dc = wdGetDataSetContext(); $search = ltrim( $wgRequest->getVal( 'search-text' ) ); $prefix = $wgRequest->getVal( 'prefix' ); $query = $wgRequest->getVal( 'query' ); $definedMeaningId = $wgRequest->getVal( 'definedMeaningId' ); $offset = $wgRequest->getVal( 'offset' ); $attributesLevel = $wgRequest->getVal( 'attributesLevel' ); $annotationAttributeId = $wgRequest->getVal( 'annotationAttributeId' ); $syntransId = $wgRequest->getVal( 'syntransId' ); $langCode = $wgLang->getCode(); $sql = ''; $dbr = wfGetDB( DB_SLAVE ); $rowText = 'spelling'; switch ( $query ) { case 'relation-type': $sqlActual = $this->getSQLForCollectionOfType( 'RELT', $langCode ); $sqlFallback = $this->getSQLForCollectionOfType( 'RELT', 'en' ); $sql = $this->constructSQLWithFallback( $sqlActual, $sqlFallback, array( "member_mid", "spelling", "collection_mid" ) ); break; case 'class': // constructSQLWithFallback is a bit broken in this case, showing several time the same lines // so : not using it. The English fall back has been included in the SQL query $sql = $this->getSQLForClasses( $langCode ); break; case $wgDefinedMeaningAttributes: $sql = $this->getSQLToSelectPossibleAttributes( $definedMeaningId, $attributesLevel, $syntransId, $annotationAttributeId, 'DM' ); break; case 'text-attribute': $sql = $this->getSQLToSelectPossibleAttributes( $definedMeaningId, $attributesLevel, $syntransId, $annotationAttributeId, 'TEXT' ); break; case 'translated-text-attribute': $sql = $this->getSQLToSelectPossibleAttributes( $definedMeaningId, $attributesLevel, $syntransId, $annotationAttributeId, 'TRNS' ); break; case $wgLinkAttribute: $sql = $this->getSQLToSelectPossibleAttributes( $definedMeaningId, $attributesLevel, $syntransId, $annotationAttributeId, 'URL' ); break; case $wgOptionAttribute: $sql = $this->getSQLToSelectPossibleAttributes( $definedMeaningId, $attributesLevel, $syntransId, $annotationAttributeId, 'OPTN' ); break; case 'language': require_once( 'languages.php' ); $sql = getSQLForLanguageNames( $langCode ); $rowText = 'language_name'; break; case $wgDefinedMeaning: $sql = "SELECT {$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" ); break; case 'class-attributes-level': $sql = $this->getSQLForLevels( $langCode ); break; case 'collection': $sql = $this->getSQLForCollection( $langCode ); break; case 'transaction': $sql = "SELECT transaction_id, user_id, user_ip, " . " CONCAT(SUBSTRING(timestamp, 1, 4), '-', SUBSTRING(timestamp, 5, 2), '-', SUBSTRING(timestamp, 7, 2), ' '," . " SUBSTRING(timestamp, 9, 2), ':', SUBSTRING(timestamp, 11, 2), ':', SUBSTRING(timestamp, 13, 2)) AS time, comment" . " FROM {$dc}_transactions WHERE 1"; $rowText = "CONCAT(SUBSTRING(timestamp, 1, 4), '-', SUBSTRING(timestamp, 5, 2), '-', SUBSTRING(timestamp, 7, 2), ' '," . " SUBSTRING(timestamp, 9, 2), ':', SUBSTRING(timestamp, 11, 2), ':', SUBSTRING(timestamp, 13, 2))"; break; } if ( $search != '' ) { if ( $query == 'transaction' ) { $searchCondition = " AND $rowText LIKE " . $dbr->addQuotes( "%$search%" ); } elseif ( $query == 'class' ) { $searchCondition = " AND $rowText LIKE " . $dbr->addQuotes( "$search%" ); } elseif ( $query == "$wgDefinedMeaningAttributes" or // should be 'relation-type' in html, there is a bug I cannot find $query == "$wgLinkAttribute" or $query == "$wgOptionAttribute" or $query == 'translated-text-attribute' or $query == 'text-attribute' ) { $searchCondition = " HAVING $rowText LIKE " . $dbr->addQuotes( "$search%" ); } elseif ( $query == 'language' ) { $searchCondition = " HAVING $rowText LIKE " . $dbr->addQuotes( "%$search%" ); } elseif ( $query == 'relation-type' ) { // not sure in which case 'relation-type' happens... $searchCondition = " WHERE $rowText LIKE " . $dbr->addQuotes( "$search%" ); } else { $searchCondition = " AND $rowText LIKE " . $dbr->addQuotes( "$search%" ); } } else { $searchCondition = ""; } if ( $query == 'transaction' ) { $orderBy = 'transaction_id DESC'; } else { $orderBy = $rowText; } $sql .= $searchCondition . " ORDER BY $orderBy LIMIT "; if ( $offset > 0 ) { $sql .= " $offset, "; } // print only 10 results $sql .= "10"; # == Actual query here // wfdebug("]]]".$sql."\n"); $queryResult = $dbr->query( $sql ); $o->id = new Attribute( "id", wfMsg( 'ow_ID' ), "id" ); # == Process query switch( $query ) { case 'relation-type': list( $recordSet, $editor ) = $this->getRelationTypeAsRecordSet( $queryResult ); break; case 'class': list( $recordSet, $editor ) = $this->getClassAsRecordSet( $queryResult ); break; case "$wgDefinedMeaningAttributes": list( $recordSet, $editor ) = $this->getDefinedMeaningAttributeAsRecordSet( $queryResult ); break; case 'text-attribute': list( $recordSet, $editor ) = $this->getTextAttributeAsRecordSet( $queryResult ); break; case 'translated-text-attribute': list( $recordSet, $editor ) = $this->getTranslatedTextAttributeAsRecordSet( $queryResult ); break; case "$wgLinkAttribute": list( $recordSet, $editor ) = $this->getLinkAttributeAsRecordSet( $queryResult ); break; case "$wgOptionAttribute": list( $recordSet, $editor ) = $this->getOptionAttributeAsRecordSet( $queryResult ); break; case "$wgDefinedMeaning": list( $recordSet, $editor ) = $this->getDefinedMeaningAsRecordSet( $queryResult ); break; case 'class-attributes-level': list( $recordSet, $editor ) = $this->getClassAttributeLevelAsRecordSet( $queryResult ); break; case 'collection': list( $recordSet, $editor ) = $this->getCollectionAsRecordSet( $queryResult ); break; case 'language': list( $recordSet, $editor ) = $this->getLanguageAsRecordSet( $queryResult ); break; case 'transaction': list( $recordSet, $editor ) = $this->getTransactionAsRecordSet( $queryResult ); break; } $dbr->freeResult( $queryResult ); $output = $editor->view( new IdStack( $prefix . 'table' ), $recordSet ); echo $output; }