r73073 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r73072‎ | r73073 | r73074 >
Date:17:21, 15 September 2010
Author:awjrichards
Status:ok
Tags:
Comment:
Followup r73066, r73067. Also added a 'sanity check' to make sure configuration is set properly
Modified paths:
  • /trunk/extensions/VariablePage/VariablePage.body.php (modified) (history)
  • /trunk/extensions/VariablePage/VariablePage.php (modified) (history)

Diff [purge]

Index: trunk/extensions/VariablePage/VariablePage.body.php
@@ -4,12 +4,17 @@
55
66 public function __construct() {
77 parent::__construct( 'VariablePage' );
 8+
 9+ // make sure configuration will result in something sane
 10+ if ( !$this->sanityCheck() ) {
 11+ throw new MWException( 'VariablePage configuation not sane! Either $wgVariablePageDefault must be set or probabilites in $wgVariablePagePossibilities must add up to 100.' );
 12+ }
813 }
914
1015 public function execute() {
1116 global $wgOut, $wgRequest;
1217 global $wgVariablePagePossibilities, $wgVariablePageUtmMedium;
13 -
 18+
1419 $lang = ( preg_match( '/^[A-Za-z-]+$/', $wgRequest->getVal( 'lang' ) ) ) ? $wgRequest->getVal( 'lang' ) : 'en' ;
1520 $utm_source = $wgRequest->getVal( 'utm_source' );
1621 $utm_medium = ( strlen($wgVariablePageUtmMedium )) ? $wgVariablePageUtmMedium : $wgRequest->getVal( 'utm_medium' );
@@ -37,6 +42,8 @@
3843 * @return string $url
3944 */
4045 public function determinePage( $page_possibilities ) {
 46+ global $wgVariablePageDefault;
 47+
4148 /**
4249 * Determine a random number to measure probability again
4350 *
@@ -51,5 +58,31 @@
5259 return $url;
5360 }
5461 }
 62+
 63+ // if all else fails, return the default
 64+ return $wgVariablePageDefault;
5565 }
 66+
 67+ /**
 68+ * Check configuartion sanity
 69+ *
 70+ * Probabilities defined in $wgVariablePagePossibilities MUST add
 71+ * up to 100 -or- $wgVariablePageDefault MUST be set.
 72+ *
 73+ * @return bool
 74+ */
 75+ public function sanityCheck() {
 76+ global $wgVariablePagePossibilities, $wgVariablePageDefault;
 77+
 78+ $total_probability = 0;
 79+ foreach ( $wgVariablePagePossibilities as $url => $probability ) {
 80+ $total_probability += $probability;
 81+ }
 82+
 83+ if ( $total_probability != 100 && !strlen( $wgVariablePageDefault )) {
 84+ return FALSE;
 85+ } else {
 86+ return TRUE;
 87+ }
 88+ }
5689 }
Index: trunk/extensions/VariablePage/VariablePage.php
@@ -26,6 +26,9 @@
2727 * The key in the array is the full URL path, the value is an integer representing
2828 * a percentage (0-100) probability of a user being redirected to that page.
2929 *
 30+ * The percentages here MUST add up to 100 -or- a value must be set for
 31+ * $wgVariablePageDefault
 32+ *
3033 * The following will redirect a user to http://foo.com/bar 90% of the time:
3134 * $wgVariablePagePossibilities = array(
3235 * 'http://foo.com/bar' => 90,
@@ -42,6 +45,14 @@
4346 */
4447 $wgVariablePageUtmMedium = '';
4548
 49+/**
 50+ * The default URL to send a user to in the event that one of the URLs in
 51+ * $wgVariablePagePossibilities not selected.
 52+ *
 53+ * Either this must be set or the probabilities in $wgVariablePagePossibiliites
 54+ * must add up to 100.
 55+ */
 56+$wgVariablePageDefault = '';
4657
4758 $dir = dirname( __FILE__ ) . '/';
4859

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r73066VariablePage: Set a default value for $wgVariablePageUtmMedium, minor style f...catrope15:17, 15 September 2010
r73067VariablePage: Make it explicit that 10000=100*100 to make the algorithm more ...catrope15:19, 15 September 2010

Status & tagging log