r51435 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r51434‎ | r51435 | r51436 >
Date:20:34, 3 June 2009
Author:robin
Status:resolved (Comments)
Tags:
Comment:
a very simple special page to go to a random page in your test wiki
Modified paths:
  • /trunk/extensions/WikimediaIncubator/SpecialRandomByTest.php (added) (history)
  • /trunk/extensions/WikimediaIncubator/WikimediaIncubator.php (modified) (history)

Diff [purge]

Index: trunk/extensions/WikimediaIncubator/WikimediaIncubator.php
@@ -10,7 +10,7 @@
1111 'path' => __FILE__,
1212 'name' => 'Wikimedia Incubator',
1313 'author' => 'SPQRobin',
14 - 'version' => '2.2.0',
 14+ 'version' => '2.3.0',
1515 'url' => 'http://www.mediawiki.org/wiki/Extension:WikimediaIncubator',
1616 'description' => 'Test wiki features for Wikimedia Incubator',
1717 'descriptionmsg' => 'wminc-desc',
@@ -52,3 +52,6 @@
5353 $wgHooks['UserCreateForm'][] = 'AutoTestWiki::onUserCreateForm';
5454 $wgHooks['AddNewAccount'][] = 'AutoTestWiki::onAddNewAccount';
5555
 56+/* Random page by test */
 57+$wgAutoloadClasses['SpecialRandomByTest'] = $dir . 'SpecialRandomByTest.php';
 58+$wgSpecialPages['RandomByTest'] = 'SpecialRandomByTest';
Index: trunk/extensions/WikimediaIncubator/SpecialRandomByTest.php
@@ -0,0 +1,19 @@
 2+<?php
 3+/**
 4+* Special page to go to a random page in your test wiki
 5+ * @file
 6+ */
 7+
 8+class SpecialRandomByTest extends RandomPage
 9+{
 10+ public function __construct() {
 11+ global $wgExtraRandompageSQL, $wgUser, $wmincPref;
 12+ if(IncubatorTest::isNormalPrefix()) {
 13+ $wgExtraRandompageSQL = 'page_title like "W'.$wgUser->getOption($wmincPref . '-project').'/'.$wgUser->getOption($wmincPref . '-code').'/%%"';
 14+ } elseif($wgUser->getOption($wmincPref . '-project') == 'inc') {
 15+ $wgExtraRandompageSQL = 'page_title not like "W_/%%" OR "W_/%%/%%"';
 16+ }
 17+
 18+ parent::__construct( 'RandomByTest' );
 19+ }
 20+}
Property changes on: trunk/extensions/WikimediaIncubator/SpecialRandomByTest.php
___________________________________________________________________
Name: svn:eol-style
121 + native

Comments

#Comment by Tim Starling (talk | contribs)   04:26, 6 June 2009

Don't override the configuration variables, that will lead to unintended consequences. Add a function to RandomPage which gets extra SQL, and returns an empty string by default, and then override it in your own class.

#Comment by SPQRobin (talk | contribs)   10:49, 6 June 2009

What do you mean with unintended consequences?

#Comment by Tim Starling (talk | contribs)   15:32, 6 June 2009

For example, say if someone sets $wgExtraRandompageSQL in LocalSettings.php and expects it to work, and it does, except when a setup hook from another extension recaches its special page description list, and to do so, creates instances of all the special page objects. The the user finds that Special:Random works only on the second and subsequent visits to their wiki on any given day. They go to #mediawiki and waste two hours of some developer's time tracking the problem down.

Better to avoid that kind of thing before it happens. You can type pretty fast, right?

#Comment by SPQRobin (talk | contribs)   16:46, 6 June 2009

Introduced the function in r51541 and updated the extension in r51542. Is it ok like that?

#Comment by SPQRobin (talk | contribs)   17:04, 6 June 2009

...fixed in r51544

Status & tagging log