Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
bovender committed Apr 28, 2019
2 parents 58a644c + 07d03ad commit 0f11f3b
Show file tree
Hide file tree
Showing 14 changed files with 124 additions and 85 deletions.
21 changes: 21 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# This Dockerfile can be used to create a Docker image/container
# that runs the unit tests on the PubmedParser extension.
FROM mediawiki:1.32
MAINTAINER Daniel Kraus (https://www.bovender.de)
RUN apt update -yqq && \
apt install -yqq \
php7.0-sqlite \
sqlite3 \
unzip \
zip
RUN curl https://raw.githubusercontent.com/composer/getcomposer.org/cb19f2aa3aeaa2006c0cd69a7ef011eb31463067/web/installer -s | php -- --quiet
RUN php composer.phar install

COPY . /var/www/html/extensions/PubmedParser/
RUN mkdir /data && chown www-data /data

WORKDIR /var/www/html/maintenance
RUN php install.php --pass admin --dbtype sqlite --extensions PubmedParser Tests admin

WORKDIR /var/www/html/tests/phpunit
CMD ["php", "phpunit.php", "--group", "bovender"]
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.PHONY: test

test:
docker run -it --rm -v ${PWD}:/var/www/html/extensions/PubmedParser bovender/pubmedparser

build-test-container:
docker build -t bovender/pubmedparser .
84 changes: 48 additions & 36 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,65 +1,77 @@
Version 4.0.2 (2017-03-19)
------------------------------------------------------------------------
# Changelog

- Fix: Prevent log flooding with warnings in certain situations.
All notable changes to this project will be documented in this file.

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [4.0.3][] - 2019-04-28

Version 4.0.1 (2016-11-09)
------------------------------------------------------------------------
### Fixed

- IMPROVEMENT: Use only https to access the Pubmed API.
- Articles with single authors would not be formatted correctly.

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
## [4.0.2][] - 2017-03-19

### Fixed

Version 4.0.0 (2016-11-05)
------------------------------------------------------------------------
- Prevent log flooding with warnings in certain situations.

- FIX: Prevent database errors on updating a citation with 'reload'.
- FIX: The caching table in the database is now created in a database transaction.
- FIX: The caching table in the database now uses the custom table prefix (you may want to manually rename an existing Pubmed table to include the prefix before running the new version of the extension.)
- FIX: Undefined variable errors.
- NEW: Compatibility with MediaWiki 1.25 and newer. The extension is not compatible with MediaWiki 1.24 and older.
## [4.0.1][] - 2016-11-09

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
### Changed

- Use only https to access the Pubmed API.

Version 3.2.1 (2016-06-04)
------------------------------------------------------------------------
## [4.0.0][] - 2016-11-05

- FIX: Do not crash on database access (due to call to ignoreErrors function that has been turned into a protected function in newer MediaWiki versions).
### Changed

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- Compatibility with MediaWiki 1.25 and newer. The extension is not compatible with MediaWiki 1.24 and older.

### Fixed

Version 3.2.0 (2016-06-04)
------------------------------------------------------------------------
- Prevent database errors on updating a citation with 'reload'.
- The caching table in the database is now created in a database transaction.
- The caching table in the database now uses the custom table prefix (you may want to manually rename an existing Pubmed table to include the prefix before running the new version of the extension.)
- Undefined variable errors.

- FIX: Prevent "instance of MySqlUpdater" error.
- NEW: Ability to give PMC ID as an alternative to PMID ('PMC1234567').
- NEW: Ability to output PubmedCentral ID.
## [3.2.1][] - 2016-06-04

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
### Fixed

- Do not crash on database access (due to call to ignoreErrors function that has been turned into a protected function in newer MediaWiki versions).

## [3.2.0][] - 2016-06-04

Version 3.1.0 (2014-10-15)
------------------------------------------------------------------------
### Added

* Change: The extension requires PHP 5.3.0 or later.
* Change: Use persistent database connections to increase performance.
* Changed: The name of the 'reload' option can be customized in the system messages.
* New: The template name to use for the citation can now be given as a parameter (with a leading '#').
- Ability to give PMC ID as an alternative to PMID ('PMC1234567').
- Ability to output PubmedCentral ID.

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
### Fixed

- Prevent "instance of MySqlUpdater" error.

## [3.1.0][] - 2014-10-15

Version 3.0.0 (2014-09-10)
------------------------------------------------------------------------
### Added

- The template name to use for the citation can now be given as a parameter (with a leading '#').

### Changed

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- The extension requires PHP 5.3.0 or later.
- Use persistent database connections to increase performance.
- The name of the 'reload' option can be customized in the system messages.

## [3.0.0][] - 2014-09-10

[4.0.3]: https://github.com/bovender/PubmedParser/releases/tag/v4.0.3
[4.0.2]: https://github.com/bovender/PubmedParser/releases/tag/v4.0.2
[4.0.1]: https://github.com/bovender/PubmedParser/releases/tag/v4.0.1
[4.0.0]: https://github.com/bovender/PubmedParser/releases/tag/v4.0.0
[3.2.1]: https://github.com/bovender/PubmedParser/releases/tag/v3.2.1
[3.2.0]: https://github.com/bovender/PubmedParser/releases/tag/v3.2.0
[3.1.0]: https://github.com/bovender/PubmedParser/releases/tag/v3.1.0
[3.0.0]: https://github.com/bovender/PubmedParser/releases/tag/v3.0.0
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ manually rename all your database tables!

PubmedParser

Copyright (C) 2011-2017 Daniel Kraus ([bovender](https://www.bovender.de))
Copyright (C) 2011-2019 Daniel Kraus ([bovender](https://www.bovender.de))

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
Expand Down
2 changes: 1 addition & 1 deletion extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "PubmedParser",
"type": "parserhook",
"url": "https://www.mediawiki.org/wiki/Extension:PubmedParser",
"version": "4.0.2",
"version": "4.0.3",
"license-name": "GPL-2.0+",
"descriptionmsg": "pubmedparser-desc",
"requires": {
Expand Down
6 changes: 3 additions & 3 deletions includes/PubmedParser_Article.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*
* \file PubmedParser.Article.php
*
* Copyright 2011-2017 Daniel Kraus <krada@gmx.net>
* Copyright 2011-2019 Daniel Kraus <krada@gmx.net>
*
* 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
Expand Down Expand Up @@ -161,7 +161,7 @@ function authors( $useInitials = false ) {
$a = $this->authorName( 0, $useInitials );
if ( $numAuthors > 2 ) {
$a .= " " . Extension::$etAl;
} elseif ( $numAuthors = 2 ) {
} elseif ( $numAuthors == 2 ) {
$a .= ' ' . Extension::$and . ' ' . $this->authorName( 1, $useInitials );
}
return $a;
Expand All @@ -184,7 +184,7 @@ function allAuthors( $useInitials = false ) {
// the last author's name.
$a = substr( $a, 0, strlen( $a )-2 ) . ' ' . Extension::$and
. ' ' . $this->authorName( $i, $useInitials );
} elseif ( $numAuthors = 1 ) {
} elseif ( $numAuthors == 1 ) {
$a = $this->authorName( 0, $useInitials );
} else {
$a = $this->collectiveName;
Expand Down
64 changes: 32 additions & 32 deletions includes/PubmedParser_Core.php
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
<?php
/*
* \file PubmedParserFetcher.body.php
*
* Copyright 2011-2017 Daniel Kraus <bovender@bovender.de>
*
*
* Copyright 2011-2019 Daniel Kraus <bovender@bovender.de>
*
* 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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* 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.
*/
namespace PubmedParser;

if ( !defined( 'MEDIAWIKI' ) ) {
die( 'This is an extension to MediaWiki and cannot be run standalone.' );
}
Expand All @@ -29,9 +29,9 @@
* booleans, objects, resources, etc.
* Taken from: http://www.php.net/manual/en/function.ctype-digit.php#87113
*/
function ctype_digit2 ($str) {
return (is_string($str) || is_int($str) || is_float($str)) &&
preg_match('/^\d+\z/', $str);
function ctype_digit2 ($str) {
return (is_string($str) || is_int($str) || is_float($str)) &&
preg_match('/^\d+\z/', $str);
}

/*! The central class of the PubmedParser extension.
Expand All @@ -43,12 +43,12 @@ class Core
/**
* Constructor
* @param $pmid Pubmed identifier for the article; must be an integer.
* @note The optional parameters $param1 and $param2 may contain one of
* three parametrs: The name of a <ref name="..."></ref> structure, the name
* of the template to use to build the citation, or the keyword 'reload' to
* force reloading the Pubmed XML data from the internet. Note that to be
* able to distinguish a template name from a reference name, the template
* name MUST be prefixed with '#' (configurable in MediaWiki system
* @note The optional parameters $param1 and $param2 may contain one of
* three parametrs: The name of a <ref name="..."></ref> structure, the name
* of the template to use to build the citation, or the keyword 'reload' to
* force reloading the Pubmed XML data from the internet. Note that to be
* able to distinguish a template name from a reference name, the template
* name MUST be prefixed with '#' (configurable in MediaWiki system
* messages).
*/
function __construct( $pmid = 0, $param1 = '', $param2 = '' ) {
Expand Down Expand Up @@ -94,12 +94,12 @@ function execute() {

// set noparse to false to enable full parsing of the output
// (required for expansion of templates)
return array( $output, 'noparse' => false );
return array( $output, 'noparse' => false );
}

/**
* Builds a wiki template with Pubmed data.
* @param PubmedArticle $article PubmedArticle object that contains the
* @param PubmedArticle $article PubmedArticle object that contains the
* data.
* @return String containing a Wiki template with parametrized Pubmed data.
* @note Article is given as a parameter to facilitate unit testing.
Expand Down Expand Up @@ -146,7 +146,7 @@ function lookUp() {
$this->status = PUBMEDPARSER_INVALIDPMID;
return;
}

$this->status = PUBMEDPARSER_OK;
$xml = null;
if ( ! $this->reload ) {
Expand All @@ -156,7 +156,7 @@ function lookUp() {
}
};

if ( !$xml ) {
if ( ! is_string( $xml ) ) {
// fetch the article information from PubMed in XML format
// note: it's important to have retmode=xml, not rettype=xml!
// rettype=xml returns an HTML page with formatted XML-like text;
Expand All @@ -168,15 +168,15 @@ function lookUp() {
return;
}

if ( $xml ) {
if ( is_string( $xml ) ) {
/* Now that we have the data, let's attempt to store it locally
* in the cache.
*/
$this->storeInDb( $this->pmid, $xml );
}
} // if no xml in database
if ( $xml ) {

if ( is_string( $xml ) ) {
$this->article = new Article( $this->pmid, $xml );
if ( !$this->article->xml ) {
$this->status = PUBMEDPARSER_INVALIDXML;
Expand All @@ -191,21 +191,21 @@ function lookUp() {
// Database caching

/** Fetches a PMID record from the wiki database, if available.
* @param $pmid Pubmed ID to look up.
* @return XML string containing the Pubmed record, of null if the
* @param $pmid Pubmed ID to look up.
* @return XML string containing the Pubmed record, of null if the
* record was not found.
* @note $pmid must be an integer to prevent SQL injections. Since
* it is a scalar, specifying a typed parameter in the function
* signature does not work. This is a private method that is called
* by PubmedParserFetcher::lookUp() which ensures that PMIDs are
* @note $pmid must be an integer to prevent SQL injections. Since
* it is a scalar, specifying a typed parameter in the function
* signature does not work. This is a private method that is called
* by PubmedParserFetcher::lookUp() which ensures that PMIDs are
* integers.
*/
private function fetchFromDb( $pmid ) {
$dbr = $this->getReadDb();
$res = $dbr->select(
'pubmed',
'xml',
'pmid = ' . $pmid,
$res = $dbr->select(
'pubmed',
'xml',
'pmid = ' . $pmid,
__METHOD__
);
if ( $dbr->lastErrno() == 0 ) {
Expand Down
2 changes: 1 addition & 1 deletion includes/PubmedParser_Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*
* \file PubmedParser_Extension.php
*
* Copyright 2011-2017 Daniel Kraus <bovender@bovender.de>
* Copyright 2011-2019 Daniel Kraus <bovender@bovender.de>
*
* 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
Expand Down
14 changes: 7 additions & 7 deletions includes/PubmedParser_Helpers.php
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
<?php
/*
* \file PubmedParser.helpers.php
*
* Copyright 2011-2017 Daniel Kraus <krada@gmx.net>
*
*
* Copyright 2011-2019 Daniel Kraus <krada@gmx.net>
*
* 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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* 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.
*/
namespace PubmedParser;

if ( !defined( 'MEDIAWIKI' ) ) {
die( 'This is an extension to MediaWiki and cannot be run standalone.' );
}
Expand Down Expand Up @@ -63,7 +63,7 @@ public static function Pmc2Pmid($pmc, &$pmid) {
if (self::FetchRemote($url, $json)) {
$data = json_decode($json, true);
try {
$pmid = $data['records'][0]['pmid'];
$pmid = $data['records'][0]['pmid'];
$result = true;
}
catch (Exception $e) { }
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php
/**
* Unit tests for the PubmedParser extension.
* group Database
* @group Database
* @group bovender
* @covers PubmedParser\Article
*/
namespace PubmedParser;
Expand Down
Loading

0 comments on commit 0f11f3b

Please sign in to comment.