Addshore has submitted this change and it was merged. Change subject: Update the contributors table with each edit using Hooks ......................................................................
Update the contributors table with each edit using Hooks Bug: T134939 Change-Id: I82a111862405e8906cba6e1a00af139322229c85 --- M extension.json M includes/ContributorsHooks.php 2 files changed, 69 insertions(+), 1 deletion(-) Approvals: Addshore: Looks good to me, approved jenkins-bot: Verified diff --git a/extension.json b/extension.json index 2f5cae0..eade002 100644 --- a/extension.json +++ b/extension.json @@ -26,6 +26,9 @@ "ContributorsHooks": "includes/ContributorsHooks.php" }, "Hooks": { + "PageContentSaveComplete": [ + "ContributorsHooks::onPageContentSaveComplete" + ], "LoadExtensionSchemaUpdates": [ "ContributorsHooks::onLoadExtensionSchemaUpdates" ], diff --git a/includes/ContributorsHooks.php b/includes/ContributorsHooks.php index 30b9b9a..766e39d 100644 --- a/includes/ContributorsHooks.php +++ b/includes/ContributorsHooks.php @@ -123,5 +123,70 @@ return true; } -} +/** + * Updates the contributors table with each edit made by a user to a page + * @param $article + * @param $user + * @param $content + * @param $summary + * @param $isMinor + * @param $isWatch + * @param $section + * @param $flags + * @param $revision + * @param $status + * @param $baseRevId + * @throws Exception + */ + public static function onPageContentSaveComplete( $article, $user, $content, $summary, $isMinor, $isWatch, $section, $flags, $revision, $status, $baseRevId ) { + $dbw = wfGetDB( DB_MASTER ); + $dbr = wfGetDB( DB_SLAVE ); + $pageId = $article->getId(); + $userId = $user->getId(); + $text = $user->getName(); + $cond = array( 'cn_page_id' => $pageId, 'cn_user_id' => $userId, 'cn_user_text' => $text ); + + $res = $dbr->select( + 'contributors', + 'cn_revision_count', + $cond, + __METHOD__ + ); + if ( $res->numRows() == 0 ) + { + $dbw->insert( 'contributors', + array( + 'cn_page_id' => $pageId, + 'cn_user_id' => $userId, + 'cn_user_text' => $text, + 'cn_revision_count' => 1 + ), + __METHOD__ + ); + } + else + { + foreach ( $res as $row ) { + + $dbw->upsert( 'contributors', + array( + 'cn_page_id' => $pageId, + 'cn_user_id' => $userId, + 'cn_user_text' => $text, + 'cn_revision_count' => 1 + ), + array( + 'cn_page_id', + 'cn_user_id', + 'cn_user_text' + ), + array( + 'cn_revision_count' => $row->cn_revision_count + 1 + ), + __METHOD__ + ); + } + } + } +} -- To view, visit https://gerrit.wikimedia.org/r/296909 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I82a111862405e8906cba6e1a00af139322229c85 Gerrit-PatchSet: 13 Gerrit-Project: mediawiki/extensions/Contributors Gerrit-Branch: master Gerrit-Owner: Devirk <devikrishna...@gmail.com> Gerrit-Reviewer: Addshore <addshorew...@gmail.com> Gerrit-Reviewer: Niharika29 <nihar...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits