Download the PHP package noris/jsoner without Composer

On this page you can find all versions of the php package noris/jsoner. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package jsoner

TL;DR (MW 1.25+)

Install curl, fileinfo, intl and mbstring for PHP. Put this in your composer.local.json:

{
    "require": {
        "noris/jsoner": "~1.0"
    }
}

and run composer update. Then, append this to your LocalSettings.php:

wfLoadExtension( 'Jsoner' );
$jsonerBaseUrl = 'https://example.com/api/';
$jsonerUser = '<your_user>';
$jsonerPass = '<your_pass>';

Jsoner

This is a MediaWiki extension that allows one to embed external JSON data (i.e. from a REST API) into an article.

Requirements

This extension requires at least PHP >= 5.6 and the following PHP extensions:

Using Debian / Ubuntu you can install the extensions like this:

sudo apt-get install php5-curl php5-intl
sudo service apache2 restart

To test if they are enabled (use your php.ini):

$ php5 --php-ini /etc/php5/apache2/php.ini -m | grep -E 'fileinfo|mbstring|intl|curl'
curl
fileinfo
intl
mbstring

Installation

Download (recommended, with Composer)

Put this to your composer.local.json:

{
    "require": {
        "noris/jsoner": "~1.0"
    }
}

and run composer update (or composer install if you don't have a composer.lock yet).

Download (not recommended, manually)

Download the extension and put it in your extension/ folder.

Add to MediaWiki

To enable this extension, add this to your LocalSettings.php:

wfLoadExtension( 'Jsoner' );

This will enable the Jsoner extension and add the following functions to the MediaWiki parser:

Configuration

The extension has multiple settings. Please put them after the wfLoadExtension( 'Jsoner' );.

$jsonerBaseUrl (default = null)

$jsonerBaseUrl = 'https://example.com/api/';

This can be used to prefix all #jsoner calls (the url argument specifically) with this url so that you don't have to repeat yourself, if you only consume data from one domain. If omitted, you have to provide complete domains in url.

$jsonerUser / $jsonerPass (default = null)

$jsonerUser = '<your_user>';
$jsonerPass = '<your_pass>';

If both are set, this is passed to cURL to authenticate. If omitted, cURL tries unauthenticated.

Usage

Jsoner has a pipes and filters architecture. First, data is fetched, then filters are applied and finally, the data is transformed in a representation.

Fetch → [Filter ...] → Transformer

This looks like this in MediaWiki syntax:

// Fetch         → Filter              → Filter                  → Transformer
{{ #jsoner:url=… | f-SelectSubtree=foo | f-SelectKeys=name,email | t-JsonDump }}

Lets run something interesting:

{{ #jsoner:url=http://pokeapi.co/api/v2/pokemon/1/ | f-SelectSubtree=stats | t-JsonDump }}

↓

[
    {
        "base_stat": 45,
        "effort": 0,
        "stat": {
            "name": "speed",
            "url": "http://pokeapi.co/api/v2/stat/6/"
        }
    },
    {
        "base_stat": 65,
        "effort": 0,
        "stat": {
            "name": "special-defense",
            "url": "http://pokeapi.co/api/v2/stat/5/"
        }
    },
    {
        "base_stat": 65,
        "effort": 1,
        "stat": {
            "name": "special-attack",
            "url": "http://pokeapi.co/api/v2/stat/4/"
        }
    },
    {
        "base_stat": 49,
        "effort": 0,
        "stat": {
            "name": "defense",
            "url": "http://pokeapi.co/api/v2/stat/3/"
        }
    },
    {
        "base_stat": 49,
        "effort": 0,
        "stat": {
            "name": "attack",
            "url": "http://pokeapi.co/api/v2/stat/2/"
        }
    },
    {
        "base_stat": 45,
        "effort": 0,
        "stat": {
            "name": "hp",
            "url": "http://pokeapi.co/api/v2/stat/1/"
        }
    }
]

As you can see, Filters are prefixed with f- and Transformers are prefixed with t-.

Available Filters

A typical call looks like this

{{ #jsoner:url=… | f-SelectSubtree=foo | }}

CensorKeysFilter (f-CensorKeys)

Runs on a list and returns a list. Usage: f-CensorKeys=key(,key)*,replacement

Example: f-CensorKeys=email,--protected--

[
  {
    "name": "Bob",
    "email": "[email protected]"
  },
  {
    "name": "Tom",
    "email": "[email protected]"
  }
]   

↓

[
  {
    "name": "Bob",
    "email": "--protected--"
  },
  {
    "name": "Tom",
    "email": "--protected--"
  }
]

ReduceKeysFilter (f-Reduce)

Runs on a list and returns a list. Usage: f-Reduce=(\w+),(\w+)(\.\w+)*

Example: f-Reduce=mail,data.email

[
  {
    "id": "1",
    "data": {
      "email": "[email protected]",
      "city": "Berlin"
    }
  },
  {
    "id": 2,
    "data": {
      "email": "[email protected]",
      "city": "Hamburg"
    }
  }
]

↓

[
  {
    "id": "1",
    "data": {
      "email": "[email protected]",
      "city": "Berlin"
    },
    "mail": "[email protected]"
  },
  {
    "id": 2,
    "data": {
      "email": "[email protected]",
      "city": "Hamburg"
    },
    "mail": "[email protected]"
  }
]

RemoveKeysFilter (f-RemoveKeys)

Runs on a list and returns a list. Usage: f-RemoveKeys=key(,key)*

Example: f-RemoveKeys=email

[
  {
    "name": "Bob",
    "email": "[email protected]"
  },
  {
    "name": "Tom",
    "email": "[email protected]"
  }
]

↓

[
  {
    "name": "Bob"
  },
  {
    "name": "Tom"
  }
]

SelectKeysFilter (f-SelectKeys)

Runs on a list and returns a list. Usage: f-SelectKeys=key(,key)*

Example: f-SelectKeys=email

[
  {
    "name": "Bob",
    "email": "[email protected]"
  },
  {
    "name": "Tom",
    "email": "[email protected]"
  }
]

↓

[
  {
    "email": "[email protected]"
  },
  {
    "email": "[email protected]"
  }
]

SelectSubtreeFilter (f-SelectSubtree)

Runs on an object and returns a list. Usage: f-SelectSubtree=key

Example: f-SelectSubtree=records

{
  "recordCount": 2,
  "records": [
    {
      "name": "Bob",
      "email": "[email protected]"
    },
    {
      "name": "Tom",
      "email": "[email protected]"
    }
  ]
}

↓

[
  {
    "name": "Bob",
    "email": "[email protected]"
  },
  {
    "name": "Tom",
    "email": "[email protected]"
  }
]

SelectRecordFilter (f-SelectRecord)

Runs on a list and returns a list. Usage: [f-SelectRecord=key:value]

Example: f-SelectRecord=email:[email protected]

[
  {
    "name": "Bob",
    "email": "[email protected]"
  },
  {
    "name": "Tom",
    "email": "[email protected]"
  }
]

↓

[
  {
    "name": "Tom",
    "email": "[email protected]"
  }
]

Available Transformers

There must be always a transformer at the end of the pipeline.

InlineListTransformer (t-InlineList)

Creates a comma-separated list of values from a list.

Usage: t-InlineList=key

With a list as input, calling t-InlineList=email

[
  {
    "name": "Bob",
    "email": "[email protected]"
  },
  {
    "name": "Tom",
    "email": "[email protected]"
  }
]

↓

[email protected], [email protected]

Good for, you guessed it: lists!

JsonDumpTransformer (t-JsonDump)

Dumps the JSON data into a <pre> tag. Nice for debugging.

SingleElementTransformer (t-SingleElement)

Returns a single JSON value out of an object or a list. If the input is a list, the SingleElementTransformer will use the first element in the list to display something.

Usage: t-SingleElement=key

With a list as input, calling t-SingleElement=name

[
  {
    "name": "Bob",
    "email": "[email protected]"
  },
  {
    "name": "Tom",
    "email": "[email protected]"
  }
]

↓

Bob

With an object as input, calling t-SingleElement=name

{
    "name": "Bob",
    "email": "[email protected]"
}

↓

Bob

Nice for single values like IDs.

StackedElementTransformer (t-StackedElement)

Creates a <br /> separated (on top of each other) stack out of an object or a list. If the input is a list, the StackedElementTransformer uses the first element in the list and displays that.

With a list as input:

[
  {
    "name": "Bob",
    "email": "[email protected]"
  },
  {
    "name": "Tom",
    "email": "[email protected]"
  }
]

↓

Bob
[email protected]

With an object as input:

{
    "name": "Tom",
    "email": "[email protected]"
}

↓

Tom
[email protected]

Useful for address data.

WikitextTableTransformer (t-WikitextTable)

Creates a nice and sortable Wikitext table out of a list of objects.

[
  {
    "name": "Bob",
    "email": "[email protected]"
  },
  {
    "name": "Tom",
    "email": "[email protected]"
  }
]

↓

╔════════╦═════════════════╗
║ name ▼ ║ email         ▼ ║
╠════════╬═════════════════╣
║ Bob    ║ [email protected] ║
║ Tom    ║ [email protected] ║
╚════════╩═════════════════╝

MediaWikiTemplateTransformer (t-mwTemplate)

Creates Wikitext depending on the given template. You probably have to create a suiting template for the query. Uses key=value pairs.

Wiki-String: {{ template |key=value }}

Usage: t-mwTemplate=template

With t-mwTemplate=jsoner-template

[
  {
    "name": "Bob",
    "email": "[email protected]"
    "username": "bobexample"
  },
  {
    "name": "Tom",
    "email": "[email protected]"
    "username": "tomexample"
  }
]

↓

╔════════╦═════════════════╦══════════════╗
║ name ▼ ║ email         ▼ ║username    ▼ ║
╠════════╬═════════════════╣══════════════╣
║ Bob    ║ [email protected] ║ bobexample   ║
║ Tom    ║ [email protected] ║ tomexample   ║
╚════════╩═════════════════╩══════════════╝

The output is depending on the template you use.

MediaWikiTemplateTransformerAnonymous (t-mwTemplateAnonymous)

Creates Wikitext depending on the given template. You probably have to create a suiting template for the query. Doesn't use key=value pairs, uses the Anonymous templating in the Mediawiki. Template in this use case : template= {{{1}}} {{{2}}}

Usage: t-mwTemplateAnonymous=template

[
  {
    "name": "Bob",
    "email": "[email protected]"
    "username": "bobexample"
  },
  {
    "name": "Tom",
    "email": "[email protected]"
    "username": "tomexample"
  }
]

↓

Bob [email protected] Tom [email protected] 

The output is depending on the template you use.

Limitations

Development

This extension is under development. Anything may change.

You can clone is using

git clone [email protected]:noris-network/Jsoner.git && cd Jsoner
make devenv

To install it into your development MediaWiki, just symlink it to your extensions folder

# Assuming you are in Jsoner folder
cd /path/to/your/extensions/folder
ln -s /path/to/the/Jsoner/extension Jsoner

Then, install it like described above.

To see what you can do run one of

make
make help

To test, you can run

make test

To fix warnings etc. from make test, you can run:

make fix

To clean, you can run

make clean

License

GPL v3


All versions of jsoner with dependencies

PHP Build Version
Package Version
Requires php Version >=5.6
ext-curl Version *
ext-fileinfo Version *
ext-intl Version *
ext-mbstring Version *
league/uri Version 4.1.*
rwillians/stingray Version ^2.0
composer/installers Version ~1.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package noris/jsoner contains the following files

Loading the files please wait ....