Merge "Make the spelling and pluralization of "Active filters" consistent"
[lhc/web/wiklou.git] / includes / specials / pagers / ContribsPager.php
index e31498a..81a1f5a 100644 (file)
@@ -64,12 +64,12 @@ class ContribsPager extends RangeChronologicalPager {
                        $this->messages[$msg] = $this->msg( $msg )->escaped();
                }
 
-               $this->target = isset( $options['target'] ) ? $options['target'] : '';
-               $this->contribs = isset( $options['contribs'] ) ? $options['contribs'] : 'users';
-               $this->namespace = isset( $options['namespace'] ) ? $options['namespace'] : '';
-               $this->tagFilter = isset( $options['tagfilter'] ) ? $options['tagfilter'] : false;
-               $this->nsInvert = isset( $options['nsInvert'] ) ? $options['nsInvert'] : false;
-               $this->associated = isset( $options['associated'] ) ? $options['associated'] : false;
+               $this->target = $options['target'] ?? '';
+               $this->contribs = $options['contribs'] ?? 'users';
+               $this->namespace = $options['namespace'] ?? '';
+               $this->tagFilter = $options['tagfilter'] ?? false;
+               $this->nsInvert = $options['nsInvert'] ?? false;
+               $this->associated = $options['associated'] ?? false;
 
                $this->deletedOnly = !empty( $options['deletedOnly'] );
                $this->topOnly = !empty( $options['topOnly'] );
@@ -407,24 +407,13 @@ class ContribsPager extends RangeChronologicalPager {
        }
 
        /**
-        * Generates each row in the contributions list.
+        * Check whether the revision associated is valid for formatting. If has no associated revision
+        * id then null is returned.
         *
-        * Contributions which are marked "top" are currently on top of the history.
-        * For these contributions, a [rollback] link is shown for users with roll-
-        * back privileges. The rollback link restores the most recent version that
-        * was not written by the target user.
-        *
-        * @todo This would probably look a lot nicer in a table.
         * @param object $row
-        * @return string
+        * @return Revision|null
         */
-       function formatRow( $row ) {
-               $ret = '';
-               $classes = [];
-               $attribs = [];
-
-               $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
-
+       public function tryToCreateValidRevision( $row ) {
                /*
                 * There may be more than just revision rows. To make sure that we'll only be processing
                 * revisions here, let's _try_ to build a revision out of our row (without displaying
@@ -440,8 +429,30 @@ class ContribsPager extends RangeChronologicalPager {
                        $validRevision = false;
                }
                Wikimedia\restoreWarnings();
+               return $validRevision ? $rev : null;
+       }
+
+       /**
+        * Generates each row in the contributions list.
+        *
+        * Contributions which are marked "top" are currently on top of the history.
+        * For these contributions, a [rollback] link is shown for users with roll-
+        * back privileges. The rollback link restores the most recent version that
+        * was not written by the target user.
+        *
+        * @todo This would probably look a lot nicer in a table.
+        * @param object $row
+        * @return string
+        */
+       function formatRow( $row ) {
+               $ret = '';
+               $classes = [];
+               $attribs = [];
+
+               $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
 
-               if ( $validRevision ) {
+               $rev = $this->tryToCreateValidRevision( $row );
+               if ( $rev ) {
                        $attribs['data-mw-revid'] = $rev->getId();
 
                        $page = Title::newFromRow( $row );
@@ -593,7 +604,10 @@ class ContribsPager extends RangeChronologicalPager {
 
                // Let extensions add data
                Hooks::run( 'ContributionsLineEnding', [ $this, &$ret, $row, &$classes, &$attribs ] );
-               $attribs = wfArrayFilterByKey( $attribs, [ Sanitizer::class, 'isReservedDataAttribute' ] );
+               $attribs = array_filter( $attribs,
+                       [ Sanitizer::class, 'isReservedDataAttribute' ],
+                       ARRAY_FILTER_USE_KEY
+               );
 
                // TODO: Handle exceptions in the catch block above.  Do any extensions rely on
                // receiving empty rows?
@@ -640,10 +654,10 @@ class ContribsPager extends RangeChronologicalPager {
         * @return array Options array with processed start and end date filter options
         */
        public static function processDateFilter( array $opts ) {
-               $start = isset( $opts['start'] ) ? $opts['start'] : '';
-               $end = isset( $opts['end'] ) ? $opts['end'] : '';
-               $year = isset( $opts['year'] ) ? $opts['year'] : '';
-               $month = isset( $opts['month'] ) ? $opts['month'] : '';
+               $start = $opts['start'] ?? '';
+               $end = $opts['end'] ?? '';
+               $year = $opts['year'] ?? '';
+               $month = $opts['month'] ?? '';
 
                if ( $start !== '' && $end !== '' && $start > $end ) {
                        $temp = $start;