Permalink
Browse files

cleanup.

  • Loading branch information...
1 parent 8464031 commit d0468086520df47770dcaa1517ae4ab1fd6bcfac @Pathoschild committed Jun 17, 2012
@@ -266,7 +266,7 @@ public function __construct($backend, $user, $event, $wiki) {
$this->db = $backend->GetDatabase();
/* set user */
- $this->_userName = $backend->FormatUsername($user);
+ $this->_userName = $backend->formatUsername($user);
/* set event */
$this->eventID = isset($event) ? $event : self::DEFAULT_EVENT;
@@ -324,7 +324,7 @@ public function get_next($echo = true) {
########
public function Connect($dbname) {
/* reset variables */
- $this->user = array('name' => $this->backend->FormatUsername($this->_userName));
+ $this->user = array('name' => $this->backend->formatUsername($this->_userName));
/* connect & fetch user details */
if ($dbname) {
@@ -385,7 +385,7 @@ public function default_wiki($defaultDbname = NULL) {
if (!$unifiedDbnames) {
$this->selectManually = true;
$encoded = urlencode($this->user['name']);
- echo '<div id="result" class="neutral" data-is-error="1">', htmlentities($this->user['name']), ' has no global account, so we cannot auto-select an eligible wiki. Please select a wiki (see <a href="//toolserver.org/~pathoschild/stalktoy/?target=', $encoded, '" title="global details about this user">global details about this user</a>).</div>';
+ echo '<div id="result" class="neutral" data-is-error="1">', htmlentities($this->user['name']), ' has no global account, so we cannot auto-select an eligible wiki. Please select a wiki (see <a href="//toolserver.org/~pathoschild/stalktoy/?target=', $encoded, '" title="global details about this user">global details about this user</a>).</div>';
return false;
}
@@ -710,7 +710,7 @@ public function is_at_most($value, $max, $msg_eligible, $msg_not) {
echo '
<form action="" method="get">
<label for="user">User:</label>
- <input type="text" name="user" id="user" value="', $backend->FormatFormValue($script->user['name']), '" /> at
+ <input type="text" name="user" id="user" value="', $backend->formatValue($script->user['name']), '" /> at
<select name="wiki" id="wiki">
<option value="">auto-select wiki</option>', "\n";
@@ -2401,7 +2401,7 @@ public function is_at_most($value, $max, $msg_eligible, $msg_not) {
echo
'<h3>Result</h3>',
'<div class="', $class, '" id="result" data-is-eligible="', ($script->eligible ? 1 : 0), '">',
- htmlentities($name), ' is ', ($script->eligible ? '' : 'not '), 'eligible to ', $action, ' in the <a href="', $event['url'], '" title="', $backend->FormatFormValue($event['name']), '">', $event['name'], '</a>. ';
+ htmlentities($name), ' is ', ($script->eligible ? '' : 'not '), 'eligible to ', $action, ' in the <a href="', $event['url'], '" title="', $backend->formatValue($event['name']), '">', $event['name'], '</a>. ';
if ($script->eligible && isset($script->event['append_eligible']))
echo $script->event['append_eligible'];
elseif (!$script->eligible && isset($script->event['append_ineligible']))
@@ -172,7 +172,7 @@ public function header() {
$title = isset($link[2]) ? $link[2] : $link[0];
$desc = isset( $link[1] ) ? $link[1] : '';
$desc = str_replace( '\'', '&#38;', $desc );
- $url = $this->config['root_url'] . $this->strip_nonlatin( str_replace(' ', '', $link[0]) );
+ $url = $this->config['root_url'] . $link[0];
echo '<li><a href="', $url, '" title="', $desc, '">', $title, '</a></li>';
}
@@ -25,67 +25,27 @@ public function __construct() {
$this->profiler = new Profiler();
}
-
- #################################################
- ## Argument handling
- #################################################
- /**
- * Enforces a schema defining valid arguments and default values on a key=>value array.
- * Argument keys not found in the schema will throw an exception. Missing keys will be added
- * using the default values specified in the schema.
- * @param array $arguments An associative array to apply the schema to.
- * @param array $schema An associative array whose keys are the allowed keys in $arguments,
- * and whose values are the default values to apply to missing keys.
- * @return array The modified argument array.
- * @throws UnexpectedValueException The argument array contains keys not found in the schema.
- */
- public function ApplyArgumentSchema( $arguments, $schema ) {
- /* no arguments */
- if(!isset($arguments) || count($arguments) == 0)
- {
- $arguments = $schema;
- return $arguments;
- }
-
- /* filter invalid keys */
- foreach($arguments as $key => $value)
- {
- if(!array_key_exists($key, $schema))
- throw new UnexpectedValueException('The argument array contains keys not found in the schema. Found key ' + $key + ' in [' . join(', ', array_keys($arguments)) . '], expected one of [' + join(',', array_keys($schema)) + '].');
- }
-
- /* apply schema */
- foreach($schema as $key => $value)
- {
- if(!array_key_exists($key, $arguments))
- $arguments[$key] = $value;
- }
-
- return $arguments;
- }
-
-
#################################################
## String manipulation
#################################################
#############################
## Format string for form output
#############################
/**
- * Format a string for output in a form field.
+ * Format a string as an attribute value.
* @param string $str The string to format.
* @return string The formatted string.
*/
- public function FormatFormValue( $str ) {
+ public function formatValue( $str ) {
return htmlentities($str, ENT_QUOTES, 'UTF-8');
}
-
+
/**
* Make the first character in the string uppercase. This is a workaround for Unicode handling: PHP's ucfirst is not multi-byte safe.
* @param string $str The string to format.
* @return string The formatted string, with uppercase first letter.
**/
- public function FormatUppercaseFirst( $str ) {
+ public function formatInitialCapital( $str ) {
return mb_strtoupper(mb_substr($str, 0, 1, 'UTF-8'), 'UTF-8') . mb_substr($str, 1, mb_strlen($str, 'UTF-8') - 1, 'UTF-8');
}
@@ -94,23 +54,20 @@ public function FormatUppercaseFirst( $str ) {
* @param string $str The string to format.
* @return string The formatted string: trimmed, with an uppercase first letter, and with underscores replaced with spaces.
*/
- public function FormatUsername( $str ) {
+ public function formatUsername( $str ) {
/* normalize whitespace */
$str = str_replace('_', ' ', trim($str));
/* make uppercase */
- return $this->FormatUppercaseFirst($str);
+ return $this->formatInitialCapital($str);
}
/**
* Format a string as an HTML anchor value.
* @param string $str The string to format.
* @return string The formatted string.
*/
- public function FormatAnchor( $str ) {
- return $this->strip_nonlatin($str);
- }
- public function strip_nonlatin( $str ) {
+ public function formatAnchor( $str ) {
return strtolower(str_replace('%', '_', urlencode($str)));
}
}
@@ -20,8 +20,8 @@
***************/
$user = $backend->get('user', $backend->getRouteValue());
if($user != null)
- $user = $backend->FormatUsername($user);
-$user_form = $backend->FormatFormValue($user);
+ $user = $backend->formatUsername($user);
+$user_form = $backend->formatValue($user);
$show_all = $backend->get('show_all', false);
@@ -30,7 +30,7 @@
***************/
echo '<form action="" method="get">
<label for="user">User name:</label>
- <input type="text" name="user" id="user" value="', $backend->FormatFormValue($user), '" />', ($user == 'Shanel' ? '&hearts;' : ''), '<br />
+ <input type="text" name="user" id="user" value="', $backend->formatValue($user), '" />', ($user == 'Shanel' ? '&hearts;' : ''), '<br />
<input type="checkbox" id="show_all" name="show_all" ', ($show_all ? 'checked="checked" ' : ''), '/> <label
for="show_all">Show wikis with no activity</label><br />
<input type="submit" value="Analyze »" />
@@ -158,8 +158,8 @@
$groupKey = $groupRow['ggp_group'];
$group = array(
'key' => $groupKey,
- 'name' => $backend->FormatUppercaseFirst(str_replace('_', ' ', $groupKey)),
- 'anchor' => $backend->FormatAnchor($groupKey),
+ 'name' => $backend->formatInitialCapital(str_replace('_', ' ', $groupKey)),
+ 'anchor' => $backend->formatAnchor($groupKey),
'rights' => array(),
'members' => 0,
'wikis' => 0,
@@ -66,7 +66,7 @@
/* apply user */
if($user && strpos($target, '{user.') !== false) {
- $user = $backend->FormatUsername($user);
+ $user = $backend->formatUsername($user);
$row = $db->Query('SELECT gu_id AS id, gu_name AS name, gu_registration AS registration, gu_locked AS locked, gu_hidden AS hidden FROM centralauth_p.globaluser WHERE gu_name = ? LIMIT 1', array($user))->fetchAssoc();
if($row) {
foreach($tokens['user'] as $token => $description)
View
@@ -56,7 +56,7 @@ public function __construct( $backend, $target ) {
$this->db->Connect('metawiki_p');
/* store target (name, address, or range) */
- $this->target = $this->FormatUsername( $target );
+ $this->target = $this->formatUsername( $target );
$this->target_url = urlencode( $this->target );
$this->target_wiki_url = str_replace( '+', '_', $this->target_url );

0 comments on commit d046808

Please sign in to comment.