jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/350244 )

Change subject: reorg files and get ready for release
......................................................................


reorg files and get ready for release

Change-Id: I9a9428d8586f8c58c44387bb14e4698d030763d6
---
D ChangeLog.mediawiki
A README.mediawiki
D WhoIsWatching_body.php
M extension.json
A src/SpecialPage.php
R src/i18n/Alias.php
6 files changed, 455 insertions(+), 273 deletions(-)

Approvals:
  jenkins-bot: Verified
  MarkAHershberger: Looks good to me, approved



diff --git a/ChangeLog.mediawiki b/ChangeLog.mediawiki
deleted file mode 100644
index 8fba8eb..0000000
--- a/ChangeLog.mediawiki
+++ /dev/null
@@ -1,28 +0,0 @@
-Changes since 0.11:
-
-
-Incompatibilites:
-* Requires at least MediaWiki 1.26
-* If you've made changes to the message displayed at the bottom of the page in 
[[MediaWiki:number_of_watching_users_pageview]], you'll need to see if it 
matches what is in [[MediaWiki:whoiswatchingpageview]] on your wiki.
-* Note the use of permissions is preferred to globals to allow access to the 
Special Page
-
-
-Other Changes:
-* Use extension.json
-* Remove .i18n.php stub.
-* Add rights so that we can use those instead of globals to control access:
-** addpagetoanywatchlist: gets to use the special page to add users.
-** seepagewatchers: gets to see the watchers.
-* Clean up WhoIsWatching::execute() method:
-** Use fewer globals.  Use GlobalVarConfig where possible.
-** Use protected methods for various parts of the execution path.
-** Add stub (WhoIsWatching::eNotifUser()) to later notify editors when their 
watchlists are changed.
-** Add stub (WhoIsWatching::uiNotifyUser()) to later provide better feedback 
to users of this extension.
-** Instead of listing out every user to choose from, provide autocomplete for 
user selection.
-** Instead of showing a confusing "usage" message, provide an autocomplete 
input box so that the user can select a page to inspect.
-** Provide slightly better error messages.
-** Refactor to make code more readable.
-* Adapted to changes in core MediaWiki since 1.25:
-** Moved $wgPageShowWatchingUsers which was removed from core in 1.25 to 
$whoiswathing_showwatchingusers
-** Since the message had to be changed anyway, moved the message from 
number_of_watching_users_pageview to whoiswatchingpageview
-* Remove use of sprintf for i18n construction.
diff --git a/README.mediawiki b/README.mediawiki
new file mode 100644
index 0000000..02a8242
--- /dev/null
+++ b/README.mediawiki
@@ -0,0 +1,90 @@
+The WhoIsWatching extension allows to find out who is watching a particular 
page, and add others to watchlist for that page
+
+== Rationale ==
+Even though this notion goes against Wikipedia and Wikimedia 
[[w:en:Wikipedia:Watchlist#Privacy_of_watchlists|privacy policy]], some wikis 
may actually like to see which of its users are watching particular pages. This 
extension provides just such an interface at the bottom of every page. 
Additionally, this extension has an option to allow any user to add any page to 
any other user's watch list.
+
+== Installation Instructions ==
+=== Step 1 ===
+Download the version of the extension code appropriate for your MediaWiki 
version from [[Special:ExtensionDistributor/WhoIsWatching|here]] and extract 
into the '''extensions/WhoIsWatching''' folder.
+
+=== Step 2 ===
+Add the following text to your 
'''[[Manual:LocalSettings.php|LocalSettings.php]]'''
+<source lang="php">wfLoadExtension( "WhoIsWatching" );
+# $whoiswatching_nametype = "RealName";
+# $whoiswatching_allowaddingpeople = false;
+# $whoiswatching_showifzero = true;
+# $whoiswatching_showwatchingusers = false;
+# $whoiswatching_maxPicklistUsers = 10;
+# $wgGroupPermissions['sysop']['addpagetoanywatchlist'] = true;
+# $wgGroupPermissions['sysop']['seepagewatchers'] = true;
+</source>
+
+=== Additional Configuration ===
+You can simply start using the extension without changing anything else. The 
only additional configuration that is currently possible for the extension 
defines how to display the names of the users watching the pages. In 
''SpecialWhoIsWatching.php'', there is
+<source lang=php># Set the following to either 'UserName' or 'RealName' to 
display the list of watching users as such.
+$whoiswatching_nametype = 'RealName';
+</source>
+As the comment implies, depending on the value of this variable, you can 
display either the real names of the watching users or their wiki usernames. 
The reason some wiki's may want to switch over to the 'UserName' mode is if 
they do not require their members to have a valid real name.
+
+Another configurable option in the extension is the ability to switch on/off 
the option to allow any user to add any page to any other user's watch list. 
This is done in ''SpecialWhoIsWatching.php'', where there is
+<source lang="php"># Set true if you don't want to use permissions and users 
are allowed to add
+# to other user's watchlists.
+$whoiswatching_allowaddingpeople = true;
+</source>
+
+It is also possible to only display the count of watching people if the count 
is greater than zero. This is done in ''SpecialWhoIsWatching.php'', where there 
is
+<source lang="php"># Set to true if you want people with permission to see 0 
if no one is watching
+# the page.
+$whoiswatching_showifzero = true;
+</source>Finally, newer versions of this extension, while we attempt to be 
backward compatible, allow you to use permissions instead of global 
variables.<source lang="php"># Set to true if you don't want to use permissions.
+$whoiswatching_showwatchingusers = true;
+</source>By default, users in the sysop group have permission to see page 
watchers and add pages to anyone's watchlist.   You can grant these permissions 
to logged in users, too, or any group you think needs it.<source lang="php"># 
Give all logged in users full access.
+$wgGroupPermissions['user']['addpagetoanywatchlist'] = true;
+$wgGroupPermissions['user']['seepagewatchers'] = true;
+</source>
+
+== Revisions ==
+*0.12 -- 2016-05-22:  '''Incompatibilites''':
+** Requires at least MediaWiki 1.26
+
+** If you've made changes to the message displayed at the bottom of the page 
in [[MediaWiki:number_of_watching_users_pageview]], you'll need to see if it 
matches what is in [[MediaWiki:whoiswatchingpageview]] on your wiki.
+
+** Note the use of permissions is preferred to globals to allow access to the 
Special Page '''Other Changes''':
+** Use extension.json
+
+** Remove .i18n.php stub.
+
+** Add rights so that we can use those instead of globals to control access:
+*** addpagetoanywatchlist: gets to use the special page to add users.
+*** seepagewatchers: gets to see the watchers.
+
+** Clean up WhoIsWatching::execute() method:
+*** Use fewer globals.  Use GlobalVarConfig where possible.
+*** Use protected methods for various parts of the execution path.
+*** Add stub (WhoIsWatching::eNotifUser()) to later notify editors when their 
watchlists are changed.
+*** Add stub (WhoIsWatching::uiNotifyUser()) to later provide better feedback 
to users of this extension.
+*** Instead of listing out every user to choose from, provide autocomplete for 
user selection.
+*** Instead of showing a confusing "usage" message, provide an autocomplete 
input box so that the user can select a page to inspect.
+*** Provide slightly better error messages.
+*** Refactor to make code more readable.
+
+** Adapted to changes in core MediaWiki since 1.25:
+*** Moved $wgPageShowWatchingUsers which was removed from core in 1.25 to 
$whoiswathing_showwatchingusers
+*** Since the message had to be changed anyway, moved the message from 
number_of_watching_users_pageview to whoiswatchingpageview
+*** Remove use of sprintf for i18n construction.
+* v0.9 - October 6, 2008
+** Fixed the extension instantiation to work across MW versions
+** Fixed the feature that displays count of users if zero
+* v0.8 - September 29, 2008 - optionally display a count of 0 watching users 
(contributed by [[user:Djomp]])
+* v0.7 - September 5, 2008 - added descriptionmsg, change special page alias 
loading method; removed obsolete code (by [[user:siebrand]])
+* v0.6 - June 6, 2008 - Optionally disable the feature to make other users 
watch the page.
+* v0.5 - May 12, 2008
+** Better handling of user names
+* v0.4 - December 27, 2007
+** new feature - add other users to the list of people watching the page
+** sort the list of people watching the page
+** minor bug fix on listing which page the information is pertaining to when 
the page is a category
+* v0.3 - November 25, 2007 - More standard way to load i18n messages (resolve 
bug about "Call to undefined function wfLoadExtensionMessages()")
+* v0.2 - November 23, 2007
+* v0.1 - October 12, 2007 - Initial publication.
+
diff --git a/WhoIsWatching_body.php b/WhoIsWatching_body.php
deleted file mode 100644
index a87e585..0000000
--- a/WhoIsWatching_body.php
+++ /dev/null
@@ -1,239 +0,0 @@
-<?php
-
-class WhoIsWatching extends SpecialPage {
-
-       protected $targetPage = null;
-       protected $nameType;
-       protected $allowAddingPeople;
-       protected $showWatchingUsers;
-       protected $showIfZero;
-
-       function __construct() {
-               parent::__construct( 'WhoIsWatching' );
-
-               $conf = new GlobalVarConfig( "whoiswatching_" );
-               $user = $this->getUser();
-               $this->nameType = $conf->get( "nametype" );
-               $this->allowAddingPeople = ( !$user->isAnon() && $conf->get( 
"allowaddingpeople" ) ) ||
-                       $user->isAllowed( "addpagetoanywatchlist" );
-               $this->showWatchingUsers = $conf->get( "showwatchingusers" ) ||
-                       $user->isAllowed( "seepagewatchers" );
-
-               return true;
-       }
-
-       function execute( $par ) {
-               parent::execute( $par );
-
-               if ( $this->getTargetPage( $par ) ) {
-                       if ( $this->addWatchersForm() ) {
-                               return true;
-                       }
-                       $this->showWatchingUsers();
-               }
-       }
-
-       public function checkPermissions() {
-               if ( $this->showWatchingUsers || $this->allowAddingPeople ) {
-                       return true;
-               }
-               throw new ErrorPageError(
-                       "whoiswatching-permission-denied-title", 
"whoiswatching-permission-denied",
-                       [ $this->getLanguage()->commaList( [ "seepagewatchers", 
"addpagetoanywatchlist" ] ) ]
-               );
-       }
-
-       protected function getTargetPage( $par ) {
-               $title = $this->getRequest()->getVal( 'page' );
-               if ( !$title && !$par ) {
-                       return $this->pickPage();
-               }
-
-               if ( $title ) {
-                       $nsRevLookup = array_flip( 
MWNamespace::getCanonicalNamespaces() );
-                       $ns = $this->getRequest()->getVal( 'ns', '' );
-                       if ( !ctype_digit( $ns ) ) {
-                               $ns = isset( $nsRevLookup[ $ns ] ) ? 
$nsRevLookup[ $ns ] : null;
-                       }
-                       $this->targetPage = Title::newFromText( $title, $ns );
-               } else {
-                       $this->targetPage = Title::newFromText( $par );
-               }
-
-               if ( !$this->targetPage ) {
-                       throw new ErrorPageError( "whoiswatching-usage-title", 
"specialwhoiswatchingusage" );
-               }
-               $ns = $this->targetPage->getNamespace();
-               if ( $ns < 0 ) {
-                       throw new ErrorPageError(
-                               "whoiswatching-not-possible-title", 
"whoiswatching-not-possible", [ $this->targetPage ]
-                       );
-               }
-
-               return true;
-       }
-
-       protected function addWatchersForm() {
-               if ( $this->allowAddingPeople === false ) {
-                       return false;
-               }
-
-               $this->getOutput()->addModules( 'mediawiki.userSuggest' );
-
-               $this->getOutput()->addHTML(
-                       Html::openElement(
-                               'form',
-                               [ 'method' => 'post',
-                                 'action' => $this->getPageTitle( 
$this->targetPage )->getLocalUrl(),
-                                 'name' => 'uluser',
-                                 'id' => 'mw-whoiswatching-form1' ]
-                       ) .
-                       Html::hidden( 'addToken', 
$this->getUser()->getEditToken( __CLASS__ ) ) .
-            ( !$this->targetPage->exists() ? '<b>This page does not (yet) 
exist!</b>' : '' ) .
-                       Xml::fieldset( $this->msg( 'whoiswatching-lookup-user' 
)->text() ) .
-                       Xml::inputLabel(
-                               $this->msg( 'whoiswatching-user-editname' 
)->text(),
-                               'user',
-                               'username',
-                               30,
-                               '',
-                               [ 'autofocus' => true,
-                                 'class' => 'mw-autocomplete-user' ] // used 
by mediawiki.userSuggest
-                       ) . ' ' .
-                       Xml::submitButton( $this->msg( 'whoiswatching-adduser' 
)->text() ) .
-                       Html::closeElement( 'fieldset' ) .
-                       Html::closeElement( 'form' ) . "\n"
-               );
-
-               if ( $this->maybeAddWatcher() ) {
-                       $this->uiNotifyUser();
-               }
-               return false;
-       }
-
-       protected function maybeAddWatcher() {
-               $req = $this->getRequest();
-               $token = $req->getVal( 'addToken' );
-               if ( $req->wasPosted() && $token ) {
-                       if ( $this->getUser()->matchEditToken( $token, 
__CLASS__ ) ) {
-                               $user = User::newFromName( $req->getVal( 'user' 
) );
-                               $title = $this->targetPage;
-                               $user->addWatch( $title );
-                               $this->getOutput()->redirect( 
$this->getPageTitle( $title )->getLocalUrl() );
-                $this->eNotifUser( 'add', $title, $user );
-                               return true;
-                       }
-
-                       throw new ErrorPageError( 'sessionfailure-title', 
'sessionfailure' );
-               }
-               return true;
-       }
-
-       protected function eNotifUser( $action, Title $title, User $user ) {
-       }
-
-       protected function uiNotifyUser( ) {
-       }
-
-       protected function pickPage() {
-               $target = $this->getRequest()->getVal( "target" );
-               if ( $target ) {
-                       $this->getOutput()->redirect( $this->getPageTitle( 
$target )->getLocalUrl() );
-                       return false;
-               }
-               $this->getOutput()->addHTML(
-                       Html::openElement(
-                               'form',
-                               [ 'method' => 'get',
-                                 'action' => $this->getPageTitle( $target 
)->getLocalUrl(),
-                                 'name' => 'uluser',
-                                 'id' => 'mw-whoiswatching-form1' ] ) .
-                       Html::hidden( 'title', 
$this->getPageTitle()->getPrefixedText() ) .
-                       Xml::fieldset( $this->msg( 'whoiswatching-lookup-title' 
)->text() ) .
-                       Xml::inputLabel( $this->msg( 'whoiswatching-title' 
)->text(), 'target',
-                                                        
'whoiswatching-target', 40,
-                                                        str_replace( '_', ' ', 
$this->targetPage ),
-                                                        [ 'class' => 
'mw-searchInput' ] ) . ' ' .
-                       Xml::submitButton( $this->msg( 
'whoiswatching-select-title' )->text() ) .
-                       Html::closeElement( 'fieldset' ) .
-                       Html::closeElement( 'form' ) . "\n"
-               );
-               return false;
-       }
-
-       public function maybeRemoveWatcher( array $formData ) {
-               foreach ( $formData as $watcherID => $remove ) {
-                       if ( $remove ) {
-                               $watcher = User::newFromId( $watcherID );
-                               $watcher->removeWatch( $this->targetPage );
-                               $this->eNotifUser( 'remove', $this->targetPage, 
$watcher );
-                       }
-               }
-       }
-
-       protected function showWatchingUsers() {
-               if ( $this->showWatchingUsers === false ) {
-                       return;
-               }
-
-               $out = $this->getOutput();
-               $out->addWikiText(
-                       "== ". wfMessage( 'specialwhoiswatchingpage' )->params( 
$this->targetPage )->plain() . " =="
-               );
-
-               $dbr = wfGetDB( DB_SLAVE );
-               $watchingusers = [];
-               $res = $dbr->select(
-                       'watchlist', 'wl_user', [ 'wl_namespace' => 
$this->targetPage->getNamespace(),
-                                                                         
'wl_title' => $this->targetPage->getDBkey() ], __METHOD__ );
-               foreach ( $res as $row ) {
-                       $u = User::newFromID( $row->wl_user );
-                       $key = $u->mId;
-                       $display = $u->getRealName();
-                       if ( ( $this->nameType == 'UserName' ) || 
!$u->getRealName() ) {
-                               $display = $u->getName();
-                       }
-                       $watchingusers[$key] = $display;
-               }
-
-               asort( $watchingusers );
-
-               $users = [];
-               foreach ( $watchingusers as $id => $link ) {
-                       $users[ $id ] = [ 'type' => 'check', 'label' => $link ];
-               }
-               if ( $this->allowAddingPeople ) {
-                       $form = new HTMLForm( $users, $this->getContext() );
-                       $form->setSubmitText( $this->msg( 
'whoiswatching-deluser' )->text() );
-                       $form->setSubmitCallback( [ $this, 'maybeRemoveWatcher' 
] );
-                       $form->show();
-               }
-       }
-
-       public static function onSkinTemplateOutputPageBeforeExec( Skin 
$template, QuickTemplate $tpl ) {
-               $conf = new GlobalVarConfig( "whoiswatching_" );
-               $showIfZero = $conf->get( "showifzero" );
-               $showWatchingUsers = $conf->get( "showwatchingusers" );
-
-               if (
-                       
RequestContext::getMain()->getOutput()->getTitle()->getNamespace() >= 0 &&
-                       $showWatchingUsers
-               ) {
-                       $dbr = wfGetDB( DB_SLAVE );
-                       $title = $template->getTitle();
-                       $res = $dbr->select( 'watchlist', 'COUNT(*) as count', [
-                                                                'wl_namespace' 
=> $title->getNamespace(),
-                                                                'wl_title' => 
$title->getDBkey(),
-                       ], __METHOD__ );
-                       $watch = $dbr->fetchObject( $res );
-                       if ( $watch->count > 0 || $showIfZero ) {
-                               $msg = wfMessage( 
'whoiswatching_users_pageview',
-                                       
RequestContext::getMain()->getLanguage()->formatNum( $watch->count )
-                               )->parse();
-                               $tpl->set( 'numberofwatchingusers', $msg );
-                       }
-               }
-
-               return true;
-       }
-}
diff --git a/extension.json b/extension.json
index 8a8ab80..6f2ebd8 100644
--- a/extension.json
+++ b/extension.json
@@ -15,7 +15,7 @@
        "descriptionmsg": "whoiswatching-desc",
        "type": "specialpage",
        "SpecialPages": {
-               "WhoIsWatching": "WhoIsWatching"
+               "WhoIsWatching": "WhoIsWatching\\WhoIsWatching"
        },
        "MessagesDirs": {
                "WhoIsWatching": [
@@ -23,14 +23,14 @@
                ]
        },
        "ExtensionMessagesFiles": {
-               "WhoIsWatchingAlias": "WhoIsWatching.alias.php"
+               "WhoIsWatchingAlias": "src/i18n/Alias.php"
        },
        "AutoloadClasses": {
-               "WhoIsWatching": "WhoIsWatching_body.php"
+               "WhoIsWatching\\WhoIsWatching": "src/SpecialPage.php"
        },
        "Hooks": {
                "SkinTemplateOutputPageBeforeExec": [
-                       "WhoIsWatching::onSkinTemplateOutputPageBeforeExec"
+                       
"WhoIsWatching\\WhoIsWatching::onSkinTemplateOutputPageBeforeExec"
                ]
        },
        "GroupPermissions": {
@@ -46,9 +46,9 @@
        "config": {
                "_prefix": "whoiswatching_",
                "nametype": "RealName",
-               "allowaddingpeople": true,
+               "allowaddingpeople": false,
                "showifzero": true,
-               "showwatchingusers": true,
+               "showwatchingusers": false,
                "maxPicklistUsers": 10
        },
        "manifest_version": 1
diff --git a/src/SpecialPage.php b/src/SpecialPage.php
new file mode 100644
index 0000000..f58ffc8
--- /dev/null
+++ b/src/SpecialPage.php
@@ -0,0 +1,359 @@
+<?php
+/**
+ * Special page for WhoIsWatching
+ *
+ * Copyright (C) 2017  Mark A. Hershberger
+ *
+ * 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+namespace WhoIsWatching;
+
+use ErrorPageError;
+use GlobalVarConfig;
+use HTML;
+use HTMLForm;
+use MWNamespace;
+use QuickTemplate;
+use RequestContext;
+use Skin;
+use SpecialPage;
+use Title;
+use User;
+use XML;
+
+class WhoIsWatching extends SpecialPage {
+
+       protected $targetPage = null;
+       protected $nameType;
+       protected $allowAddingPeople;
+       protected $showWatchingUsers;
+       protected $showIfZero;
+
+       /**
+        * Ye olde constructor
+        * @return boolean
+        */
+       function __construct() {
+               parent::__construct( 'whoiswatching' );
+
+               $conf = new GlobalVarConfig( "whoiswatching_" );
+               $user = $this->getUser();
+               $this->nameType = $conf->get( "nametype" );
+               $this->allowAddingPeople = ( !$user->isAnon()
+                                                                        && 
$conf->get( "allowaddingpeople" ) )
+                                                                || 
$user->isAllowed( "addpagetoanywatchlist" );
+               $this->showWatchingUsers = $conf->get( "showwatchingusers" ) ||
+                       $user->isAllowed( "seepagewatchers" );
+
+               return true;
+       }
+
+       /**
+        * Page executioner
+        * @param string $par page we're messing with
+        * @return boolean
+        */
+       function execute( $par ) {
+               parent::execute( $par );
+
+               if ( $this->getTargetPage( $par ) ) {
+                       if ( $this->addWatchersForm() ) {
+                               return true;
+                       }
+                       $this->showWatchingUsers();
+               }
+       }
+
+       /**
+        * Add to upstream check permissions
+        * @return void
+        * @throws ErrorPageError
+        */
+       public function checkPermissions() {
+               if ( $this->showWatchingUsers || $this->allowAddingPeople ) {
+                       return parent::checkPermissions();
+               }
+               throw new ErrorPageError(
+                       "whoiswatching-permission-denied-title",
+                       "whoiswatching-permission-denied",
+                       [ $this->getLanguage()->commaList(
+                               [ "seepagewatchers", "addpagetoanywatchlist" ]
+                       ) ]
+               );
+       }
+
+       /**
+        * Either return the page chosen or display a page chooser and return 
false
+        * @param string $par the passed in parameter
+        * @return boolean|Title
+        * @throws ErrorPageError
+        */
+       protected function getTargetPage( $par ) {
+               $title = $this->getRequest()->getVal( 'page' );
+               if ( !$title && !$par ) {
+                       return $this->pickPage();
+               }
+
+               if ( $title ) {
+                       $nsRevLookup = array_flip( 
MWNamespace::getCanonicalNamespaces() );
+                       $nameSpace = $this->getRequest()->getVal( 'ns', '' );
+                       if ( !ctype_digit( $nameSpace ) ) {
+                               $nameSpace = isset( $nsRevLookup[ $nameSpace ] )
+                                                  ? $nsRevLookup[ $nameSpace ]
+                                                  : null;
+                       }
+                       $this->targetPage = Title::newFromText( $title, 
$nameSpace );
+               } else {
+                       $this->targetPage = Title::newFromText( $par );
+               }
+
+               if ( !$this->targetPage ) {
+                       throw new ErrorPageError(
+                               "whoiswatching-usage-title", 
"specialwhoiswatchingusage"
+                       );
+               }
+               $nameSpace = $this->targetPage->getNamespace();
+               if ( $nameSpace < 0 ) {
+                       throw new ErrorPageError(
+                               "whoiswatching-not-possible-title",
+                               "whoiswatching-not-possible",
+                               [ $this->targetPage ]
+                       );
+               }
+
+               return true;
+       }
+
+       /**
+        * The form for adding a watcher.
+        * @return boolean
+        */
+       protected function addWatchersForm() {
+               if ( $this->allowAddingPeople === false ) {
+                       return false;
+               }
+
+               $this->getOutput()->addModules( 'mediawiki.userSuggest' );
+
+               $this->getOutput()->addHTML(
+                       Html::openElement(
+                               'form',
+                               [ 'method' => 'post',
+                                 'action' => $this->getPageTitle( 
$this->targetPage )
+                                 ->getLocalUrl(),
+                                 'name' => 'uluser',
+                                 'id' => 'mw-whoiswatching-form1' ]
+                       ) .
+                       Html::hidden( 'addToken',
+                                                 
$this->getUser()->getEditToken( __CLASS__ ) ) .
+                       ( !$this->targetPage->exists()
+                         ? '<b>This page does not (yet) exist!</b>'
+                         : ''
+                       ) .
+                       Xml::fieldset( $this->msg( 'whoiswatching-lookup-user' 
)->text() ) .
+                       Xml::inputLabel(
+                               $this->msg( 'whoiswatching-user-editname' 
)->text(),
+                               'user',
+                               'username',
+                               30,
+                               '',
+                               [ 'autofocus' => true,
+                                  // used by mediawiki.userSuggest
+                                 'class' => 'mw-autocomplete-user' ]
+                       ) . ' ' .
+                       Xml::submitButton( $this->msg( 'whoiswatching-adduser' 
)->text() ) .
+                       Html::closeElement( 'fieldset' ) .
+                       Html::closeElement( 'form' ) . "\n"
+               );
+
+               if ( $this->maybeAddWatcher() ) {
+                       $this->uiNotifyUser();
+               }
+               return false;
+       }
+
+       /**
+        * Add a watcher if the request did so
+        * @return boolean
+        * @throws ErrorPageError
+        */
+       protected function maybeAddWatcher() {
+               $req = $this->getRequest();
+               $token = $req->getVal( 'addToken' );
+               if ( $req->wasPosted() && $token ) {
+                       if ( $this->getUser()->matchEditToken( $token, 
__CLASS__ ) ) {
+                               $user = User::newFromName( $req->getVal( 'user' 
) );
+                               $title = $this->targetPage;
+                               $user->addWatch( $title );
+                               $this->getOutput()->redirect
+                                       ( $this->getPageTitle( $title 
)->getLocalUrl() );
+                               $this->eNotifUser( 'add', $title, $user );
+                               return true;
+                       }
+
+                       throw new ErrorPageError
+                               ( 'sessionfailure-title', 'sessionfailure' );
+               }
+               return true;
+       }
+
+       /**
+        * FIXME needs to be fleshed out
+        * @param string $action taked
+        * @param Title $title page updated
+        * @param User $user affected
+        */
+       protected function eNotifUser( $action, Title $title, User $user ) {
+       }
+
+       /**
+        * FIXME needs to be fleshed out
+        */
+       protected function uiNotifyUser() {
+       }
+
+       /**
+        * If the user selected a page, redirect to work on it.  If not,
+        * show the form.
+        * @return boolean
+        */
+       protected function pickPage() {
+               $target = $this->getRequest()->getVal( "target" );
+               if ( $target ) {
+                       $this->getOutput()->redirect
+                               ( $this->getPageTitle( $target )->getLocalUrl() 
);
+                       return false;
+               }
+               $this->getOutput()->addHTML(
+                       Html::openElement(
+                               'form',
+                               [ 'method' => 'get',
+                                 'action' => $this->getPageTitle( $target 
)->getLocalUrl(),
+                                 'name' => 'uluser',
+                                 'id' => 'mw-whoiswatching-form1' ] ) .
+                       Html::hidden( 'title', 
$this->getPageTitle()->getPrefixedText() ) .
+                       Xml::fieldset
+                       ( $this->msg( 'whoiswatching-lookup-title' )->text() ) .
+                       Xml::inputLabel
+                       ( $this->msg( 'whoiswatching-title' )->text(), 'target',
+                         'whoiswatching-target', 40,
+                         str_replace( '_', ' ', $this->targetPage ),
+                         [ 'class' => 'mw-searchInput' ] ) . ' ' .
+                       Xml::submitButton
+                       ( $this->msg( 'whoiswatching-select-title' )->text() ) .
+                       Html::closeElement( 'fieldset' ) .
+                       Html::closeElement( 'form' ) . "\n"
+               );
+               return false;
+       }
+
+       /**
+        * Remove any posted for removal
+        * @param array $formData posted data
+        */
+       public function maybeRemoveWatcher( array $formData ) {
+               foreach ( $formData as $watcherID => $remove ) {
+                       if ( $remove ) {
+                               $watcher = User::newFromId( $watcherID );
+                               $watcher->removeWatch( $this->targetPage );
+                               $this->eNotifUser( 'remove', $this->targetPage, 
$watcher );
+                       }
+               }
+       }
+
+       /**
+        * Show watching users if we can
+        * @return null
+        */
+       protected function showWatchingUsers() {
+               if ( $this->showWatchingUsers === false ) {
+                       return;
+               }
+
+               $out = $this->getOutput();
+               $out->addWikiText(
+                       "== ". wfMessage( 'specialwhoiswatchingpage' )
+                       ->params( $this->targetPage )->plain() . " =="
+               );
+
+               $dbr = wfGetDB( DB_SLAVE );
+               $watchingusers = [];
+               $res = $dbr->select(
+                       'watchlist', 'wl_user',
+                       [ 'wl_namespace' => $this->targetPage->getNamespace(),
+                         'wl_title' => $this->targetPage->getDBkey() ], 
__METHOD__
+               );
+               foreach ( $res as $row ) {
+                       $u = User::newFromID( $row->wl_user );
+                       $key = $u->mId;
+                       $display = $u->getRealName();
+                       if ( ( $this->nameType == 'UserName' ) || 
!$u->getRealName() ) {
+                               $display = $u->getName();
+                       }
+                       $watchingusers[$key] = $display;
+               }
+
+               asort( $watchingusers );
+
+               $users = [];
+               foreach ( $watchingusers as $id => $link ) {
+                       $users[ $id ] = [ 'type' => 'check', 'label' => $link ];
+               }
+               if ( $this->allowAddingPeople ) {
+                       $form = new HTMLForm( $users, $this->getContext() );
+                       $form->setSubmitText
+                               ( $this->msg( 'whoiswatching-deluser' )->text() 
);
+                       $form->setSubmitCallback( [ $this, 'maybeRemoveWatcher' 
] );
+                       $form->show();
+               }
+       }
+
+       /**
+        * Hook to display link to page watchers
+        * @param Skin $template skin
+        * @param QuickTemplate $tpl template
+        * @return boolean
+        */
+       public static function onSkinTemplateOutputPageBeforeExec(
+               Skin $template, QuickTemplate $tpl
+       ) {
+               $conf = new GlobalVarConfig( "whoiswatching_" );
+               $showIfZero = $conf->get( "showifzero" );
+               $showWatchingUsers = $conf->get( "showwatchingusers" );
+
+               if (
+                       RequestContext::getMain()->getOutput()->
+                       getTitle()->getNamespace() >= 0
+                       && $showWatchingUsers
+               ) {
+                       $dbr = wfGetDB( DB_SLAVE );
+                       $title = $template->getTitle();
+                       $res = $dbr->select( 'watchlist', 'COUNT(*) as count', [
+                                                                'wl_namespace' 
=> $title->getNamespace(),
+                                                                'wl_title' => 
$title->getDBkey(),
+                       ], __METHOD__ );
+                       $watch = $dbr->fetchObject( $res );
+                       if ( $watch->count > 0 || $showIfZero ) {
+                               $msg = wfMessage( 
'whoiswatching_users_pageview',
+                                       
RequestContext::getMain()->getLanguage()->formatNum
+                                                                 ( 
$watch->count )
+                               )->parse();
+                               $tpl->set( 'numberofwatchingusers', $msg );
+                       }
+               }
+
+               return true;
+       }
+}
diff --git a/WhoIsWatching.alias.php b/src/i18n/Alias.php
similarity index 100%
rename from WhoIsWatching.alias.php
rename to src/i18n/Alias.php

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I9a9428d8586f8c58c44387bb14e4698d030763d6
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WhoIsWatching
Gerrit-Branch: master
Gerrit-Owner: MarkAHershberger <[email protected]>
Gerrit-Reviewer: MarkAHershberger <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to