MaxSem has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/364635 )
Change subject: Disallow slow query when filtering only by namespace ...................................................................... Disallow slow query when filtering only by namespace Bug: T168599 Change-Id: I9c5a1c364b7a8df796c931d3f3a12f0549ff3933 --- M i18n/en.json M i18n/qqq.json M src/SpecialPage.php 3 files changed, 21 insertions(+), 10 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/PageAssessments refs/changes/35/364635/1 diff --git a/i18n/en.json b/i18n/en.json index 30c4dd8..d5594e3 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -36,5 +36,6 @@ "pageassessments-importance": "Importance", "pageassessments-class": "Class", "pageassessments-timestamp": "Timestamp", - "pageassessments-total-results": "Total results: $1" + "pageassessments-total-results": "Total results: $1", + "pageassessments-error-namespace-filter": "Filtering by namespace also requires filtering by project or page title." } diff --git a/i18n/qqq.json b/i18n/qqq.json index 1dcd474..c0d52a8 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -38,5 +38,6 @@ "pageassessments-importance": "Label for the results table column header\n{{Identical|Importance}}", "pageassessments-class": "Label for the results table column header\n{{Identical|Class}}", "pageassessments-timestamp": "Label for the results table column header\n{{Identical|Timestamp}}", - "pageassessments-total-results": "Summary shown above the search results, with total number found" + "pageassessments-total-results": "Summary shown above the search results, with total number found", + "pageassessments-error-namespace-filter": "Shown by Special:PageAssessments when an invalid combination of filters is used" } diff --git a/src/SpecialPage.php b/src/SpecialPage.php index a83abca..30d3142 100644 --- a/src/SpecialPage.php +++ b/src/SpecialPage.php @@ -10,6 +10,7 @@ use QueryPage; use ResultWrapper; use Skin; +use Status; use Title; /** @@ -77,16 +78,16 @@ if ( strlen( $project ) > 0 ) { $info['conds']['pap_project_title'] = $project; } - // Namespace (if it's set, it's either an integer >= 0, 'all', or the empty string). - $namespace = $this->getRequest()->getVal( 'namespace' ); - if ( strlen( $namespace ) > 0 && $namespace !== 'all' ) { - $info['conds']['page_namespace'] = $namespace; - } // Page title. $pageTitle = $this->getRequest()->getVal( 'page_title' ); if ( strlen( $pageTitle ) > 0 ) { $title = Title::newFromText( $pageTitle )->getDBkey(); $info['conds']['page_title'] = $title; + } + // Namespace (if it's set, it's either an integer >= 0, 'all', or the empty string). + $namespace = $this->getRequest()->getVal( 'namespace' ); + if ( strlen( $namespace ) > 0 && $namespace !== 'all' ) { + $info['conds']['page_namespace'] = $namespace; } return $info; } @@ -296,10 +297,18 @@ $form = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() ); $form->setMethod( 'get' ); $form->setSubmitTextMsg( 'pageassessments-search' ); - $form->setSubmitCallback( function () { - // No callback required, but HTMLForm says we have to set one. + $form->setSubmitCallback( function ( array $data, HTMLForm $form ) { + // Filtering only by namespace can be slow, disallow it: + // https://phabricator.wikimedia.org/T168599 + if ( $data['namespace'] !== null + && $data['namespace'] !== 'all' + // strlen( null ) produces 0 + && !strlen( $data['project'] ) + && !strlen( $data['page_title'] ) + ) { + return Status::newFatal( 'pageassessments-error-namespace-filter' ); + } } ); return $form; } - } -- To view, visit https://gerrit.wikimedia.org/r/364635 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I9c5a1c364b7a8df796c931d3f3a12f0549ff3933 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/PageAssessments Gerrit-Branch: master Gerrit-Owner: MaxSem <maxsem.w...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits