Pmiazga has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/375419 )

Change subject: Hygiene: cleanup SpecialMobileDiff and InlineDifferenceEngine 
classes
......................................................................

Hygiene: cleanup SpecialMobileDiff and InlineDifferenceEngine classes

Mostly an outcome of PHPStorm inspections.

Changes
 - renamed $output->addHtml() to proper $output->addHTML()
 - renamed $title->getLocalUrl() to proper $title->getLocalURL()
 - removed uncessary arguments
 - removed non-existent argument for appendQueryValue() call
 - added missing method access modifiers
 - removed redundant else syntax
 - added missing phpdoc @throws and @param annotations
 - use (int) casting instead of intval. Casting is up to 6x faster

Change-Id: Ia1149ef5e8c6bc2604f2906dda41bd57df8c1901
---
M includes/diff/InlineDifferenceEngine.php
M includes/specials/SpecialMobileDiff.php
2 files changed, 25 insertions(+), 26 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend 
refs/changes/19/375419/1

diff --git a/includes/diff/InlineDifferenceEngine.php 
b/includes/diff/InlineDifferenceEngine.php
index d858143..160a586 100644
--- a/includes/diff/InlineDifferenceEngine.php
+++ b/includes/diff/InlineDifferenceEngine.php
@@ -51,6 +51,10 @@
        /**
         * Render the inline difference between two revisions
         * using InlineDiffEngine
+        * @throws MWException If the content is not an instance of TextContent 
and
+        * wgContentHandlerTextFallback was set to 'fail'.
+        *
+        * @param bool $diffOnly
         */
        public function showDiffPage( $diffOnly = false ) {
                $output = $this->getOutput();
@@ -76,14 +80,14 @@
                if ( $warnings ) {
                        $warnings = MobileUI::warningBox( $warnings );
                }
-               $output->addHtml(
+               $output->addHTML(
                        $warnings .
                        '<div id="mw-mf-minidiff">' .
                        $diff .
                        '</div>'
                );
 
-               $output->addHtml( Html::rawElement(
+               $output->addHTML( Html::rawElement(
                        'div',
                        [
                                'class' => 'patrollink'
@@ -101,11 +105,7 @@
         * @return bool
         */
        public function isHiddenFromUser() {
-               if ( $this->isDeletedDiff() && ( !$this->unhide || 
!$this->isUserAllowedToSee() ) ) {
-                       return true;
-               } else {
-                       return false;
-               }
+               return $this->isDeletedDiff() && ( !$this->unhide || 
!$this->isUserAllowedToSee() );
        }
 
        /**
@@ -139,7 +139,7 @@
                                )->parse();
                        } else {
                                // Give explanation and add a link to view the 
diff...
-                               $query = $this->getRequest()->appendQueryValue( 
'unhide', '1', true );
+                               $query = $this->getRequest()->appendQueryValue( 
'unhide', '1' );
                                $link = $this->getTitle()->getFullURL( $query );
                                $msg = $context->msg(
                                        $suppressed ? 
'rev-suppressed-unhide-diff' : 'rev-deleted-unhide-diff',
@@ -154,10 +154,11 @@
         * Creates an inline diff
         * @param Content $otext Old content
         * @param Content $ntext New content
+        * @throws \MediaWiki\Diff\ComplexityException
         *
         * @return string
         */
-       function generateTextDiffBody( $otext, $ntext ) {
+       public function generateTextDiffBody( $otext, $ntext ) {
                global $wgContLang;
 
                // First try wikidiff2
@@ -173,9 +174,7 @@
                $nta = explode( "\n", $wgContLang->segmentForDiff( $ntext ) );
                $diffs = new Diff( $ota, $nta );
                $formatter = new InlineDiffFormatter();
-               $difftext = $wgContLang->unsegmentForDiff( $formatter->format( 
$diffs ) );
-
-               return $difftext;
+               return $wgContLang->unsegmentForDiff( $formatter->format( 
$diffs ) );
        }
 
        /**
@@ -208,7 +207,7 @@
                        $linkInfo = Html::linkButton(
                                $this->msg( 'markaspatrolleddiff' )->escaped(),
                                [
-                                       'href' => $this->mNewPage->getLocalUrl( 
[
+                                       'href' => $this->mNewPage->getLocalURL( 
[
                                                'action' => 'markpatrolled',
                                                'rcid' => $linkInfo['rcid'],
                                        ] ),
diff --git a/includes/specials/SpecialMobileDiff.php 
b/includes/specials/SpecialMobileDiff.php
index 3dde5ac..ca72a99 100644
--- a/includes/specials/SpecialMobileDiff.php
+++ b/includes/specials/SpecialMobileDiff.php
@@ -62,8 +62,8 @@
 
                // check 2 parameters are passed and are numbers
                if ( count( $revids ) === 2 && $revids[0] && $revids[1] ) {
-                       $id = intval( $revids[1] );
-                       $prevId = intval( $revids[0] );
+                       $id = (int) $revids[1];
+                       $prevId = (int) $revids[0];
                        if ( $id && $prevId ) {
                                $rev = static::getRevision( $id );
                                // deal with identical ids
@@ -79,7 +79,7 @@
                                }
                        }
                } elseif ( count( $revids ) === 1 ) {
-                       $id = intval( $revids[0] );
+                       $id = (int) $revids[0];
                        if ( $id ) {
                                $rev = static::getRevision( $id );
                                if ( $rev ) {
@@ -95,7 +95,7 @@
         * @return bool false when revision not exist
         * @param string $par Revision IDs separated by three points (e.g. 
123...124)
         */
-       function executeWhenAvailable( $par ) {
+       public function executeWhenAvailable( $par ) {
                $ctx = MobileContext::singleton();
                $this->setHeaders();
                $output = $this->getOutput();
@@ -105,7 +105,7 @@
                $rev = $revisions[1];
                $prev = $revisions[0];
 
-               if ( is_null( $rev ) ) {
+               if ( $rev === null ) {
                        $this->executeBadQuery();
                        return false;
                }
@@ -132,14 +132,14 @@
                // Allow other extensions to load more stuff here
                Hooks::run( 'BeforeSpecialMobileDiffDisplay', [ &$output, $ctx, 
$revisions ] );
 
-               $output->addHtml( '<div id="mw-mf-diffview" 
class="content-unstyled"><div id="mw-mf-diffarea">' );
+               $output->addHTML( '<div id="mw-mf-diffview" 
class="content-unstyled"><div id="mw-mf-diffarea">' );
 
                $this->displayDiffPage();
-               $output->addHtml( '</div>' );
+               $output->addHTML( '</div>' );
 
                $this->showFooter( $ctx );
 
-               $output->addHtml( '</div>' );
+               $output->addHTML( '</div>' );
 
                return true;
        }
@@ -243,7 +243,7 @@
                $ts = new MWTimestamp( $this->rev->getTimestamp() );
 
                return Html::openElement( 'div', [ 'id' => 'mw-mf-diff-info', 
'class' => 'page-summary' ] )
-                       . Html::openElement( 'h2', [] )
+                       . Html::openElement( 'h2' )
                                . Html::element( 'a',
                                        [
                                                'href' => 
$this->targetTitle->getLocalURL()
@@ -301,7 +301,7 @@
        private function showFooter( IContextSource $context ) {
                $output = $this->getOutput();
 
-               $output->addHtml(
+               $output->addHTML(
                        Html::openElement( 'div', [ 'id' => 'mw-mf-userinfo',
                                'class' => 'position-fixed' ] ) .
                        Html::openElement( 'div', [ 'class' => 'post-content' ] 
)
@@ -317,7 +317,7 @@
                                'data-user-name' => $user->getName(),
                                'data-user-gender' => $user->getOption( 
'gender' ),
                        ];
-                       $output->addHtml(
+                       $output->addHTML(
                                Html::openElement( 'div', $attrs ) .
                                $this->getLinkRenderer()->makeLink(
                                        $user->getUserPage(),
@@ -338,7 +338,7 @@
                } else {
                        $ipAddr = $this->rev->getUserText();
                        $userPage = SpecialPage::getTitleFor( 'Contributions', 
$ipAddr );
-                       $output->addHtml(
+                       $output->addHTML(
                                Html::element( 'div', [
                                        'class' => MobileUI::iconClass( 
'anonymous', 'before', 'mw-mf-user mw-mf-anon' ),
                                ], $this->msg( 
'mobile-frontend-diffview-anonymous' ) ) .
@@ -348,7 +348,7 @@
                        );
                }
 
-               $output->addHtml(
+               $output->addHTML(
                        Html::closeElement( 'div' ) .
                        Html::closeElement( 'div' )
                );

-- 
To view, visit https://gerrit.wikimedia.org/r/375419
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia1149ef5e8c6bc2604f2906dda41bd57df8c1901
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Pmiazga <pmia...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to