Index: trunk/extensions/ProofreadPage/ApiQueryProofread.php |
— | — | @@ -0,0 +1,104 @@ |
| 2 | +<?php |
| 3 | +/* |
| 4 | + * Created on August 8, 2011 |
| 5 | + * |
| 6 | + * API module for MediaWiki's Proofread extension |
| 7 | + * |
| 8 | + * This program is free software; you can redistribute it and/or modify |
| 9 | + * it under the terms of the GNU General Public License as published by |
| 10 | + * the Free Software Foundation; either version 2 of the License, or |
| 11 | + * (at your option) any later version. |
| 12 | + * |
| 13 | + * This program is distributed in the hope that it will be useful, |
| 14 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | + * GNU General Public License for more details. |
| 17 | + * |
| 18 | + * You should have received a copy of the GNU General Public License along |
| 19 | + * with this program; if not, write to the Free Software Foundation, Inc., |
| 20 | + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 21 | + * http://www.gnu.org/copyleft/gpl.html |
| 22 | + */ |
| 23 | + |
| 24 | +class ApiQueryProofread extends ApiQueryBase { |
| 25 | + |
| 26 | + public function execute() { |
| 27 | + $pageSet = $this->getPageSet(); |
| 28 | + $pages = $pageSet->getGoodTitles(); |
| 29 | + if ( !count( $pages ) ) { |
| 30 | + return true; |
| 31 | + } |
| 32 | + |
| 33 | + // Only include pages that can use the proofread tag |
| 34 | + // Why doesn't it strtolower in getCanonicalIndex? |
| 35 | + $pageNamespaceText = strtolower( wfMsgForContent( 'proofreadpage_namespace' ) ); |
| 36 | + $pageNamespaceId = MWNamespace::getCanonicalIndex( $pageNamespaceText ); |
| 37 | + $pageIds = array(); |
| 38 | + foreach ( $pages AS $pageId => $title ) { |
| 39 | + if ( $title->getNamespace() == $pageNamespaceId ) { |
| 40 | + $pageIds[] = $pageId; |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + if ( !count( $pageIds ) ) { |
| 45 | + return true; |
| 46 | + } |
| 47 | + |
| 48 | + // Determine the categories defined in MediaWiki: pages |
| 49 | + $qualityCategories = $qualityText = array(); |
| 50 | + for ( $i = 0; $i < 5; $i++ ) { |
| 51 | + $cat = Title::makeTitleSafe( NS_CATEGORY, wfMsgForContent( "proofreadpage_quality{$i}_category" ) ); |
| 52 | + if ( $cat ) { |
| 53 | + $qualityCategories[$i] = $cat->getPrefixedText(); |
| 54 | + $qualityText[$i] = $cat->getText(); |
| 55 | + } |
| 56 | + } |
| 57 | + $qualityLevels = array_flip( $qualityCategories ); |
| 58 | + |
| 59 | + // <Reedy> johnduhart, it'd seem sane rather than duplicating the functionality |
| 60 | + $params = new FauxRequest(array( |
| 61 | + 'action' => 'query', |
| 62 | + 'prop' => 'categories', |
| 63 | + 'pageids' => implode( '|', $pageIds ), |
| 64 | + 'clcategories' => implode( '|', $qualityCategories ), |
| 65 | + 'cllimit' => 'max' |
| 66 | + )); |
| 67 | + |
| 68 | + $api = new ApiMain($params); |
| 69 | + $api->execute(); |
| 70 | + $data = $api->getResultData(); |
| 71 | + unset( $api ); |
| 72 | + |
| 73 | + $result = $this->getResult(); |
| 74 | + foreach ( $data['query']['pages'] as $pageid => $data) { |
| 75 | + $pageQuality = $qualityLevels[ $data['categories'][0]['title'] ]; |
| 76 | + if ( $pageQuality === null ) { |
| 77 | + continue; |
| 78 | + } |
| 79 | + $val = array( 'quality' => $pageQuality, 'quality_text' => $qualityText[ $pageQuality ] ); |
| 80 | + $result->addValue( array( 'query', 'pages', $pageid ), 'proofread', $val ); |
| 81 | + } |
| 82 | + } |
| 83 | + |
| 84 | + public function getCacheMode( $params ) { |
| 85 | + return 'public'; |
| 86 | + } |
| 87 | + |
| 88 | + public function getAllowedParams() { |
| 89 | + return array(); |
| 90 | + } |
| 91 | + |
| 92 | + public function getDescription() { |
| 93 | + return 'Returns information about the current proofread status of the given pages.'; |
| 94 | + } |
| 95 | + |
| 96 | + protected function getExamples() { |
| 97 | + return array( |
| 98 | + 'api.php?action=query&generator=allpages&gapnamespace=104&prop=proofread' |
| 99 | + ); |
| 100 | + } |
| 101 | + |
| 102 | + public function getVersion() { |
| 103 | + return __CLASS__ . ': $Id$'; |
| 104 | + } |
| 105 | +} |
Property changes on: trunk/extensions/ProofreadPage/ApiQueryProofread.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 106 | + native |
Added: svn:keywords |
2 | 107 | + Id |
Index: trunk/extensions/ProofreadPage/ProofreadPage.php |
— | — | @@ -44,6 +44,10 @@ |
45 | 45 | $wgSpecialPages['PagesWithoutScans'] = 'PagesWithoutScans'; |
46 | 46 | $wgSpecialPageGroups['PagesWithoutScans'] = 'maintenance'; |
47 | 47 | |
| 48 | +# api prop |
| 49 | +$wgAutoloadClasses['ApiQueryProofread'] = $dir . 'ApiQueryProofread.php'; |
| 50 | +$wgAPIPropModules['proofread'] = 'ApiQueryProofread'; |
| 51 | + |
48 | 52 | # Group allowed to modify pagequality |
49 | 53 | $wgGroupPermissions['user']['pagequality'] = true; |
50 | 54 | |