summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--actions/block.php7
-rw-r--r--actions/groupblock.php7
-rw-r--r--actions/newnotice.php24
-rw-r--r--classes/Inbox.php43
-rw-r--r--classes/Profile.php63
-rw-r--r--doc-src/bookmarklet2
-rw-r--r--lib/noticelist.php5
7 files changed, 114 insertions, 37 deletions
diff --git a/actions/block.php b/actions/block.php
index 5fae45dff..fe4ec0088 100644
--- a/actions/block.php
+++ b/actions/block.php
@@ -168,4 +168,11 @@ class BlockAction extends ProfileFormAction
return;
}
}
+
+ function showScripts()
+ {
+ parent::showScripts();
+ $this->autofocus('form_action-yes');
+ }
+
}
diff --git a/actions/groupblock.php b/actions/groupblock.php
index ec673358e..88d7634a2 100644
--- a/actions/groupblock.php
+++ b/actions/groupblock.php
@@ -214,5 +214,12 @@ class GroupblockAction extends Action
303);
}
}
+
+ function showScripts()
+ {
+ parent::showScripts();
+ $this->autofocus('form_action-yes');
+ }
+
}
diff --git a/actions/newnotice.php b/actions/newnotice.php
index ed0fa1b2b..748d104ff 100644
--- a/actions/newnotice.php
+++ b/actions/newnotice.php
@@ -184,13 +184,21 @@ class NewnoticeAction extends Action
$options = array('reply_to' => ($replyto == 'false') ? null : $replyto);
- if ($user->shareLocation() && $this->arg('notice_data-geo')) {
-
- $locOptions = Notice::locationOptions($this->trimmed('lat'),
- $this->trimmed('lon'),
- $this->trimmed('location_id'),
- $this->trimmed('location_ns'),
- $user->getProfile());
+ if ($user->shareLocation()) {
+ // use browser data if checked; otherwise profile data
+ if ($this->arg('notice_data-geo')) {
+ $locOptions = Notice::locationOptions($this->trimmed('lat'),
+ $this->trimmed('lon'),
+ $this->trimmed('location_id'),
+ $this->trimmed('location_ns'),
+ $user->getProfile());
+ } else {
+ $locOptions = Notice::locationOptions(null,
+ null,
+ null,
+ null,
+ $user->getProfile());
+ }
$options = array_merge($options, $locOptions);
}
@@ -201,8 +209,6 @@ class NewnoticeAction extends Action
$upload->attachToNotice($notice);
}
-
-
if ($this->boolean('ajax')) {
header('Content-Type: text/xml;charset=utf-8');
$this->xw->startDocument('1.0', 'UTF-8');
diff --git a/classes/Inbox.php b/classes/Inbox.php
index 0d807946d..2533210b7 100644
--- a/classes/Inbox.php
+++ b/classes/Inbox.php
@@ -96,12 +96,23 @@ class Inbox extends Memcached_DataObject
$inbox = new Inbox();
$inbox->user_id = $user_id;
- $inbox->notice_ids = call_user_func_array('pack', array_merge(array('N*'), $ids));
+ $inbox->pack($ids);
$inbox->fake = true;
return $inbox;
}
+ /**
+ * Append the given notice to the given user's inbox.
+ * Caching updates are managed for the inbox itself.
+ *
+ * If the notice is already in this inbox, the second
+ * add will be silently dropped.
+ *
+ * @param int @user_id
+ * @param int $notice_id
+ * @return boolean success
+ */
static function insertNotice($user_id, $notice_id)
{
$inbox = DB_DataObject::staticGet('inbox', 'user_id', $user_id);
@@ -114,13 +125,10 @@ class Inbox extends Memcached_DataObject
return false;
}
- $ids = unpack('N*', $inbox->notice_ids);
-
- // bulk inserts sometimes fail and get restarted.
- // Skip if this one has been inserted before.
-
- if (in_array($notice_id, $ids)) {
- // effectively successful
+ $ids = $inbox->unpack();
+ if (in_array(intval($notice_id), $ids)) {
+ // Already in there, we probably re-ran some inbox adds
+ // due to an error. Skip the dupe silently.
return true;
}
@@ -160,7 +168,7 @@ class Inbox extends Memcached_DataObject
}
}
- $ids = unpack('N*', $inbox->notice_ids);
+ $ids = $inbox->unpack();
if (!empty($since_id)) {
$newids = array();
@@ -239,4 +247,21 @@ class Inbox extends Memcached_DataObject
}
return new ArrayWrapper($items);
}
+
+ /**
+ * Saves a list of integer notice_ids into a packed blob in this object.
+ * @param array $ids list of integer notice_ids
+ */
+ protected function pack(array $ids)
+ {
+ $this->notice_ids = call_user_func_array('pack', array_merge(array('N*'), $ids));
+ }
+
+ /**
+ * @return array of integer notice_ids
+ */
+ protected function unpack()
+ {
+ return unpack('N*', $this->notice_ids);
+ }
}
diff --git a/classes/Profile.php b/classes/Profile.php
index 5de35c191..54f557ea7 100644
--- a/classes/Profile.php
+++ b/classes/Profile.php
@@ -225,31 +225,62 @@ class Profile extends Memcached_DataObject
{
$notice = new Notice();
- $notice->profile_id = $this->id;
+ // Temporary hack until notice_profile_id_idx is updated
+ // to (profile_id, id) instead of (profile_id, created, id).
+ // It's been falling back to PRIMARY instead, which is really
+ // very inefficient for a profile that hasn't posted in a few
+ // months. Even though forcing the index will cause a filesort,
+ // it's usually going to be better.
+ if (common_config('db', 'type') == 'mysql') {
+ $index = '';
+ $query =
+ "select id from notice force index (notice_profile_id_idx) ".
+ "where profile_id=" . $notice->escape($this->id);
+
+ if ($since_id != 0) {
+ $query .= " and id > $since_id";
+ }
- $notice->selectAdd();
- $notice->selectAdd('id');
+ if ($max_id != 0) {
+ $query .= " and id < $max_id";
+ }
- if ($since_id != 0) {
- $notice->whereAdd('id > ' . $since_id);
- }
+ $query .= ' order by id DESC';
- if ($max_id != 0) {
- $notice->whereAdd('id <= ' . $max_id);
- }
+ if (!is_null($offset)) {
+ $query .= " LIMIT $limit OFFSET $offset";
+ }
+
+ $notice->query($query);
+ } else {
+ $index = '';
- $notice->orderBy('id DESC');
+ $notice->profile_id = $this->id;
- if (!is_null($offset)) {
- $notice->limit($offset, $limit);
+ $notice->selectAdd();
+ $notice->selectAdd('id');
+
+ if ($since_id != 0) {
+ $notice->whereAdd('id > ' . $since_id);
+ }
+
+ if ($max_id != 0) {
+ $notice->whereAdd('id <= ' . $max_id);
+ }
+
+ $notice->orderBy('id DESC');
+
+ if (!is_null($offset)) {
+ $notice->limit($offset, $limit);
+ }
+
+ $notice->find();
}
$ids = array();
- if ($notice->find()) {
- while ($notice->fetch()) {
- $ids[] = $notice->id;
- }
+ while ($notice->fetch()) {
+ $ids[] = $notice->id;
}
return $ids;
diff --git a/doc-src/bookmarklet b/doc-src/bookmarklet
index bab0ad445..ae359d2db 100644
--- a/doc-src/bookmarklet
+++ b/doc-src/bookmarklet
@@ -2,4 +2,4 @@ A bookmarklet is a small piece of javascript code used as a bookmark. This one w
Drag-and-drop the following link to your bookmarks bar or right-click it and add it to your browser favorites to keep it handy.
-<a href="javascript:(function(){var%20d=document,w=window,e=w.getSelection,k=d.getSelection,x=d.selection,s=(e?e():(k)?k():(x?x.createRange().text:0)),f='http://%%site.server%%/%%site.path%%/index.php?action=bookmarklet',l=d.location,e=encodeURIComponent,g=f+'&status_textarea=%E2%80%9C'+((e(s))?e(s):e(document.title))+'%E2%80%9D%20%E2%80%94%20'+l.href;function%20a(){if(!w.open(g,'t','toolbar=0,resizable=0,scrollbars=1,status=1,width=450,height=200')){l.href=g;}}a();})()">Post to %%site.name%%</a>
+<a href="javascript:(function(){var%20d=document,w=window,e=w.getSelection,k=d.getSelection,x=d.selection,s=(e?e():(k)?k():(x?x.createRange().text:0)),f='http://%%site.server%%/%%site.path%%/index.php?action=bookmarklet',l=d.location,e=encodeURIComponent,g=f+'&status_textarea=%E2%80%9C'+((e(s))?e(s):e(document.title))+'%E2%80%9D%20%E2%80%94%20'+e(l.href);function%20a(){if(!w.open(g,'t','toolbar=0,resizable=0,scrollbars=1,status=1,width=450,height=200')){l.href=g;}}a();})()">Post to %%site.name%%</a>
diff --git a/lib/noticelist.php b/lib/noticelist.php
index 0d4cd4dd9..83c8de9f6 100644
--- a/lib/noticelist.php
+++ b/lib/noticelist.php
@@ -340,8 +340,9 @@ class NoticeListItem extends Widget
function showNickname()
{
- $this->out->element('span', array('class' => 'nickname fn'),
- $this->profile->nickname);
+ $this->out->raw('<span class="nickname fn">' .
+ htmlspecialchars($this->profile->nickname) .
+ '</span>');
}
/**