Index: trunk/extensions/PageTriage/README |
— | — | @@ -5,8 +5,6 @@ |
6 | 6 | It is very focused on the Wikipedia article creation workflow, though it could probably be adapted |
7 | 7 | for use on other wikis. |
8 | 8 | |
9 | | -PageTriage is licensed under the same terms as MediaWiki itself. |
10 | | - |
11 | 9 | PageTriage by: |
12 | 10 | @author Ryan Kaldari <rkaldari@wikimedia.org> |
13 | 11 | @author Benny Situ <bsitu@wikimedia.org> |
Index: trunk/extensions/PageTriage/PageTriage.php |
— | — | @@ -87,16 +87,6 @@ |
88 | 88 | */ |
89 | 89 | function efPageTriageSchemaUpdates( $updater = null ) { |
90 | 90 | $base = dirname( __FILE__ ) . "/sql"; |
91 | | - if ( $updater === null ) { |
92 | | - global $wgDBtype, $wgExtNewTables, $wgExtNewFields; |
93 | | - if ( $wgDBtype == 'mysql' ) { |
94 | | - $wgExtNewTables[] = array( 'pagetriage', $base . '/PageTriage.sql' ); |
95 | | - } |
96 | | - } else { |
97 | | - if ( $updater->getDB()->getType() == 'mysql' ) { |
98 | | - $updater->addExtensionTable( 'pagetriage', "$base/PageTriage.sql" ); |
99 | | - } |
100 | | - } |
101 | 91 | $updater->addExtensionTable( 'pagetriage_tags', $base . '/PageTriageTags.sql' ); |
102 | 92 | $updater->addExtensionTable( 'pagetriage_page_tags', $base . '/PageTriagePageTags.sql' ); |
103 | 93 | $updater->addExtensionTable( 'pagetriage_page', $base . '/PageTriagePage.sql' ); |
— | — | @@ -113,6 +103,8 @@ |
114 | 104 | function efPageTriageUnitTests( &$files ) { |
115 | 105 | $base = dirname( __FILE__ ) . '/tests'; |
116 | 106 | $files[] = $base . '/phpunit/SpecialPageTriageTest.php'; |
| 107 | + $files[] = $base . '/phpunit/ArticleMetadataTest.php'; |
| 108 | + $files[] = $base . '/phpunit/ApiPageTriageGetMetadataTest.php'; |
117 | 109 | return true; |
118 | 110 | } |
119 | 111 | |
Index: trunk/extensions/PageTriage/sql/PageTriage.sql |
— | — | @@ -1,30 +0,0 @@ |
2 | | - |
3 | | -CREATE TABLE /*_*/pagetriage ( |
4 | | - ptr_user int UNSIGNED NOT NULL, |
5 | | - ptr_recentchanges_id int NOT NULL, |
6 | | - ptr_timestamp varbinary(14) NOT NULL |
7 | | -) /*$wgDBTableOptions*/; |
8 | | - |
9 | | -CREATE UNIQUE INDEX /*i*/ptr_user_rc ON /*_*/pagetriage (ptr_user,ptr_recentchanges_id); |
10 | | - |
11 | | -CREATE INDEX /*i*/ptr_timestamp ON /*_*/pagetriage (ptr_timestamp); |
12 | | - |
13 | | -CREATE TABLE /*_*/pagetriage_checkouts ( |
14 | | - ptc_id int UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT, |
15 | | - ptc_user int UNSIGNED NOT NULL, |
16 | | - ptc_recentchanges_id int NOT NULL, |
17 | | - ptc_timestamp varbinary(14) NOT NULL |
18 | | -) /*$wgDBTableOptions*/; |
19 | | - |
20 | | -CREATE INDEX /*i*/ptc_user_rc ON /*_*/pagetriage_checkouts (ptc_user,ptc_recentchanges_id); |
21 | | - |
22 | | -CREATE UNIQUE INDEX /*i*/ptc_recentchanges_id ON /*_*/pagetriage_checkouts (ptc_recentchanges_id); |
Index: trunk/extensions/PageTriage/PageTriage.hooks.php |
— | — | @@ -88,6 +88,22 @@ |
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
| 92 | + * Remove the metadata we added when the article is deleted. |
| 93 | + * |
| 94 | + * 'ArticleDeleteComplete': after an article is deleted |
| 95 | + * $article: the WikiPage that was deleted |
| 96 | + * $user: the user that deleted the article |
| 97 | + * $reason: the reason the article was deleted |
| 98 | + * $id: id of the article that was deleted |
| 99 | + */ |
| 100 | + public static function onArticleDeleteComplete( $article, $user, $reason, $id ) { |
| 101 | + // delete everything |
| 102 | + $articleMetadata = new ArticleMetadata( array( $id ) ); |
| 103 | + $articleMetadata->deleteMetadata(); |
| 104 | + return true; |
| 105 | + } |
| 106 | + |
| 107 | + /** |
92 | 108 | * Add page to page triage queue |
93 | 109 | */ |
94 | 110 | private static function addToPageTriageQueue( $pageId ) { |
Index: trunk/extensions/PageTriage/tests/phpunit/ApiPageTriageGetMetadataTest.php |
— | — | @@ -0,0 +1,34 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Tests for ApiPageTriageGetMetadata class |
| 5 | + * |
| 6 | + * @group EditorEngagement |
| 7 | + * @author Ian Baker |
| 8 | + */ |
| 9 | +class ApiPageTriageGetMetadataTest extends MediaWikiTestCase { |
| 10 | + |
| 11 | + protected $pageTriage; |
| 12 | + |
| 13 | + protected function setUp() { |
| 14 | + parent::setUp(); |
| 15 | + |
| 16 | + // Insert some made up articles into the database |
| 17 | + } |
| 18 | + |
| 19 | + protected function tearDown() { |
| 20 | + parent::tearDown(); |
| 21 | + |
| 22 | + // Remove the made up articles |
| 23 | + } |
| 24 | + |
| 25 | + public function testGetMetadata() { |
| 26 | + $pageId = 1; // TODO: make a test page, then fetch it here. |
| 27 | + |
| 28 | + list( $result, $request, $session ) = $this->doApiRequest( array( |
| 29 | + 'action' => 'pagetriagegetmetadata', |
| 30 | + 'page_id' => $pageId) ); |
| 31 | + |
| 32 | + |
| 33 | + } |
| 34 | + |
| 35 | +} |
Index: trunk/extensions/PageTriage/tests/phpunit/ArticleMetadataTest.php |
— | — | @@ -0,0 +1,30 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Tests for ArticleMetadata class |
| 5 | + * |
| 6 | + * @group EditorEngagement |
| 7 | + * @author Ian Baker |
| 8 | + */ |
| 9 | +class ArticleMetadataTest extends MediaWikiTestCase { |
| 10 | + |
| 11 | + protected $pageTriage; |
| 12 | + |
| 13 | + protected function setUp() { |
| 14 | + parent::setUp(); |
| 15 | + |
| 16 | + $title = Title::newFromText( "Some test article" ); |
| 17 | + $page = WikiPage::factory( $title ); |
| 18 | + } |
| 19 | + |
| 20 | + protected function tearDown() { |
| 21 | + parent::tearDown(); |
| 22 | + |
| 23 | + } |
| 24 | + |
| 25 | + public function testDeleteMetadata() { |
| 26 | + // TODO: delete an article's metadata |
| 27 | + |
| 28 | + return true; |
| 29 | + } |
| 30 | + |
| 31 | +} |
Index: trunk/extensions/PageTriage/includes/ArticleMetadata.php |
— | — | @@ -51,6 +51,47 @@ |
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
| 55 | + * Delete all the metadata for an article |
| 56 | + * |
| 57 | + * @param $pageId - the page id to be deleted |
| 58 | + */ |
| 59 | + protected function deleteMetadata( $pageId = null ) { |
| 60 | + if( is_null($pageId) ) { |
| 61 | + $pageId = $this->mPageId; |
| 62 | + } |
| 63 | + |
| 64 | + // $pageId can be an array or a single value. |
| 65 | + |
| 66 | + $dbw->begin(); |
| 67 | + $dbw->delete( |
| 68 | + 'pagetriage_page_tags', |
| 69 | + array( 'ptrpt_page_id' => $pageId ), |
| 70 | + __METHOD__, |
| 71 | + array() |
| 72 | + ); |
| 73 | + |
| 74 | + $dbw->delete( |
| 75 | + 'pagetriage_page', |
| 76 | + array( 'ptrp_page_id' => $pageId ), |
| 77 | + __METHOD__, |
| 78 | + array() |
| 79 | + ); |
| 80 | + |
| 81 | + $dbw->delete( |
| 82 | + 'pagetriage_log', |
| 83 | + array( 'ptrl_page_id' => $pageId ), |
| 84 | + __METHOD__, |
| 85 | + array() |
| 86 | + ); |
| 87 | + |
| 88 | + // also remove it from the cache |
| 89 | + $this->flushMetadataFromCache( $pageId ); |
| 90 | + $dbw->commit(); |
| 91 | + |
| 92 | + return true; |
| 93 | + } |
| 94 | + |
| 95 | + /** |
55 | 96 | * Flush the metadata in cache |
56 | 97 | * @param $pageId - page id to be flushed, if null is provided, all |
57 | 98 | * page id in $this->mPageId will be flushed |
Index: trunk/extensions/PageTriage/api/ApiQueryPageTriage.php |
— | — | @@ -1,136 +0,0 @@ |
2 | | -<?php |
3 | | -/** |
4 | | - * PageTriage extension API |
5 | | - * |
6 | | - * Copyright © 2011 Wikimedia Foundation and Ian Baker <ian@wikimedia.org> |
7 | | - * Based on code by Victor Vasiliev, Bryan Tong Minh, Roan Kattouw, and Alex Z. |
8 | | - * |
9 | | - * This program is free software; you can redistribute it and/or modify |
10 | | - * it under the terms of the GNU General Public License as published by |
11 | | - * the Free Software Foundation; either version 2 of the License, or |
12 | | - * (at your option) any later version. |
13 | | - * |
14 | | - * This program is distributed in the hope that it will be useful, |
15 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | | - * GNU General Public License for more details. |
18 | | - * |
19 | | - * You should have received a copy of the GNU General Public License along |
20 | | - * with this program; if not, write to the Free Software Foundation, Inc., |
21 | | - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
22 | | - * http://www.gnu.org/copyleft/gpl.html |
23 | | - */ |
24 | | - |
25 | | -/** |
26 | | - * Query module to checkout and checkin pages for PageTriage |
27 | | - * |
28 | | - * @ingroup API |
29 | | - * @ingroup Extensions |
30 | | - */ |
31 | | -class ApiQueryPageTriage extends ApiBase { |
32 | | - |
33 | | - public function __construct( $query, $moduleName ) { |
34 | | - parent::__construct( $query, $moduleName, 'ptr' ); |
35 | | - } |
36 | | - |
37 | | - public function execute() { |
38 | | - # get the current user. |
39 | | - $context = $this->createContext(); |
40 | | - $userId = $context->getUser()->getId(); |
41 | | - |
42 | | - $params = $this->extractRequestParams(); |
43 | | - $mode = $params['mode']; |
44 | | - |
45 | | - if( !preg_match('/^\D+$/', $params['id'] ) ) { |
46 | | - $this->dieUsageMsg( array( 'pagetriage-api-invalidid', $params['id'] ) ); |
47 | | - } |
48 | | - |
49 | | - // expire old checkouts. |
50 | | - // TODO: make the time configurable. |
51 | | - wfDebug( __METHOD__ . " expiring PageTriage checkouts older than 15 minutes\n" ); |
52 | | - $dbw = wfGetDB( DB_MASTER ); |
53 | | - $dbw->delete( |
54 | | - 'pagetriage_checkouts', |
55 | | - 'ptc_timestamp < ' . $dbw->timestamp( time() - 15 * 60 ), |
56 | | - __METHOD__ |
57 | | - ); |
58 | | - |
59 | | - $res = $this->getResult(); |
60 | | - |
61 | | - if( $mode === 'checkout' ) { |
62 | | - // the unique index on ptc_recentchanges_id ensures that this will fail if there's an existing row. |
63 | | - // doing it this way allows for atomic checking w/o starting a transaction. |
64 | | - // |
65 | | - // this happens on the master because we expect even a small amount of lag to |
66 | | - // entirely break it. it's a small table and a small number of people will be using it. |
67 | | - $dbw->insert( |
68 | | - 'pagetriage_checkouts', |
69 | | - array( |
70 | | - 'ptc_user' => $userId, |
71 | | - 'ptc_recentchanges_id' => $params['id'], |
72 | | - 'ptc_timestamp' => $dbw->timestamp() |
73 | | - ), |
74 | | - __METHOD__ |
75 | | - ); |
76 | | - |
77 | | - // this won't be set if the insert failed. |
78 | | - $checkoutId = $dbw->insertId(); |
79 | | - |
80 | | - if( $checkoutId ) { |
81 | | - $res->addValue( 'pagetriage', 'checkout-id', $checkoutId ); |
82 | | - $res->addValue( 'pagetriage', 'result', 'ok' ); |
83 | | - } else { |
84 | | - $res->addValue( 'pagetriage', 'result', 'already-checked-out' ); |
85 | | - } |
86 | | - } elseif ( $mode === 'checkin' ) { |
87 | | - // delete this user's row, if any. |
88 | | - $dbw->delete( |
89 | | - 'pagetriage_checkouts', |
90 | | - array( |
91 | | - 'ptc_user' => $userId, |
92 | | - 'ptc_recentchanges_id' => $params['id'], |
93 | | - ), |
94 | | - __METHOD__ |
95 | | - ); |
96 | | - |
97 | | - $res->addValue( 'pagetriage', 'result', 'ok' ); |
98 | | - } |
99 | | - } |
100 | | - |
101 | | - public function getAllowedParams() { |
102 | | - return array( |
103 | | - 'id' => array( |
104 | | - ApiBase::PARAM_TYPE => 'integer', |
105 | | - ), |
106 | | - 'mode' => array( |
107 | | - ApiBase::PARAM_DFLT => 'checkout', |
108 | | - ApiBase::PARAM_ISMULTI => false, |
109 | | - ApiBase::PARAM_TYPE => array( |
110 | | - 'checkout', 'checkin', |
111 | | - ), |
112 | | - ) |
113 | | - ); |
114 | | - } |
115 | | - |
116 | | - public function getParamDescription() { |
117 | | - return array( |
118 | | - 'id' => 'The ID of the recentchanges entry you\'d like to check out/in', |
119 | | - 'mode' => 'What you\'d like to do', |
120 | | - ); |
121 | | - } |
122 | | - |
123 | | - public function getDescription() { |
124 | | - return 'Check out or check in a page for page triage.'; |
125 | | - } |
126 | | - |
127 | | - public function getExamples() { |
128 | | - return array( |
129 | | - 'api.php?action=pagetriage&id=12345', |
130 | | - 'api.php?action=pagetriage&id=12345&mode=checkin', |
131 | | - ); |
132 | | - } |
133 | | - |
134 | | - public function getVersion() { |
135 | | - return __CLASS__ . ': $Id: $'; |
136 | | - } |
137 | | -} |