Avoid having to check for notices without rendered copies in upgrade.php
authorMikael Nordfeldth <mmn@hethane.se>
Wed, 6 Jan 2016 14:32:00 +0000 (15:32 +0100)
committerMikael Nordfeldth <mmn@hethane.se>
Wed, 6 Jan 2016 14:32:27 +0000 (15:32 +0100)
Always call the Notice->getRendered() function to get a rendered copy.
We could perhaps put some sanitation there too in the future

18 files changed:
actions/apisearchatom.php
classes/Notice.php
lib/apiaction.php
lib/rss10action.php
plugins/Activity/lib/systemlistitem.php
plugins/Activity/lib/unfollowlistitem.php
plugins/ActivityModeration/ActivityModerationPlugin.php
plugins/ActivityVerbPost/ActivityVerbPostPlugin.php
plugins/DirectionDetector/DirectionDetectorPlugin.php
plugins/EmailSummary/lib/useremailsummaryhandler.php
plugins/Favorite/classes/Fave.php
plugins/Linkback/lib/util.php
plugins/Mapstraction/actions/map.php
plugins/Oembed/actions/oembed.php
plugins/Realtime/RealtimePlugin.php
plugins/Share/SharePlugin.php
plugins/SubMirror/classes/SubMirror.php
scripts/upgrade.php

index b686edb00aeabb9a89e0243e23f1bf93ec6a59ae..7e79808a9630aeeee13ca5e11ff3c5417b424456 100644 (file)
@@ -327,7 +327,7 @@ class ApiSearchAtomAction extends ApiPrivateAuthAction
                                      'rel'  => 'alternate',
                                      'href' => $nurl));
         $this->element('title', null, common_xml_safe_str(trim($notice->content)));
-        $this->element('content', array('type' => 'html'), $notice->rendered);
+        $this->element('content', array('type' => 'html'), $notice->getRendered());
         $this->element('updated', null, common_date_w3dtf($notice->created));
         $this->element('link', array('type' => 'image/png',
                                      // XXX: Twitter uses rel="image" (not valid)
index 138c9f1b645f34f86328afd8f46ac74ce596c074..25e8da4aaf72fa23e89fdf4c3e6612147310978b 100644 (file)
@@ -259,6 +259,14 @@ class Notice extends Managed_DataObject
 
     public function getRendered()
     {
+        if (is_null($this->rendered) || $this->rendered === '') {
+            // update to include rendered content on-the-fly, so we don't have to have a fix-up script in upgrade.php
+            $orig = clone($this);
+            $this->rendered = common_render_content($this->getContent(),
+                                                    $this->getProfile(),
+                                                    $this->hasParent() ? $this->getParent() : null);
+            $this->update($orig);
+        }
         return $this->rendered;
     }
 
@@ -816,6 +824,7 @@ class Notice extends Managed_DataObject
             $content = $actobj->content ?: $actobj->summary;
         }
         $stored->rendered = $actor->isLocal() ? $content : common_purify($content);
+        // yeah, just don't use getRendered() here since it's not inserted yet ;)
         $stored->content = common_strip_html($stored->rendered);
 
         // Maybe a missing act-time should be fatal if the actor is not local?
@@ -1835,7 +1844,7 @@ class Notice extends Managed_DataObject
                 // The notice is probably a share or similar, which don't
                 // have a representational URL of their own.
             }
-            $act->content = common_xml_safe_str($this->rendered);
+            $act->content = common_xml_safe_str($this->getRendered());
 
             $profile = $this->getProfile();
 
@@ -2069,7 +2078,7 @@ class Notice extends Managed_DataObject
             $object->id      = $this->getUri();
             //FIXME: = $object->title ?: sprintf(... because we might get a title from StartActivityObjectFromNotice
             $object->title   = sprintf('New %1$s by %2$s', ActivityObject::canonicalType($object->type), $this->getProfile()->getNickname());
-            $object->content = $this->rendered;
+            $object->content = $this->getRendered();
             $object->link    = $this->getUrl();
 
             $object->extra[] = array('status_net', array('notice_id' => $this->id));
index 9a574008aacf7bf9474c74d29f546061935d85f2..8420bfb51ea53cd12395d567514d9129fdb70d94 100644 (file)
@@ -408,7 +408,7 @@ class ApiAction extends Action
 
         // StatusNet-specific
 
-        $twitter_status['statusnet_html'] = $notice->rendered;
+        $twitter_status['statusnet_html'] = $notice->getRendered();
         $twitter_status['statusnet_conversation_id'] = intval($notice->conversation);
 
         // The event call to handle NoticeSimpleStatusArray lets plugins add data to the output array
@@ -503,7 +503,7 @@ class ApiAction extends Action
 
             // We trim() to avoid extraneous whitespace in the output
 
-            $entry['content'] = common_xml_safe_str(trim($notice->rendered));
+            $entry['content'] = common_xml_safe_str(trim($notice->getRendered()));
             $entry['title'] = $profile->nickname . ': ' . common_xml_safe_str(trim($notice->content));
             $entry['link'] = common_local_url('shownotice', array('notice' => $notice->id));
             $entry['published'] = common_date_iso8601($notice->created);
index 137015530b0af7b2b8457eea44e0913efb1ec8ba..6940ab4319590d34af19d63cea6edb7641e6b843 100644 (file)
@@ -209,8 +209,8 @@ class Rss10Action extends ManagedAction
         $this->element('title', null, $title);
         $this->element('link', null, $nurl);
         $this->element('description', null, $profile->nickname."'s status on ".common_exact_date($notice->created));
-        if ($notice->rendered) {
-            $this->element('content:encoded', null, common_xml_safe_str($notice->rendered));
+        if ($notice->getRendered()) {
+            $this->element('content:encoded', null, common_xml_safe_str($notice->getRendered()));
         }
         $this->element('dc:date', null, common_date_w3dtf($notice->created));
         $this->element('dc:creator', null, ($profile->fullname) ? $profile->fullname : $profile->nickname);
index 958dfbc495906991fa6cd8b0e7c571c28477580c..661fd1fe4ca2eeaa591eaaf51b72a1a45e59ef93 100644 (file)
@@ -68,7 +68,7 @@ class SystemListItem extends NoticeListItemAdapter
 
         $out->elementStart('div', 'system-activity');
 
-        $out->raw($notice->rendered);
+        $out->raw($notice->getRendered());
 
         $out->elementEnd('div');
     }
index 0ecb8bef5a0095a96e59ff636545fce50e018a11..276288bf057135eebeeb3e4d2474bd93b9868e8c 100644 (file)
@@ -68,7 +68,7 @@ class UnfollowListItem extends SystemListItem
 
         $out->elementStart('div', 'unfollow-activity');
 
-        $out->raw($notice->rendered);
+        $out->raw($notice->getRendered());
 
         $out->elementEnd('div');
     }
index c7a24ba991beaceba3fae7641a59de107f8d62c4..35eb5eb17a3d73ac19e2d8d389918336553eb500 100644 (file)
@@ -144,8 +144,6 @@ class ActivityModerationPlugin extends ActivityVerbHandlerPlugin
         foreach($props as $prop) {
             $stored->$prop = $target->$prop;
         }
-        //$stored->content = $stored->content ?: _('Notice deleted.');
-        //$stored->rendered = $stored->rendered ?: $stored->rendered;
 
         // Let's see if this has been deleted already.
         try {
index 5dd0ee12d7bafb426cb7b9a8a8b277020e2d3c8b..a28009e2fcc1b977403bbfbd216a2643d6a6b73f 100644 (file)
@@ -74,7 +74,7 @@ class ActivityVerbPostPlugin extends ActivityVerbHandlerPlugin
         $object->type    = $notice->object_type ?: ActivityObject::NOTE;
         $object->id      = $notice->getUri();
         $object->title   = sprintf('New %1$s by %2$s', ActivityObject::canonicalType($object->type), $notice->getProfile()->getNickname());
-        $object->content = $notice->rendered;
+        $object->content = $notice->getRendered();
         $object->link    = $notice->getUrl();
 
         $object->extra[] = array('status_net', array('notice_id' => $notice->getID()));
@@ -102,7 +102,7 @@ class ActivityVerbPostPlugin extends ActivityVerbHandlerPlugin
 
     protected function showNoticeContent(Notice $stored, HTMLOutputter $out, Profile $scoped=null)
     {
-        $out->raw($stored->rendered);
+        $out->raw($stored->getRendered());
     }
 
     protected function getActionTitle(ManagedAction $action, $verb, Notice $target, Profile $scoped)
index 561d38cd38f6fc0fbcee7ae9ecdc138b789233ba..b721ebb20e62f7195b1cff6ed22b65cc1fe8c2db 100644 (file)
@@ -37,6 +37,7 @@ class DirectionDetectorPlugin extends Plugin {
      * @param object $notice notice is going to be saved
      */
     public function onStartNoticeSave($notice){
+        // don't use getRendered() here since it's not saved yet and thus can't ->update in case that would happen
         if(!preg_match('/<span class="rtl">/', $notice->rendered) && self::isRTL($notice->content))
             $notice->rendered = '<span class="rtl">'.$notice->rendered.'</span>';
         return true;
index f900d93595108d3238493e419b96a08e1d0739fe..621d14122cff67137ba23460cce509520482169c 100644 (file)
@@ -171,7 +171,7 @@ class UserEmailSummaryHandler extends QueueHandler
             $out->element('a', array('href' => $profile->profileurl),
                           $profile->nickname);
             $out->text(' ');
-            $out->raw($notice->rendered);
+            $out->raw($notice->getRendered());
             $out->elementStart('div', array('style' => 'font-size: 0.8em; padding-top: 4px;'));
             $noticeurl = $notice->getLocalUrl();
             // above should always return an URL
index a5acb66d20d80ef5bbf91c11a57ed7df3e187f39..77b97c80932a8b9f3378ffe6fed28a04c444c62d 100644 (file)
@@ -63,7 +63,7 @@ class Fave extends Managed_DataObject
         //        notice's nickname and %3$s is the content of the favorited notice.)
         $act->content = sprintf(_('%1$s favorited something by %2$s: %3$s'),
                                 $actor->getNickname(), $target->getProfile()->getNickname(),
-                                $target->rendered ?: $target->content);
+                                $target->getRendered());
         $act->actor   = $actor->asActivityObject();
         $act->target  = $target->asActivityObject();
         $act->objects = array(clone($act->target));
@@ -186,7 +186,7 @@ class Fave extends Managed_DataObject
         //        notice's nickname and %3$s is the content of the favorited notice.)
         $act->content = sprintf(_('%1$s favorited something by %2$s: %3$s'),
                                 $actor->getNickname(), $target->getProfile()->getNickname(),
-                                $target->rendered ?: $target->content);
+                                $target->getRendered());
 
         $act->actor     = $actor->asActivityObject();
         $act->target    = $target->asActivityObject();
@@ -343,7 +343,7 @@ class Fave extends Managed_DataObject
         $actobj->objects = array(clone($actobj->target));
         $actobj->verb = ActivityVerb::FAVORITE;
         $actobj->title = ActivityUtils::verbToTitle($actobj->verb);
-        $actobj->content = $this->getTarget()->rendered ?: $this->getTarget()->content;
+        $actobj->content = $this->getTarget()->getRendered();
         return $actobj;
     }
 
index ee498a47715b5db595c666593a33bbf69495295e..2f024dd2338a4d4a838d13b1feb94bad40a9d67a 100644 (file)
@@ -388,7 +388,7 @@ function linkback_save($source, $target, $response, $notice_or_user) {
         //        notice's nickname and %3$s is the content of the favorited notice.)
         $act->content = sprintf(_('%1$s favorited something by %2$s: %3$s'),
                                 $profile->getNickname(), $notice_or_user->getProfile()->getNickname(),
-                                $notice_or_user->rendered ?: $notice_or_user->content);
+                                $notice_or_user->getRendered());
         if($entry['rsvp']) {
             $act->content = $options['rendered'];
         }
index 48861af9942605295b9b81bf775ed9c7032420c3..75a065a26a36ca74806f7673627c9be85c723194 100644 (file)
@@ -146,7 +146,7 @@ class MapAction extends Action
 
         $arr = $act->twitterStatusArray($notice, true);
         $arr['url'] = $notice->getUrl(true);
-        $arr['html'] = $notice->rendered;
+        $arr['html'] = $notice->getRendered();
         $arr['source'] = $arr['source'];
 
         if (!empty($notice->reply_to)) {
index ccba4c42a585dfd8a77949598764a9cff09833a0..88ba52aa9f50b415dd2333553a05b005da2817ce 100644 (file)
@@ -88,7 +88,7 @@ class OembedAction extends Action
             $oembed['author_name']=$authorname;
             $oembed['author_url']=$profile->profileurl;
             $oembed['url']=$notice->getUrl();
-            $oembed['html']=$notice->rendered;
+            $oembed['html']=$notice->getRendered();
             break;
 
         case 'attachment':
index fbfb0aae306d3460878557e2004e1be6f0b902f5..172e9272af865995a9a75dfd546072e337362082 100644 (file)
@@ -322,7 +322,7 @@ class RealtimePlugin extends Plugin
 
         $arr = $act->twitterStatusArray($notice, true);
         $arr['url'] = $notice->getUrl(true);
-        $arr['html'] = htmlspecialchars($notice->rendered);
+        $arr['html'] = htmlspecialchars($notice->getRendered());
         $arr['source'] = htmlspecialchars($arr['source']);
         $arr['conversation_url'] = $notice->getConversationUrl();
 
@@ -335,7 +335,7 @@ class RealtimePlugin extends Plugin
             $original = Notice::getKV('id', $notice->repeat_of);
             if ($original instanceof Notice) {
                 $arr['retweeted_status']['url'] = $original->getUrl(true);
-                $arr['retweeted_status']['html'] = htmlspecialchars($original->rendered);
+                $arr['retweeted_status']['html'] = htmlspecialchars($original->getRendered());
                 $arr['retweeted_status']['source'] = htmlspecialchars($original->source);
                 $originalProfile = $original->getProfile();
                 $arr['retweeted_status']['user']['profile_url'] = $originalProfile->profileurl;
index d1aece5c3df49d5f694bad85a85212e63fc2362d..d34bcc779e2b2253efcd5d907270af17e16d0af4 100644 (file)
@@ -170,7 +170,7 @@ class SharePlugin extends ActivityVerbHandlerPlugin
         $object          = new Activity();
         $object->actor   = $stored->getProfile()->asActivityObject();
         $object->verb    = ActivityVerb::SHARE;
-        $object->content = $stored->rendered;
+        $object->content = $stored->getRendered();
         $this->extendActivity($stored, $object);
 
         return $object;
index de63841e729e84f44f712d7efaa0c3bbb5f555ba..a24f7fad5ce3d801f6e0dbab71fc859e2dd93221 100644 (file)
@@ -195,7 +195,7 @@ class SubMirror extends Managed_DataObject
     {
         $options = array('is_local' => Notice::LOCAL_PUBLIC,
                          'url' => $notice->getUrl(), // pass through the foreign link...
-                         'rendered' => $notice->rendered);
+                         'rendered' => $notice->getRendered());
 
         $saved = Notice::saveNew($profile->id,
                                  $notice->content,
index 33b0baa35cac34796004b4f6bb4920f5060aea44..56c81c8b31bcac66b902d97f6fc7d85f30a8c9e0 100755 (executable)
@@ -41,7 +41,6 @@ function main()
 
         // These replace old "fixup_*" scripts
 
-        fixupNoticeRendered();
         fixupNoticeConversation();
         initConversation();
         fixupGroupURI();
@@ -94,26 +93,6 @@ function updateSchemaPlugins()
     printfnq("DONE.\n");
 }
 
-function fixupNoticeRendered()
-{
-    printfnq("Ensuring all notices have rendered HTML...");
-
-    $notice = new Notice();
-
-    $notice->whereAdd('rendered IS NULL');
-    $notice->find();
-
-    while ($notice->fetch()) {
-        $original = clone($notice);
-        $notice->rendered = common_render_content($notice->content,
-                                                  $notice->getProfile(),
-                                                  $notice->hasParent() ? $notice->getParent() : null);
-        $notice->update($original);
-    }
-
-    printfnq("DONE.\n");
-}
-
 function fixupNoticeConversation()
 {
     printfnq("Ensuring all notices have a conversation ID...");