X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fspecialpage%2FChangesListSpecialPage.php;h=282d7642399835a362b71fdc156776467570de30;hb=3d54d208bc0dd54baef18b3891ff0faf1d300214;hp=cb2ae34e358896af625980a177589d02580b84c8;hpb=7b9568f540d93058188cce0d4bf18ce8833b6b64;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/specialpage/ChangesListSpecialPage.php b/includes/specialpage/ChangesListSpecialPage.php index cb2ae34e35..eb2cadaee9 100644 --- a/includes/specialpage/ChangesListSpecialPage.php +++ b/includes/specialpage/ChangesListSpecialPage.php @@ -22,7 +22,7 @@ */ use MediaWiki\Logger\LoggerFactory; use Wikimedia\Rdbms\DBQueryTimeoutError; -use Wikimedia\Rdbms\ResultWrapper; +use Wikimedia\Rdbms\IResultWrapper; use Wikimedia\Rdbms\FakeResultWrapper; use Wikimedia\Rdbms\IDatabase; @@ -33,6 +33,12 @@ use Wikimedia\Rdbms\IDatabase; * @ingroup SpecialPage */ abstract class ChangesListSpecialPage extends SpecialPage { + /** + * Maximum length of a tag description in UTF-8 characters. + * Longer descriptions will be truncated. + */ + const TAG_DESC_CHARACTER_LIMIT = 120; + /** * Preference name for saved queries. Subclasses that use saved queries should override this. * @var string @@ -115,7 +121,11 @@ abstract class ChangesListSpecialPage extends SpecialPage { 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds, &$query_options, &$join_conds ) { - $conds[] = 'rc_user = 0'; + $actorMigration = ActorMigration::newMigration(); + $actorQuery = $actorMigration->getJoin( 'rc_user' ); + $tables += $actorQuery['tables']; + $join_conds += $actorQuery['joins']; + $conds[] = $actorMigration->isAnon( $actorQuery['fields']['rc_user'] ); }, 'isReplacedInStructuredUi' => true, @@ -129,7 +139,11 @@ abstract class ChangesListSpecialPage extends SpecialPage { 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds, &$query_options, &$join_conds ) { - $conds[] = 'rc_user != 0'; + $actorMigration = ActorMigration::newMigration(); + $actorQuery = $actorMigration->getJoin( 'rc_user' ); + $tables += $actorQuery['tables']; + $join_conds += $actorQuery['joins']; + $conds[] = $actorMigration->isNotAnon( $actorQuery['fields']['rc_user'] ); }, 'isReplacedInStructuredUi' => true, ] @@ -214,8 +228,10 @@ abstract class ChangesListSpecialPage extends SpecialPage { 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds, &$query_options, &$join_conds ) { - $user = $ctx->getUser(); - $conds[] = 'rc_user_text != ' . $dbr->addQuotes( $user->getName() ); + $actorQuery = ActorMigration::newMigration()->getWhere( $dbr, 'rc_user', $ctx->getUser() ); + $tables += $actorQuery['tables']; + $join_conds += $actorQuery['joins']; + $conds[] = 'NOT(' . $actorQuery['conds'] . ')'; }, 'cssClassSuffix' => 'self', 'isRowApplicableCallable' => function ( $ctx, $rc ) { @@ -230,8 +246,11 @@ abstract class ChangesListSpecialPage extends SpecialPage { 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds, &$query_options, &$join_conds ) { - $user = $ctx->getUser(); - $conds[] = 'rc_user_text = ' . $dbr->addQuotes( $user->getName() ); + $actorQuery = ActorMigration::newMigration() + ->getWhere( $dbr, 'rc_user', $ctx->getUser(), false ); + $tables += $actorQuery['tables']; + $join_conds += $actorQuery['joins']; + $conds[] = $actorQuery['conds']; }, 'cssClassSuffix' => 'others', 'isRowApplicableCallable' => function ( $ctx, $rc ) { @@ -257,7 +276,7 @@ abstract class ChangesListSpecialPage extends SpecialPage { 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds, &$query_options, &$join_conds ) { - $conds[] = 'rc_bot = 0'; + $conds['rc_bot'] = 0; }, 'cssClassSuffix' => 'bot', 'isRowApplicableCallable' => function ( $ctx, $rc ) { @@ -272,7 +291,7 @@ abstract class ChangesListSpecialPage extends SpecialPage { 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds, &$query_options, &$join_conds ) { - $conds[] = 'rc_bot = 1'; + $conds['rc_bot'] = 1; }, 'cssClassSuffix' => 'human', 'isRowApplicableCallable' => function ( $ctx, $rc ) { @@ -471,7 +490,7 @@ abstract class ChangesListSpecialPage extends SpecialPage { 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds, &$query_options, &$join_conds ) { - $conds[] = 'rc_patrolled = 1'; + $conds[] = 'rc_patrolled != 0'; }, 'cssClassSuffix' => 'unpatrolled', 'isRowApplicableCallable' => function ( $ctx, $rc ) { @@ -553,7 +572,7 @@ abstract class ChangesListSpecialPage extends SpecialPage { public function execute( $subpage ) { $this->rcSubpage = $subpage; - $this->considerActionsForDefaultSavedQuery(); + $this->considerActionsForDefaultSavedQuery( $subpage ); $opts = $this->getOptions(); try { @@ -570,8 +589,15 @@ abstract class ChangesListSpecialPage extends SpecialPage { // Used by "live update" and "view newest" to check // if there's new changes with minimal data transfer if ( $this->getRequest()->getBool( 'peek' ) ) { - $code = $rows->numRows() > 0 ? 200 : 204; + $code = $rows->numRows() > 0 ? 200 : 204; $this->getOutput()->setStatusCode( $code ); + + if ( $this->getUser()->isAnon() !== + $this->getRequest()->getFuzzyBool( 'isAnon' ) + ) { + $this->getOutput()->setStatusCode( 205 ); + } + return; } @@ -622,9 +648,11 @@ abstract class ChangesListSpecialPage extends SpecialPage { * Check whether or not the page should load defaults, and if so, whether * a default saved query is relevant to be redirected to. If it is relevant, * redirect properly with all necessary query parameters. + * + * @param string $subpage */ - protected function considerActionsForDefaultSavedQuery() { - if ( !$this->isStructuredFilterUiEnabled() ) { + protected function considerActionsForDefaultSavedQuery( $subpage ) { + if ( !$this->isStructuredFilterUiEnabled() || $this->including() ) { return; } @@ -670,7 +698,7 @@ abstract class ChangesListSpecialPage extends SpecialPage { // but are still valid and requested in the URL $query = array_merge( $this->getRequest()->getValues(), $query ); unset( $query[ 'title' ] ); - $this->getOutput()->redirect( $this->getPageTitle()->getCanonicalURL( $query ) ); + $this->getOutput()->redirect( $this->getPageTitle( $subpage )->getCanonicalURL( $query ) ); } else { // There's a default, but the version is not 2, and the server can't // actually recognize the query itself. This happens if it is before @@ -697,7 +725,7 @@ abstract class ChangesListSpecialPage extends SpecialPage { */ protected function includeRcFiltersApp() { $out = $this->getOutput(); - if ( $this->isStructuredFilterUiEnabled() ) { + if ( $this->isStructuredFilterUiEnabled() && !$this->including() ) { $jsData = $this->getStructuredFilterJsData(); $messages = []; @@ -785,15 +813,15 @@ abstract class ChangesListSpecialPage extends SpecialPage { isset( $explicitlyDefinedTags[ $tagName ] ) || isset( $softwareActivatedTags[ $tagName ] ) ) { - // Parse description - $desc = ChangeTags::tagLongDescriptionMessage( $tagName, $context ); - $result[] = [ 'name' => $tagName, 'label' => Sanitizer::stripAllTags( ChangeTags::tagDescription( $tagName, $context ) ), - 'description' => $desc ? Sanitizer::stripAllTags( $desc->parse() ) : '', + 'description' => + ChangeTags::truncateTagDescription( + $tagName, self::TAG_DESC_CHARACTER_LIMIT, $context + ), 'cssClass' => Sanitizer::escapeClass( 'mw-tag-' . $tagName ), 'hits' => $hits, ]; @@ -829,7 +857,7 @@ abstract class ChangesListSpecialPage extends SpecialPage { */ protected function outputTimeout() { $this->getOutput()->addHTML( - '
' . + '
' . $this->msg( 'recentchanges-timeout' )->parse() . '
' ); @@ -838,7 +866,7 @@ abstract class ChangesListSpecialPage extends SpecialPage { /** * Get the database result for this special page instance. Used by ApiFeedRecentChanges. * - * @return bool|ResultWrapper Result or false + * @return bool|IResultWrapper Result or false */ public function getRows() { $opts = $this->getOptions(); @@ -1427,7 +1455,7 @@ abstract class ChangesListSpecialPage extends SpecialPage { * @param array $query_options Array of query options; see IDatabase::select $options * @param array $join_conds Array of join conditions; see IDatabase::select $join_conds * @param FormOptions $opts - * @return bool|ResultWrapper Result or false + * @return bool|IResultWrapper Result or false */ protected function doMainQuery( $tables, $fields, $conds, $query_options, $join_conds, FormOptions $opts @@ -1498,7 +1526,7 @@ abstract class ChangesListSpecialPage extends SpecialPage { /** * Send output to the OutputPage object, only called if not used feeds * - * @param ResultWrapper $rows Database rows + * @param IResultWrapper $rows Database rows * @param FormOptions $opts */ public function webOutput( $rows, $opts ) { @@ -1517,7 +1545,7 @@ abstract class ChangesListSpecialPage extends SpecialPage { /** * Build and output the actual changes list. * - * @param ResultWrapper $rows Database rows + * @param IResultWrapper $rows Database rows * @param FormOptions $opts */ abstract public function outputChangesList( $rows, $opts ); @@ -1616,6 +1644,7 @@ abstract class ChangesListSpecialPage extends SpecialPage { # Collapsible $collapsedState = $this->getRequest()->getCookie( 'changeslist-state' ); $collapsedClass = $collapsedState === 'collapsed' ? ' mw-collapsed' : ''; + $legend = '
' . $legendHeading . @@ -1637,7 +1666,7 @@ abstract class ChangesListSpecialPage extends SpecialPage { ] ); $out->addModules( 'mediawiki.special.changeslist.legend.js' ); - if ( $this->isStructuredFilterUiEnabled() ) { + if ( $this->isStructuredFilterUiEnabled() && !$this->including() ) { $out->addModules( 'mediawiki.rcfilters.filters.ui' ); $out->addModuleStyles( 'mediawiki.rcfilters.filters.base.styles' ); } @@ -1686,22 +1715,27 @@ abstract class ChangesListSpecialPage extends SpecialPage { return; } + $actorMigration = ActorMigration::newMigration(); + $actorQuery = $actorMigration->getJoin( 'rc_user' ); + $tables += $actorQuery['tables']; + $join_conds += $actorQuery['joins']; + // 'registered' but not 'unregistered', experience levels, if any, are included in 'registered' if ( in_array( 'registered', $selectedExpLevels ) && !in_array( 'unregistered', $selectedExpLevels ) ) { - $conds[] = 'rc_user != 0'; + $conds[] = $actorMigration->isNotAnon( $actorQuery['fields']['rc_user'] ); return; } if ( $selectedExpLevels === [ 'unregistered' ] ) { - $conds[] = 'rc_user = 0'; + $conds[] = $actorMigration->isAnon( $actorQuery['fields']['rc_user'] ); return; } $tables[] = 'user'; - $join_conds['user'] = [ 'LEFT JOIN', 'rc_user = user_id' ]; + $join_conds['user'] = [ 'LEFT JOIN', $actorQuery['fields']['rc_user'] . ' = user_id' ]; if ( $now === 0 ) { $now = time(); @@ -1731,7 +1765,7 @@ abstract class ChangesListSpecialPage extends SpecialPage { if ( in_array( 'unregistered', $selectedExpLevels ) ) { $selectedExpLevels = array_diff( $selectedExpLevels, [ 'unregistered' ] ); - $conditions[] = 'rc_user = 0'; + $conditions[] = $actorMigration->isAnon( $actorQuery['fields']['rc_user'] ); } if ( $selectedExpLevels === [ 'newcomer' ] ) { @@ -1753,7 +1787,7 @@ abstract class ChangesListSpecialPage extends SpecialPage { } elseif ( $selectedExpLevels === [ 'experienced', 'learner' ] ) { $conditions[] = $aboveNewcomer; } elseif ( $selectedExpLevels === [ 'experienced', 'learner', 'newcomer' ] ) { - $conditions[] = 'rc_user != 0'; + $conditions[] = $actorMigration->isNotAnon( $actorQuery['fields']['rc_user'] ); } if ( count( $conditions ) > 1 ) { @@ -1773,7 +1807,7 @@ abstract class ChangesListSpecialPage extends SpecialPage { return true; } - return self::checkStructuredFilterUiEnabled( + return static::checkStructuredFilterUiEnabled( $this->getConfig(), $this->getUser() ); @@ -1798,7 +1832,7 @@ abstract class ChangesListSpecialPage extends SpecialPage { * * @since 1.31 * @param Config $config - * @param User $user User object + * @param User $user * @return bool */ public static function checkStructuredFilterUiEnabled( Config $config, User $user ) {