Index: trunk/extensions/PageTriage/api/ApiPageTriageList.php |
— | — | @@ -0,0 +1,106 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * API module to generate a list of pages to triage |
| 5 | + * |
| 6 | + * @ingroup API |
| 7 | + * @ingroup Extensions |
| 8 | + */ |
| 9 | +class ApiPageTriageList extends ApiBase { |
| 10 | + |
| 11 | + // Holds the various options for filtering the list |
| 12 | + protected $opts; |
| 13 | + |
| 14 | + public function execute() { |
| 15 | + |
| 16 | + // Get the API parameters and store them |
| 17 | + $this->opts = $this->extractRequestParams(); |
| 18 | + |
| 19 | + // Retrieve the list of page IDs |
| 20 | + $pages = $this->getPageIds(); |
| 21 | + $pages = implode( ', ', $pages ); |
| 22 | + |
| 23 | + // Output the results |
| 24 | + $result = array( 'result' => 'success', 'pages' => $pages ); |
| 25 | + $this->getResult()->addValue( null, $this->getModuleName(), $result ); |
| 26 | + } |
| 27 | + |
| 28 | + /** |
| 29 | + * Return all the page ids in PageTraige matching the specified filters |
| 30 | + * @return an array of ids |
| 31 | + */ |
| 32 | + protected function getPageIds() { |
| 33 | + |
| 34 | + // Initialize required variables |
| 35 | + $pages = array(); |
| 36 | + $conds = array(); |
| 37 | + $options = array(); |
| 38 | + |
| 39 | + // Database setup |
| 40 | + $dbr = wfGetDB( DB_SLAVE ); |
| 41 | + |
| 42 | + // If a limit was specified, limit the results to that number |
| 43 | + if ( $this->opts['limit'] ) { |
| 44 | + $options = array( 'LIMIT' => $this->opts['limit'] ); |
| 45 | + } |
| 46 | + |
| 47 | + // TODO: Handle filtering options |
| 48 | + |
| 49 | + // Pull page IDs from database |
| 50 | + $res = $dbr->select( |
| 51 | + 'pagetriage_page', |
| 52 | + 'ptrp_page_id', |
| 53 | + $conds, |
| 54 | + __METHOD__, |
| 55 | + $options |
| 56 | + ); |
| 57 | + |
| 58 | + // Loop through result set and return ids |
| 59 | + foreach ( $res as $row ) { |
| 60 | + $pages[] = $row->ptrp_page_id; |
| 61 | + } |
| 62 | + |
| 63 | + return $pages; |
| 64 | + } |
| 65 | + |
| 66 | + public function getAllowedParams() { |
| 67 | + return array( |
| 68 | + 'showbots' => array( |
| 69 | + ApiBase::PARAM_TYPE => 'boolean', |
| 70 | + ), |
| 71 | + 'showredirs' => array( |
| 72 | + ApiBase::PARAM_TYPE => 'boolean', |
| 73 | + ), |
| 74 | + 'limit' => array( |
| 75 | + ApiBase::PARAM_DFLT => '5000', |
| 76 | + ApiBase::PARAM_TYPE => 'integer', |
| 77 | + ), |
| 78 | + 'namespace' => array( |
| 79 | + ApiBase::PARAM_DFLT => '0', |
| 80 | + ApiBase::PARAM_TYPE => 'integer', |
| 81 | + ), |
| 82 | + ); |
| 83 | + } |
| 84 | + |
| 85 | + public function getParamDescription() { |
| 86 | + return array( |
| 87 | + 'showbots' => 'Whether to include bot edits or not', |
| 88 | + 'showredirs' => 'Whether to include redirects or not', |
| 89 | + 'limit' => 'The maximum number of results to return', |
| 90 | + 'namespace' => 'What namespace to pull pages from', |
| 91 | + ); |
| 92 | + } |
| 93 | + |
| 94 | + public function getDescription() { |
| 95 | + return 'Get a list of page IDs for building a PageTriage queue.'; |
| 96 | + } |
| 97 | + |
| 98 | + public function getExamples() { |
| 99 | + return array( |
| 100 | + 'api.php?action=pagetriagelist&limit=1000&namespace=0', |
| 101 | + ); |
| 102 | + } |
| 103 | + |
| 104 | + public function getVersion() { |
| 105 | + return __CLASS__ . ': $Id: ApiPageTriageList.php $'; |
| 106 | + } |
| 107 | +} |
Property changes on: trunk/extensions/PageTriage/api/ApiPageTriageList.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 108 | + native |
Index: trunk/extensions/PageTriage/PageTriage.php |
— | — | @@ -60,6 +60,7 @@ |
61 | 61 | $wgAutoloadClasses['PageTriageHooks'] = $dir . 'PageTriage.hooks.php'; |
62 | 62 | |
63 | 63 | $wgAutoloadClasses['ApiQueryPageTriage'] = $dir . 'api/ApiQueryPageTriage.php'; |
| 64 | +$wgAutoloadClasses['ApiPageTriageList'] = $dir . 'api/ApiPageTriageList.php'; |
64 | 65 | $wgAutoloadClasses['ApiPageTriageGetMetadata'] = $dir . 'api/ApiPageTriageGetMetadata.php'; |
65 | 66 | |
66 | 67 | // custom exceptions |
— | — | @@ -69,6 +70,7 @@ |
70 | 71 | |
71 | 72 | // api modules |
72 | 73 | $wgAPIModules['pagetriage'] = 'ApiQueryPageTriage'; |
| 74 | +$wgAPIModules['pagetriagelist'] = 'ApiPageTriageList'; |
73 | 75 | $wgAPIModules['pagetriagegetmetadata'] = 'ApiPageTriageGetMetadata'; |
74 | 76 | |
75 | 77 | // hooks |