MarkAHershberger has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/350245 )
Change subject: More file reorg + hack for deleting users
......................................................................
More file reorg + hack for deleting users
Change-Id: I21a989957efbb8057ccda8a14448358b20e3c721
---
M .gitignore
M README.mediawiki
M extension.json
A modules/ext.whoIsWatching.css
A src/Hook.php
R src/SpecialWhoIsWatching.php
6 files changed, 99 insertions(+), 56 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WhoIsWatching
refs/changes/45/350245/1
diff --git a/.gitignore b/.gitignore
index 8d96304..aa302b0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,3 +7,5 @@
.*.swp
\#*\#
.\#*
+
+PHPTAGS.sqlite
diff --git a/README.mediawiki b/README.mediawiki
index 02a8242..b69717a 100644
--- a/README.mediawiki
+++ b/README.mediawiki
@@ -43,6 +43,10 @@
$wgGroupPermissions['user']['seepagewatchers'] = true;
</source>
+== Known Issues ==
+
+The first time after a you submit a request to remove a page from the users
watchlist, the user is still shown on the form. To get around this it is
disabled and displayed with a red strikethrough.
+
== Revisions ==
*0.12 -- 2016-05-22: '''Incompatibilites''':
** Requires at least MediaWiki 1.26
@@ -87,4 +91,3 @@
* 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/extension.json b/extension.json
index 6f2ebd8..5863794 100644
--- a/extension.json
+++ b/extension.json
@@ -15,7 +15,7 @@
"descriptionmsg": "whoiswatching-desc",
"type": "specialpage",
"SpecialPages": {
- "WhoIsWatching": "WhoIsWatching\\WhoIsWatching"
+ "WhoIsWatching": "WhoIsWatching\\SpecialWhoIsWatching"
},
"MessagesDirs": {
"WhoIsWatching": [
@@ -26,11 +26,12 @@
"WhoIsWatchingAlias": "src/i18n/Alias.php"
},
"AutoloadClasses": {
- "WhoIsWatching\\WhoIsWatching": "src/SpecialPage.php"
+ "WhoIsWatching\\SpecialWhoIsWatching":
"src/SpecialWhoIsWatching.php",
+ "WhoIsWatching\\Hook": "src/Hook.php"
},
"Hooks": {
"SkinTemplateOutputPageBeforeExec": [
-
"WhoIsWatching\\WhoIsWatching::onSkinTemplateOutputPageBeforeExec"
+
"WhoIsWatching\\Hook::onSkinTemplateOutputPageBeforeExec"
]
},
"GroupPermissions": {
@@ -43,6 +44,17 @@
"addpagetoanywatchlist",
"seepagewatchers"
],
+ "ResourceModules": {
+ "ext.whoIsWatching": {
+ "styles": [
+ "modules/ext.whoIsWatching.css"
+ ]
+ }
+ },
+ "ResourceFileModulePaths": {
+ "localBasePath": "",
+ "remoteExtPath": ""
+ },
"config": {
"_prefix": "whoiswatching_",
"nametype": "RealName",
diff --git a/modules/ext.whoIsWatching.css b/modules/ext.whoIsWatching.css
new file mode 100644
index 0000000..867016e
--- /dev/null
+++ b/modules/ext.whoIsWatching.css
@@ -0,0 +1,3 @@
+input:disabled+label {
+ text-decoration: line-through red;
+}
diff --git a/src/Hook.php b/src/Hook.php
new file mode 100644
index 0000000..fd13fc9
--- /dev/null
+++ b/src/Hook.php
@@ -0,0 +1,61 @@
+<?php
+/*
+ * 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 GlobalVarConfig;
+use QuickTemplate;
+use RequestContext;
+use Skin;
+
+class Hook {
+ /**
+ * 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" );
+ $title = $template->getTitle();
+ $user = $template->getUser();
+ $showWatchingUsers = $conf->get( "showwatchingusers" )
+ || $user->isAllowed(
'seepagewatchers' );
+
+ if ( $title->getNamespace() >= 0 && $showWatchingUsers ) {
+ $dbr = wfGetDB( DB_SLAVE );
+ $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/src/SpecialPage.php b/src/SpecialWhoIsWatching.php
similarity index 84%
rename from src/SpecialPage.php
rename to src/SpecialWhoIsWatching.php
index f58ffc8..56a5a3b 100644
--- a/src/SpecialPage.php
+++ b/src/SpecialWhoIsWatching.php
@@ -25,15 +25,12 @@
use HTML;
use HTMLForm;
use MWNamespace;
-use QuickTemplate;
-use RequestContext;
-use Skin;
use SpecialPage;
use Title;
use User;
use XML;
-class WhoIsWatching extends SpecialPage {
+class SpecialWhoIsWatching extends SpecialPage {
protected $targetPage = null;
protected $nameType;
@@ -178,9 +175,7 @@
Html::closeElement( 'form' ) . "\n"
);
- if ( $this->maybeAddWatcher() ) {
- $this->uiNotifyUser();
- }
+ $this->maybeAddWatcher();
return false;
}
@@ -216,12 +211,6 @@
* @param User $user affected
*/
protected function eNotifUser( $action, Title $title, User $user ) {
- }
-
- /**
- * FIXME needs to be fleshed out
- */
- protected function uiNotifyUser() {
}
/**
@@ -262,12 +251,19 @@
/**
* Remove any posted for removal
* @param array $formData posted data
+ * @param HTMLForm $form the whole form
*/
- public function maybeRemoveWatcher( array $formData ) {
+ protected function maybeRemoveWatcher( array $formData, HTMLForm $form
) {
foreach ( $formData as $watcherID => $remove ) {
if ( $remove ) {
$watcher = User::newFromId( $watcherID );
$watcher->removeWatch( $this->targetPage );
+ # We should somehow remove this field from the
form,
+ # but it looks too late now.
+ $field = $form->getField( $watcherID );
+ $field->mParams['disabled'] = true;
+ $field->setShowEmptyLabel( false );
+ $this->getOutput()->addModules(
"ext.whoIsWatching" );
$this->eNotifUser( 'remove', $this->targetPage,
$watcher );
}
}
@@ -315,45 +311,11 @@
$form = new HTMLForm( $users, $this->getContext() );
$form->setSubmitText
( $this->msg( 'whoiswatching-deluser' )->text()
);
- $form->setSubmitCallback( [ $this, 'maybeRemoveWatcher'
] );
+ $form->setSubmitCallback(
+ function ( $formData, $form ) {
+ return $this->maybeRemoveWatcher(
$formData, $form );
+ } );
$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;
}
}
--
To view, visit https://gerrit.wikimedia.org/r/350245
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I21a989957efbb8057ccda8a14448358b20e3c721
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WhoIsWatching
Gerrit-Branch: master
Gerrit-Owner: MarkAHershberger <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits