Merge pull request #600 from jgen/develop

Bump PHP version up to 5.6 & Linting/fixes
This commit is contained in:
Shish 2017-03-10 11:11:38 +00:00 committed by GitHub
commit 55ee93fd27
16 changed files with 1455 additions and 62 deletions

View File

@ -1,9 +1,8 @@
language: php language: php
php: php:
- 5.4
- 5.5
- 5.6 - 5.6
- 7.0 - 7.0
- 7.1
sudo: false sudo: false

View File

@ -29,7 +29,7 @@ check out one of the versioned branches.
# Requirements # Requirements
- MySQL/MariaDB 5.1+ (with experimental support for PostgreSQL 9+ and SQLite 3) - MySQL/MariaDB 5.1+ (with experimental support for PostgreSQL 9+ and SQLite 3)
- [Stable PHP](https://en.wikipedia.org/wiki/PHP#Release_history) (5.5 as of writing) - [Stable PHP](https://en.wikipedia.org/wiki/PHP#Release_history) (5.6+ as of writing)
- GD or ImageMagick - GD or ImageMagick
# Installation # Installation

View File

@ -19,7 +19,7 @@
], ],
"require" : { "require" : {
"php" : ">=5.4.8", "php" : ">=5.6",
"flexihash/flexihash" : "^2.0.0", "flexihash/flexihash" : "^2.0.0",
"ifixit/php-akismet" : "1.*", "ifixit/php-akismet" : "1.*",
@ -29,11 +29,15 @@
"bower-asset/jquery" : "1.12.3", "bower-asset/jquery" : "1.12.3",
"bower-asset/jquery-timeago" : "1.5.2", "bower-asset/jquery-timeago" : "1.5.2",
"bower-asset/tablesorter" : "2.0.5", "bower-asset/tablesorter" : "2.*",
"bower-asset/mediaelement" : "2.21.1", "bower-asset/mediaelement" : "2.21.1",
"bower-asset/js-cookie" : "2.1.1" "bower-asset/js-cookie" : "2.1.1"
}, },
"require-dev" : {
"phpunit/phpunit" : "5.*"
},
"vendor-copy": { "vendor-copy": {
"vendor/bower-asset/jquery/dist/jquery.min.js" : "lib/vendor/js/jquery-1.12.3.min.js", "vendor/bower-asset/jquery/dist/jquery.min.js" : "lib/vendor/js/jquery-1.12.3.min.js",
"vendor/bower-asset/jquery/dist/jquery.min.map" : "lib/vendor/js/jquery-1.12.3.min.map", "vendor/bower-asset/jquery/dist/jquery.min.map" : "lib/vendor/js/jquery-1.12.3.min.map",

1343
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -263,11 +263,34 @@ class SQLite extends DBEngine {
// }}} // }}}
// {{{ cache engines // {{{ cache engines
interface CacheEngine { interface CacheEngine {
/**
* @param string $key
* @return mixed
*/
public function get($key); public function get($key);
/**
* @param string $key
* @param mixed $val
* @param integer $time
* @return void
*/
public function set($key, $val, $time=0); public function set($key, $val, $time=0);
/**
* @return void
*/
public function delete($key); public function delete($key);
/**
* @return integer
*/
public function get_hits(); public function get_hits();
/**
* @return integer
*/
public function get_misses(); public function get_misses();
} }
class NoCache implements CacheEngine { class NoCache implements CacheEngine {
@ -324,7 +347,7 @@ class MemcacheCache implements CacheEngine {
/** /**
* @param string $key * @param string $key
* @param mixed $val * @param mixed $val
* @param int $time * @param integer $time
*/ */
public function set($key, $val, $time=0) { public function set($key, $val, $time=0) {
assert('!is_null($key)'); assert('!is_null($key)');
@ -401,6 +424,10 @@ class Database {
* @var null|PDO * @var null|PDO
*/ */
private $db = null; private $db = null;
/**
* @var float
*/
public $dbtime = 0.0; public $dbtime = 0.0;
/** /**
@ -509,7 +536,7 @@ class Database {
} }
/** /**
* @return bool * @return boolean|null
* @throws SCoreException * @throws SCoreException
*/ */
public function commit() { public function commit() {
@ -525,7 +552,7 @@ class Database {
} }
/** /**
* @return bool * @return boolean|null
* @throws SCoreException * @throws SCoreException
*/ */
public function rollback() { public function rollback() {
@ -566,6 +593,10 @@ class Database {
return $this->engine->name; return $this->engine->name;
} }
/**
* @param null|PDO $db
* @param string $sql
*/
private function count_execs($db, $sql, $inputarray) { private function count_execs($db, $sql, $inputarray) {
if ((defined('DEBUG_SQL') && DEBUG_SQL === true) || (!defined('DEBUG_SQL') && @$_GET['DEBUG_SQL'])) { if ((defined('DEBUG_SQL') && DEBUG_SQL === true) || (!defined('DEBUG_SQL') && @$_GET['DEBUG_SQL'])) {
$fp = @fopen("data/sql.log", "a"); $fp = @fopen("data/sql.log", "a");
@ -786,35 +817,35 @@ class MockDatabase extends Database {
/** /**
* @param string $query * @param string $query
* @param array $args * @param array $args
* @return array|PDOStatement * @return PDOStatement
*/ */
public function get_all($query, $args=array()) {return $this->execute($query, $args);} public function get_all($query, $args=array()) {return $this->execute($query, $args);}
/** /**
* @param string $query * @param string $query
* @param array $args * @param array $args
* @return mixed|null|PDOStatement * @return PDOStatement
*/ */
public function get_row($query, $args=array()) {return $this->execute($query, $args);} public function get_row($query, $args=array()) {return $this->execute($query, $args);}
/** /**
* @param string $query * @param string $query
* @param array $args * @param array $args
* @return array|PDOStatement * @return PDOStatement
*/ */
public function get_col($query, $args=array()) {return $this->execute($query, $args);} public function get_col($query, $args=array()) {return $this->execute($query, $args);}
/** /**
* @param string $query * @param string $query
* @param array $args * @param array $args
* @return array|PDOStatement * @return PDOStatement
*/ */
public function get_pairs($query, $args=array()) {return $this->execute($query, $args);} public function get_pairs($query, $args=array()) {return $this->execute($query, $args);}
/** /**
* @param string $query * @param string $query
* @param array $args * @param array $args
* @return mixed|PDOStatement * @return PDOStatement
*/ */
public function get_one($query, $args=array()) {return $this->execute($query, $args);} public function get_one($query, $args=array()) {return $this->execute($query, $args);}

View File

@ -92,6 +92,9 @@ abstract class Extension {
$this->theme = $this->get_theme_object(get_called_class()); $this->theme = $this->get_theme_object(get_called_class());
} }
/**
* @return boolean
*/
public function is_live() { public function is_live() {
global $database; global $database;
return ( return (

View File

@ -175,6 +175,10 @@ class Image {
return $images; return $images;
} }
/**
* @param string[] $tags
* @return boolean
*/
public function validate_accel($tags) { public function validate_accel($tags) {
$yays = 0; $yays = 0;
$nays = 0; $nays = 0;

View File

@ -8,7 +8,7 @@ require_once "lib/context.php";
/** /**
* Make some data safe for printing into HTML * Make some data safe for printing into HTML
* *
* @param $input * @param string $input
* @return string * @return string
*/ */
function html_escape($input) { function html_escape($input) {
@ -18,7 +18,7 @@ function html_escape($input) {
/** /**
* Unescape data that was made safe for printing into HTML * Unescape data that was made safe for printing into HTML
* *
* @param $input * @param string $input
* @return string * @return string
*/ */
function html_unescape($input) { function html_unescape($input) {
@ -28,7 +28,7 @@ function html_unescape($input) {
/** /**
* Make sure some data is safe to be used in integer context * Make sure some data is safe to be used in integer context
* *
* @param $input * @param string $input
* @return int * @return int
*/ */
function int_escape($input) { function int_escape($input) {
@ -42,7 +42,7 @@ function int_escape($input) {
/** /**
* Make sure some data is safe to be used in URL context * Make sure some data is safe to be used in URL context
* *
* @param $input * @param string $input
* @return string * @return string
*/ */
function url_escape($input) { function url_escape($input) {
@ -77,7 +77,7 @@ function url_escape($input) {
/** /**
* Make sure some data is safe to be used in SQL context * Make sure some data is safe to be used in SQL context
* *
* @param $input * @param string $input
* @return string * @return string
*/ */
function sql_escape($input) { function sql_escape($input) {
@ -90,7 +90,7 @@ function sql_escape($input) {
* Turn all manner of HTML / INI / JS / DB booleans into a PHP one * Turn all manner of HTML / INI / JS / DB booleans into a PHP one
* *
* @param mixed $input * @param mixed $input
* @return bool * @return boolean
*/ */
function bool_escape($input) { function bool_escape($input) {
/* /*
@ -125,7 +125,7 @@ function bool_escape($input) {
* Some functions require a callback function for escaping, * Some functions require a callback function for escaping,
* but we might not want to alter the data * but we might not want to alter the data
* *
* @param $input * @param string $input
* @return string * @return string
*/ */
function no_escape($input) { function no_escape($input) {
@ -202,7 +202,7 @@ function truncate($string, $limit, $break=" ", $pad="...") {
/** /**
* Turn a human readable filesize into an integer, eg 1KB -> 1024 * Turn a human readable filesize into an integer, eg 1KB -> 1024
* *
* @param $limit * @param string|integer $limit
* @return int * @return int
*/ */
function parse_shorthand_int($limit) { function parse_shorthand_int($limit) {
@ -232,7 +232,7 @@ function parse_shorthand_int($limit) {
/** /**
* Turn an integer into a human readable filesize, eg 1024 -> 1KB * Turn an integer into a human readable filesize, eg 1024 -> 1KB
* *
* @param $int * @param integer $int
* @return string * @return string
*/ */
function to_shorthand_int($int) { function to_shorthand_int($int) {
@ -254,7 +254,7 @@ function to_shorthand_int($int) {
/** /**
* Turn a date into a time, a date, an "X minutes ago...", etc * Turn a date into a time, a date, an "X minutes ago...", etc
* *
* @param $date * @param string $date
* @param bool $html * @param bool $html
* @return string * @return string
*/ */
@ -267,7 +267,7 @@ function autodate($date, $html=true) {
/** /**
* Check if a given string is a valid date-time. ( Format: yyyy-mm-dd hh:mm:ss ) * Check if a given string is a valid date-time. ( Format: yyyy-mm-dd hh:mm:ss )
* *
* @param $dateTime * @param string $dateTime
* @return bool * @return bool
*/ */
function isValidDateTime($dateTime) { function isValidDateTime($dateTime) {
@ -283,7 +283,7 @@ function isValidDateTime($dateTime) {
/** /**
* Check if a given string is a valid date. ( Format: yyyy-mm-dd ) * Check if a given string is a valid date. ( Format: yyyy-mm-dd )
* *
* @param $date * @param string $date
* @return bool * @return bool
*/ */
function isValidDate($date) { function isValidDate($date) {
@ -297,6 +297,9 @@ function isValidDate($date) {
return false; return false;
} }
/**
* @param string[] $inputs
*/
function validate_input($inputs) { function validate_input($inputs) {
$outputs = array(); $outputs = array();
@ -391,8 +394,8 @@ function validate_input($inputs) {
* *
* FIXME: also check that IP ban ext is installed * FIXME: also check that IP ban ext is installed
* *
* @param $ip * @param string $ip
* @param $ban_reason * @param string $ban_reason
* @return string * @return string
*/ */
function show_ip($ip, $ban_reason) { function show_ip($ip, $ban_reason) {
@ -616,6 +619,7 @@ function zglob($pattern) {
/** /**
* Gets contact link as mailto: or http: * Gets contact link as mailto: or http:
* @return string
*/ */
function contact_link() { function contact_link() {
global $config; global $config;
@ -1734,6 +1738,9 @@ function _get_user() {
return $user; return $user;
} }
/**
* @return string
*/
function _get_query() { function _get_query() {
return @$_POST["q"]?:@$_GET["q"]; return @$_POST["q"]?:@$_GET["q"];
} }

View File

@ -86,6 +86,12 @@ xanax
$event->panel->add_block($sb); $event->panel->add_block($sb);
} }
/**
* Throws if the comment contains banned words.
* @param string $comment
* @param CommentPostingException|SCoreException $ex
* @throws CommentPostingException|SCoreException if the comment contains banned words.
*/
private function test_text($comment, $ex) { private function test_text($comment, $ex) {
$comment = strtolower($comment); $comment = strtolower($comment);
@ -105,6 +111,9 @@ xanax
} }
} }
/**
* @return string[]
*/
private function get_words() { private function get_words() {
global $config; global $config;
$words = array(); $words = array();

View File

@ -59,6 +59,11 @@ class _SafeOuroborosImage
* @var integer * @var integer
*/ */
public $width = null; public $width = null;
/**
* File extension
* @var string
*/
public $file_ext = '';
/** /**
* File Size in bytes * File Size in bytes
* @var integer * @var integer
@ -189,7 +194,7 @@ class _SafeOuroborosImage
* Constructor * Constructor
* @param Image $img * @param Image $img
*/ */
function __construct(Image $img) public function __construct(Image $img)
{ {
global $config; global $config;
// author // author
@ -343,7 +348,7 @@ class _SafeOuroborosTag
public $name = ''; public $name = '';
public $type = 0; public $type = 0;
function __construct(array $tag) public function __construct(array $tag)
{ {
$this->count = $tag['count']; $this->count = $tag['count'];
$this->id = $tag['id']; $this->id = $tag['id'];

View File

@ -157,6 +157,11 @@ class SetupBlock extends Block {
$this->body .= "<input type='hidden' name='_type_$name' value='int'>\n"; $this->body .= "<input type='hidden' name='_type_$name' value='int'>\n";
} }
/**
* @param string $name
* @param string[] $options
* @param null|string $label
*/
public function add_choice_option($name, $options, $label=null) { public function add_choice_option($name, $options, $label=null) {
global $config; global $config;
$current = $config->get_string($name); $current = $config->get_string($name);
@ -176,6 +181,11 @@ class SetupBlock extends Block {
$this->body .= $html; $this->body .= $html;
} }
/**
* @param string $name
* @param string[] $options
* @param null|string $label
*/
public function add_multichoice_option($name, $options, $label=null) { public function add_multichoice_option($name, $options, $label=null) {
global $config; global $config;
$current = $config->get_array($name); $current = $config->get_array($name);

View File

@ -83,18 +83,6 @@ class TagEditCloud extends Extension {
} }
switch($sort_method) { switch($sort_method) {
case 'a':
case 'p':
default:
$order_by = $sort_method == 'a' ? "tag" : "count DESC";
$tag_data = $database->get_all("
SELECT tag, FLOOR(LN(LN(count - :tag_min1 + 1)+1)*150)/200 AS scaled, count
FROM tags
WHERE count >= :tag_min2
ORDER BY $order_by
LIMIT :limit",
array("tag_min1" => $tags_min, "tag_min2" => $tags_min, "limit" => $max_count));
break;
case 'r': case 'r':
$relevant_tags = array_diff($image->get_tag_array(),$ignore_tags); $relevant_tags = array_diff($image->get_tag_array(),$ignore_tags);
if(count($relevant_tags) == 0) { if(count($relevant_tags) == 0) {
@ -113,6 +101,18 @@ class TagEditCloud extends Extension {
LIMIT :limit", LIMIT :limit",
array("tag_min1" => $tags_min, "tag_min2" => $tags_min, "limit" => $max_count)); array("tag_min1" => $tags_min, "tag_min2" => $tags_min, "limit" => $max_count));
break; break;
case 'a':
case 'p':
default:
$order_by = $sort_method == 'a' ? "tag" : "count DESC";
$tag_data = $database->get_all("
SELECT tag, FLOOR(LN(LN(count - :tag_min1 + 1)+1)*150)/200 AS scaled, count
FROM tags
WHERE count >= :tag_min2
ORDER BY $order_by
LIMIT :limit",
array("tag_min1" => $tags_min, "tag_min2" => $tags_min, "limit" => $max_count));
break;
} }
$counter = 1; $counter = 1;

View File

@ -220,7 +220,7 @@ class Wiki extends Extension {
/** /**
* @param string $title * @param string $title
* @param int|null $revision * @param integer $revision
* @return WikiPage * @return WikiPage
*/ */
private function get_page($title, $revision=-1) { private function get_page($title, $revision=-1) {

View File

@ -114,6 +114,9 @@ do_install();
// utilities {{{ // utilities {{{
// TODO: Can some of these be pushed into "core/util.inc.php" ? // TODO: Can some of these be pushed into "core/util.inc.php" ?
/**
* @return int
*/
function check_gd_version() { function check_gd_version() {
$gdversion = 0; $gdversion = 0;
@ -129,6 +132,9 @@ function check_gd_version() {
return $gdversion; return $gdversion;
} }
/**
* @return int
*/
function check_im_version() { function check_im_version() {
$convert_check = exec("convert"); $convert_check = exec("convert");
@ -469,6 +475,12 @@ EOD;
echo "\n"; echo "\n";
} // }}} } // }}}
/**
* @param boolean $isPDO
* @param string $errorMessage1
* @param string $errorMessage2
* @param integer $exitCode
*/
function handle_db_errors(/*bool*/ $isPDO, /*str*/ $errorMessage1, /*str*/ $errorMessage2, /*int*/ $exitCode) { function handle_db_errors(/*bool*/ $isPDO, /*str*/ $errorMessage1, /*str*/ $errorMessage2, /*int*/ $exitCode) {
$errorMessage1Extra = ($isPDO ? "Please check and ensure that the database configuration options are all correct." : "Please check the server log files for more information."); $errorMessage1Extra = ($isPDO ? "Please check and ensure that the database configuration options are all correct." : "Please check the server log files for more information.");
print <<<EOD print <<<EOD

View File

@ -16,7 +16,7 @@ if(is_null(User::by_name("demo"))) {
$userPage->onUserCreation(new UserCreationEvent("test", "test", "")); $userPage->onUserCreation(new UserCreationEvent("test", "test", ""));
} }
abstract class ShimmiePHPUnitTestCase extends PHPUnit_Framework_TestCase { abstract class ShimmiePHPUnitTestCase extends \PHPUnit_Framework_TestCase {
protected $backupGlobalsBlacklist = array('database', 'config'); protected $backupGlobalsBlacklist = array('database', 'config');
private $images = array(); private $images = array();

View File

@ -164,7 +164,7 @@ class Layout {
$flash = $page->get_cookie("flash_message"); $flash = $page->get_cookie("flash_message");
$flash_html = ""; $flash_html = "";
if($flash) { if(!empty($flash)) {
$flash_html = "<b id='flash'>".nl2br(html_escape($flash))." <a href='#' onclick=\"\$('#flash').hide(); return false;\">[X]</a></b>"; $flash_html = "<b id='flash'>".nl2br(html_escape($flash))." <a href='#' onclick=\"\$('#flash').hide(); return false;\">[X]</a></b>";
} }
@ -242,7 +242,7 @@ EOD;
/** /**
* @param string $link * @param string $link
* @param null|string $desc * @param null|string $desc
* @param array $pages_matched * @param string[] $pages_matched
* @return null|string * @return null|string
*/ */
public function navlinks($link, $desc, $pages_matched) { public function navlinks($link, $desc, $pages_matched) {