Mollywhite has uploaded a new change for review.
https://gerrit.wikimedia.org/r/74076
Change subject: Code cleanup
......................................................................
Code cleanup
Fixing whitespace, spelling error. Ran PHPUnit tests, as well
as stylize.php and checkSyntax.php
Change-Id: I3644f37b550310d392d30e4ba814b57f614c514f
---
M BookManagerv2.hooks.php
M BookManagerv2.php
M includes/ApiJsonSchema.php
A includes/JsonBookContentHandler.php
M includes/JsonContent.php
M includes/JsonSchema.php
M includes/RemoteSchema.php
7 files changed, 93 insertions(+), 43 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/BookManagerv2
refs/changes/76/74076/1
diff --git a/BookManagerv2.hooks.php b/BookManagerv2.hooks.php
index 7fa43d3..c90fd35 100644
--- a/BookManagerv2.hooks.php
+++ b/BookManagerv2.hooks.php
@@ -1,7 +1,7 @@
<?php
/**
* Hooks for the BookManagerv2 extension
- *
+ *
* @file
* @ingroup Extensions
*
@@ -22,7 +22,7 @@
*/
class BookManagerv2Hooks {
-
+
public static function readingInterfaceUX( $out, $prev, $next,
$chapterList, $metadata ) {
global $wgExtensionAssetsPath;
$imagePath = $wgExtensionAssetsPath . "/BookManagerv2/images/";
@@ -31,7 +31,7 @@
. Html::openElement( 'div', array( 'class' =>
'mw-bookmanagerv2-nav-constrain' ) )
. Html::openElement( 'div', array( 'class' =>
'mw-bookmanagerv2-nav-bar' ) )
. Html::openElement( 'a', array(
- 'class' => array(
+ 'class' => array(
'mw-bookmanagerv2-nav-icon',
'mw-bookmanagerv2-nav-data' )
)
@@ -64,7 +64,7 @@
. Html::closeElement( 'a' )
. Html::openElement( 'a', array(
'class' => 'mw-bookmanagerv2-nav-next',
- 'href' => $next->link )
+ 'href' => $next->link )
)
. $next->title
. Html::element( 'img', array(
@@ -73,8 +73,8 @@
), '' )
. Html::closeElement( 'a' )
. Html::closeElement( 'div' )
- . Html::rawElement( 'div', array(
- 'class' => array(
+ . Html::rawElement( 'div', array(
+ 'class' => array(
'mw-bookmanagerv2-nav-dropdown',
'mw-bookmanagerv2-nav-data' )
),
@@ -89,7 +89,7 @@
)
. Html::closeElement( 'div' )
. Html::closeElement( 'div' );
-
+
$out->prependHTML( $html );
}
@@ -98,8 +98,8 @@
if ( $out->getTitle()->getNamespace() == NS_MAIN ) {
if ( $out->getRevisionId() != null ) {
$out->addModules( "ext.BookManagerv2" );
- $prev = (object) array( "link"=>"/prev.html",
"title"=>"Previous" );
- $next = (object) array( "link"=>"/next.html",
"title"=>"Next" );
+ $prev = (object) array( "link" => "/prev.html",
"title" => "Previous" );
+ $next = (object) array( "link" => "/next.html",
"title" => "Next" );
$chapterList = Html::element( 'p', array(),
'Chapter 1' )
. Html::element( 'p', array(), 'Chapter
2' )
. Html::element( 'p', array(), 'Chapter
3' );
@@ -107,9 +107,9 @@
. 'Title: '
. Html::element( 'span', array( 'class'
=> 'title' ), 'Title' )
. Html::closeElement( 'p' )
- . Html::element( 'p', array(), 'Author:
Author');
+ . Html::element( 'p', array(), 'Author:
Author' );
self::readingInterfaceUX( $out, $prev, $next,
$chapterList, $metadata );
- }
+ }
}
return true;
}
diff --git a/BookManagerv2.php b/BookManagerv2.php
index e8566bd..1084d5e 100644
--- a/BookManagerv2.php
+++ b/BookManagerv2.php
@@ -23,7 +23,7 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
USA.
- *
+ *
*/
$wgExtensionCredits['parserhook'][] = array(
@@ -40,7 +40,7 @@
define( 'NS_BOOK', 240 );
define( 'NS_BOOK_TALK', 241 );
-//Configuration
+// Configuration
/**
* @var bool|string: URI or false if not set.
@@ -73,7 +73,7 @@
*/
function jsonValidate( $object, $schema = NULL ) {
if ( NULL == $schema ) {
- //Default to using JSON schema
+ // Default to using JSON schema
$json = file_get_contents( __DIR__ . '/schemas/bookschema.json'
);
$schema = FormatJson::decode( $json, true );
}
@@ -87,25 +87,26 @@
// Register files
$wgAutoloadClasses += array(
- //Hooks
+ // Hooks
'BookManagerv2Hooks' => __DIR__ . '/BookManagerv2.hooks.php',
'JsonHooks' => __DIR__ . '/includes/JsonHooks.php',
- //ContentHandler
+ // ContentHandler
'JsonBookContent' => __DIR__ . '/includes/JsonContent.php',
+ 'JsonBookContentHandler' => __DIR__ .
'/includes/JsonBookContentHandler.php',
- //ResourceLoaderModule
+ // ResourceLoaderModule
'RemoteSchema' => __DIR__ . '/includes/RemoteSchema.php',
- //Json
+ // Json
'JsonTreeRef' => __DIR__ . '/includes/JsonSchema.php',
'JsonSchemaException' => __DIR__ . '/includes/JsonSchema.php',
- //API
+ // API
'ApiJsonSchema' => __DIR__ . '/includes/ApiJsonSchema.php',
);
-//Messages
+// Messages
$wgExtensionMessagesFiles += array(
'BookManagerv2' => __DIR__ . '/BookManagerv2.i18n.php',
'BookManagerv2Namespaces' => __DIR__ . '/BookManagerv2.namespaces.php',
@@ -119,7 +120,7 @@
$wgResourceModules['ext.BookManagerv2'] = array(
'scripts' => 'ext.BookManagerv2.js',
'styles' => 'ext.BookManagerv2.css',
- 'localBasePath' => dirname(__FILE__) . '/modules',
+ 'localBasePath' => dirname( __FILE__ ) . '/modules',
'remoteExtPath' => 'BookManagerv2/modules'
);
diff --git a/includes/ApiJsonSchema.php b/includes/ApiJsonSchema.php
index b9db868..26d5982 100644
--- a/includes/ApiJsonSchema.php
+++ b/includes/ApiJsonSchema.php
@@ -123,7 +123,7 @@
$result = $this->getResult();
$result->addValue( null, 'title', $title->getText() );
- foreach( $schema as $k => &$v ) {
+ foreach ( $schema as $k => &$v ) {
$result->addValue( null, $k, $v );
}
}
diff --git a/includes/JsonBookContentHandler.php
b/includes/JsonBookContentHandler.php
new file mode 100644
index 0000000..c554bed
--- /dev/null
+++ b/includes/JsonBookContentHandler.php
@@ -0,0 +1,49 @@
+<?php
+/**
+ * JSON Schema Content Handler
+ *
+ * @file
+ * @ingroup Extensions
+ * @ingroup BookManagerv2
+ *
+ * @author Ori Livneh <[email protected]>
+ */
+
+class JsonBookContentHandler extends TextContentHandler {
+
+ public function __construct( $modelId = 'JsonSchema' ) {
+ parent::__construct( $modelId, array( CONTENT_FORMAT_JSON ) );
+ }
+
+ /**
+ * Unserializes a JsonSchemaContent object.
+ *
+ * @param string $text Serialized form of the content
+ * @param null|string $format The format used for serialization
+ *
+ * @return Content the JsonSchemaContent object wrapping $text
+ */
+ public function unserializeContent( $text, $format = null ) {
+ $this->checkFormat( $format );
+ return new JsonSchemaContent( $text );
+ }
+
+ /**
+ * Creates an empty JsonSchemaContent object.
+ *
+ * @return Content
+ */
+ public function makeEmptyContent() {
+ return new JsonSchemaContent( '' );
+ }
+
+ /** JSON Schema is English **/
+ public function getPageLanguage( Title $title, Content $content = null
) {
+ return wfGetLangObj( 'en' );
+ }
+
+ /** JSON Schema is English **/
+ public function getPageViewLanguage( Title $title, Content $content =
null ) {
+ return wfGetLangObj( 'en' );
+ }
+}
diff --git a/includes/JsonContent.php b/includes/JsonContent.php
index dbfa473..5095dbb 100644
--- a/includes/JsonContent.php
+++ b/includes/JsonContent.php
@@ -24,7 +24,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
USA.
*/
-/**
+/**
* Represents the content of a JSON book page
*/
class JsonBookContent extends TextContent {
@@ -47,7 +47,7 @@
*/
function validate() {
$block = $this->getJsonData();
- if ( !is_array( $block ) ) {
+ if ( !is_array( $block ) ) {
throw new JsonSchemaException(
wfMessage( 'bookmanagerv2-invalid-json'
)->parse() );
}
@@ -104,7 +104,7 @@
static function objectRow( $key, $val ) {
$th = Xml::elementClean( 'th', array(), $key );
if ( is_array( $val ) ) {
- $td = Xml::tags( 'td', array(),
+ $td = Xml::tags( 'td', array(),
self::objectTable( $val ) );
} else {
if ( is_string( $val ) ) {
@@ -113,7 +113,7 @@
$val = FormatJson::encode( $val );
}
- $td = Xml::elementClean( 'td',
+ $td = Xml::elementClean( 'td',
array( 'class' => 'value' ), $val );
}
@@ -144,5 +144,5 @@
function getHighlightHtml() {
$schema = $this->getJsonData();
return is_array( $block ) ? self::objectTable( $block ) : '';
- }
+ }
}
diff --git a/includes/JsonSchema.php b/includes/JsonSchema.php
index 1b2a1f3..7eff22f 100644
--- a/includes/JsonSchema.php
+++ b/includes/JsonSchema.php
@@ -160,7 +160,7 @@
* Note: this merely acts as a passthrough to MediaWiki's wfMessage
call.
*/
public static function uiMessage() {
- if( function_exists( 'wfMessage' ) ) {
+ if ( function_exists( 'wfMessage' ) ) {
return call_user_func_array( 'wfMessage', $params =
func_get_args() );
}
else {
@@ -265,7 +265,7 @@
* infer it from the data.
*/
public function getType() {
- if( array_key_exists( 'type', $this->schemaref->node ) ) {
+ if ( array_key_exists( 'type', $this->schemaref->node ) ) {
$nodetype = $this->schemaref->node['type'];
}
else {
@@ -320,7 +320,7 @@
*/
public function getDataPathAsString() {
$retval = "";
- foreach( $this->getDataPath() as $item ) {
+ foreach ( $this->getDataPath() as $item ) {
$retval .= '[' . json_encode( $item ) . ']';
}
return $retval;
@@ -345,7 +345,7 @@
public function getMappingChildRef( $key ) {
$snode = $this->schemaref->node;
$nodename = null;
- if( array_key_exists( 'properties', $snode ) &&
+ if ( array_key_exists( 'properties', $snode ) &&
array_key_exists( $key, $snode['properties'] ) ) {
$schemadata = $snode['properties'][$key];
$nodename = isset( $schemadata['title'] ) ?
$schemadata['title'] : $key;
@@ -379,7 +379,7 @@
*/
public function getSequenceChildRef( $i ) {
// TODO: make this conform to draft-03 by also allowing single
object
- if( array_key_exists( 'items', $this->schemaref->node ) ) {
+ if ( array_key_exists( 'items', $this->schemaref->node ) ) {
$schemanode = $this->schemaref->node['items'][0];
}
else {
@@ -397,7 +397,7 @@
* Return true on success, and throw a JsonSchemaException on failure.
*/
public function validate() {
- if( array_key_exists( 'enum', $this->schemaref->node ) &&
+ if ( array_key_exists( 'enum', $this->schemaref->node ) &&
!in_array( $this->node, $this->schemaref->node['enum']
) ) {
$msg = JsonUtil::uiMessage(
'jsonschema-invalid-notinenum', $this->node, $this->getDataPathTitles() );
$e = new JsonSchemaException( $msg );
@@ -411,12 +411,12 @@
$datatype = 'object';
}
if ( $datatype == 'number' && $schematype == 'integer' &&
- $this->node == (int)$this->node) {
+ $this->node == (int)$this->node ) {
// Alright, it'll work as an int
$datatype = 'integer';
}
if ( $datatype != $schematype ) {
- if ( is_null( $datatype ) && !is_object( $this->parent
)) {
+ if ( is_null( $datatype ) && !is_object( $this->parent
) ) {
$msg = JsonUtil::uiMessage(
'jsonschema-invalidempty' );
$e = new JsonSchemaException( $msg );
$e->subtype = "validate-fail-null";
@@ -446,7 +446,7 @@
if ( array_key_exists( 'properties', $this->schemaref->node ) )
{
foreach ( $this->schemaref->node['properties'] as $skey
=> $svalue ) {
$keyRequired = array_key_exists( 'required',
$svalue ) ? $svalue['required'] : false;
- if( $keyRequired && !array_key_exists( $skey,
$this->node ) ) {
+ if ( $keyRequired && !array_key_exists( $skey,
$this->node ) ) {
$msg = JsonUtil::uiMessage(
'jsonschema-invalid-missingfield', $skey );
$e = new JsonSchemaException( $msg );
$e->subtype =
"validate-fail-missingfield";
@@ -500,7 +500,7 @@
* index.
*/
public function indexSubtree( $schemanode ) {
- if( !array_key_exists( 'type', $schemanode ) ) {
+ if ( !array_key_exists( 'type', $schemanode ) ) {
$schemanode['type'] = 'any';
}
$nodetype = $schemanode['type'];
diff --git a/includes/RemoteSchema.php b/includes/RemoteSchema.php
index 7359a78..9706bc8 100644
--- a/includes/RemoteSchema.php
+++ b/includes/RemoteSchema.php
@@ -27,7 +27,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
USA.
*/
-class RemoteSchama {
+class RemoteSchema {
const LOCK_TIMEOUT = 20;
@@ -50,8 +50,8 @@
$this->title = $title;
$this->revision = $revision;
- $this->cache = $cache ?: wfGetCache( CACHE_ANYTHING );
- $this->http = $http ?: new Http();
+ $this->cache = $cache ? : wfGetCache( CACHE_ANYTHING );
+ $this->http = $http ? : new Http();
$this->key =
"schema:{$BookManagerv2DBname}:{$title}:{$revision}";
}
@@ -123,14 +123,14 @@
return wfAppendQuery( $wgBookManagerv2SchemaApiUri, $q );
}
-
+
/**
* Returns an object containing serializable properties.
* @implements JsonSerializeable
*/
function jsonSerialize() {
return array(
- 'schema' => $this->get() ?: new StdClass(),
+ 'schema' => $this->get() ? : new StdClass(),
'revision' => $this->revision
);
}
@@ -145,7 +145,7 @@
return false;
}
$raw = $this->http->get( $this->getUri(), self::LOCK_TIMEOUT *
0.8 );
- return FormatJson::decode( $raw, true ) ?: false;
+ return FormatJson::decode( $raw, true ) ? : false;
}
}
--
To view, visit https://gerrit.wikimedia.org/r/74076
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I3644f37b550310d392d30e4ba814b57f614c514f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/BookManagerv2
Gerrit-Branch: master
Gerrit-Owner: Mollywhite <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits