もっとPHP 8.2対応

このコミットが含まれているのは:
守矢諏訪子 2023-08-29 02:37:25 +09:00
コミット e8e27ca83e
40個のファイルの変更260行の追加151行の削除

1
.gitignore vendored
ファイルの表示

@ -16,4 +16,3 @@ TODO.rym
config-*.php
good-config.php
*.mo
/vendor/

ファイルの表示

@ -27,6 +27,8 @@ defined('GNUSOCIAL') || die();
class Attention extends Managed_DataObject
{
public $is_mariadb;
public $__table = 'attention'; // table name
public $notice_id; // int(4) primary_key not_null
public $profile_id; // int(4) primary_key not_null

ファイルの表示

@ -30,6 +30,8 @@ defined('GNUSOCIAL') || die();
*/
class File extends Managed_DataObject
{
public $is_mariadb;
public $__table = 'file'; // table name
public $id; // int(4) primary_key not_null
public $urlhash; // varchar(64) unique_key

ファイルの表示

@ -887,11 +887,12 @@ class Notice extends Managed_DataObject
$stored->verb = $act->verb;
// we use mb_strlen because it _might_ be that the content is just the string "0"...
$content = mb_strlen($act->content) ? $act->content : $act->summary;
if (is_null($content)) {
$content = ($act->content !== null && mb_strlen($act->content)) ? $act->content : $act->summary;
if ($content !== null) {
throw new ClientException(_('投稿はNULLです。'));
}
if (mb_strlen($content)===0 && !is_null($actobj)) {
if (($actobj !== null && $actobj->content !== null && mb_strlen($actobj->content)) === 0) {
$content = mb_strlen($actobj->content) ? $actobj->content : $actobj->summary;
}
// Strip out any bad HTML from $content. URI.Base is used to sort out relative URLs.

ファイルの表示

@ -22,6 +22,8 @@ defined('GNUSOCIAL') || die();
class Reply extends Managed_DataObject
{
public $is_mariadb;
###START_AUTOCODE
/* the code below is auto generated do not remove the above tag */

ファイルの表示

@ -387,11 +387,11 @@ class Action extends HTMLOutputter // lawsuit
$lm = $this->lastModified();
$etag = $this->etag();
if ($etag) {
if ($etag !== null) {
header('ETag: ' . $etag);
}
if ($lm) {
if ($lm !== null) {
header('Last-Modified: ' . date(DATE_RFC1123, $lm));
if ($this->isCacheable()) {
header('Expires: ' . gmdate('D, d M Y H:i:s', 0) . ' GMT');
@ -401,9 +401,8 @@ class Action extends HTMLOutputter // lawsuit
}
$checked = false;
if ($etag) {
$if_none_match = (array_key_exists('HTTP_IF_NONE_MATCH', $_SERVER)) ?
$_SERVER['HTTP_IF_NONE_MATCH'] : null;
if ($etag !== null) {
$if_none_match = isset($_SERVER['HTTP_IF_NONE_MATCH']) ? $_SERVER['HTTP_IF_NONE_MATCH'] : null;
if ($if_none_match) {
// If this check fails, ignore the if-modified-since below.
$checked = true;
@ -415,7 +414,7 @@ class Action extends HTMLOutputter // lawsuit
}
}
if (!$checked && $lm && array_key_exists('HTTP_IF_MODIFIED_SINCE', $_SERVER)) {
if (!$checked && $lm !== null && isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
$if_modified_since = $_SERVER['HTTP_IF_MODIFIED_SINCE'];
$ims = strtotime($if_modified_since);
if ($lm <= $ims) {

ファイルの表示

@ -44,6 +44,9 @@ require_once INSTALLDIR . '/lib/groups/grouplist.php';
*/
class GroupMiniList extends GroupList
{
public $widgetOpts;
public $scoped;
function show()
{
$this->out->elementStart('ul', 'entities groups xoxo');

ファイルの表示

@ -31,6 +31,9 @@ if (!defined('GNUSOCIAL')) { exit(1); }
class InlineAttachmentList extends AttachmentList
{
public $widgetOpts;
public $scoped;
function showListStart()
{
$this->out->element('h4', 'attachments-title', _('Attachments'));

ファイルの表示

@ -37,6 +37,8 @@ defined('GNUSOCIAL') || die();
*/
class ConversationNoticeStream extends ScopingNoticeStream
{
public $scoped;
public function __construct($id, Profile $scoped = null)
{
parent::__construct(

ファイルの表示

@ -49,6 +49,9 @@ if (!defined('GNUSOCIAL') && !defined('STATUSNET')) { exit(1); }
*/
class NoticeList extends Widget
{
public $widgetOpts;
public $scoped;
/** the current stream of notices being displayed. */
var $notice = null;

ファイルの表示

@ -44,6 +44,9 @@ defined('GNUSOCIAL') || die();
*/
class NoticeListItem extends Widget
{
public $widgetOpts;
public $scoped;
/** The notice this item will show. */
public $notice = null;
@ -238,7 +241,7 @@ class NoticeListItem extends Widget
// -> The id
$id = (empty($this->repeat)) ? $this->notice->id : $this->repeat->id;
$id_prefix = (strlen($this->id_prefix) ? $this->id_prefix . '-' : '');
$id_decl = "${id_prefix}notice-${id}";
$id_decl = "{$id_prefix}notice-{$id}";
$attrs['id'] = $id_decl;
// -> The class

ファイルの表示

@ -44,6 +44,9 @@ if (!defined('GNUSOCIAL') && !defined('STATUSNET')) { exit(1); }
*/
class PrimaryNoticeList extends NoticeList
{
public $widgetOpts;
public $scoped;
public function show()
{
$this->out->elementStart('div', array('id' =>'notices_primary'));

ファイルの表示

@ -38,6 +38,9 @@ defined('GNUSOCIAL') || die();
class ProfileNoticeStream extends ScopingNoticeStream
{
public $widgetOpts;
public $scoped;
protected $target;
public function __construct(Profile $target, Profile $scoped = null)

ファイルの表示

@ -38,6 +38,8 @@ defined('GNUSOCIAL') || die();
class ReplyNoticeStream extends ScopingNoticeStream
{
public $scoped;
public function __construct($userId, Profile $scoped = null)
{
parent::__construct(

ファイルの表示

@ -42,6 +42,9 @@ if (!defined('GNUSOCIAL')) { exit(1); }
*/
class AccountProfileBlock extends ProfileBlock
{
public $widgetOpts;
public $scoped;
protected $profile = null;
protected $user = null;

ファイルの表示

@ -41,6 +41,9 @@ if (!defined('GNUSOCIAL')) { exit(1); }
class ProfileMiniList extends ProfileList
{
public $widgetOpts;
public $scoped;
const MAX_PROFILES = PROFILES_PER_MINILIST; // put it in the class
function startList()

ファイルの表示

@ -4,6 +4,9 @@ if (!defined('GNUSOCIAL')) { exit(1); }
class SubscribersMiniList extends ProfileMiniList
{
public $widgetOpts;
public $scoped;
public function newListItem(Profile $profile)
{
return new SubscribersMiniListItem($profile, $this->action);

ファイルの表示

@ -658,7 +658,7 @@ function common_remove_unicode_formatting($text)
{
// Strip Unicode text formatting/direction codes
// this is pretty dangerous for visualisation of text and can be used for mischief
return preg_replace('/[\\x{200b}-\\x{200f}\\x{202a}-\\x{202e}]/u', '', $text);
return $text !== null ? preg_replace('/[\\x{200b}-\\x{200f}\\x{202a}-\\x{202e}]/u', '', $text) : null;
}
/**

ファイルの表示

@ -42,6 +42,8 @@ defined('GNUSOCIAL') || die();
*/
class xmloutputter
{
private const EMPTY_TAG = ['base', 'meta', 'link', 'hr', 'br', 'param', 'img', 'area', 'input', 'col', 'source'];
/**
* Wrapped XMLWriter object, which does most of the heavy lifting
* for output.
@ -146,14 +148,20 @@ class xmloutputter
*
* @return void
*/
public function elementStart(string $tag, $attrs = null): void
public function elementStart(string $tag, null|array|string $attrs = null): void
{
$this->xw->startElement($tag);
if (is_array($attrs)) {
foreach ($attrs as $name => $value) {
if (!is_null($value)) $this->xw->writeAttribute($name, $value);
if ($value !== null) {
$this->xw->writeAttribute($name, $value);
}
}
} elseif (is_string($attrs)) {
return;
}
if (is_string($attrs)) {
$this->xw->writeAttribute('class', $attrs);
}
}
@ -175,15 +183,13 @@ class xmloutputter
*/
public function elementEnd(string $tag): void
{
static $empty_tag = ['base', 'meta', 'link', 'hr',
'br', 'param', 'img', 'area',
'input', 'col', 'source', ];
// XXX: check namespace
if (in_array($tag, $empty_tag)) {
if (in_array($tag, self::EMPTY_TAG, true)) {
$this->xw->endElement();
} else {
$this->xw->fullEndElement();
return;
}
$this->xw->fullEndElement();
}
/**
@ -273,6 +279,8 @@ class xmloutputter
*/
public function flush(): void
{
$this->xw->flush();
if (headers_sent()) {
$this->xw->flush();
}
}
}

ファイルの表示

@ -23,6 +23,12 @@
defined('GNUSOCIAL') || die();
include("classes/Fave.php");
include("lib/threadednoticelistfavesitem.php");
include("lib/favcommand.php");
include("lib/popularnoticestream.php");
include("lib/favenoticestream.php");
include("lib/popularnoticesection.php");
include("lib/threadednoticelistinlinefavesitem.php");
class FavoriteModule extends ActivityVerbHandlerModule
{

ファイルの表示

@ -46,6 +46,9 @@ if (!defined('GNUSOCIAL')) { exit(1); }
*/
class FavorForm extends Form
{
public $widgetOpts;
public $scoped;
/**
* Notice to favor
*/

ファイルの表示

@ -37,6 +37,8 @@ defined('GNUSOCIAL') || die();
*/
class FaveNoticeStream extends ScopingNoticeStream
{
public $scoped;
public function __construct(Profile $target, Profile $scoped = null)
{
$stream = new RawFaveNoticeStream($target, $scoped);

ファイルの表示

@ -45,6 +45,9 @@ if (!defined('STATUSNET') && !defined('LACONICA')) {
*/
class PopularNoticeSection extends NoticeSection
{
public $widgetOpts;
public $scoped;
protected $viewer;
function __construct($out, Profile $viewer=null)

ファイルの表示

@ -38,6 +38,9 @@ defined('GNUSOCIAL') || die();
class PopularNoticeStream extends ScopingNoticeStream
{
public $widgetOpts;
public $scoped;
public function __construct(Profile $scoped=null)
{
parent::__construct(

ファイルの表示

@ -18,6 +18,11 @@
*/
if (!defined('GNUSOCIAL')) { exit(1); }
include("lib/repeatcommand.php");
//include("lib/repeatedbymenoticestream.php");
//include("lib/repeatsofmenoticestream.php");
//include("lib/threadednoticelistinlinerepeatsitem.php");
include("lib/threadednoticelistrepeatsitem.php");
/**
* @package Activity

ファイルの表示

@ -65,16 +65,27 @@ class AccountManagerPlugin extends Plugin
function onStartShowHTML($action)
{
//Account management discovery link
header('Link: <'.common_local_url('AccountManagementControlDocument').'>; rel="'. AccountManagerPlugin::AM_REL.'"; type="application/json"');
if (headers_sent($filename, $linenum)) {
error_log("Headers already sent in $filename on line $linenum\n");
return;
}
//Account management login status
$cur = common_current_user();
if(empty($cur)) {
header('X-Account-Management-Status: none');
} else {
//TODO it seems " should be escaped in the name and id, but the spec doesn't seem to indicate how to do that
header('X-Account-Management-Status: active; name="' . $cur->nickname . '"; id="' . $cur->nickname . '"');
try {
//Account management discovery link
$url = htmlspecialchars(common_local_url('AccountManagementControlDocument'), ENT_QUOTES, 'UTF-8');
header('Link: <'.$url.'>; rel="'. AccountManagerPlugin::AM_REL.'"; type="application/json"');
//Account management login status
$cur = common_current_user();
if(empty($cur)) {
header('X-Account-Management-Status: none');
} else {
$nickname = htmlspecialchars($cur->nickname, ENT_QUOTES, 'UTF-8');
header('X-Account-Management-Status: active; name="' . $nickname . '"; id="' . $nickname . '"');
}
} catch (Exception $e) {
throw new Exception($e->getMessage());
}
}

ファイルの表示

@ -30,6 +30,9 @@
if (!defined('GNUSOCIAL')) { exit(1); }
include("classes/Bookmark.php");
include("lib/bookmarksnoticestream.php");
include("lib/deliciousbackupimporter.php");
include("lib/deliciousbookmarkimporter.php");
/**
* Bookmark plugin main class

ファイルの表示

@ -42,6 +42,9 @@ if (!defined('STATUSNET')) {
*/
class BookmarksAction extends Action
{
public $page;
public $notices;
var $user = null;
var $gc = null;

ファイルの表示

@ -74,6 +74,8 @@ class RawBookmarksNoticeStream extends NoticeStream
class BookmarksNoticeStream extends ScopingNoticeStream
{
public $scoped;
public function __construct($user_id, $own, Profile $scoped = null)
{
$stream = new RawBookmarksNoticeStream($user_id, $own);

ファイルの表示

@ -37,6 +37,8 @@ defined('GNUSOCIAL') || die();
*/
class InboxAction extends MailboxAction
{
public $user;
/**
* Title of the page.
*

ファイルの表示

@ -46,6 +46,9 @@ if (!defined('STATUSNET')) {
*/
class MailboxMenu extends Menu
{
public $widgetOpts;
public $scoped;
function show()
{
$cur = common_current_user();

ファイルの表示

@ -38,6 +38,9 @@ defined('GNUSOCIAL') || die();
*/
class MessageForm extends Form
{
public $widgetOpts;
public $scoped;
protected $to = null;
protected $content = null;

ファイルの表示

@ -31,6 +31,8 @@
if (!defined('GNUSOCIAL')) { exit(1); }
include("classes/Happening.php");
include("classes/RSVP.php");
include("lib/eventsnoticestream.php");
include("lib/eventtimelist.php");
/**
* Event plugin

ファイルの表示

@ -53,6 +53,8 @@ class RawEventsNoticeStream extends NoticeStream
class EventsNoticeStream extends ScopingNoticeStream
{
public $scoped;
// possible values of RSVP in our database
protected $rsvp = ['Y', 'N', '?'];
protected $target = null;

ファイルの表示

@ -46,6 +46,9 @@ if (!defined('STATUSNET')) {
*/
class NewpollForm extends Form
{
public $widgetOpts;
public $scoped;
protected $question = null;
protected $options = array();

ファイルの表示

@ -62,12 +62,14 @@ define('PUBLICDIR', INSTALLDIR . DIRECTORY_SEPARATOR . 'public');
define('GNUSOCIAL', true);
define('STATUSNET', true); // compatibility
include("../lib/util/util.php");
$user = null;
$action = null;
function getPath($req)
{
$p = null;
$p = "";
if ((common_config('site', 'fancy') || !array_key_exists('PATH_INFO', $_SERVER))
&& array_key_exists('p', $req)
@ -81,8 +83,6 @@ function getPath($req)
} else {
$p = $path;
}
} else {
$p = null;
}
// Trim all initial '/'

ファイルの表示

@ -7,6 +7,7 @@
*/
class HTMLPurifier_AttrTransform_NameSync extends HTMLPurifier_AttrTransform
{
public $idDef;
public function __construct()
{

ファイルの表示

@ -304,6 +304,10 @@ class HTMLPurifier_Lexer
*/
public function normalize($html, $config, $context)
{
if ($html === null) {
return;
}
// normalize newlines to \n
if ($config->get('Core.NormalizeNewlines')) {
$html = str_replace("\r\n", "\n", $html);

ファイルの表示

@ -26,6 +26,7 @@
class HTMLPurifier_Lexer_DOMLex extends HTMLPurifier_Lexer
{
public $_entity_parser;
/**
* @type HTMLPurifier_TokenFactory
@ -47,6 +48,7 @@ class HTMLPurifier_Lexer_DOMLex extends HTMLPurifier_Lexer
*/
public function tokenizeHTML($html, $config, $context)
{
if ($html === null) return;
$html = $this->normalize($html, $config, $context);
// attempt to armor stray angled brackets that cannot possibly

ファイルの表示

@ -58,142 +58,144 @@ class HTMLPurifier_Strategy_RemoveForeignElements extends HTMLPurifier_Strategy
$e =& $context->get('ErrorCollector');
}
foreach ($tokens as $token) {
if ($remove_until) {
if (empty($token->is_tag) || $token->name !== $remove_until) {
continue;
}
}
if (!empty($token->is_tag)) {
// DEFINITION CALL
// before any processing, try to transform the element
if (isset($definition->info_tag_transform[$token->name])) {
$original_name = $token->name;
// there is a transformation for this tag
// DEFINITION CALL
$token = $definition->
info_tag_transform[$token->name]->transform($token, $config, $context);
if ($e) {
$e->send(E_NOTICE, 'Strategy_RemoveForeignElements: Tag transform', $original_name);
if ($tokens !== null) {
foreach ($tokens as $token) {
if ($remove_until) {
if (empty($token->is_tag) || $token->name !== $remove_until) {
continue;
}
}
if (!empty($token->is_tag)) {
// DEFINITION CALL
if (isset($definition->info[$token->name])) {
// mostly everything's good, but
// we need to make sure required attributes are in order
if (($token instanceof HTMLPurifier_Token_Start || $token instanceof HTMLPurifier_Token_Empty) &&
$definition->info[$token->name]->required_attr &&
($token->name != 'img' || $remove_invalid_img) // ensure config option still works
) {
$attr_validator->validateToken($token, $config, $context);
$ok = true;
foreach ($definition->info[$token->name]->required_attr as $name) {
if (!isset($token->attr[$name])) {
$ok = false;
break;
// before any processing, try to transform the element
if (isset($definition->info_tag_transform[$token->name])) {
$original_name = $token->name;
// there is a transformation for this tag
// DEFINITION CALL
$token = $definition->
info_tag_transform[$token->name]->transform($token, $config, $context);
if ($e) {
$e->send(E_NOTICE, 'Strategy_RemoveForeignElements: Tag transform', $original_name);
}
}
if (isset($definition->info[$token->name])) {
// mostly everything's good, but
// we need to make sure required attributes are in order
if (($token instanceof HTMLPurifier_Token_Start || $token instanceof HTMLPurifier_Token_Empty) &&
$definition->info[$token->name]->required_attr &&
($token->name != 'img' || $remove_invalid_img) // ensure config option still works
) {
$attr_validator->validateToken($token, $config, $context);
$ok = true;
foreach ($definition->info[$token->name]->required_attr as $name) {
if (!isset($token->attr[$name])) {
$ok = false;
break;
}
}
if (!$ok) {
if ($e) {
$e->send(
E_ERROR,
'Strategy_RemoveForeignElements: Missing required attribute',
$name
);
}
continue;
}
$token->armor['ValidateAttributes'] = true;
}
if (isset($hidden_elements[$token->name]) && $token instanceof HTMLPurifier_Token_Start) {
$textify_comments = $token->name;
} elseif ($token->name === $textify_comments && $token instanceof HTMLPurifier_Token_End) {
$textify_comments = false;
}
} elseif ($escape_invalid_tags) {
// invalid tag, generate HTML representation and insert in
if ($e) {
$e->send(E_WARNING, 'Strategy_RemoveForeignElements: Foreign element to text');
}
$token = new HTMLPurifier_Token_Text(
$generator->generateFromToken($token)
);
} else {
// check if we need to destroy all of the tag's children
// CAN BE GENERICIZED
if (isset($hidden_elements[$token->name])) {
if ($token instanceof HTMLPurifier_Token_Start) {
$remove_until = $token->name;
} elseif ($token instanceof HTMLPurifier_Token_Empty) {
// do nothing: we're still looking
} else {
$remove_until = false;
}
if ($e) {
$e->send(E_ERROR, 'Strategy_RemoveForeignElements: Foreign meta element removed');
}
} else {
if ($e) {
$e->send(E_ERROR, 'Strategy_RemoveForeignElements: Foreign element removed');
}
}
if (!$ok) {
continue;
}
} elseif ($token instanceof HTMLPurifier_Token_Comment) {
// textify comments in script tags when they are allowed
if ($textify_comments !== false) {
$data = $token->data;
$token = new HTMLPurifier_Token_Text($data);
} elseif ($trusted || $check_comments) {
// always cleanup comments
$trailing_hyphen = false;
if ($e) {
// perform check whether or not there's a trailing hyphen
if (substr($token->data, -1) == '-') {
$trailing_hyphen = true;
}
}
$token->data = rtrim($token->data, '-');
$found_double_hyphen = false;
while (strpos($token->data, '--') !== false) {
$found_double_hyphen = true;
$token->data = str_replace('--', '-', $token->data);
}
if ($trusted || !empty($comment_lookup[trim($token->data)]) ||
($comment_regexp !== null && preg_match($comment_regexp, trim($token->data)))) {
// OK good
if ($e) {
$e->send(
E_ERROR,
'Strategy_RemoveForeignElements: Missing required attribute',
$name
);
if ($trailing_hyphen) {
$e->send(
E_NOTICE,
'Strategy_RemoveForeignElements: Trailing hyphen in comment removed'
);
}
if ($found_double_hyphen) {
$e->send(E_NOTICE, 'Strategy_RemoveForeignElements: Hyphens in comment collapsed');
}
}
} else {
if ($e) {
$e->send(E_NOTICE, 'Strategy_RemoveForeignElements: Comment removed');
}
continue;
}
$token->armor['ValidateAttributes'] = true;
}
if (isset($hidden_elements[$token->name]) && $token instanceof HTMLPurifier_Token_Start) {
$textify_comments = $token->name;
} elseif ($token->name === $textify_comments && $token instanceof HTMLPurifier_Token_End) {
$textify_comments = false;
}
} elseif ($escape_invalid_tags) {
// invalid tag, generate HTML representation and insert in
if ($e) {
$e->send(E_WARNING, 'Strategy_RemoveForeignElements: Foreign element to text');
}
$token = new HTMLPurifier_Token_Text(
$generator->generateFromToken($token)
);
} else {
// check if we need to destroy all of the tag's children
// CAN BE GENERICIZED
if (isset($hidden_elements[$token->name])) {
if ($token instanceof HTMLPurifier_Token_Start) {
$remove_until = $token->name;
} elseif ($token instanceof HTMLPurifier_Token_Empty) {
// do nothing: we're still looking
} else {
$remove_until = false;
}
if ($e) {
$e->send(E_ERROR, 'Strategy_RemoveForeignElements: Foreign meta element removed');
}
} else {
if ($e) {
$e->send(E_ERROR, 'Strategy_RemoveForeignElements: Foreign element removed');
}
}
continue;
}
} elseif ($token instanceof HTMLPurifier_Token_Comment) {
// textify comments in script tags when they are allowed
if ($textify_comments !== false) {
$data = $token->data;
$token = new HTMLPurifier_Token_Text($data);
} elseif ($trusted || $check_comments) {
// always cleanup comments
$trailing_hyphen = false;
if ($e) {
// perform check whether or not there's a trailing hyphen
if (substr($token->data, -1) == '-') {
$trailing_hyphen = true;
}
}
$token->data = rtrim($token->data, '-');
$found_double_hyphen = false;
while (strpos($token->data, '--') !== false) {
$found_double_hyphen = true;
$token->data = str_replace('--', '-', $token->data);
}
if ($trusted || !empty($comment_lookup[trim($token->data)]) ||
($comment_regexp !== null && preg_match($comment_regexp, trim($token->data)))) {
// OK good
if ($e) {
if ($trailing_hyphen) {
$e->send(
E_NOTICE,
'Strategy_RemoveForeignElements: Trailing hyphen in comment removed'
);
}
if ($found_double_hyphen) {
$e->send(E_NOTICE, 'Strategy_RemoveForeignElements: Hyphens in comment collapsed');
}
}
} else {
// strip comments
if ($e) {
$e->send(E_NOTICE, 'Strategy_RemoveForeignElements: Comment removed');
}
continue;
}
} elseif ($token instanceof HTMLPurifier_Token_Text) {
} else {
// strip comments
if ($e) {
$e->send(E_NOTICE, 'Strategy_RemoveForeignElements: Comment removed');
}
continue;
}
} elseif ($token instanceof HTMLPurifier_Token_Text) {
} else {
continue;
$result[] = $token;
}
$result[] = $token;
}
if ($remove_until && $e) {
// we removed tokens until the end, throw error