diff options
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/console.php | 162 | ||||
-rwxr-xr-x | scripts/enjitqueuehandler.php | 58 | ||||
-rw-r--r-- | scripts/makegroupadmin.php | 89 | ||||
-rw-r--r-- | scripts/registeruser.php | 81 | ||||
-rwxr-xr-x | scripts/update_translations.php | 44 |
5 files changed, 392 insertions, 42 deletions
diff --git a/scripts/console.php b/scripts/console.php new file mode 100755 index 000000000..41dd43f28 --- /dev/null +++ b/scripts/console.php @@ -0,0 +1,162 @@ +#!/usr/bin/env php +<?php +/* + * StatusNet - the distributed open-source microblogging tool + * Copyright (C) 2009, StatusNet, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +# Abort if called from a web server + +define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); + +$helptext = <<<ENDOFHELP +console.php - provide an interactive PHP interpreter for testing + +ENDOFHELP; + +require_once INSTALLDIR.'/scripts/commandline.inc'; + +if (function_exists('posix_isatty')) { + define('CONSOLE_INTERACTIVE', posix_isatty(0)); +} else { + // Windows? Assume we're on a terminal. :P + define('CONSOLE_INTERACTIVE', false); +} +if (CONSOLE_INTERACTIVE) { + define('CONSOLE_READLINE', function_exists('readline')); +} + +if (CONSOLE_READLINE && CONSOLE_INTERACTIVE && file_exists(CONSOLE_HISTORY)) { + define(CONSOLE_HISTORY, getenv("HOME") . "/.statusnet_console_history"); + readline_read_history(CONSOLE_HISTORY); +} + +function read_input_line($prompt) +{ + if (CONSOLE_INTERACTIVE) { + if (CONSOLE_READLINE) { + $line = readline($prompt); + readline_add_history($line); + return $line; + } else { + return readline_emulation($prompt); + } + } else { + return fgets(STDIN); + } +} + +/** + * On Unix-like systems where PHP readline extension isn't present, + * -cough- Mac OS X -cough- we can shell out to bash to do it for us. + * This lets us at least handle things like arrow keys, but we don't + * get any entry history. :( + * + * Shamelessly ripped from when I wrote the same code for MediaWiki. :) + * @author Brion Vibber <brion@status.net> + * + * @param string $prompt + * @return mixed string on success, false on fail or EOF + */ +function readline_emulation($prompt) +{ + if(file_exists(trim(shell_exec('which bash')))) { + $encPrompt = escapeshellarg($prompt); + $command = "read -er -p $encPrompt && echo \"\$REPLY\""; + $encCommand = escapeshellarg($command); + $metaCommand = "bash -c $encCommand"; + + // passthru passes our STDIN and TTY to the child... + // We can pull the returned string via output buffering. + ob_start(); + $retval = false; + passthru($metaCommand, $retval); + $line = ob_get_contents(); + ob_end_clean(); + + if ($retval == 0) { + return $line; + } elseif ($retval == 127) { + // Couldn't execute bash even though we thought we saw it. + // Shell probably spit out an error message, sorry :( + // Fall through to fgets()... + } else { + // EOF/ctrl+D + return false; + } + } + + // Fallback... we'll have no editing controls, EWWW + if (feof(STDIN)) { + return false; + } + print $prompt; + return fgets(STDIN); +} + +function console_help() +{ + print "Welcome to StatusNet's interactive PHP console!\n"; + print "Type some PHP code and it'll execute...\n"; + print "\n"; + print "Hint: return a value of any type to output it via var_export():\n"; + print " \$profile = new Profile();\n"; + print " \$profile->find();\n"; + print " \$profile->fetch();\n"; + print " return \$profile;\n"; + print "\n"; + print "Note that PHP is cranky and you can easily kill your session by mistyping.\n"; + print "\n"; + print "Type ctrl+D or enter 'exit' to exit.\n"; +} + + +print "StatusNet interactive PHP console... type ctrl+D or enter 'exit' to exit.\n"; +$prompt = common_config('site', 'name') . '> '; +while (!feof(STDIN)) { + $line = read_input_line($prompt); + if ($line === false) { + print "\n"; + break; + } elseif ($line !== '') { + try { + if (trim($line) == 'exit') { + break; + } elseif (trim($line) == 'help') { + console_help(); + continue; + } + + // Let's do this! + $result = eval($line); + if ($result === false) { + // parse error + } elseif ($result === null) { + // no return + } else { + // return value from eval'd code + var_export($result); + } + } catch(Exception $e) { + print get_class($e) . ": " . $e->getMessage() . "\n"; + } + } + print "\n"; +} + +if (CONSOLE_READLINE && CONSOLE_INTERACTIVE) { + @readline_write_history(CONSOLE_HISTORY); +} diff --git a/scripts/enjitqueuehandler.php b/scripts/enjitqueuehandler.php index 08f733b07..afcac539a 100755 --- a/scripts/enjitqueuehandler.php +++ b/scripts/enjitqueuehandler.php @@ -46,8 +46,8 @@ class EnjitQueueHandler extends QueueHandler function start() { - $this->log(LOG_INFO, "Starting EnjitQueueHandler"); - $this->log(LOG_INFO, "Broadcasting to ".common_config('enjit', 'apiurl')); + $this->log(LOG_INFO, "Starting EnjitQueueHandler"); + $this->log(LOG_INFO, "Broadcasting to ".common_config('enjit', 'apiurl')); return true; } @@ -56,16 +56,16 @@ class EnjitQueueHandler extends QueueHandler $profile = Profile::staticGet($notice->profile_id); - $this->log(LOG_INFO, "Posting Notice ".$notice->id." from ".$profile->nickname); + $this->log(LOG_INFO, "Posting Notice ".$notice->id." from ".$profile->nickname); - if ( ! $notice->is_local ) { - $this->log(LOG_INFO, "Skipping remote notice"); - return "skipped"; - } + if ( ! $notice->is_local ) { + $this->log(LOG_INFO, "Skipping remote notice"); + return "skipped"; + } - # - # Build an Atom message from the notice - # + # + # Build an Atom message from the notice + # $noticeurl = common_local_url('shownotice', array('notice' => $notice->id)); $msg = $profile->nickname . ': ' . $notice->content; @@ -86,36 +86,18 @@ class EnjitQueueHandler extends QueueHandler $atom .= "<updated>".common_date_w3dtf($notice->modified)."</updated>\n"; $atom .= "</entry>\n"; - $url = common_config('enjit', 'apiurl') . "/submit/". common_config('enjit','apikey'); - $data = "msg=$atom"; + $url = common_config('enjit', 'apiurl') . "/submit/". common_config('enjit','apikey'); + $data = array( + 'msg' => $atom, + ); - # - # POST the message to $config['enjit']['apiurl'] - # - $ch = curl_init(); + # + # POST the message to $config['enjit']['apiurl'] + # + $request = HTTPClient::start(); + $response = $request->post($url, null, $data); - curl_setopt($ch, CURLOPT_URL, $url); - - curl_setopt($ch, CURLOPT_HEADER, 1); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ch, CURLOPT_POST, 1) ; - curl_setopt($ch, CURLOPT_POSTFIELDS, $data); - - # SSL and Debugging options - # - # curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); - # curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); - # curl_setopt($ch, CURLOPT_VERBOSE, 1); - - $result = curl_exec($ch); - - $code = curl_getinfo($ch, CURLINFO_HTTP_CODE ); - - $this->log(LOG_INFO, "Response Code: $code"); - - curl_close($ch); - - return $code; + return $response->isOk(); } } diff --git a/scripts/makegroupadmin.php b/scripts/makegroupadmin.php new file mode 100644 index 000000000..a68798451 --- /dev/null +++ b/scripts/makegroupadmin.php @@ -0,0 +1,89 @@ +#!/usr/bin/env php +<?php +/* + * StatusNet - a distributed open-source microblogging tool + * Copyright (C) 2008, 2009, StatusNet, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); + +$shortoptions = 'g:n:'; +$longoptions = array('nickname=', 'group='); + +$helptext = <<<END_OF_MAKEGROUPADMIN_HELP +makegroupadmin.php [options] +makes a user the admin of a group + + -g --group group to add an admin to + -n --nickname nickname of the new admin + +END_OF_MAKEGROUPADMIN_HELP; + +require_once INSTALLDIR.'/scripts/commandline.inc'; + +$nickname = get_option_value('n', 'nickname'); +$groupname = get_option_value('g', 'group'); + +if (empty($nickname) || empty($groupname)) { + print "Must provide a nickname and group.\n"; + exit(1); +} + +try { + + $user = User::staticGet('nickname', $nickname); + + if (empty($user)) { + throw new Exception("No user named '$nickname'."); + } + + $group = User_group::staticGet('nickname', $groupname); + + if (empty($group)) { + throw new Exception("No group named '$groupname'."); + } + + $member = Group_member::pkeyGet(array('group_id' => $group->id, + 'profile_id' => $user->id)); + + if (empty($member)) { + $member = new Group_member(); + + $member->group_id = $group->id; + $member->profile_id = $user->id; + $member->created = common_sql_now(); + + if (!$member->insert()) { + throw new Exception("Can't add '$nickname' to '$groupname'."); + } + } + + if ($member->is_admin) { + throw new Exception("'$nickname' is already an admin of '$groupname'."); + } + + $orig = clone($member); + + $member->is_admin = 1; + + if (!$member->update($orig)) { + throw new Exception("Can't make '$nickname' admin of '$groupname'."); + } + +} catch (Exception $e) { + print $e->getMessage() . "\n"; + exit(1); +} diff --git a/scripts/registeruser.php b/scripts/registeruser.php new file mode 100644 index 000000000..5d9c8862d --- /dev/null +++ b/scripts/registeruser.php @@ -0,0 +1,81 @@ +#!/usr/bin/env php +<?php +/* + * StatusNet - a distributed open-source microblogging tool + * Copyright (C) 2008, 2009, StatusNet, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); + +$shortoptions = 'n:w:f:e:'; +$longoptions = array('nickname=', 'password=', 'fullname=', 'email='); + +$helptext = <<<END_OF_REGISTERUSER_HELP +registeruser.php [options] +registers a user in the database + + -n --nickname nickname of the new user + -w --password password of the new user + -f --fullname full name of the new user (optional) + -e --email email address of the new user (optional) + +END_OF_REGISTERUSER_HELP; + +require_once INSTALLDIR.'/scripts/commandline.inc'; + +$nickname = get_option_value('n', 'nickname'); +$password = get_option_value('w', 'password'); +$fullname = get_option_value('f', 'fullname'); + +$email = get_option_value('e', 'email'); + +if (empty($nickname) || empty($password)) { + print "Must provide a username and password.\n"; + exit(1); +} + +try { + + $user = User::staticGet('nickname', $nickname); + + if (!empty($user)) { + throw new Exception("A user named '$nickname' already exists."); + } + + $user = User::register(array('nickname' => $nickname, + 'password' => $password, + 'fullname' => $fullname)); + + if (empty($user)) { + throw new Exception("Can't register user '$nickname' with password '$password' and fullname '$fullname'."); + } + + if (!empty($email)) { + + $orig = clone($user); + + $user->email = $email; + + if (!$user->updateKeys($orig)) { + print "Failed!\n"; + throw new Exception("Can't update email address."); + } + } + +} catch (Exception $e) { + print $e->getMessage() . "\n"; + exit(1); +} diff --git a/scripts/update_translations.php b/scripts/update_translations.php index f145c1f0b..580c472ee 100755 --- a/scripts/update_translations.php +++ b/scripts/update_translations.php @@ -39,12 +39,47 @@ set_time_limit(60); $languages = get_all_languages(); /* Update the languages */ +// Language code conversion for translatewiki.net (these are MediaWiki codes) +$codeMap = array( + 'nb' => 'no', + 'pt_BR' => 'pt-br', + 'zh_CN' => 'zh-hans', + 'zh_TW' => 'zh-hant' +); + +$doneCodes = array(); foreach ($languages as $language) { + $code = $language['lang']; + + // Skip export of source language + // and duplicates + if( $code == 'en' || $code == 'no' ) { + continue; + } + + // Do not export codes twice (happens for 'nb') + if( in_array( $code, $doneCodes ) ) { + continue; + } else { + $doneCodes[] = $code; + } + + // Convert code if needed + if( isset( $codeMap[$code] ) ) { + $twnCode = $codeMap[$code]; + } else { + $twnCode = str_replace('_', '-', strtolower($code)); // pt_BR -> pt-br + } + + // Fetch updates from translatewiki.net... + $file_url = 'http://translatewiki.net/w/i.php?' . + http_build_query(array( + 'title' => 'Special:Translate', + 'task' => 'export-to-file', + 'group' => 'out-statusnet', + 'language' => $twnCode)); - $code = $language['lang']; - $file_url = 'http://status.net/pootle/' . $code . - '/statusnet/LC_MESSAGES/statusnet.po'; $lcdir = INSTALLDIR . '/locale/' . $code; $msgdir = "$lcdir/LC_MESSAGES"; $pofile = "$msgdir/statusnet.po"; @@ -72,7 +107,8 @@ foreach ($languages as $language) { if (sha1($new_file) != $existingSHA1 || !file_exists($mofile)) { echo "Updating ".$code."\n"; file_put_contents($pofile, $new_file); - system(sprintf('msgmerge -U %s %s', $pofile, $statusnet_pot)); + // --backup=off is workaround for Mac OS X fail + system(sprintf('msgmerge -U --backup=off %s %s', $pofile, $statusnet_pot)); system(sprintf('msgfmt -f -o %s %s', $mofile, $pofile)); } else { echo "Unchanged - ".$code."\n"; |