Skip to content

Commit

Permalink
Merge pull request #170 from wikimedia/cast-page-namespace
Browse files Browse the repository at this point in the history
Record: type cast page_namespace into int; make submission_id a string
  • Loading branch information
MusikAnimal authored Jul 27, 2023
2 parents f031dec + 8394c4f commit e4ce3c4
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 15 deletions.
2 changes: 1 addition & 1 deletion i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"record-editcount": "Edit count:",
"compare": "Compare",
"record-ithenticate": "iThenticate report",
"record-url-text": "$1 of edit ($2 words)",
"record-url-text": "$1 of edit",
"record-noeditor": "No editor found",
"record-noeditor-tooltip": "The revision may have been deleted or the data is not yet available in Labs database.",
"record-ores": "ORES score: $1",
Expand Down
2 changes: 1 addition & 1 deletion i18n/qqq.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"record-editcount": "Label to indicate number of edits a user has made",
"compare": "Button label to open a panel for text comparison between two pages\n{{Identical|Compare}}",
"record-ithenticate": "Button label for a button to go to the original plagiarism report generated by Turnitin",
"record-url-text": "Label text to show amount of plagiarism. Parameters:\n* $1 - Percentage of edit that was plagiarized.\n* $2 - Number of words plagiarized.",
"record-url-text": "Label text to show amount of plagiarism. Parameters:\n* $1 - Percentage of edit that was plagiarized.",
"record-noeditor": "Column text shown to user when no editor was found in database for an edit",
"record-noeditor-tooltip": "Tooltip for a text label, shown to editor to explain why no editor could be found",
"record-ores": "Ores score for a record. \n Parameters: $1 - Decimal number indicating percentage score.",
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/AppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ public function undoReviewAction(
}

/**
* @Route("/ithenticate/{id}", name="ithenticate", requirements={"id"="\d+"})
* @Route("/ithenticate/{id}", name="ithenticate", requirements={"id"="\d+|[a-z\d+\-]"})
* @param CopyPatrolRepository $copyPatrolRepo
* @param string $iThenticateUser
* @param string $iThenticatePassword
Expand Down
14 changes: 7 additions & 7 deletions src/Model/Record.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ public function __construct(
/**
* Get the submission ID.
*
* @return int
* @return string UUID or stringified integer for older submissions.
*/
public function getSubmissionId(): int {
return $this->data['submission_id'];
public function getSubmissionId(): string {
return (string)$this->data['submission_id'];
}

/**
Expand All @@ -76,7 +76,7 @@ public function getSources(): array {
* @return string
*/
public function getPageTitle( bool $underscored = false ): string {
$nsName = $this->data['page_namespace'] === WikiRepository::NS_ID_DRAFTS ? 'Draft:' : '';
$nsName = (int)$this->data['page_namespace'] === WikiRepository::NS_ID_DRAFTS ? 'Draft:' : '';
$pageTitle = $nsName . $this->data['page_title'];
if ( !$underscored ) {
// Remove underscores for display purposes.
Expand Down Expand Up @@ -157,7 +157,7 @@ public function getOresScore(): ?float {
* @return int
*/
public function getRevId(): int {
return $this->data['rev_id'];
return (int)$this->data['rev_id'];
}

/**
Expand All @@ -166,7 +166,7 @@ public function getRevId(): int {
* @return int
*/
public function getRevParentId(): int {
return $this->data['rev_parent_id'];
return (int)$this->data['rev_parent_id'];
}

/** EDITOR / USER */
Expand Down Expand Up @@ -242,7 +242,7 @@ public function getUserContribsUrl(): string {
* @return int On the CopyPatrolRepository::STATUS_ constants.
*/
public function getStatus(): int {
return $this->data['status'];
return (int)$this->data['status'];
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Repository/CopyPatrolRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ public function getPlagiarismRecords( array $options = [], int $limit = 50 ): ar
'status_user_text', 'source_id', 'url', 'percent',
] )
->from( 'diffs', 'd' )
->join( 'd', 'report_sources', 's', 'd.submission_id = s.submission_id' )
->orderBy( 'diff_id', 'DESC' );
->join( 'd', 'report_sources', 's', 'd.submission_id = s.submission_id' );

if ( $options['id'] ) {
// if given an exact submission ID, don't allow any other filter options
Expand Down Expand Up @@ -119,6 +118,7 @@ public function getPlagiarismRecords( array $options = [], int $limit = 50 ): ar

return $outerQuery->select( '*' )
->from( '(' . $qb->getSQL() . ') a' )
->orderBy( 'diff_id', 'DESC' )
->setMaxResults( $limit )
->executeQuery()
->fetchAllAssociative();
Expand Down
10 changes: 8 additions & 2 deletions src/Repository/WikiRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,14 @@ public function getEditCounts( array $usernames ): array {
$sql = "SELECT user_name, user_editcount
FROM {$this->getDb()}.user
WHERE user_name IN (:usernames)";
return $this->executeQuery( $sql, [ 'usernames' => $usernames ], [ 'usernames' => ArrayParameterType::STRING ] )
->fetchAllKeyValue();
$ret = $this->executeQuery( $sql,
[ 'usernames' => $usernames ],
[ 'usernames' => ArrayParameterType::STRING ]
);
if ( $ret->rowCount() > 0 ) {
return $ret->fetchAllKeyValue();
}
return [];
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/Model/RecordTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function setUp(): void {
}

public function testGetters(): void {
static::assertSame( 23323186, $this->record->getSubmissionId() );
static::assertSame( '23323186', $this->record->getSubmissionId() );
static::assertSame( [
[
'source_id' => 28671,
Expand Down

0 comments on commit e4ce3c4

Please sign in to comment.