Index: trunk/extensions/ProofreadPage/ApiQueryProofreadInfo.php |
— | — | @@ -0,0 +1,115 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Created on August 21, 2011 |
| 5 | + * |
| 6 | + * This program is free software; you can redistribute it and/or modify |
| 7 | + * it under the terms of the GNU General Public License as published by |
| 8 | + * the Free Software Foundation; either version 2 of the License, or |
| 9 | + * (at your option) any later version. |
| 10 | + * |
| 11 | + * This program is distributed in the hope that it will be useful, |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | + * GNU General Public License for more details. |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU General Public License along |
| 17 | + * with this program; if not, write to the Free Software Foundation, Inc., |
| 18 | + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 19 | + * http://www.gnu.org/copyleft/gpl.html |
| 20 | + */ |
| 21 | + |
| 22 | +/** |
| 23 | + * A query action to return meta information about the proofread extension. |
| 24 | + * |
| 25 | + * @ingroup API |
| 26 | + */ |
| 27 | +class ApiQueryProofreadInfo extends ApiQueryBase { |
| 28 | + |
| 29 | + public function __construct( $query, $moduleName ) { |
| 30 | + parent::__construct( $query, $moduleName, 'pi' ); |
| 31 | + } |
| 32 | + |
| 33 | + public function execute() { |
| 34 | + $params = $this->extractRequestParams(); |
| 35 | + $prop = array_flip( $params['prop'] ); |
| 36 | + |
| 37 | + if ( isset( $prop['namespaces'] ) ) { |
| 38 | + $this->appendNamespaces(); |
| 39 | + } |
| 40 | + |
| 41 | + if ( isset( $prop['qualitylevels'] ) ) { |
| 42 | + $this->appendQualityLevels(); |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + protected function appendNamespaces() { |
| 47 | + $data = array(); |
| 48 | + |
| 49 | + $index = ProofreadPage::getIndexNamespaceId(); |
| 50 | + if ( $index != null ) { |
| 51 | + $data['index']['id'] = $index; |
| 52 | + } |
| 53 | + |
| 54 | + $page = ProofreadPage::getPageNamespaceId(); |
| 55 | + if ( $page != null ) { |
| 56 | + $data['page']['id'] = $page; |
| 57 | + } |
| 58 | + |
| 59 | + return $this->getResult()->addValue( 'query', 'proofreadnamespaces', $data ); |
| 60 | + } |
| 61 | + |
| 62 | + protected function appendQualityLevels() { |
| 63 | + $data = array(); |
| 64 | + for ( $i = 0; $i < 5; $i++ ) { |
| 65 | + $level = array(); |
| 66 | + $level['id'] = $i; |
| 67 | + $level['category'] = wfMsgForContent( "proofreadpage_quality{$i}_category" ); |
| 68 | + $data[$i] = $level; |
| 69 | + } |
| 70 | + $this->getResult()->setIndexedTagName( $data, 'level' ); |
| 71 | + return $this->getResult()->addValue( 'query', 'proofreadqualitylevels', $data ); |
| 72 | + } |
| 73 | + |
| 74 | + public function getCacheMode( $params ) { |
| 75 | + return 'public'; |
| 76 | + } |
| 77 | + |
| 78 | + public function getAllowedParams() { |
| 79 | + return array( |
| 80 | + 'prop' => array( |
| 81 | + ApiBase::PARAM_DFLT => 'namespaces|qualitylevels', |
| 82 | + ApiBase::PARAM_ISMULTI => true, |
| 83 | + ApiBase::PARAM_TYPE => array( |
| 84 | + 'namespaces', |
| 85 | + 'qualitylevels', |
| 86 | + ) |
| 87 | + ), |
| 88 | + ); |
| 89 | + } |
| 90 | + |
| 91 | + public function getParamDescription() { |
| 92 | + return array( |
| 93 | + 'prop' => array( |
| 94 | + 'Which proofread properties to get:', |
| 95 | + ' namespaces - Information about Page and Index namespaces', |
| 96 | + ' qualitylevels - List of proofread quality levels' |
| 97 | + ) |
| 98 | + ); |
| 99 | + } |
| 100 | + |
| 101 | + public function getDescription() { |
| 102 | + return 'Return information about configuration of ProofreadPage extension'; |
| 103 | + } |
| 104 | + |
| 105 | + public function getExamples() { |
| 106 | + return array( |
| 107 | + 'api.php?action=query&meta=proofreadinfo', |
| 108 | + 'api.php?action=query&meta=proofreadinfo&piprop=namespaces|qualitylevels', |
| 109 | + 'api.php?action=query&meta=proofreadinfo&piprop=namespaces', |
| 110 | + ); |
| 111 | + } |
| 112 | + |
| 113 | + public function getVersion() { |
| 114 | + return __CLASS__ . ': $Id$'; |
| 115 | + } |
| 116 | +} |
Property changes on: trunk/extensions/ProofreadPage/ApiQueryProofreadInfo.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 117 | + native |
Index: trunk/extensions/ProofreadPage/ProofreadPage.php |
— | — | @@ -48,6 +48,10 @@ |
49 | 49 | $wgAutoloadClasses['ApiQueryProofread'] = $dir . 'ApiQueryProofread.php'; |
50 | 50 | $wgAPIPropModules['proofread'] = 'ApiQueryProofread'; |
51 | 51 | |
| 52 | +# api proofreadinfo |
| 53 | +$wgAutoloadClasses['ApiQueryProofreadInfo'] = $dir . 'ApiQueryProofreadInfo.php'; |
| 54 | +$wgAPIMetaModules['proofreadinfo'] = 'ApiQueryProofreadInfo'; |
| 55 | + |
52 | 56 | # Group allowed to modify pagequality |
53 | 57 | $wgGroupPermissions['user']['pagequality'] = true; |
54 | 58 | |
Index: trunk/extensions/ProofreadPage/ProofreadPage_body.php |
— | — | @@ -25,6 +25,37 @@ |
26 | 26 | /* Parser object for index pages */ |
27 | 27 | private static $index_parser = null; |
28 | 28 | |
| 29 | + /** |
| 30 | + * Returns id of Page namespace. |
| 31 | + * |
| 32 | + * @return integer namespace id |
| 33 | + */ |
| 34 | + public static function getPageNamespaceId() { |
| 35 | + static $namespace = null; |
| 36 | + if ( $namespace !== null ) { |
| 37 | + return $namespace; |
| 38 | + } |
| 39 | + $namespaceText = strtolower( wfMsgForContent( 'proofreadpage_namespace' ) ); |
| 40 | + $namespace = MWNamespace::getCanonicalIndex( $namespaceText ); |
| 41 | + return $namespace; |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * Returns id of Index namespace. |
| 46 | + * |
| 47 | + * @return integer namespace id |
| 48 | + */ |
| 49 | + public static function getIndexNamespaceId() { |
| 50 | + static $namespace = null; |
| 51 | + if ( $namespace !== null ) { |
| 52 | + return $namespace; |
| 53 | + } |
| 54 | + $namespaceText = strtolower( wfMsgForContent( 'proofreadpage_index_namespace' ) ); |
| 55 | + $namespace = MWNamespace::getCanonicalIndex( $namespaceText ); |
| 56 | + return $namespace; |
| 57 | + } |
| 58 | + |
| 59 | + /** @deprecated */ |
29 | 60 | private static function getPageAndIndexNamespace() { |
30 | 61 | static $res = null; |
31 | 62 | if ( $res === null ) { |
Index: trunk/extensions/ProofreadPage/ApiQueryProofread.php |
— | — | @@ -29,10 +29,7 @@ |
30 | 30 | return true; |
31 | 31 | } |
32 | 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 ); |
| 33 | + $pageNamespaceId = ProofreadPage::getPageNamespaceId(); |
37 | 34 | $pageIds = array(); |
38 | 35 | foreach ( $pages AS $pageId => $title ) { |
39 | 36 | if ( $title->getNamespace() == $pageNamespaceId ) { |