r102099 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r102098‎ | r102099 | r102100 >
Date:14:57, 5 November 2011
Author:petrb
Status:ok (Comments)
Tags:
Comment:
new extension created initial folder + some stuff, it's work in progress
Modified paths:
  • /trunk/extensions/InteractiveBlockMessage (added) (history)
  • /trunk/extensions/InteractiveBlockMessage/InteractiveBlockMessage.i18n.php (added) (history)
  • /trunk/extensions/InteractiveBlockMessage/InteractiveBlockMessage.php (added) (history)
  • /trunk/extensions/InteractiveBlockMessage/InteractiveBlockMessageHooks.php (added) (history)

Diff [purge]

Index: trunk/extensions/InteractiveBlockMessage/InteractiveBlockMessage.i18n.php
@@ -0,0 +1,25 @@
 2+<?php
 3+/**
 4+ * Internationalisation file for Interactive block message extension.
 5+ *
 6+ * @file
 7+ * @ingroup Extensions
 8+ */
 9+
 10+$messages = array();
 11+
 12+/**
 13+ * English
 14+ * @author Petr Bena
 15+ */
 16+$messages['en'] = array(
 17+ // Description
 18+ 'interactiveblockmessage-desc' => 'Creates magic word {{userblocked}} which if on userspace indicates if user is blocked or not.',
 19+);
 20+
 21+/** Message documentation (Message documentation)
 22+ * @author Petr Bena
 23+ */
 24+$messages['qqq'] = array(
 25+ 'interactiveblockmessage-desc' => '{{desc}}',
 26+);
Property changes on: trunk/extensions/InteractiveBlockMessage/InteractiveBlockMessage.i18n.php
___________________________________________________________________
Added: svn:eol-style
127 + native
Index: trunk/extensions/InteractiveBlockMessage/InteractiveBlockMessage.php
@@ -0,0 +1,35 @@
 2+<?php
 3+/**
 4+ * Insert a new magic word
 5+ *
 6+ * @file
 7+ * @ingroup Extensions
 8+ * @author Petr Bena <benapetr@gmail.com>
 9+ * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
 10+ * @link http://www.mediawiki.org/wiki/Extension:OnlineStatusBar Documentation
 11+ */
 12+
 13+if ( !defined( 'MEDIAWIKI' ) ) {
 14+ echo "This is a part of mediawiki and can't be started separately";
 15+ die();
 16+}
 17+
 18+$wgExtensionCredits[version_compare( $wgVersion, '1.17', '>=' ) ? 'userpage tools' : 'other'][] = array(
 19+ 'path' => __FILE__,
 20+ 'name' => 'Interactive block message',
 21+ 'version' => '1.0.0',
 22+ 'author' => array( 'Petr Bena' ),
 23+ 'descriptionmsg' => 'interactiveblockmessage-desc',
 24+ 'url' => 'http://www.mediawiki.org/wiki/Extension:InteractiveBlockMessage',
 25+);
 26+
 27+$wgAutoloadClasses['InteractiveBlockMessage'] = "$dir/InteractiveBlockMessage.php";
 28+$wgAutoloadClasses['InteractiveBlockMessageHooks'] = "$dir/InteractiveBlockMessageHooks.php";
 29+
 30+$dir = dirname( __FILE__ );
 31+$wgExtensionMessagesFiles['InteractiveBlockMessage'] = "$dir/InteractiveBlockMessage.i18n.php";
 32+
 33+
 34+$wgHooks['LanguageGetMagic'][] = 'InteractiveBlockMessageHooks::magicWordVar';
 35+$wgHooks['MagicWordwgVariableIDs'][] = 'InteractiveBlockMessageHooks::magicWordSet';
 36+$wgHooks['ParserGetVariableValueSwitch'][] = 'InteractiveBlockMessageHooks::parserGetVariable';
Property changes on: trunk/extensions/InteractiveBlockMessage/InteractiveBlockMessage.php
___________________________________________________________________
Added: svn:eol-style
137 + native
Index: trunk/extensions/InteractiveBlockMessage/InteractiveBlockMessageHooks.php
@@ -0,0 +1,61 @@
 2+<?php
 3+
 4+/**
 5+ * Hooks for Interactive block message
 6+ *
 7+ * @group Extensions
 8+ */
 9+class InteractiveBlockMessageHooks {
 10+ /**
 11+ * @param $magicWords array
 12+ * @param $ln string (language)
 13+ * @return bool
 14+ */
 15+ public static function magicWordVar( array &$magicWords, $ln ) {
 16+ $magicWords['userblocked'] = array( 0, 'userblocked' );
 17+ return true;
 18+ }
 19+
 20+ /**
 21+ * @param $vars array
 22+ * @return bool
 23+ */
 24+ public static function magicWordSet( &$vars ) {
 25+ $vars[] = 'userblocked';
 26+ return true;
 27+ }
 28+
 29+ /**
 30+ * @param $parser Parser
 31+ * @param $varCache ??
 32+ * @param $index ??
 33+ * @param $ret string?
 34+ * @return bool
 35+ */
 36+ public static function parserGetVariable( &$parser, &$varCache, &$index, &$ret ) {
 37+ if ( $index != 'userblocked' ) {
 38+ return true;
 39+ }
 40+
 41+ if ( $parser->getTitle->getNamespace() != NS_USER && $parser->getTitle->getNamespace() != NS_USER_TALK ) {
 42+ $ret = "unknown";
 43+ return true;
 44+ }
 45+
 46+ $user = User::newFromName( $parser->getTitle()->getBaseText() );
 47+ if ($user instanceof User) {
 48+ if ($user->isBlocked()) {
 49+ $ret = "true";
 50+ return true;
 51+ } else {
 52+ $ret = "false";
 53+ return true;
 54+ }
 55+ } else {
 56+ $ret = "unknown";
 57+ return true;
 58+ }
 59+ $ret = "unknown";
 60+ return true;
 61+ }
 62+}
Property changes on: trunk/extensions/InteractiveBlockMessage/InteractiveBlockMessageHooks.php
___________________________________________________________________
Added: svn:eol-style
163 + native

Follow-up revisions

RevisionCommit summaryAuthorDate
r102100fixed orderpetrb15:03, 5 November 2011
r103809Introduced cache time and yes that comparison of infinity time really suck ho...petrb14:11, 21 November 2011

Comments

#Comment by Raindrift (talk | contribs)   21:27, 16 November 2011

Caching will likely be an issue for this extension. You may want to check out this page on how to disable it. Ideally, you'd be able to add a dependency on some other page that's edited when the user is blocked/unblocked, so the cache is just cleared when the block status changes. I'm not sure if that's possible, though, since I don't know if there's any page to depend on.

#Comment by Petrb (talk | contribs)   00:25, 17 November 2011

You are right, this could be a problem, but as you said, I don't know if it's possible to solve it, anyway if you look at the purpose of this extension, it shouldn't be that big problem. Idea is to let people create interactive template which changes its content when user get unblocked as replacement for static templates which are being used now (in case of enwp), in worst case it shows wrong information, which would be same wrong as what happens now with static templates. This already happens with other magic words implemented in mediawiki core, even these get cached, and unless you purge they may return wrong value. I don't know if parser can actually prevent page caching at all, maybe yes, but if not, keep in mind that it's very unlike that this problem would happen, since most of people who would open the user talk page with this magic word would have possibly the cache expired that time (it doesn't happen frequently that you open a talk page of anon user who was blocked in past, especially in time when block is expired cache would be probably expired too)

#Comment by Bawolff (talk | contribs)   00:32, 17 November 2011

Yes you can disable parser cache on per page basis - but its something to avoid if at all possible (Especially if your goal is to eventually get the extension enabled on a Wikimedia wiki).

Its also possible to tell the parser to only cache the page for X number of seconds. Thus you could probably calculate how many seconds are left in the block (being careful for situations where user blocked for 100 years, or indef) and tell the parser to only cache the page that long ($parser->getOutput()->updateCacheTime($seconds) or something)

#Comment by Petrb (talk | contribs)   00:45, 17 November 2011

right, I will do that

#Comment by Petrb (talk | contribs)   13:45, 21 November 2011

could you please tell me where can I find this cache stuff? I've been browsing doc however I couldn't find anything like what you mentioned here

#Comment by Petrb (talk | contribs)   13:46, 21 November 2011

I mean: $parser->getOutput()->updateCacheTime($seconds) there is no function like that, or I couldn't find it at least

#Comment by Bawolff (talk | contribs)   13:56, 21 November 2011

Sorry, I meant $parser->getOutput()->updateCacheExpiry($seconds); [1]

#Comment by Petrb (talk | contribs)   00:43, 17 November 2011

see r103425 I tried that what you suggested there, hope it's ok

#Comment by Raindrift (talk | contribs)   23:01, 21 November 2011

This looks good starting from r103809. Marking OK.

#Comment by Bawolff (talk | contribs)   04:48, 15 December 2011

Personally I think 'variable' (or 'parser' since no one really uses variable) would be a better extension type (because it's making a new variable) and nothing else is using 'userpage tools', but I don't feel strongly about that.

Status & tagging log