r95351 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r95350‎ | r95351 | r95352 >
Date:23:20, 23 August 2011
Author:johnduhart
Status:ok
Tags:
Comment:
(bug 29396) Adds API module to retrieve the namespace IDs and quality categories. Patch by Beau
Modified paths:
  • /trunk/extensions/ProofreadPage/ApiQueryProofread.php (modified) (history)
  • /trunk/extensions/ProofreadPage/ApiQueryProofreadInfo.php (added) (history)
  • /trunk/extensions/ProofreadPage/ProofreadPage.php (modified) (history)
  • /trunk/extensions/ProofreadPage/ProofreadPage_body.php (modified) (history)

Diff [purge]

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
1117 + native
Index: trunk/extensions/ProofreadPage/ProofreadPage.php
@@ -48,6 +48,10 @@
4949 $wgAutoloadClasses['ApiQueryProofread'] = $dir . 'ApiQueryProofread.php';
5050 $wgAPIPropModules['proofread'] = 'ApiQueryProofread';
5151
 52+# api proofreadinfo
 53+$wgAutoloadClasses['ApiQueryProofreadInfo'] = $dir . 'ApiQueryProofreadInfo.php';
 54+$wgAPIMetaModules['proofreadinfo'] = 'ApiQueryProofreadInfo';
 55+
5256 # Group allowed to modify pagequality
5357 $wgGroupPermissions['user']['pagequality'] = true;
5458
Index: trunk/extensions/ProofreadPage/ProofreadPage_body.php
@@ -25,6 +25,37 @@
2626 /* Parser object for index pages */
2727 private static $index_parser = null;
2828
 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 */
2960 private static function getPageAndIndexNamespace() {
3061 static $res = null;
3162 if ( $res === null ) {
Index: trunk/extensions/ProofreadPage/ApiQueryProofread.php
@@ -29,10 +29,7 @@
3030 return true;
3131 }
3232
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();
3734 $pageIds = array();
3835 foreach ( $pages AS $pageId => $title ) {
3936 if ( $title->getNamespace() == $pageNamespaceId ) {

Status & tagging log