MarkAHershberger has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/400462 )
Change subject: Add methods to retrieve log and latest entry
......................................................................
Add methods to retrieve log and latest entry
* Need to cache instead of using multiple db queries
* Add maint script for showing log.
Change-Id: Ife3d4c1544acbd34bff27cadc6de5377ef555f68
---
M ApprovedRevs_body.php
A maintenance/ShowLog.php
2 files changed, 162 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ApprovedRevs
refs/changes/62/400462/1
diff --git a/ApprovedRevs_body.php b/ApprovedRevs_body.php
index 9d46c68..21f0338 100644
--- a/ApprovedRevs_body.php
+++ b/ApprovedRevs_body.php
@@ -35,6 +35,63 @@
return $revID;
}
+ /**
+ * Get the person who made the last approval (or un-approval) for this page
+ *
+ * @param Title $title page
+ * @return User
+ */
+ public static function getLastApprovalUser( Title $title ) {
+ $log = self::getApprovalLog( $title );
+ return User::newFromID( $log->current()->user_id );
+ }
+
+ /**
+ * Get the date of the last entry in the approval log for this page
+ *
+ * @param Title $title page
+ * @return Timestamp
+ */
+ public static function getLastApprovalDate( Title $title ) {
+ $log = self::getApprovalLog( $title );
+ return new MWTimestamp( $log->current()->log_timestamp );
+ }
+
+ /**
+ * Get the status of the last entry in the approval log for this page
+ *
+ * @param Title $title page
+ * @return Timestamp
+ */
+ public static function getLastApprovalStatus( Title $title ) {
+ $log = self::getApprovalLog( $title );
+ return $log->current()->log_action;
+ }
+
+ /**
+ * Get the approval log for this page
+ *
+ * @param Title $title page
+ * @return array of elements where [ 'ts' => timestamp, 'user' => user id ]
+ */
+ public static function getApprovalLog( Title $title ) {
+ $dbr = wfGetDB( DB_SLAVE );
+ $query = DatabaseLogEntry::getSelectQueryData();
+
+ $query['conds'] = [
+ 'log_type' => 'approval',
+ 'log_title' => $title->getDBKey()
+ ];
+ $query['options'] = [ 'ORDER BY' => 'log_timestamp desc' ];
+
+ $res = $dbr->select(
+ $query['tables'], $query['fields'], $query['conds'],
+ __METHOD__, $query['options'], $query['join_conds']
+ );
+
+ return $res;
+ }
+
/**
* Returns whether or not this page has a revision ID.
*/
diff --git a/maintenance/ShowLog.php b/maintenance/ShowLog.php
new file mode 100644
index 0000000..75fbd78
--- /dev/null
+++ b/maintenance/ShowLog.php
@@ -0,0 +1,105 @@
+<?php
+
+/**
+ * This script shows the approval log for a page.
+ *
+ * Usage:
+ * --title Title
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @author Jeroen De Dauw
+ * @author Yaron Koren
+ * @ingroup Maintenance
+ */
+
+// Allow people to have different layouts.
+if ( ! isset( $IP ) ) {
+ $IP = getenv( "MW_INSTALL_PATH" )
+ ? getenv( "MW_INSTALL_PATH" )
+ : __DIR__ . '/../../../';
+}
+if ( !is_readable( "$IP/maintenance/Maintenance.php" ) ) {
+ die( "Please set MW_INSTALL_PATH to the MediaWiki installation." );
+}
+require_once "$IP/maintenance/Maintenance.php";
+
+class ShowLog extends Maintenance {
+
+ public function __construct() {
+ parent::__construct();
+
+ $this->mDescription = "Show the approval log for a page.";
+ $this->addOption( "title", "Target page.", true, true, "t" );
+ }
+
+ /**
+ * Where the magic happens.
+ */
+ public function execute() {
+ $this->title = Title::newFromText( $this->getOption( "title" )
);
+ if ( !$this->title->exists() ) {
+ $this->error( "Title does not exist!", 1 );
+ }
+
+ $log = ApprovedRevs::getApprovalLog( $this->title );
+ if ( $log->numRows() === 0 ) {
+ $this->error(
+ "No entries in the approval log for
[[$this->title]].", 1
+ );
+ }
+
+ $this->printHeader();
+ foreach ( $log as $row ) {
+ $this->print( $row );
+ }
+ }
+
+ protected function printHeader() {
+ $this->output(
+ "Most Recently by: "
+ . ApprovedRevs::getLastApprovalUser( $this->title )
+ . "\n"
+ );
+ $this->output(
+ "Most Recently on: "
+ . ApprovedRevs::getLastApprovalDate( $this->title )
+ . "\n"
+ );
+ $this->output(
+ "Most Recently set to: "
+ . ApprovedRevs::getLastApprovalStatus( $this->title )
+ . "\n"
+ );
+
+ $this->output( "== Log for '$this->title' ==\n" );
+ $this->output( sprintf(
+ "%20s %9s %s\n", "Approver", "State", "Timestamp"
+ ) );
+ $this->output( "------------------------------------\n" );
+ }
+
+ protected function print( $row ) {
+ $time = new MWTimestamp( $row->log_timestamp );
+ $this->output( sprintf(
+ "%20s %9s %s\n", substr( $row->user_name, 0, 20 ),
+ $row->log_action, $time->getHumanTimestamp()
+ ) );
+ }
+}
+
+$maintClass = "ShowLog";
+require_once DO_MAINTENANCE;
--
To view, visit https://gerrit.wikimedia.org/r/400462
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ife3d4c1544acbd34bff27cadc6de5377ef555f68
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ApprovedRevs
Gerrit-Branch: master
Gerrit-Owner: MarkAHershberger <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits