Skip to content

Commit 5e87bbe

Browse files
Merge pull request #4 from edg2s/composer
Update composer dependencies and fix errors
2 parents 94a50c0 + 894136c commit 5e87bbe

File tree

5 files changed

+78
-11
lines changed

5 files changed

+78
-11
lines changed

.phan/config.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
$cfg = require __DIR__ . '/../vendor/mediawiki/mediawiki-phan-config/src/config.php';
4+
5+
return $cfg;

composer.json

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
{
22
"require-dev": {
3-
"jakub-onderka/php-parallel-lint": "1.0.0",
4-
"mediawiki/mediawiki-codesniffer": "23.0.0",
5-
"jakub-onderka/php-console-highlighter": "0.3.2",
6-
"mediawiki/minus-x": "0.3.1"
3+
"mediawiki/mediawiki-codesniffer": "35.0.0",
4+
"mediawiki/mediawiki-phan-config": "0.10.6",
5+
"mediawiki/minus-x": "1.1.1",
6+
"php-parallel-lint/php-console-highlighter": "0.5.0",
7+
"php-parallel-lint/php-parallel-lint": "1.2.0"
78
},
89
"scripts": {
910
"fix": [
@@ -14,9 +15,7 @@
1415
"parallel-lint . --exclude vendor --exclude node_modules",
1516
"phpcs -s -p",
1617
"minus-x check ."
17-
]
18-
},
19-
"extra": {
20-
"phan-taint-check-plugin": "1.5.0"
18+
],
19+
"phan": "phan -d . --long-progress-bar"
2120
}
2221
}

includes/Hooks.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use DatabaseUpdater;
66
use Inbox\Models\Email;
7+
use MailAddress;
78
use OutputPage;
89
use SkinTemplate;
910
use SpecialPage;
@@ -18,6 +19,16 @@ public static function onLoadExtensionSchemaUpdates( DatabaseUpdater $updater )
1819
$updater->addExtensionTable( 'inbox_email', dirname( __DIR__ ) . "/sql/inbox.sql" );
1920
}
2021

22+
/**
23+
* @param array $headers Associative array of headers for the email
24+
* @param MailAddress|array $to To address
25+
* @param MailAddress $from From address
26+
* @param string $subject Subject of the email
27+
* @param string $body Body of the message
28+
* @return bool|string|void True or no return value to continue sending email in the
29+
* regular way, or false to skip the regular method of sending mail. Return a string
30+
* to return a php-mail-error message containing the error.
31+
*/
2132
public static function onAlternateUserMailer( $headers, $to, $from, $subject, $body ) {
2233
$email = new Email( $headers, $to, $from, $subject, $body );
2334
$email->save();
@@ -52,6 +63,10 @@ public static function onPersonalUrls( &$personal_urls, &$title, $sk ) {
5263
$personal_urls = wfArrayInsertAfter( $personal_urls, [ 'inbox' => $inboxLink ], 'userpage' );
5364
}
5465

66+
/**
67+
* @param array &$modifiedTimes
68+
* @param OutputPage $out
69+
*/
5570
public static function onOutputPageCheckLastModified( array &$modifiedTimes, OutputPage $out ) {
5671
$user = $out->getUser();
5772
if ( $user->isLoggedIn() ) {

includes/Models/Email.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,34 @@
33
namespace Inbox\Models;
44

55
use FormatJson;
6+
use MailAddress;
67
use MediaWiki\MediaWikiServices;
8+
use stdClass;
9+
use Wikimedia\Rdbms\ResultWrapper;
710

811
class Email {
912

13+
/** @var array */
1014
private $headers;
15+
/** @var string */
16+
private $to;
17+
/** @var string */
1118
private $from;
19+
/** @var string */
1220
private $subject;
21+
/** @var string */
1322
private $body;
23+
/** @var string */
1424
private $timestamp;
1525

26+
/**
27+
* @param array $headers Associative array of headers for the email
28+
* @param MailAddress|array $to To address
29+
* @param MailAddress $from From address
30+
* @param string $subject Subject of the email
31+
* @param string $body Body of the message
32+
* @param string|null $timestamp
33+
*/
1634
public function __construct( $headers, $to, $from, $subject, $body, $timestamp = null ) {
1735
$this->headers = $headers;
1836
$this->to = $to[ 0 ]->address;
@@ -22,6 +40,10 @@ public function __construct( $headers, $to, $from, $subject, $body, $timestamp =
2240
$this->timestamp = $timestamp ?: wfTimestampNow();
2341
}
2442

43+
/**
44+
* @param string $emailAddress
45+
* @return string
46+
*/
2547
public static function getNewestEmailTimestamp( $emailAddress ) {
2648
$dbr = MediaWikiServices::getInstance()->getDBLoadBalancer()->getConnection( DB_REPLICA );
2749
return $dbr->selectField(
@@ -33,6 +55,9 @@ public static function getNewestEmailTimestamp( $emailAddress ) {
3355
);
3456
}
3557

58+
/**
59+
* Save email to DB
60+
*/
3661
public function save() {
3762
$dbw = MediaWikiServices::getInstance()->getDBLoadBalancer()->getConnection( DB_MASTER );
3863
$dbw->insert(
@@ -67,6 +92,10 @@ public static function getUnreadCount( $emailAddress ) {
6792
);
6893
}
6994

95+
/**
96+
* @param string $emailAddress
97+
* @return ResultWrapper
98+
*/
7099
public static function getAll( $emailAddress ) {
71100
$dbr = MediaWikiServices::getInstance()->getDBLoadBalancer()->getConnection( DB_REPLICA );
72101
return $dbr->select(
@@ -78,6 +107,11 @@ public static function getAll( $emailAddress ) {
78107
);
79108
}
80109

110+
/**
111+
* @param string $emailAddress
112+
* @param string $id
113+
* @return stdClass
114+
*/
81115
public static function get( $emailAddress, $id ) {
82116
$dbr = MediaWikiServices::getInstance()->getDBLoadBalancer()->getConnection( DB_REPLICA );
83117
return $dbr->selectRow(
@@ -87,6 +121,9 @@ public static function get( $emailAddress, $id ) {
87121
);
88122
}
89123

124+
/**
125+
* @param string $id
126+
*/
90127
public static function markRead( $id ) {
91128
$dbw = MediaWikiServices::getInstance()->getDBLoadBalancer()->getConnection( DB_MASTER );
92129
$dbw->update(

includes/Specials/SpecialInbox.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use FormatJson;
66
use Html;
77
use Inbox\Models\Email;
8-
use Sanitizer;
98
use SpecialPage;
109

1110
class SpecialInbox extends SpecialPage {
@@ -24,22 +23,26 @@ public function execute( $par ) {
2423
} else {
2524
$this->showAllEmails( $this->getUser()->getEmail() );
2625
}
27-
2826
}
2927

28+
/**
29+
* @param string $emailAddress
30+
* @param string $emailId
31+
*/
3032
private function showEmail( $emailAddress, $emailId ) {
3133
$out = $this->getOutput();
3234
$email = Email::get( $emailAddress, $emailId );
3335
if ( $email ) {
3436
$out->setArticleBodyOnly( true );
37+
// @phan-suppress-next-line SecurityCheck-XSS
3538
$out->addHTML( $email->email_subject );
3639
$out->addHTML( '<hr />' );
3740
$headers = array_change_key_case( FormatJson::decode( $email->email_headers, true ) );
3841
if ( strpos( $headers[ 'content-type' ], 'multipart' ) !== false ) {
3942
preg_match( '/boundary=\"(.*?)\"/', $headers[ 'content-type' ], $m );
4043
$boundary = $m[1];
4144
$parts = explode( '--' . $boundary, $email->email_body );
42-
$this->showEmailcontent( $parts[1], true );
45+
$this->showEmailcontent( $parts[1], true );
4346
$out->addHTML( '<hr />' );
4447
$this->showEmailcontent( $parts[2] );
4548
} elseif ( strpos( $headers[ 'content-type' ], 'text/plain' ) >= 0 ) {
@@ -55,6 +58,10 @@ private function showEmail( $emailAddress, $emailId ) {
5558
}
5659
}
5760

61+
/**
62+
* @param string $content
63+
* @param bool $plainText
64+
*/
5865
private function showEmailcontent( $content, $plainText = false ) {
5966
$this->getOutput()->addHTML( Html::rawElement(
6067
$plainText ? 'pre' : 'div',
@@ -63,11 +70,15 @@ private function showEmailcontent( $content, $plainText = false ) {
6370
) );
6471
}
6572

73+
/**
74+
* @param string $emailAddress
75+
*/
6676
private function showAllEmails( $emailAddress ) {
6777
parent::execute( null );
6878
$emails = Email::getAll( $emailAddress );
6979
if ( $emails ) {
7080
$this->getOutput()->addModuleStyles( 'inbox.style' );
81+
// @phan-suppress-next-line SecurityCheck-XSS
7182
$this->getOutput()->addHTML( Html::rawElement(
7283
'table',
7384
[ 'class' => 'email-all mw-datatable' ],

0 commit comments

Comments
 (0)