From 604906deb5161684c3fab2b6fdcd0e7e6672cb89 Mon Sep 17 00:00:00 2001 From: Jack Phoenix Date: Tue, 23 Feb 2010 12:30:23 +0000 Subject: [PATCH] API: coding style cleanup, fix copyright symbol, more braces --- includes/api/ApiFeedWatchlist.php | 59 +++++++++++++++---------------- includes/api/ApiFormatBase.php | 47 +++++++++++++----------- includes/api/ApiFormatDbg.php | 10 +++--- includes/api/ApiFormatJson.php | 30 ++++++++-------- includes/api/ApiFormatPhp.php | 10 +++--- includes/api/ApiFormatRaw.php | 28 ++++++++------- includes/api/ApiFormatTxt.php | 10 +++--- includes/api/ApiFormatWddx.php | 35 +++++++++--------- 8 files changed, 119 insertions(+), 110 deletions(-) diff --git a/includes/api/ApiFeedWatchlist.php b/includes/api/ApiFeedWatchlist.php index 2fd2d7491b..f18cbe39f5 100644 --- a/includes/api/ApiFeedWatchlist.php +++ b/includes/api/ApiFeedWatchlist.php @@ -1,11 +1,11 @@ @gmail.com + * Copyright © 2006 Yuri Astrakhan @gmail.com * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -25,7 +25,7 @@ if ( !defined( 'MEDIAWIKI' ) ) { // Eclipse helper - will be ignored in production - require_once ( "ApiBase.php" ); + require_once( "ApiBase.php" ); } /** @@ -38,7 +38,7 @@ if ( !defined( 'MEDIAWIKI' ) ) { class ApiFeedWatchlist extends ApiBase { public function __construct( $main, $action ) { - parent :: __construct( $main, $action ); + parent::__construct( $main, $action ); } /** @@ -53,7 +53,6 @@ class ApiFeedWatchlist extends ApiBase { * Wrap the result as an RSS/Atom feed. */ public function execute() { - global $wgFeedClasses, $wgFeedLimit, $wgSitename, $wgContLanguageCode; try { @@ -64,13 +63,13 @@ class ApiFeedWatchlist extends ApiBase { $dbr = wfGetDB( DB_SLAVE ); // Prepare parameters for nested request - $fauxReqArr = array ( + $fauxReqArr = array( 'action' => 'query', 'meta' => 'siteinfo', 'siprop' => 'general', 'list' => 'watchlist', 'wlprop' => 'title|user|comment|timestamp', - 'wldir' => 'older', // reverse order - from newest to oldest + 'wldir' => 'older', // reverse order - from newest to oldest 'wlend' => $dbr->timestamp( $endTime ), // stop at this time 'wllimit' => ( 50 > $wgFeedLimit ) ? $wgFeedLimit : 50 ); @@ -83,12 +82,12 @@ class ApiFeedWatchlist extends ApiBase { } // Check for 'allrev' parameter, and if found, show all revisions to each page on wl. - if ( !is_null ( $params['allrev'] ) ) { + if ( !is_null( $params['allrev'] ) ) { $fauxReqArr['wlallrev'] = ''; } // Create the request - $fauxReq = new FauxRequest ( $fauxReqArr ); + $fauxReq = new FauxRequest( $fauxReqArr ); // Execute $module = new ApiMain( $fauxReq ); @@ -103,11 +102,11 @@ class ApiFeedWatchlist extends ApiBase { } $feedTitle = $wgSitename . ' - ' . wfMsgForContent( 'watchlist' ) . ' [' . $wgContLanguageCode . ']'; - $feedUrl = SpecialPage::getTitleFor( 'Watchlist' )->getFullUrl(); + $feedUrl = SpecialPage::getTitleFor( 'Watchlist' )->getFullURL(); $feed = new $wgFeedClasses[$params['feedformat']] ( $feedTitle, htmlspecialchars( wfMsgForContent( 'watchlist' ) ), $feedUrl ); - ApiFormatFeedWrapper :: setResult( $this->getResult(), $feed, $feedItems ); + ApiFormatFeedWrapper::setResult( $this->getResult(), $feed, $feedItems ); } catch ( Exception $e ) { @@ -115,7 +114,7 @@ class ApiFeedWatchlist extends ApiBase { $this->getMain()->setCacheMaxAge( 0 ); $feedTitle = $wgSitename . ' - Error - ' . wfMsgForContent( 'watchlist' ) . ' [' . $wgContLanguageCode . ']'; - $feedUrl = SpecialPage::getTitleFor( 'Watchlist' )->getFullUrl(); + $feedUrl = SpecialPage::getTitleFor( 'Watchlist' )->getFullURL(); $feedFormat = isset( $params['feedformat'] ) ? $params['feedformat'] : 'rss'; $feed = new $wgFeedClasses[$feedFormat] ( $feedTitle, htmlspecialchars( wfMsgForContent( 'watchlist' ) ), $feedUrl ); @@ -128,15 +127,15 @@ class ApiFeedWatchlist extends ApiBase { } $errorText = $e->getMessage(); - $feedItems[] = new FeedItem( "Error ($errorCode)", $errorText, "", "", "" ); - ApiFormatFeedWrapper :: setResult( $this->getResult(), $feed, $feedItems ); + $feedItems[] = new FeedItem( "Error ($errorCode)", $errorText, '', '', '' ); + ApiFormatFeedWrapper::setResult( $this->getResult(), $feed, $feedItems ); } } private function createFeedItem( $info ) { $titleStr = $info['title']; - $title = Title :: newFromText( $titleStr ); - $titleUrl = $title->getFullUrl(); + $title = Title::newFromText( $titleStr ); + $titleUrl = $title->getFullURL(); $comment = isset( $info['comment'] ) ? $info['comment'] : null; $timestamp = $info['timestamp']; $user = $info['user']; @@ -150,28 +149,28 @@ class ApiFeedWatchlist extends ApiBase { global $wgFeedClasses; $feedFormatNames = array_keys( $wgFeedClasses ); return array ( - 'feedformat' => array ( - ApiBase :: PARAM_DFLT => 'rss', - ApiBase :: PARAM_TYPE => $feedFormatNames + 'feedformat' => array( + ApiBase::PARAM_DFLT => 'rss', + ApiBase::PARAM_TYPE => $feedFormatNames ), - 'hours' => array ( - ApiBase :: PARAM_DFLT => 24, - ApiBase :: PARAM_TYPE => 'integer', - ApiBase :: PARAM_MIN => 1, - ApiBase :: PARAM_MAX => 72, + 'hours' => array( + ApiBase::PARAM_DFLT => 24, + ApiBase::PARAM_TYPE => 'integer', + ApiBase::PARAM_MIN => 1, + ApiBase::PARAM_MAX => 72, ), 'allrev' => null, - 'wlowner' => array ( - ApiBase :: PARAM_TYPE => 'user' + 'wlowner' => array( + ApiBase::PARAM_TYPE => 'user' ), - 'wltoken' => array ( - ApiBase :: PARAM_TYPE => 'string' + 'wltoken' => array( + ApiBase::PARAM_TYPE => 'string' ) ); } public function getParamDescription() { - return array ( + return array( 'feedformat' => 'The format of the feed', 'hours' => 'List pages modified within this many hours from now', 'allrev' => 'Include multiple revisions of the same page within given timeframe.', @@ -185,7 +184,7 @@ class ApiFeedWatchlist extends ApiBase { } protected function getExamples() { - return array ( + return array( 'api.php?action=feedwatchlist' ); } diff --git a/includes/api/ApiFormatBase.php b/includes/api/ApiFormatBase.php index d5f1ea4412..3ad1419d70 100644 --- a/includes/api/ApiFormatBase.php +++ b/includes/api/ApiFormatBase.php @@ -1,11 +1,11 @@ @gmail.com + * Copyright © 2006 Yuri Astrakhan @gmail.com * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -25,7 +25,7 @@ if ( !defined( 'MEDIAWIKI' ) ) { // Eclipse helper - will be ignored in production - require_once ( 'ApiBase.php' ); + require_once( 'ApiBase.php' ); } /** @@ -45,13 +45,14 @@ abstract class ApiFormatBase extends ApiBase { * @param $format string Format name */ public function __construct( $main, $format ) { - parent :: __construct( $main, $format ); + parent::__construct( $main, $format ); $this->mIsHtml = ( substr( $format, - 2, 2 ) === 'fm' ); // ends with 'fm' - if ( $this->mIsHtml ) + if ( $this->mIsHtml ) { $this->mFormat = substr( $format, 0, - 2 ); // remove ending 'fm' - else + } else { $this->mFormat = $format; + } $this->mFormat = strtoupper( $this->mFormat ); $this->mCleared = false; } @@ -125,8 +126,9 @@ abstract class ApiFormatBase extends ApiBase { // Some printers (ex. Feed) do their own header settings, // in which case $mime will be set to null - if ( is_null( $mime ) ) + if ( is_null( $mime ) ) { return; // skip any initialization + } header( "Content-Type: $mime; charset=utf-8" ); @@ -197,8 +199,7 @@ See complete documentation, or // For non-HTML output, clear all errors that might have been // displayed if display_errors=On // Do this only once, of course - if ( !$this->mCleared ) - { + if ( !$this->mCleared ) { ob_clean(); $this->mCleared = true; } @@ -228,11 +229,11 @@ See complete documentation, or } /** - * Prety-print various elements in HTML format, such as xml tags and - * URLs. This method also escapes characters like < - * @param $text string - * @return string - */ + * Pretty-print various elements in HTML format, such as xml tags and + * URLs. This method also escapes characters like < + * @param $text string + * @return string + */ protected function formatHTML( $text ) { global $wgUrlProtocols; @@ -254,12 +255,15 @@ See complete documentation, or $text = preg_replace( "#\\$[^<>\n]+\\$#", '\\0', $text ); } - /* Temporary fix for bad links in help messages. As a special case, + /** + * Temporary fix for bad links in help messages. As a special case, * XML-escaped metachars are de-escaped one level in the help message - * for legibility. Should be removed once we have completed a fully-html - * version of the help message. */ - if ( $this->mUnescapeAmps ) + * for legibility. Should be removed once we have completed a fully-HTML + * version of the help message. + */ + if ( $this->mUnescapeAmps ) { $text = preg_replace( '/&(amp|quot|lt|gt);/', '&\1;', $text ); + } return $text; } @@ -284,7 +288,7 @@ See complete documentation, or class ApiFormatFeedWrapper extends ApiFormatBase { public function __construct( $main ) { - parent :: __construct( $main, 'feed' ); + parent::__construct( $main, 'feed' ); } /** @@ -326,13 +330,14 @@ class ApiFormatFeedWrapper extends ApiFormatBase { */ public function execute() { $data = $this->getResultData(); - if ( isset ( $data['_feed'] ) && isset ( $data['_feeditems'] ) ) { + if ( isset( $data['_feed'] ) && isset( $data['_feeditems'] ) ) { $feed = $data['_feed']; $items = $data['_feeditems']; $feed->outHeader(); - foreach ( $items as & $item ) + foreach ( $items as & $item ) { $feed->outItem( $item ); + } $feed->outFooter(); } else { // Error has occured, print something useful diff --git a/includes/api/ApiFormatDbg.php b/includes/api/ApiFormatDbg.php index 597184a6c7..89dad1e433 100644 --- a/includes/api/ApiFormatDbg.php +++ b/includes/api/ApiFormatDbg.php @@ -1,11 +1,11 @@ .@home.nl + * Copyright © 2008 Roan Kattouw .@home.nl * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -25,7 +25,7 @@ if ( !defined( 'MEDIAWIKI' ) ) { // Eclipse helper - will be ignored in production - require_once ( 'ApiFormatBase.php' ); + require_once( 'ApiFormatBase.php' ); } /** @@ -34,7 +34,7 @@ if ( !defined( 'MEDIAWIKI' ) ) { class ApiFormatDbg extends ApiFormatBase { public function __construct( $main, $format ) { - parent :: __construct( $main, $format ); + parent::__construct( $main, $format ); } public function getMimeType() { @@ -49,7 +49,7 @@ class ApiFormatDbg extends ApiFormatBase { } public function getDescription() { - return 'Output data in PHP\'s var_export() format' . parent :: getDescription(); + return 'Output data in PHP\'s var_export() format' . parent::getDescription(); } public function getVersion() { diff --git a/includes/api/ApiFormatJson.php b/includes/api/ApiFormatJson.php index ab62b9e960..c1ea892d06 100644 --- a/includes/api/ApiFormatJson.php +++ b/includes/api/ApiFormatJson.php @@ -1,11 +1,11 @@ @gmail.com + * Copyright © 2006 Yuri Astrakhan @gmail.com * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -25,7 +25,7 @@ if ( !defined( 'MEDIAWIKI' ) ) { // Eclipse helper - will be ignored in production - require_once ( 'ApiFormatBase.php' ); + require_once( 'ApiFormatBase.php' ); } /** @@ -36,7 +36,7 @@ class ApiFormatJson extends ApiFormatBase { private $mIsRaw; public function __construct( $main, $format ) { - parent :: __construct( $main, $format ); + parent::__construct( $main, $format ); $this->mIsRaw = ( $format === 'rawfm' ); } @@ -59,37 +59,39 @@ class ApiFormatJson extends ApiFormatBase { } public function execute() { - $prefix = $suffix = ""; + $prefix = $suffix = ''; $params = $this->extractRequestParams(); $callback = $params['callback']; if ( !is_null( $callback ) ) { - $prefix = preg_replace( "/[^][.\\'\\\"_A-Za-z0-9]/", "", $callback ) . "("; - $suffix = ")"; + $prefix = preg_replace( "/[^][.\\'\\\"_A-Za-z0-9]/", '', $callback ) . '('; + $suffix = ')'; } $this->printText( $prefix . FormatJson::encode( $this->getResultData(), $this->getIsHtml() ) . - $suffix ); + $suffix + ); } public function getAllowedParams() { - return array ( + return array( 'callback' => null, ); } public function getParamDescription() { - return array ( + return array( 'callback' => 'If specified, wraps the output into a given function call. For safety, all user-specific data will be restricted.', ); } public function getDescription() { - if ( $this->mIsRaw ) - return 'Output data with the debuging elements in JSON format' . parent :: getDescription(); - else - return 'Output data in JSON format' . parent :: getDescription(); + if ( $this->mIsRaw ) { + return 'Output data with the debuging elements in JSON format' . parent::getDescription(); + } else { + return 'Output data in JSON format' . parent::getDescription(); + } } public function getVersion() { diff --git a/includes/api/ApiFormatPhp.php b/includes/api/ApiFormatPhp.php index a2d5d1ec2e..07e371cc41 100644 --- a/includes/api/ApiFormatPhp.php +++ b/includes/api/ApiFormatPhp.php @@ -1,11 +1,11 @@ @gmail.com + * Copyright © 2006 Yuri Astrakhan @gmail.com * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -25,7 +25,7 @@ if ( !defined( 'MEDIAWIKI' ) ) { // Eclipse helper - will be ignored in production - require_once ( 'ApiFormatBase.php' ); + require_once( 'ApiFormatBase.php' ); } /** @@ -34,7 +34,7 @@ if ( !defined( 'MEDIAWIKI' ) ) { class ApiFormatPhp extends ApiFormatBase { public function __construct( $main, $format ) { - parent :: __construct( $main, $format ); + parent::__construct( $main, $format ); } public function getMimeType() { @@ -46,7 +46,7 @@ class ApiFormatPhp extends ApiFormatBase { } public function getDescription() { - return 'Output data in serialized PHP format' . parent :: getDescription(); + return 'Output data in serialized PHP format' . parent::getDescription(); } public function getVersion() { diff --git a/includes/api/ApiFormatRaw.php b/includes/api/ApiFormatRaw.php index ee8f573cd0..9eff79a89f 100644 --- a/includes/api/ApiFormatRaw.php +++ b/includes/api/ApiFormatRaw.php @@ -1,11 +1,11 @@ .@home.nl + * Copyright © 2009 Roan Kattouw .@home.nl * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -25,7 +25,7 @@ if ( !defined( 'MEDIAWIKI' ) ) { // Eclipse helper - will be ignored in production - require_once ( 'ApiFormatBase.php' ); + require_once( 'ApiFormatBase.php' ); } /** @@ -40,32 +40,34 @@ class ApiFormatRaw extends ApiFormatBase { * @param $errorFallback Formatter object to fall back on for errors */ public function __construct( $main, $errorFallback ) { - parent :: __construct( $main, 'raw' ); + parent::__construct( $main, 'raw' ); $this->mErrorFallback = $errorFallback; } public function getMimeType() { $data = $this->getResultData(); - if ( isset( $data['error'] ) ) + if ( isset( $data['error'] ) ) { return $this->mErrorFallback->getMimeType(); + } + + if ( !isset( $data['mime'] ) ) { + ApiBase::dieDebug( __METHOD__, 'No MIME type set for raw formatter' ); + } - if ( !isset( $data['mime'] ) ) - ApiBase::dieDebug( __METHOD__, "No MIME type set for raw formatter" ); - return $data['mime']; } public function execute() { $data = $this->getResultData(); - if ( isset( $data['error'] ) ) - { + if ( isset( $data['error'] ) ) { $this->mErrorFallback->execute(); return; } - - if ( !isset( $data['text'] ) ) - ApiBase::dieDebug( __METHOD__, "No text given for raw formatter" ); + + if ( !isset( $data['text'] ) ) { + ApiBase::dieDebug( __METHOD__, 'No text given for raw formatter' ); + } $this->printText( $data['text'] ); } diff --git a/includes/api/ApiFormatTxt.php b/includes/api/ApiFormatTxt.php index dcb3d28095..bbe0e9a455 100644 --- a/includes/api/ApiFormatTxt.php +++ b/includes/api/ApiFormatTxt.php @@ -1,11 +1,11 @@ .@home.nl + * Copyright © 2008 Roan Kattouw .@home.nl * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -25,7 +25,7 @@ if ( !defined( 'MEDIAWIKI' ) ) { // Eclipse helper - will be ignored in production - require_once ( 'ApiFormatBase.php' ); + require_once( 'ApiFormatBase.php' ); } /** @@ -34,7 +34,7 @@ if ( !defined( 'MEDIAWIKI' ) ) { class ApiFormatTxt extends ApiFormatBase { public function __construct( $main, $format ) { - parent :: __construct( $main, $format ); + parent::__construct( $main, $format ); } public function getMimeType() { @@ -49,7 +49,7 @@ class ApiFormatTxt extends ApiFormatBase { } public function getDescription() { - return 'Output data in PHP\'s print_r() format' . parent :: getDescription(); + return 'Output data in PHP\'s print_r() format' . parent::getDescription(); } public function getVersion() { diff --git a/includes/api/ApiFormatWddx.php b/includes/api/ApiFormatWddx.php index 9b382081e3..23ef6b26d0 100644 --- a/includes/api/ApiFormatWddx.php +++ b/includes/api/ApiFormatWddx.php @@ -1,11 +1,11 @@ @gmail.com + * Copyright © 2006 Yuri Astrakhan @gmail.com * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -25,7 +25,7 @@ if ( !defined( 'MEDIAWIKI' ) ) { // Eclipse helper - will be ignored in production - require_once ( 'ApiFormatBase.php' ); + require_once( 'ApiFormatBase.php' ); } /** @@ -34,7 +34,7 @@ if ( !defined( 'MEDIAWIKI' ) ) { class ApiFormatWddx extends ApiFormatBase { public function __construct( $main, $format ) { - parent :: __construct( $main, $format ); + parent::__construct( $main, $format ); } public function getMimeType() { @@ -53,8 +53,8 @@ class ApiFormatWddx extends ApiFormatBase { } else { // Don't do newlines and indentation if we weren't asked // for pretty output - $nl = ( $this->getIsHtml() ? "" : "\n" ); - $indstr = " "; + $nl = ( $this->getIsHtml() ? '' : "\n" ); + $indstr = ' '; $this->printText( "$nl" ); $this->printText( "$nl" ); $this->printText( "$indstr
$nl" ); @@ -69,11 +69,11 @@ class ApiFormatWddx extends ApiFormatBase { * Recursively go through the object and output its data in WDDX format. */ function slowWddxPrinter( $elemValue, $indent = 0 ) { - $indstr = ( $this->getIsHtml() ? "" : str_repeat( ' ', $indent ) ); - $indstr2 = ( $this->getIsHtml() ? "" : str_repeat( ' ', $indent + 2 ) ); - $nl = ( $this->getIsHtml() ? "" : "\n" ); + $indstr = ( $this->getIsHtml() ? '' : str_repeat( ' ', $indent ) ); + $indstr2 = ( $this->getIsHtml() ? '' : str_repeat( ' ', $indent + 2 ) ); + $nl = ( $this->getIsHtml() ? '' : "\n" ); switch ( gettype( $elemValue ) ) { - case 'array' : + case 'array': // Check whether we've got an associative array () // or a regular array () $cnt = count( $elemValue ); @@ -81,8 +81,9 @@ class ApiFormatWddx extends ApiFormatBase { // Regular array $this->printText( $indstr . Xml::element( 'array', array( 'length' => $cnt ), null ) . $nl ); - foreach ( $elemValue as $subElemValue ) + foreach ( $elemValue as $subElemValue ) { $this->slowWddxPrinter( $subElemValue, $indent + 2 ); + } $this->printText( "$indstr$nl" ); } else { // Associative array () @@ -97,20 +98,20 @@ class ApiFormatWddx extends ApiFormatBase { $this->printText( "$indstr$nl" ); } break; - case 'integer' : - case 'double' : + case 'integer': + case 'double': $this->printText( $indstr . Xml::element( 'number', null, $elemValue ) . $nl ); break; - case 'string' : + case 'string': $this->printText( $indstr . Xml::element( 'string', null, $elemValue ) . $nl ); break; - default : - ApiBase :: dieDebug( __METHOD__, 'Unknown type ' . gettype( $elemValue ) ); + default: + ApiBase::dieDebug( __METHOD__, 'Unknown type ' . gettype( $elemValue ) ); } } public function getDescription() { - return 'Output data in WDDX format' . parent :: getDescription(); + return 'Output data in WDDX format' . parent::getDescription(); } public function getVersion() { -- 2.20.1