Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions SpecialUpload.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?php
namespace Avatar;

use MediaWiki\Html\Html;
use MediaWiki\MediaWikiServices;
use MediaWiki\Xml\Xml;

class SpecialUpload extends \SpecialPage {

Expand Down Expand Up @@ -39,7 +41,7 @@ public function execute($par) {
}

private function displayMessage($msg) {
$this->getOutput()->addHTML(\Html::rawElement('div', array('class' => 'error', 'id' => 'errorMsg'), $msg));
$this->getOutput()->addHTML(Html::rawElement('div', array('class' => 'error', 'id' => 'errorMsg'), $msg));
}

private function processUpload() {
Expand Down Expand Up @@ -114,17 +116,17 @@ private function processUpload() {

public function displayForm() {
$html = '<p></p>';
$html .= \Html::hidden('avatar', '');
$html .= Html::hidden('avatar', '');

$html .= \Xml::element('button', array('id' => 'pickfile'), $this->msg('uploadavatar-selectfile'));
$html .= Xml::element('button', array('id' => 'pickfile'), $this->msg('uploadavatar-selectfile'));

$html .= ' ';

// Submit button
$html .= \Xml::submitButton($this->msg('uploadavatar-submit')->text());
$html .= Xml::submitButton($this->msg('uploadavatar-submit')->text());

// Wrap with a form
$html = \Xml::tags('form', array('action' => $this->getPageTitle()->getLinkURL(), 'method' => 'post'), $html);
$html = Xml::tags('form', array('action' => $this->getPageTitle()->getLinkURL(), 'method' => 'post'), $html);

$this->getOutput()->addWikiMsg('uploadavatar-notice');
$this->getOutput()->addHTML($html);
Expand Down
59 changes: 29 additions & 30 deletions SpecialView.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<?php
namespace Avatar;

use MediaWiki\Html\FormOptions;
use MediaWiki\Html\Html;
use MediaWiki\MediaWikiServices;
use MediaWiki\Xml\Xml;

class SpecialView extends \SpecialPage {

Expand All @@ -22,15 +25,15 @@ public function execute($par) {
$this->outputHeader();

// Parse options
$opt = new \FormOptions;
$opt = new FormOptions;
$opt->add('user', '');
$opt->add('delete', '');
$opt->add('reason', '');
$opt->fetchValuesFromRequest($this->getRequest());

// Parse user
$user = $opt->getValue('user');
$userObj = \User::newFromName($user);
$userObj = MediaWikiServices::getInstance()->getUserFactory()->newFromName($user);
$userExists = $userObj && $userObj->getId() !== 0;

// If current task is delete and user is not allowed
Expand Down Expand Up @@ -61,11 +64,11 @@ public function execute($par) {
$haveAvatar = Avatars::hasAvatar($userObj);

if ($haveAvatar) {
$html = \Xml::tags('img', array(
$html = Xml::tags('img', array(
'src' => Avatars::getLinkFor($user, 'original') . '&nocache&ver=' . dechex(time()),
'height' => 400,
), '');
$html = \Xml::tags('p', array(), $html);
$html = Xml::tags('p', array(), $html);
$this->getOutput()->addHTML($html);

// Add a delete button
Expand All @@ -84,27 +87,26 @@ private function showForm($user) {
global $wgScript;

// This is essential as we need to submit the form to this page
$html = \Html::hidden('title', $this->getPageTitle());
$html = Html::hidden('title', $this->getPageTitle());

$html .= \Xml::inputLabel(
$this->msg('viewavatar-username')->text(),
'user',
'',
45,
$user,
array('class' => 'mw-autocomplete-user') # This together with mediawiki.userSuggest will give us an auto completion
);
$html .= Html::label($this->msg('viewavatar-username')->text(), 'ext-avatar-username');
$html .= Html::input('user', $user, 'text', [
'class' => 'mw-autocomplete-user',
'size' => 45,
'id' => 'ext-avatar-username', # This together with mediawiki.userSuggest will give us an auto completion
]);

$html .= ' ';

// Submit button
$html .= \Xml::submitButton($this->msg('viewavatar-submit')->text());
$html .= Html::submitButton($this->msg('viewavatar-submit')->text());

// Fieldset
$html = \Xml::fieldset($this->msg('viewavatar-legend')->text(), $html);
// Warp Fieldset
$legend = Html::element('legend', [], $this->msg('viewavatar-legend')->text());
$html = Html::openElement('fieldset') . $legend . $html . Html::closeElement('fieldset');

// Wrap with a form
$html = \Xml::tags('form', array('action' => $wgScript, 'method' => 'get'), $html);
$html = Xml::tags('form', array('action' => $wgScript, 'method' => 'get'), $html);

$this->getOutput()->addHTML($html);
}
Expand All @@ -113,27 +115,24 @@ private function showDeleteForm($user) {
global $wgScript;

// This is essential as we need to submit the form to this page
$html = \Html::hidden('title', $this->getPageTitle());
$html .= \Html::hidden('delete', 'true');
$html .= \Html::hidden('user', $user);
$html = Html::hidden('title', $this->getPageTitle());
$html .= Html::hidden('delete', 'true');
$html .= Html::hidden('user', $user);

$html .= \Xml::inputLabel(
$this->msg('viewavatar-delete-reason')->text(),
'reason',
'',
45
);
$html .= Html::label($this->msg('viewavatar-delete-reason')->text(), 'ext-avatar-reason');
$html .= Html::input('reason', '', 'text', ['size' => 45, 'id' => 'ext-avatar-reason']);

$html .= ' ';

// Submit button
$html .= \Xml::submitButton($this->msg('viewavatar-delete-submit')->text());
$html .= Html::submitButton($this->msg('viewavatar-delete-submit')->text());

// Fieldset
$html = \Xml::fieldset($this->msg('viewavatar-delete-legend')->text(), $html);
// Warp Fieldset
$legend = Html::element('legend', [], $this->msg('viewavatar-delete-legend')->text());
$html = Html::openElement('fieldset') . $legend . $html . Html::closeElement('fieldset');

// Wrap with a form
$html = \Xml::tags('form', array('action' => $wgScript, 'method' => 'get'), $html);
$html = Xml::tags('form', array('action' => $wgScript, 'method' => 'get'), $html);

$this->getOutput()->addHTML($html);
}
Expand Down
4 changes: 3 additions & 1 deletion avatar.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

// For some configurations, extensions are symbolic linked
// This is the workaround for ../..
use MediaWiki\MediaWikiServices;

$dir = dirname(dirname(dirname($_SERVER['SCRIPT_FILENAME'])));

// This switches working directory to the root directory of MediaWiki.
Expand All @@ -28,7 +30,7 @@
$res = $wgDefaultAvatarRes;
}

$user = User::newFromName($username);
$user = MediaWikiServices::getInstance()->getUserFactory()->newFromName($username);
if ($user) {
$path = \Avatar\Avatars::getAvatar($user, $res);
}
Expand Down