Merge "Add a maintenance script for populating pp_sortkey"
[lhc/web/wiklou.git] / includes / specials / SpecialRecentchanges.php
index 75d104b..a05900b 100644 (file)
@@ -138,9 +138,6 @@ class SpecialRecentChanges extends ChangesListSpecialPage {
         * @param string $subpage
         */
        public function execute( $subpage ) {
-               global $wgStructuredChangeFiltersEnableSaving,
-                       $wgStructuredChangeFiltersEnableExperimentalViews;
-
                // Backwards-compatibility: redirect to new feed URLs
                $feedFormat = $this->getRequest()->getVal( 'feed' );
                if ( !$this->including() && $feedFormat ) {
@@ -180,19 +177,28 @@ class SpecialRecentChanges extends ChangesListSpecialPage {
                                )
                        );
 
+                       $experimentalStructuredChangeFilters =
+                               $this->getConfig()->get( 'StructuredChangeFiltersEnableExperimentalViews' );
+
                        $out->addJsConfigVars( 'wgStructuredChangeFilters', $jsData['groups'] );
                        $out->addJsConfigVars(
                                'wgStructuredChangeFiltersEnableSaving',
-                               $wgStructuredChangeFiltersEnableSaving
+                               $this->getConfig()->get( 'StructuredChangeFiltersEnableSaving' )
                        );
                        $out->addJsConfigVars(
                                'wgStructuredChangeFiltersEnableExperimentalViews',
-                               $wgStructuredChangeFiltersEnableExperimentalViews
+                               $experimentalStructuredChangeFilters
                        );
                        $out->addJsConfigVars(
-                               'wgRCFiltersChangeTags',
-                               $this->buildChangeTagList()
+                               'wgStructuredChangeFiltersEnableLiveUpdate',
+                               $this->getConfig()->get( 'StructuredChangeFiltersEnableLiveUpdate' )
                        );
+                       if ( $experimentalStructuredChangeFilters ) {
+                               $out->addJsConfigVars(
+                                       'wgRCFiltersChangeTags',
+                                       $this->buildChangeTagList()
+                               );
+                       }
                }
        }
 
@@ -202,18 +208,18 @@ class SpecialRecentChanges extends ChangesListSpecialPage {
         * @return Array Tag data
         */
        protected function buildChangeTagList() {
-               function stripAllHtml( $input ) {
-                       return trim( html_entity_decode( strip_tags( $input ) ) );
-               }
-
                $explicitlyDefinedTags = array_fill_keys( ChangeTags::listExplicitlyDefinedTags(), 0 );
                $softwareActivatedTags = array_fill_keys( ChangeTags::listSoftwareActivatedTags(), 0 );
-               $tagStats = ChangeTags::tagUsageStatistics();
 
+               // Hit counts disabled for perf reasons, see T169997
+               /*
+               $tagStats = ChangeTags::tagUsageStatistics();
                $tagHitCounts = array_merge( $explicitlyDefinedTags, $softwareActivatedTags, $tagStats );
 
                // Sort by hits
-               asort( $tagHitCounts );
+               arsort( $tagHitCounts );
+               */
+               $tagHitCounts = array_merge( $explicitlyDefinedTags, $softwareActivatedTags );
 
                // Build the list and data
                $result = [];
@@ -228,14 +234,21 @@ class SpecialRecentChanges extends ChangesListSpecialPage {
 
                                $result[] = [
                                        'name' => $tagName,
-                                       'label' => stripAllHtml( ChangeTags::tagDescription( $tagName, $this->getContext() ) ),
-                                       'description' => $desc ? stripAllHtml( $desc->parse() ) : '',
+                                       'label' => Sanitizer::stripAllTags(
+                                               ChangeTags::tagDescription( $tagName, $this->getContext() )
+                                       ),
+                                       'description' => $desc ? Sanitizer::stripAllTags( $desc->parse() ) : '',
                                        'cssClass' => Sanitizer::escapeClass( 'mw-tag-' . $tagName ),
                                        'hits' => $hits,
                                ];
                        }
                }
 
+               // Instead of sorting by hit count (disabled, see above), sort by display name
+               usort( $result, function ( $a, $b ) {
+                       return strcasecmp( $a['label'], $b['label'] );
+               } );
+
                return $result;
        }
 
@@ -302,7 +315,7 @@ class SpecialRecentChanges extends ChangesListSpecialPage {
                $opts = parent::getDefaultOptions();
                $user = $this->getUser();
 
-               $opts->add( 'days', $user->getIntOption( 'rcdays' ) );
+               $opts->add( 'days', $user->getIntOption( 'rcdays' ), FormOptions::FLOAT );
                $opts->add( 'limit', $user->getIntOption( 'rclimit' ) );
                $opts->add( 'from', '' );
 
@@ -346,7 +359,7 @@ class SpecialRecentChanges extends ChangesListSpecialPage {
                        if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) ) {
                                $opts['limit'] = $m[1];
                        }
-                       if ( preg_match( '/^days=(\d+)$/', $bit, $m ) ) {
+                       if ( preg_match( '/^days=(\d+(?:\.\d+)?)$/', $bit, $m ) ) {
                                $opts['days'] = $m[1];
                        }
                        if ( preg_match( '/^namespace=(.*)$/', $bit, $m ) ) {
@@ -367,15 +380,14 @@ class SpecialRecentChanges extends ChangesListSpecialPage {
         * @inheritdoc
         */
        protected function buildQuery( &$tables, &$fields, &$conds,
-               &$query_options, &$join_conds, FormOptions $opts ) {
-
+               &$query_options, &$join_conds, FormOptions $opts
+       ) {
                $dbr = $this->getDB();
                parent::buildQuery( $tables, $fields, $conds,
                        $query_options, $join_conds, $opts );
 
                // Calculate cutoff
                $cutoff_unixtime = time() - ( $opts['days'] * 86400 );
-               $cutoff_unixtime = $cutoff_unixtime - ( $cutoff_unixtime % 86400 );
                $cutoff = $dbr->timestamp( $cutoff_unixtime );
 
                $fromValid = preg_match( '/^[0-9]{14}$/', $opts['from'] );
@@ -392,8 +404,8 @@ class SpecialRecentChanges extends ChangesListSpecialPage {
         * @inheritdoc
         */
        protected function doMainQuery( $tables, $fields, $conds, $query_options,
-               $join_conds, FormOptions $opts ) {
-
+               $join_conds, FormOptions $opts
+       ) {
                $dbr = $this->getDB();
                $user = $this->getUser();
 
@@ -656,6 +668,15 @@ class SpecialRecentChanges extends ChangesListSpecialPage {
                                [ 'class' => 'rcfilters-container' ]
                        );
 
+                       $loadingContainer = Html::rawElement(
+                               'div',
+                               [ 'class' => 'rcfilters-spinner' ],
+                               Html::element(
+                                       'div',
+                                       [ 'class' => 'rcfilters-spinner-bounce' ]
+                               )
+                       );
+
                        // Wrap both with rcfilters-head
                        $this->getOutput()->addHTML(
                                Html::rawElement(
@@ -664,6 +685,9 @@ class SpecialRecentChanges extends ChangesListSpecialPage {
                                        $rcfilterContainer . $rcoptions
                                )
                        );
+
+                       // Add spinner
+                       $this->getOutput()->addHTML( $loadingContainer );
                } else {
                        $this->getOutput()->addHTML( $rcoptions );
                }