r114722 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r114721‎ | r114722 | r114723 >
Date:23:31, 4 April 2012
Author:bsitu
Status:deferred
Tags:
Comment:
Add api for triaging/untriaging article and logging
Modified paths:
  • /trunk/extensions/PageTriage/PageTriage.hooks.php (modified) (history)
  • /trunk/extensions/PageTriage/PageTriage.php (modified) (history)
  • /trunk/extensions/PageTriage/api/ApiPageTriageAction.php (added) (history)
  • /trunk/extensions/PageTriage/includes/PageTriage.php (added) (history)

Diff [purge]

Index: trunk/extensions/PageTriage/PageTriage.hooks.php
@@ -107,27 +107,8 @@
108108 * Add page to page triage queue
109109 */
110110 private static function addToPageTriageQueue( $pageId ) {
111 - $dbr = wfGetDB( DB_SLAVE );
112 - $dbw = wfGetDB( DB_MASTER );
113 -
114 - // Pull page creation date from database
115 - $res = $dbr->select(
116 - 'revision',
117 - 'MIN(rev_timestamp) AS creation_date',
118 - array( 'rev_page' => $pageId ),
119 - __METHOD__
120 - );
121 - foreach ( $res as $row ) {
122 - $creationDate = $row->creation_date;
123 - }
124 -
125 - $row = array(
126 - 'ptrp_page_id' => $pageId,
127 - 'ptrp_triaged' => 0,
128 - 'ptrp_timestamp' => $creationDate
129 - );
130 -
131 - $dbw->replace( 'pagetriage_page', array( 'ptrp_page_id' ), $row, __METHOD__ );
 111+ $pageTriage = new PageTriage( $pageId );
 112+ $pageTriage->addToPageTriageQueue();
132113 }
133114
134115 /**
Index: trunk/extensions/PageTriage/includes/PageTriage.php
@@ -0,0 +1,140 @@
 2+<?php
 3+
 4+class PageTriage {
 5+
 6+ // database property
 7+ protected $mPageId;
 8+ protected $mTriaged;
 9+ protected $mTimestamp;
 10+
 11+ // additional property
 12+ protected $mMetadata;
 13+
 14+ /**
 15+ * @param $pageId int
 16+ */
 17+ public function __construct( $pageId ) {
 18+ $this->mPageId = intval( $pageId );
 19+ }
 20+
 21+ /**
 22+ * Add page to page triage queue
 23+ * @return bool
 24+ */
 25+ public function addToPageTriageQueue() {
 26+ $dbr = wfGetDB( DB_SLAVE );
 27+ $dbw = wfGetDB( DB_MASTER );
 28+
 29+ // Pull page creation date from database
 30+ $res = $dbr->selectRow(
 31+ 'revision',
 32+ 'MIN(rev_timestamp) AS creation_date',
 33+ array( 'rev_page' => $this->mPageId ),
 34+ __METHOD__
 35+ );
 36+
 37+ if ( !$res ) {
 38+ return false;
 39+ }
 40+
 41+ $row = array(
 42+ 'ptrp_page_id' => $this->mPageId,
 43+ 'ptrp_triaged' => '0',
 44+ 'ptrp_timestamp' => $res->creation_date
 45+ );
 46+
 47+ $dbw->replace( 'pagetriage_page', array( 'ptrp_page_id' ), $row, __METHOD__ );
 48+
 49+ return true;
 50+ }
 51+
 52+ /**
 53+ * set the triage status of an article in pagetriage queue
 54+ * @param $triaged string - '1'/'0'
 55+ * @param $user User
 56+ */
 57+ public function setTriageStatus( $triaged, User $user = null ) {
 58+ $dbw = wfGetDB( DB_MASTER );
 59+
 60+ $row = array();
 61+ if ( $triaged === '1' ) {
 62+ $row['ptrp_triaged'] = '1';
 63+ } else {
 64+ $row['ptrp_triaged'] = '0';
 65+ }
 66+
 67+ $this->mTriaged = $row['ptrp_triaged'];
 68+
 69+ $dbw->begin();
 70+ $dbw->update( 'pagetriage_page', $row, array( 'ptrp_page_id' => $this->mPageId ), __METHOD__ );
 71+
 72+ // Log it if set by user
 73+ if ( $dbw->affectedRows() > 0 && !is_null( $user ) && !$user->isAnon() ) {
 74+ $this->logUserTriageAction( $user );
 75+ }
 76+ $dbw->commit();
 77+ }
 78+
 79+ /**
 80+ * Load a page triage record
 81+ * @return false
 82+ */
 83+ public function retrieve() {
 84+ $dbr = wfGetDB( DB_SLAVE );
 85+
 86+ $res = $dbr->selectRow(
 87+ array( 'pagetriage_page' ),
 88+ array( 'ptrp_triaged', 'ptrp_timestamp' ),
 89+ array( 'ptrp_page_id' => $this->mPageId ),
 90+ __METHOD__
 91+ );
 92+
 93+ if ( !$res ) {
 94+ return false;
 95+ }
 96+
 97+ $this->mTriaged = $res->ptrp_triaged;
 98+ $this->mTimestamp = $res->ptrp_timestamp;
 99+ return true;
 100+ }
 101+
 102+ public function retrieveTriageLog() {
 103+ // get the triage log
 104+ }
 105+
 106+ public function loadMetadata() {
 107+ $metaData = new ArticleMetadata( array( $this->mPageId ) );
 108+ $this->mMetadata = $metaData->getMetadata();
 109+ }
 110+
 111+ /**
 112+ * Get the metadata for this page
 113+ * @return array
 114+ */
 115+ public function getMetadata() {
 116+ if ( is_null( $this->mMetadata ) ) {
 117+ $this->loadMetadata();
 118+ }
 119+
 120+ return $this->mMetadata;
 121+ }
 122+
 123+ /**
 124+ * Log the user triage action
 125+ * @param $user User
 126+ */
 127+ protected function logUserTriageAction( $user ) {
 128+ $dbw = wfGetDB( DB_MASTER );
 129+
 130+ $row = array(
 131+ 'ptrl_page_id' => $this->mPageId,
 132+ 'ptrl_user_id' => $user->getID(),
 133+ 'ptrl_triaged' => $this->mTriaged,
 134+ 'ptrl_timestamp' => $dbw->timestamp( wfTimestampNow() )
 135+ );
 136+
 137+ $row['ptrl_id'] = $dbw->nextSequenceValue( 'pagetriage_log_ptrl_id' );
 138+ $dbw->insert( 'pagetriage_log', $row, __METHOD__ );
 139+ }
 140+
 141+}
Property changes on: trunk/extensions/PageTriage/includes/PageTriage.php
___________________________________________________________________
Added: svn:eol-style
1142 + native
Index: trunk/extensions/PageTriage/api/ApiPageTriageAction.php
@@ -0,0 +1,73 @@
 2+<?php
 3+
 4+class ApiPageTriageAction extends ApiBase {
 5+
 6+ public function execute() {
 7+ global $wgUser;
 8+
 9+ if ( $wgUser->isAnon() || $wgUser->isBlocked( false ) ) {
 10+ $this->dieUsage( "You don't have permission to do that", 'permission-denied' );
 11+ }
 12+
 13+ //@Todo: Add more user permission checking
 14+
 15+ $params = $this->extractRequestParams();
 16+
 17+ $pageTriage = new PageTriage( $params['pageid'] );
 18+ $pageTriage->setTriageStatus( $params['triaged'], $wgUser );
 19+
 20+ $result = array( 'result' => 'success' );
 21+ $this->getResult()->addValue( null, $this->getModuleName(), $result );
 22+ }
 23+
 24+ public function needsToken() {
 25+ return true;
 26+ }
 27+
 28+ public function getTokenSalt() {
 29+ return '';
 30+ }
 31+
 32+ public function getAllowedParams() {
 33+ return array(
 34+ 'pageid' => array(
 35+ ApiBase::PARAM_REQUIRED => true,
 36+ ApiBase::PARAM_TYPE => 'integer'
 37+ ),
 38+ 'triaged' => array(
 39+ ApiBase::PARAM_REQUIRED => true,
 40+ ApiBase::PARAM_TYPE => array(
 41+ '1',
 42+ '0',
 43+ ),
 44+ ),
 45+ 'token' => array(
 46+ ApiBase::PARAM_REQUIRED => true,
 47+ )
 48+ );
 49+ }
 50+
 51+ public function mustBePosted() {
 52+ return true;
 53+ }
 54+
 55+ public function isWriteMode() {
 56+ return true;
 57+ }
 58+
 59+ public function getVersion() {
 60+ return __CLASS__ . ': $Id$';
 61+ }
 62+
 63+ public function getParamDescription() {
 64+ return array(
 65+ 'pageid' => 'The article for which to be marked as triaged or untriaged',
 66+ 'triaged' => 'whether the article is triaged or not',
 67+ 'token' => 'edit token'
 68+ );
 69+ }
 70+
 71+ public function getDescription() {
 72+ return 'Mark an article as triaged or untriaged';
 73+ }
 74+}
Property changes on: trunk/extensions/PageTriage/api/ApiPageTriageAction.php
___________________________________________________________________
Added: svn:eol-style
175 + native
Added: svn:keywords
276 + Id
Index: trunk/extensions/PageTriage/PageTriage.php
@@ -56,12 +56,14 @@
5757 $wgSpecialPages['PageTriage'] = 'SpecialPageTriage';
5858 $wgSpecialPageGroups['PageTriage'] = 'changes';
5959 $wgAutoloadClasses['ArticleMetadata'] = $dir . 'includes/ArticleMetadata.php';
 60+$wgAutoloadClasses['PageTriage'] = $dir . 'includes/PageTriage.php';
6061 $wgAutoloadClasses['PageTriageUtil'] = $dir . 'includes/PageTriageUtil.php';
6162 $wgAutoloadClasses['PageTriageHooks'] = $dir . 'PageTriage.hooks.php';
6263
6364 $wgAutoloadClasses['ApiPageTriageList'] = $dir . 'api/ApiPageTriageList.php';
6465 $wgAutoloadClasses['ApiPageTriageGetMetadata'] = $dir . 'api/ApiPageTriageGetMetadata.php';
6566 $wgAutoloadClasses['ApiPageTriageStats'] = $dir . 'api/ApiPageTriageStats.php';
 67+$wgAutoloadClasses['ApiPageTriageAction'] = $dir . 'api/ApiPageTriageAction.php';
6668
6769 // custom exceptions
6870 $wgAutoloadClasses['MWArticleMetadataMissingPageIdException'] = $dir . 'includes/ArticleMetadata.php';
@@ -72,6 +74,7 @@
7375 $wgAPIModules['pagetriagelist'] = 'ApiPageTriageList';
7476 $wgAPIModules['pagetriagegetmetadata'] = 'ApiPageTriageGetMetadata';
7577 $wgAPIModules['pagetriagestats'] = 'ApiPageTriageStats';
 78+$wgAPIModules['pagetriageaction'] = 'ApiPageTriageAction';
7679
7780 // hooks
7881 $wgHooks['LoadExtensionSchemaUpdates'][] = 'efPageTriageSchemaUpdates';

Status & tagging log