Kipcool has submitted this change and it was merged.
Change subject: Transactions query() and some corrections
......................................................................
Transactions query() and some corrections
Partial fix for bug 56220 and some documentation corrections and
additions.
Patch 2: Added comments and documentation regarding SpecialTransaction.php
plus added int to a defined meaning comment.
Patch 3: Forgot to add Patch 2 corrections. Added the files as Patch 3.
Sorry.
Kindly commit if there are no errors or suggestions. Thanks!
Bug: 56220
Change-Id: I6732c607f0a4e22e59491fe177cfec022a87c1b1
---
M OmegaWiki.md
M OmegaWiki/DefinedMeaning.php
M OmegaWiki/OmegaWikiDatabaseAPI.php
M OmegaWiki/SpecialTransaction.php
M OmegaWiki/Transaction.php
5 files changed, 123 insertions(+), 36 deletions(-)
Approvals:
Kipcool: Verified; Looks good to me, approved
diff --git a/OmegaWiki.md b/OmegaWiki.md
index ca054cd..9865f63 100644
--- a/OmegaWiki.md
+++ b/OmegaWiki.md
@@ -109,6 +109,8 @@
* SpecialExportTSV
* SpecialImportTSV
* SpecialLanguages
+ * Unused
+ * Classes
* SpecialTransaction
* Web API
* Obtaining Data
diff --git a/OmegaWiki/DefinedMeaning.php b/OmegaWiki/DefinedMeaning.php
index 3fbfc98..616df69 100644
--- a/OmegaWiki/DefinedMeaning.php
+++ b/OmegaWiki/DefinedMeaning.php
@@ -330,7 +330,7 @@
* * "option['test'] = true" used to test the function
* @param $dc opt'l str The WikiLexicalData dataset
*
- * @return array( meaning1_id, relationtype_mid, meaning2_mid)
+ * @return array( int defined_meaning_id )
* @return if not exists, array()
*
* @note options parameter can be used to extend this function.
diff --git a/OmegaWiki/OmegaWikiDatabaseAPI.php
b/OmegaWiki/OmegaWikiDatabaseAPI.php
index c27ff1a..d282055 100644
--- a/OmegaWiki/OmegaWikiDatabaseAPI.php
+++ b/OmegaWiki/OmegaWikiDatabaseAPI.php
@@ -54,7 +54,7 @@
* @param options opt'l arr An optional parameters
* @param dc opt'l str The WikiLexicalData dataset
*
- * @return array( meaning1_id, relationtype_mid, meaning2_mid)
+ * @return array( int defined_meaning_id )
* @return if not exists, array()
*
* @see Attributes::getRelationIdRelation, for a list of options.
@@ -89,6 +89,44 @@
/*! @} group OwDbAPIsyntFn ends here.*/
+ /** @addtogroup OwDbAPItransactFn OwDatabaseAPI's Transactions functions
+ * @{
+ */
+
+ /**
+ * @param transactionId req'd int The transaction id
+ * @param options opt'l arr Optional parameters
+ * @param dc opt'l str The WikiLexicalData dataset
+ *
+ * @return array( int user_id, str user_ip, str timestamp, str comment )
+ * @return if not exists, array()
+ *
+ * @see Transactions::getIdDetails, for a list of options.
+ */
+ public static function getTransactionIdDetails( $transactionId,
$options = array(), $dc = null ) {
+ $api = new OwDatabaseAPI;
+ $api->settings( 'transaction', $dc );
+ return $api->Transaction->getIdDetails( $transactionId,
$options, $api->dc );
+ }
+
+ /**
+ * @param languageId req'd int The language id
+ * @param options opt'l arr Optional parameters
+ * @param dc opt'l str The WikiLexicalData dataset
+ *
+ * @return array( int user_id, str user_ip, str timestamp, str comment )
+ * @return if not exists, array()
+ *
+ * @see Transactions::getLanguageIdLatestTransactionId, for a list of
options.
+ */
+ public static function getLanguageIdLatestTransactionId( $languageId,
$options = array(), $dc = null ) {
+ $api = new OwDatabaseAPI;
+ $api->settings( 'transaction', $dc );
+ return $api->Transaction->getLanguageIdLatestTransactionId(
$languageId, $options, $api->dc );
+ }
+
+ /*! @} group OwDbAPItransactFn ends here.*/
+
/**
* @brief sets the initial settings for static functions
*
@@ -101,6 +139,7 @@
if ( $class == 'attributes' ) { $this->Attributes = new
Attributes; }
if ( $class == 'syntrans' ) { $this->Syntrans = new Syntrans; }
if ( $class == 'definedMeaning' ) { $this->DefinedMeaning = new
DefinedMeanings; }
+ if ( $class == 'transaction' ) { $this->Transaction = new
Transactions; }
}
/**
diff --git a/OmegaWiki/SpecialTransaction.php b/OmegaWiki/SpecialTransaction.php
index d4c55c0..b354b3c 100644
--- a/OmegaWiki/SpecialTransaction.php
+++ b/OmegaWiki/SpecialTransaction.php
@@ -5,6 +5,13 @@
require_once( "Wikidata.php" );
require_once( "Utilities.php" );
+/** @file
+ *
+ * This Special Page is currently unused.
+ *
+ * @note In case this Special Page is used, kindly convert
+ * the database query functions to select functions. Thanks ~he
+ */
class SpecialTransaction extends SpecialPage {
function SpecialTransaction() {
parent::__construct( 'Transaction' );
diff --git a/OmegaWiki/Transaction.php b/OmegaWiki/Transaction.php
index ae4602f..039417a 100644
--- a/OmegaWiki/Transaction.php
+++ b/OmegaWiki/Transaction.php
@@ -6,7 +6,7 @@
require_once( 'Wikidata.php' );
/**
- * Transaction.php
+ * @file Transaction.php
*
* Manage internal transactions (NOT mysql transactions... confuzzeled yet?)
*
@@ -323,10 +323,9 @@
$result->transactionId = $transactionId;
if ( $transactionId > 0 ) {
- $dbr = wfGetDB( DB_SLAVE );
- $queryResult = $dbr->query( "SELECT user_id, user_ip,
timestamp, comment FROM {$wgDBprefix}{$dc}_transactions WHERE
transaction_id={$transactionId}" );
+ $transaction = OwDatabaseAPI::getTransactionIdDetails(
$transactionId, array(), $dc );
- if ( $transaction = $dbr->fetchObject( $queryResult ) ) {
+ if ( $transaction ) {
$result->user = getUserLabel( $transaction->user_id,
$transaction->user_ip );
if ( $result->user == null ) $result->user = "userId "
. $transaction->user_id . " not found" ;
$result->timestamp = $transaction->timestamp;
@@ -384,7 +383,7 @@
/**
* Checks the latest transaction id from syntrans (added transactions).
*
- * Other transaction ids were excluded because of the slow speed to
generate them.
+ * @note Other transaction ids were excluded because of the slow speed
to generate them.
* (any search for transaction ids which are not present will search
for all
* the rows in a column which causes the long query time).
* Syntrans seems to cover most of the changes. This function will
change
@@ -392,12 +391,19 @@
* faster (since the latest ids are already set) and accurate ( since
it would
* not be limited to added syntrans only ).
*
- * @param $languageId integer
- * @param $dc string
+ * @param languageId int language Id
+ * @param options arr optional parameters
+ * @param dc str WikiLexical dataset
*
* @return $transaction_id integer The latest transaction_id.
- * else @return -1 If the language_id is non numeric or no
transaction_id was found
- * else @return -2 if a there are any current jobs pending, this
function is skipped
+ * @return -1 If the language_id is non numeric or no transaction_id
was found
+ * @return -2 if a there are any current jobs pending, this function is
skipped
+ *
+ * @note options parameter can be used to extend this function.
+ * Though you can access this function, it is highly recommended that
you
+ * use the static function
OwDatabaseAPI::getLanguageIdLatestTransactionId instead.
+ * Also note that this function currently includes all data, even
removed ones.
+
*/
public static function getLanguageIdLatestTransactionId( $languageId,
$options = array(), $dc = null ) {
@@ -431,42 +437,75 @@
$dc = wdGetDataSetContext();
}
- $DefinedMeanings = new DefinedMeanings;
- $Transactions = new Transactions;
-
- $query =
Transactions::getLanguageIdLatestSynonymsAndTranslationsTransactionIdQuery(
$languageId );
-
- $result = $dbr->query( $query );
-
- $tid = array();
- foreach ( $result as $row ) {
- $tid[] = $row->tid;
- }
- sort( $tid );
- $transaction_id = array_pop( $tid );
+ $Transaction = new Transactions;
+ $transaction_id =
$Transaction->getLanguageIdLatestSynonymsAndTranslationsTransactionId(
$languageId );
if ( $transaction_id ) {
return $transaction_id;
}
return -1;
+
}
- public static function
getLanguageIdLatestSynonymsAndTranslationsTransactionIdQuery( $languageId,
$options = array(), $dc = null ) {
- global $wgDBprefix;
+/** @see static function Transactions::getLanguageIdLatestTransactionId
+ */
+ protected function
getLanguageIdLatestSynonymsAndTranslationsTransactionId( $languageId, $options
= array(), $dc = null ) {
if ( is_null( $dc ) ) {
$dc = wdGetDataSetContext();
}
+ $dbr = wfGetDB( DB_SLAVE );
- return "(SELECT " .
- "CASE WHEN synt.add_transaction_id IS NULL THEN -1 ELSE " .
- "synt.add_transaction_id END AS tid FROM " .
- "{$wgDBprefix}{$dc}_expression AS exp, " .
- "{$wgDBprefix}{$dc}_syntrans AS synt " .
- "WHERE language_id = $languageId " .
- "AND synt.expression_id = exp.expression_id " .
- "AND exp.remove_transaction_id IS NULL " .
- "AND synt.remove_transaction_id IS NULL " .
- "ORDER BY syntrans_sid DESC LIMIT 1)";
+ $result = $dbr->selectField(
+ array(
+ 'exp' => "{$dc}_expression",
+ 'synt' => "{$dc}_syntrans"
+ ),
+ 'synt.add_transaction_id AS tid',
+ array(
+ 'language_id' => $languageId,
+ 'synt.expression_id = exp.expression_id',
+ 'synt.remove_transaction_id' => null,
+ 'exp.remove_transaction_id' => null
+ ), __METHOD__,
+ array(
+ 'ORDER BY' => 'syntrans_sid DESC'
+ )
+ );
+
+ if ( $result ) {
+ return $result;
+ }
+ return -1;
+ }
+
+ /**
+ * @param transactionId req'd int The transaction id
+ * @param options opt'l arr Optional parameters
+ * @param dc opt'l str The WikiLexicalData dataset
+ *
+ * @return array( int user_id, str user_ip, str timestamp, str comment )
+ * @return if not exists, array()
+ *
+ * @note options parameter can be used to extend this function.
+ * Though you can access this function, it is highly recommended that
you
+ * use the static function OwDatabaseAPI::getTransactionIdDetails
instead.
+ * Also note that this function currently includes all data, even
removed ones.
+ */
+ public static function getIdDetails( $transactionId, $options, $dc ) {
+ if ( is_null( $dc ) ) {
+ $dc = wdGetDataSetContext();
+ }
+ $dbr = wfGetDB( DB_SLAVE );
+ $transaction = $dbr->selectRow(
+ "{$dc}_transactions",
+ array( 'user_id', 'user_ip', 'timestamp', 'comment' ),
+ array( 'transaction_id' => $transactionId ), __METHOD__
+ );
+
+ if ( $transaction ) {
+ return $transaction;
+ }
+ return array();
}
}
--
To view, visit https://gerrit.wikimedia.org/r/130287
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I6732c607f0a4e22e59491fe177cfec022a87c1b1
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/WikiLexicalData
Gerrit-Branch: master
Gerrit-Owner: Hiong3-eng5 <[email protected]>
Gerrit-Reviewer: Kipcool <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits