[MediaWiki-commits] [Gerrit] Update url schemas on Special:Gather - change (mediawiki...Gather)

2015-03-25 Thread Jhernandez (Code Review)
Jhernandez has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/199610

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(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Gather 
refs/changes/10/199610/1

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 );
+   }

[MediaWiki-commits] [Gerrit] Update url schemas on Special:Gather - change (mediawiki...Gather)

2015-03-25 Thread jenkins-bot (Code Review)
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(