jenkins-bot has submitted this change and it was merged.
Change subject: Update url schemas on Special:Gather
......................................................................
Update url schemas on Special:Gather
Mainly, user lists and a user list now are prefixed, so that we can have other
prefixes, like /all
* Introduce regex based routing
* Modify /User/Id to be /by/User/Id
* Add /all /all/public /all/hidden as a redirect to Special:GatherLists as
a first step to merging the two special pages.
* Fix No public list found error shown on GatherLists.
In follow up patches I'll convert Special:GatherLists to a view that will be
rendered by Special:Gather, like the views\Collection or the
views\CollectionsList.
Bug: T93774
Change-Id: I963de47101313ac6e73ec84b687b5d4ad90c5788
---
M includes/models/CollectionBase.php
M includes/specials/SpecialGather.php
M includes/specials/SpecialGatherLists.php
M tests/browser/features/support/pages/watchlist_collection_page.rb
4 files changed, 47 insertions(+), 24 deletions(-)
Approvals:
Jdlrobson: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/models/CollectionBase.php
b/includes/models/CollectionBase.php
index 61fefe0..1dac331 100644
--- a/includes/models/CollectionBase.php
+++ b/includes/models/CollectionBase.php
@@ -118,12 +118,13 @@
/**
* Return local url for collection
- * Example: /wiki/Special:Gather/user/id
+ * Example: /wiki/Special:Gather/by/user/id
*
* @return string localized url for collection
*/
public function getUrl() {
return SpecialPage::getTitleFor( 'Gather' )
+ ->getSubpage( 'by' )
->getSubpage( $this->getOwner() )
->getSubpage( $this->getId() )
->getLocalURL();
diff --git a/includes/specials/SpecialGather.php
b/includes/specials/SpecialGather.php
index 32648d7..3dd38d8 100644
--- a/includes/specials/SpecialGather.php
+++ b/includes/specials/SpecialGather.php
@@ -32,39 +32,61 @@
}
/**
- * Render the special page and redirect the user to the editor (if page
exists)
+ * Render the special page
*
- * @param string $subpage The name of the page to edit
+ * @param string $subpage
*/
public function execute( $subpage ) {
- if ( $subpage ) {
- $args = explode( '/', $subpage );
- // If there is a user argument, that's what we want to
use
- if ( isset( $args[0] ) ) {
- // Show specified user's collections
- $user = User::newFromName( $args[0] );
- } else {
- // Otherwise use current user
- $user = $this->getUser();
- }
- } else {
+ if ( preg_match( '/^$/', $subpage ) ) {
+ // Root subpage. User owned collections.
// For listing own lists, you need to be logged in
$this->requireLogin( 'gather-anon-view-lists' );
$user = $this->getUser();
- }
+ $this->renderUserCollectionsList( $user );
- if ( !( $user && $user->getId() ) ) {
- // Invalid user
- $this->renderError( new views\NotFound() );
- } else {
- if ( isset( $args ) && isset( $args[1] ) ) {
- $id = intval( $args[1] );
- $this->renderUserCollection( $user, $id );
+ } elseif ( preg_match( '/^by\/(?<user>\w+)\/?$/', $subpage,
$matches ) ) {
+ // User's collections
+ // /by/:user = /by/:user/
+ $user = User::newFromName( $matches['user'] );
+
+ if ( !( $user && $user->getId() ) ) {
+ // Invalid user
+ $this->renderError( new views\NotFound() );
} else {
$this->renderUserCollectionsList( $user );
}
+
+ } elseif ( preg_match( '/^by\/(?<user>\w+)\/(?<id>\d+)$/',
$subpage, $matches ) ) {
+ // Collection page
+ // /by/:user/:id
+ $id = $matches['id'];
+ $user = User::newFromName( $matches['user'] );
+
+ if ( !( $user && $user->getId() ) ) {
+ // Invalid user
+ $this->renderError( new views\NotFound() );
+ } else {
+ $this->renderUserCollection( $user, $id );
+ }
+
+ } elseif ( preg_match( '/^all(\/(?<mode>\w+))?\/?$/', $subpage,
$matches ) ) {
+ // All collections. Public or hidden
+ // /all = /all/ = /all/public = /all/public/
+ // /all/hidden = /all/hidden/
+
+ // mode can be hidden or public only
+ $mode = isset( $matches['mode'] ) && $matches['mode']
=== 'hidden' ?
+ 'hidden' : 'public';
+ // FIXME: Migrate Special:GatherLists here instead of
redirecting
+ $this->getOutput()->redirect(
+ SpecialPage::getTitleFor( 'GatherLists', $mode
)->getLocalURL() );
+
+ } else {
+ // Unknown subpage
+ $this->renderError( new views\NotFound() );
}
+
}
/**
diff --git a/includes/specials/SpecialGatherLists.php
b/includes/specials/SpecialGatherLists.php
index 1b4e79b..7480b00 100644
--- a/includes/specials/SpecialGatherLists.php
+++ b/includes/specials/SpecialGatherLists.php
@@ -37,7 +37,7 @@
public function renderError() {
$out = $this->getOutput();
// FIXME: Get better i18n message for this view.
- $view = new views\NoPublic();
+ $view = new views\NotFound();
$out->setPageTitle( $view->getTitle() );
$view->render( $out );
}
diff --git a/tests/browser/features/support/pages/watchlist_collection_page.rb
b/tests/browser/features/support/pages/watchlist_collection_page.rb
index 18d1058..3d743f2 100644
--- a/tests/browser/features/support/pages/watchlist_collection_page.rb
+++ b/tests/browser/features/support/pages/watchlist_collection_page.rb
@@ -2,5 +2,5 @@
include PageObject
include URL
- page_url URL.url('Special:Gather/User/0')
+ page_url URL.url('Special:Gather/by/User/0')
end
--
To view, visit https://gerrit.wikimedia.org/r/199610
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I963de47101313ac6e73ec84b687b5d4ad90c5788
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Gather
Gerrit-Branch: master
Gerrit-Owner: Jhernandez <[email protected]>
Gerrit-Reviewer: Jdlrobson <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits