From 58e971ecd185a68dc0e70a67ce8dd2919234b05a Mon Sep 17 00:00:00 2001 From: razesoldier Date: Fri, 18 Apr 2025 15:12:08 +0800 Subject: [PATCH 1/2] Use classname with namespace instead of the alias 1. The alias for Html and FormOptions has been removed in MW 1.44 2. The alias for Xml has been deprecated in MW 1.43 --- SpecialUpload.php | 12 +++++++----- SpecialView.php | 33 ++++++++++++++++++--------------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/SpecialUpload.php b/SpecialUpload.php index b0f5836..5a3e53a 100644 --- a/SpecialUpload.php +++ b/SpecialUpload.php @@ -1,7 +1,9 @@ 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() { @@ -114,17 +116,17 @@ private function processUpload() { public function displayForm() { $html = '

'; - $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); diff --git a/SpecialView.php b/SpecialView.php index 3368ef6..799977e 100755 --- a/SpecialView.php +++ b/SpecialView.php @@ -1,7 +1,10 @@ outputHeader(); // Parse options - $opt = new \FormOptions; + $opt = new FormOptions; $opt->add('user', ''); $opt->add('delete', ''); $opt->add('reason', ''); @@ -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 @@ -84,9 +87,9 @@ 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( + $html .= Xml::inputLabel( $this->msg('viewavatar-username')->text(), 'user', '', @@ -98,13 +101,13 @@ private function showForm($user) { $html .= ' '; // Submit button - $html .= \Xml::submitButton($this->msg('viewavatar-submit')->text()); + $html .= Xml::submitButton($this->msg('viewavatar-submit')->text()); // Fieldset - $html = \Xml::fieldset($this->msg('viewavatar-legend')->text(), $html); + $html = Xml::fieldset($this->msg('viewavatar-legend')->text(), $html); // 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); } @@ -113,11 +116,11 @@ 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( + $html .= Xml::inputLabel( $this->msg('viewavatar-delete-reason')->text(), 'reason', '', @@ -127,13 +130,13 @@ private function showDeleteForm($user) { $html .= ' '; // Submit button - $html .= \Xml::submitButton($this->msg('viewavatar-delete-submit')->text()); + $html .= Xml::submitButton($this->msg('viewavatar-delete-submit')->text()); // Fieldset - $html = \Xml::fieldset($this->msg('viewavatar-delete-legend')->text(), $html); + $html = Xml::fieldset($this->msg('viewavatar-delete-legend')->text(), $html); // 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); } From cf7b7b92a0ac16c5251cd3d96f137f27e9fabb04 Mon Sep 17 00:00:00 2001 From: razesoldier Date: Fri, 18 Apr 2025 16:20:04 +0800 Subject: [PATCH 2/2] Fix deprecated method calls 1. Use UserFactory instead of User 2. Use Html::label and Html::input instead of Xml::inputLabel 3. Use Html::submitButton instead of Xml::submitButton --- SpecialView.php | 38 +++++++++++++++++--------------------- avatar.php | 4 +++- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/SpecialView.php b/SpecialView.php index 799977e..fbdf137 100755 --- a/SpecialView.php +++ b/SpecialView.php @@ -33,7 +33,7 @@ public function execute($par) { // 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 @@ -89,22 +89,21 @@ private function showForm($user) { // This is essential as we need to submit the form to this page $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); @@ -120,20 +119,17 @@ private function showDeleteForm($user) { $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); diff --git a/avatar.php b/avatar.php index 528a815..420cbaa 100644 --- a/avatar.php +++ b/avatar.php @@ -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. @@ -28,7 +30,7 @@ $res = $wgDefaultAvatarRes; } - $user = User::newFromName($username); + $user = MediaWikiServices::getInstance()->getUserFactory()->newFromName($username); if ($user) { $path = \Avatar\Avatars::getAvatar($user, $res); }