Cscott has uploaded a new change for review.

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


Change subject: Create a Special:UserById page redirecting to a user page given 
a numeric id.
......................................................................

Create a Special:UserById page redirecting to a user page given a numeric id.

The numeric User ID is stable across renames, and is therefore an
appropriate primary key for identifying the user associated with a given
revision.  The Parsoid API would like to export semantic RDFa in its
DOM identifying the author of a revision by their userid, but in order
to do so requires a MW redirect from userid to the appropriate User page.
(A "permalink" for the user.)  This patch adds that redirect, as
   http://somewiki/Special:UserById/1234

(https://bugzilla.wikimedia.org/show_bug.cgi?id=45206 is the related
Parsoid feature.)

Change-Id: I91ac84d3323969aaee30ae44cd3b71fca4aa7073
---
M includes/AutoLoader.php
M includes/SpecialPageFactory.php
A includes/specials/SpecialUserbyid.php
M languages/messages/MessagesEn.php
M maintenance/language/messages.inc
5 files changed, 94 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/50/59050/1

diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php
index 88bb21b..e4bf0dd 100644
--- a/includes/AutoLoader.php
+++ b/includes/AutoLoader.php
@@ -973,6 +973,7 @@
        'SpecialUpload' => 'includes/specials/SpecialUpload.php',
        'SpecialUploadStash' => 'includes/specials/SpecialUploadStash.php',
        'SpecialUploadStashTooLargeException' => 
'includes/specials/SpecialUploadStash.php',
+       'SpecialUserbyid' => 'includes/specials/SpecialUserbyid.php',
        'SpecialUserlogout' => 'includes/specials/SpecialUserlogout.php',
        'SpecialVersion' => 'includes/specials/SpecialVersion.php',
        'SpecialWatchlist' => 'includes/specials/SpecialWatchlist.php',
diff --git a/includes/SpecialPageFactory.php b/includes/SpecialPageFactory.php
index a53b901..605611b 100644
--- a/includes/SpecialPageFactory.php
+++ b/includes/SpecialPageFactory.php
@@ -101,6 +101,7 @@
                'Listbots'                  => 'SpecialListBots',
                'Userrights'                => 'UserrightsPage',
                'EditWatchlist'             => 'SpecialEditWatchlist',
+               'Userbyid'                  => 'SpecialUserbyid',
 
                // Recent changes and logs
                'Newimages'                 => 'SpecialNewFiles',
diff --git a/includes/specials/SpecialUserbyid.php 
b/includes/specials/SpecialUserbyid.php
new file mode 100644
index 0000000..e56b561
--- /dev/null
+++ b/includes/specials/SpecialUserbyid.php
@@ -0,0 +1,78 @@
+<?php
+/**
+ * Implements Special:Userbyid
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @ingroup SpecialPage
+ */
+
+/**
+ * A special page that redirects to the User corresponding to a given
+ * numeric user id.
+ *
+ * @ingroup SpecialPage
+ */
+class SpecialUserbyid extends SpecialPage {
+
+       function __construct() {
+               parent::__construct( 'Userbyid' );
+       }
+
+       function execute( $par ) {
+               $this->setHeaders();
+               $this->outputHeader();
+
+               $request = $this->getRequest();
+               $userid = !is_null( $par ) ? $par : $request->getText( 'userid' 
);
+               if ( ! is_numeric( $userid ) ) {
+                       $this->showForm( $userid );
+               } else {
+                       $username = User::whoIs( intval( $userid ) );
+                       if ( ! $username ) {
+                               $this->getOutput()->setStatusCode( 404 );
+                               $this->showForm( $userid );
+                       } else {
+                               $userpage = Title::makeTitle( NS_USER, 
$username );
+                               $url = $userpage->getFullURL( '', false, 
PROTO_CURRENT );
+                               $this->getOutput()->redirect( $url );
+                       }
+               }
+       }
+
+       /**
+        * @param $title Title
+        */
+       function showForm( $userid ) {
+               global $wgScript;
+
+               $this->getOutput()->addHTML(
+                       Html::openElement( 'form', array( 'method' => 'get', 
'action' => $wgScript, 'id' => 'specialuserbyid' ) ) .
+                       Html::openElement( 'fieldset' ) .
+                       Html::element( 'legend', null, $this->msg( 'userbyid' 
)->text() ) .
+                       Html::hidden( 'title', 
$this->getTitle()->getPrefixedText() ) .
+                       Xml::inputLabel( $this->msg( 'userbyid-page' )->text(), 
'userid', 'userid', 25, $userid ) . ' ' .
+                       Xml::submitButton( $this->msg( 'userbyid-submit' 
)->text() ) . "\n" .
+                       Html::closeElement( 'fieldset' ) .
+                       Html::closeElement( 'form' )
+               );
+       }
+
+       protected function getGroupName() {
+               return 'users';
+       }
+}
diff --git a/languages/messages/MessagesEn.php 
b/languages/messages/MessagesEn.php
index a38a39a..bfedd0f 100644
--- a/languages/messages/MessagesEn.php
+++ b/languages/messages/MessagesEn.php
@@ -460,6 +460,7 @@
        'Unwatchedpages'            => array( 'UnwatchedPages' ),
        'Upload'                    => array( 'Upload' ),
        'UploadStash'               => array( 'UploadStash' ),
+       'Userbyid'                  => array( 'UserById' ),
        'Userlogin'                 => array( 'UserLogin' ),
        'Userlogout'                => array( 'UserLogout' ),
        'Userrights'                => array( 'UserRights', 'MakeSysop', 
'MakeBot' ),
@@ -4749,6 +4750,12 @@
 'filepath-summary' => 'This special page returns the complete path for a file.
 Images are shown in full resolution, other file types are started with their 
associated program directly.',
 
+# Special:Userbyid
+'userbyid'         => 'User by ID',
+'userbyid-page'    => 'User ID:',
+'userbyid-submit'  => 'Go',
+'userbyid-summary' => 'This special page returns the User page for a given 
numeric user iD.',
+
 # Special:FileDuplicateSearch
 'fileduplicatesearch'           => 'Search for duplicate files',
 'fileduplicatesearch-summary'   => 'Search for duplicate files based on hash 
values.',
diff --git a/maintenance/language/messages.inc 
b/maintenance/language/messages.inc
index b7ad695..a0be554 100644
--- a/maintenance/language/messages.inc
+++ b/maintenance/language/messages.inc
@@ -3602,6 +3602,12 @@
                'filepath-submit',
                'filepath-summary',
        ),
+       'userbyid' => array(
+               'userbyid',
+               'userbyid-page',
+               'userbyid-submit',
+               'userbyid-summary',
+       ),
        'fileduplicatesearch' => array(
                'fileduplicatesearch',
                'fileduplicatesearch-summary',
@@ -4059,6 +4065,7 @@
        'CoreParserFunctions'   => 'Core parser functions',
        'version'               => 'Special:Version',
        'filepath'              => 'Special:FilePath',
+       'userbyid'              => 'Special:UserById',
        'fileduplicatesearch'   => 'Special:FileDuplicateSearch',
        'special-specialpages'  => 'Special:SpecialPages',
        'special-blank'         => 'Special:BlankPage',

-- 
To view, visit https://gerrit.wikimedia.org/r/59050
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I91ac84d3323969aaee30ae44cd3b71fca4aa7073
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Cscott <wikime...@cscott.net>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to