https://www.mediawiki.org/wiki/Special:Code/MediaWiki/114419
Revision: 114419
Author: raindrift
Date: 2012-03-22 00:56:23 +0000 (Thu, 22 Mar 2012)
Log Message:
-----------
added article delete hook, deletion method
added stubs for unit tests
removed crufty code from our previous start on this feature
Modified Paths:
--------------
trunk/extensions/PageTriage/PageTriage.hooks.php
trunk/extensions/PageTriage/PageTriage.php
trunk/extensions/PageTriage/README
trunk/extensions/PageTriage/includes/ArticleMetadata.php
trunk/extensions/PageTriage/tests/phpunit/ApiPageTriageGetMetadataTest.php
trunk/extensions/PageTriage/tests/phpunit/ArticleMetadataTest.php
Removed Paths:
-------------
trunk/extensions/PageTriage/api/ApiQueryPageTriage.php
trunk/extensions/PageTriage/sql/PageTriage.sql
trunk/extensions/PageTriage/tests/phpunit/ApiQueryPageTriageTest.php
Modified: trunk/extensions/PageTriage/PageTriage.hooks.php
===================================================================
--- trunk/extensions/PageTriage/PageTriage.hooks.php 2012-03-22 00:32:21 UTC
(rev 114418)
+++ trunk/extensions/PageTriage/PageTriage.hooks.php 2012-03-22 00:56:23 UTC
(rev 114419)
@@ -88,6 +88,22 @@
}
/**
+ * Remove the metadata we added when the article is deleted.
+ *
+ * 'ArticleDeleteComplete': after an article is deleted
+ * $article: the WikiPage that was deleted
+ * $user: the user that deleted the article
+ * $reason: the reason the article was deleted
+ * $id: id of the article that was deleted
+ */
+ public static function onArticleDeleteComplete( $article, $user,
$reason, $id ) {
+ // delete everything
+ $articleMetadata = new ArticleMetadata( array( $id ) );
+ $articleMetadata->deleteMetadata();
+ return true;
+ }
+
+ /**
* Add page to page triage queue
*/
private static function addToPageTriageQueue( $pageId ) {
Modified: trunk/extensions/PageTriage/PageTriage.php
===================================================================
--- trunk/extensions/PageTriage/PageTriage.php 2012-03-22 00:32:21 UTC (rev
114418)
+++ trunk/extensions/PageTriage/PageTriage.php 2012-03-22 00:56:23 UTC (rev
114419)
@@ -87,16 +87,6 @@
*/
function efPageTriageSchemaUpdates( $updater = null ) {
$base = dirname( __FILE__ ) . "/sql";
- if ( $updater === null ) {
- global $wgDBtype, $wgExtNewTables, $wgExtNewFields;
- if ( $wgDBtype == 'mysql' ) {
- $wgExtNewTables[] = array( 'pagetriage', $base .
'/PageTriage.sql' );
- }
- } else {
- if ( $updater->getDB()->getType() == 'mysql' ) {
- $updater->addExtensionTable( 'pagetriage',
"$base/PageTriage.sql" );
- }
- }
$updater->addExtensionTable( 'pagetriage_tags', $base .
'/PageTriageTags.sql' );
$updater->addExtensionTable( 'pagetriage_page_tags', $base .
'/PageTriagePageTags.sql' );
$updater->addExtensionTable( 'pagetriage_page', $base .
'/PageTriagePage.sql' );
@@ -113,6 +103,8 @@
function efPageTriageUnitTests( &$files ) {
$base = dirname( __FILE__ ) . '/tests';
$files[] = $base . '/phpunit/SpecialPageTriageTest.php';
+ $files[] = $base . '/phpunit/ArticleMetadataTest.php';
+ $files[] = $base . '/phpunit/ApiPageTriageGetMetadataTest.php';
return true;
}
Modified: trunk/extensions/PageTriage/README
===================================================================
--- trunk/extensions/PageTriage/README 2012-03-22 00:32:21 UTC (rev 114418)
+++ trunk/extensions/PageTriage/README 2012-03-22 00:56:23 UTC (rev 114419)
@@ -5,8 +5,6 @@
It is very focused on the Wikipedia article creation workflow, though it could
probably be adapted
for use on other wikis.
-PageTriage is licensed under the same terms as MediaWiki itself.
-
PageTriage by:
@author Ryan Kaldari <[email protected]>
@author Benny Situ <[email protected]>
Deleted: trunk/extensions/PageTriage/api/ApiQueryPageTriage.php
===================================================================
--- trunk/extensions/PageTriage/api/ApiQueryPageTriage.php 2012-03-22
00:32:21 UTC (rev 114418)
+++ trunk/extensions/PageTriage/api/ApiQueryPageTriage.php 2012-03-22
00:56:23 UTC (rev 114419)
@@ -1,136 +0,0 @@
-<?php
-/**
- * PageTriage extension API
- *
- * Copyright © 2011 Wikimedia Foundation and Ian Baker <[email protected]>
- * Based on code by Victor Vasiliev, Bryan Tong Minh, Roan Kattouw, and Alex Z.
- *
- * 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
- */
-
-/**
- * Query module to checkout and checkin pages for PageTriage
- *
- * @ingroup API
- * @ingroup Extensions
- */
-class ApiQueryPageTriage extends ApiBase {
-
- public function __construct( $query, $moduleName ) {
- parent::__construct( $query, $moduleName, 'ptr' );
- }
-
- public function execute() {
- # get the current user.
- $context = $this->createContext();
- $userId = $context->getUser()->getId();
-
- $params = $this->extractRequestParams();
- $mode = $params['mode'];
-
- if( !preg_match('/^\D+$/', $params['id'] ) ) {
- $this->dieUsageMsg( array( 'pagetriage-api-invalidid',
$params['id'] ) );
- }
-
- // expire old checkouts.
- // TODO: make the time configurable.
- wfDebug( __METHOD__ . " expiring PageTriage checkouts older
than 15 minutes\n" );
- $dbw = wfGetDB( DB_MASTER );
- $dbw->delete(
- 'pagetriage_checkouts',
- 'ptc_timestamp < ' . $dbw->timestamp( time() - 15 * 60
),
- __METHOD__
- );
-
- $res = $this->getResult();
-
- if( $mode === 'checkout' ) {
- // the unique index on ptc_recentchanges_id ensures
that this will fail if there's an existing row.
- // doing it this way allows for atomic checking w/o
starting a transaction.
- //
- // this happens on the master because we expect even a
small amount of lag to
- // entirely break it. it's a small table and a small
number of people will be using it.
- $dbw->insert(
- 'pagetriage_checkouts',
- array(
- 'ptc_user' => $userId,
- 'ptc_recentchanges_id' => $params['id'],
- 'ptc_timestamp' => $dbw->timestamp()
- ),
- __METHOD__
- );
-
- // this won't be set if the insert failed.
- $checkoutId = $dbw->insertId();
-
- if( $checkoutId ) {
- $res->addValue( 'pagetriage', 'checkout-id',
$checkoutId );
- $res->addValue( 'pagetriage', 'result', 'ok' );
- } else {
- $res->addValue( 'pagetriage', 'result',
'already-checked-out' );
- }
- } elseif ( $mode === 'checkin' ) {
- // delete this user's row, if any.
- $dbw->delete(
- 'pagetriage_checkouts',
- array(
- 'ptc_user' => $userId,
- 'ptc_recentchanges_id' => $params['id'],
- ),
- __METHOD__
- );
-
- $res->addValue( 'pagetriage', 'result', 'ok' );
- }
- }
-
- public function getAllowedParams() {
- return array(
- 'id' => array(
- ApiBase::PARAM_TYPE => 'integer',
- ),
- 'mode' => array(
- ApiBase::PARAM_DFLT => 'checkout',
- ApiBase::PARAM_ISMULTI => false,
- ApiBase::PARAM_TYPE => array(
- 'checkout', 'checkin',
- ),
- )
- );
- }
-
- public function getParamDescription() {
- return array(
- 'id' => 'The ID of the recentchanges entry you\'d like
to check out/in',
- 'mode' => 'What you\'d like to do',
- );
- }
-
- public function getDescription() {
- return 'Check out or check in a page for page triage.';
- }
-
- public function getExamples() {
- return array(
- 'api.php?action=pagetriage&id=12345',
- 'api.php?action=pagetriage&id=12345&mode=checkin',
- );
- }
-
- public function getVersion() {
- return __CLASS__ . ': $Id: $';
- }
-}
Modified: trunk/extensions/PageTriage/includes/ArticleMetadata.php
===================================================================
--- trunk/extensions/PageTriage/includes/ArticleMetadata.php 2012-03-22
00:32:21 UTC (rev 114418)
+++ trunk/extensions/PageTriage/includes/ArticleMetadata.php 2012-03-22
00:56:23 UTC (rev 114419)
@@ -51,6 +51,47 @@
}
/**
+ * Delete all the metadata for an article
+ *
+ * @param $pageId - the page id to be deleted
+ */
+ protected function deleteMetadata( $pageId = null ) {
+ if( is_null($pageId) ) {
+ $pageId = $this->mPageId;
+ }
+
+ // $pageId can be an array or a single value.
+
+ $dbw->begin();
+ $dbw->delete(
+ 'pagetriage_page_tags',
+ array( 'ptrpt_page_id' => $pageId ),
+ __METHOD__,
+ array()
+ );
+
+ $dbw->delete(
+ 'pagetriage_page',
+ array( 'ptrp_page_id' => $pageId ),
+ __METHOD__,
+ array()
+ );
+
+ $dbw->delete(
+ 'pagetriage_log',
+ array( 'ptrl_page_id' => $pageId ),
+ __METHOD__,
+ array()
+ );
+
+ // also remove it from the cache
+ $this->flushMetadataFromCache( $pageId );
+ $dbw->commit();
+
+ return true;
+ }
+
+ /**
* Flush the metadata in cache
* @param $pageId - page id to be flushed, if null is provided, all
* page id in $this->mPageId will be flushed
Deleted: trunk/extensions/PageTriage/sql/PageTriage.sql
===================================================================
--- trunk/extensions/PageTriage/sql/PageTriage.sql 2012-03-22 00:32:21 UTC
(rev 114418)
+++ trunk/extensions/PageTriage/sql/PageTriage.sql 2012-03-22 00:56:23 UTC
(rev 114419)
@@ -1,30 +0,0 @@
-
--- mapping table for users to revisions
--- this information persists forever.
-CREATE TABLE /*_*/pagetriage (
- ptr_user int UNSIGNED NOT NULL,
- ptr_recentchanges_id int NOT NULL,
- ptr_timestamp varbinary(14) NOT NULL
-) /*$wgDBTableOptions*/;
-
-CREATE UNIQUE INDEX /*i*/ptr_user_rc ON /*_*/pagetriage
(ptr_user,ptr_recentchanges_id);
-
--- this stores when a page was checked. we'll be interested in that sometimes.
-CREATE INDEX /*i*/ptr_timestamp ON /*_*/pagetriage (ptr_timestamp);
-
--- This table exists to prevent concurrency problems when multiple people are
doing
--- page triage at the same time.
--- Unlike the above table, this one has rows deleted from it regularly.
--- If it's cleared, it'll lead to edit conflicts for a few minutes but it's
not a big deal.
-CREATE TABLE /*_*/pagetriage_checkouts (
- ptc_id int UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
- ptc_user int UNSIGNED NOT NULL,
- ptc_recentchanges_id int NOT NULL,
- ptc_timestamp varbinary(14) NOT NULL
-) /*$wgDBTableOptions*/;
-
--- this index is for retrieving data
-CREATE INDEX /*i*/ptc_user_rc ON /*_*/pagetriage_checkouts
(ptc_user,ptc_recentchanges_id);
-
--- this index is for enforcing one checkout per page.
-CREATE UNIQUE INDEX /*i*/ptc_recentchanges_id ON /*_*/pagetriage_checkouts
(ptc_recentchanges_id);
Modified:
trunk/extensions/PageTriage/tests/phpunit/ApiPageTriageGetMetadataTest.php
===================================================================
--- trunk/extensions/PageTriage/tests/phpunit/ApiPageTriageGetMetadataTest.php
2012-03-22 00:32:21 UTC (rev 114418)
+++ trunk/extensions/PageTriage/tests/phpunit/ApiPageTriageGetMetadataTest.php
2012-03-22 00:56:23 UTC (rev 114419)
@@ -0,0 +1,34 @@
+<?php
+/**
+ * Tests for ApiPageTriageGetMetadata class
+ *
+ * @group EditorEngagement
+ * @author Ian Baker
+ */
+class ApiPageTriageGetMetadataTest extends MediaWikiTestCase {
+
+ protected $pageTriage;
+
+ protected function setUp() {
+ parent::setUp();
+
+ // Insert some made up articles into the database
+ }
+
+ protected function tearDown() {
+ parent::tearDown();
+
+ // Remove the made up articles
+ }
+
+ public function testGetMetadata() {
+ $pageId = 1; // TODO: make a test page, then fetch it here.
+
+ list( $result, $request, $session ) = $this->doApiRequest(
array(
+ 'action' => 'pagetriagegetmetadata',
+ 'page_id' => $pageId) );
+
+
+ }
+
+}
Deleted: trunk/extensions/PageTriage/tests/phpunit/ApiQueryPageTriageTest.php
===================================================================
Modified: trunk/extensions/PageTriage/tests/phpunit/ArticleMetadataTest.php
===================================================================
--- trunk/extensions/PageTriage/tests/phpunit/ArticleMetadataTest.php
2012-03-22 00:32:21 UTC (rev 114418)
+++ trunk/extensions/PageTriage/tests/phpunit/ArticleMetadataTest.php
2012-03-22 00:56:23 UTC (rev 114419)
@@ -0,0 +1,30 @@
+<?php
+/**
+ * Tests for ArticleMetadata class
+ *
+ * @group EditorEngagement
+ * @author Ian Baker
+ */
+class ArticleMetadataTest extends MediaWikiTestCase {
+
+ protected $pageTriage;
+
+ protected function setUp() {
+ parent::setUp();
+
+ $title = Title::newFromText( "Some test article" );
+ $page = WikiPage::factory( $title );
+ }
+
+ protected function tearDown() {
+ parent::tearDown();
+
+ }
+
+ public function testDeleteMetadata() {
+ // TODO: delete an article's metadata
+
+ return true;
+ }
+
+}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs