original_string: protected static function get_page_comments($user, \context $context, $pageid, $onlyforthisuser = true) {
          global $USER, $DB;
          $params = [
              'contextid' => $context->id,
              'commentarea' => 'wiki_page',
              'itemid' => $pageid
          ];
          $sql = "SELECT c.id, c.content, c.format, c.timecreated, c.userid
                    FROM {comments} c
                   WHERE c.contextid = :contextid AND
                         c.commentarea = :commentarea AND
                         c.itemid = :itemid";
          if ($onlyforthisuser) {
              $sql .= " AND c.userid = :userid";
              $params['userid'] = $USER->id;
          }
          $sql .= " ORDER BY c.timecreated DESC";
  
          $rs = $DB->get_recordset_sql($sql, $params);
          $comments = [];
          foreach ($rs as $record) {
              if ($record->userid != $user->id) {
                  // Clean HTML in comments that were added by other users.
                  $comment = ['content' => format_text($record->content, $record->format, ['context' => $context])];
              } else {
                  // Export comments made by this user as they are stored.
                  $comment = ['content' => $record->content, 'contentformat' => $record->format];
              }
              $comment += [
                  'time' => transform::datetime($record->timecreated),
                  'userid' => transform::user($record->userid),
              ];
              $comments[] = (object)$comment;
          }
          $rs->close();
          return $comments;
      }
code: protected static function get_page_comments($user, \context $context, $pageid, $onlyforthisuser = true) {
          global $USER, $DB;
          $params = [
              'contextid' => $context->id,
              'commentarea' => 'wiki_page',
              'itemid' => $pageid
          ];
          $sql = "SELECT c.id, c.content, c.format, c.timecreated, c.userid
                    FROM {comments} c
                   WHERE c.contextid = :contextid AND
                         c.commentarea = :commentarea AND
                         c.itemid = :itemid";
          if ($onlyforthisuser) {
              $sql .= " AND c.userid = :userid";
              $params['userid'] = $USER->id;
          }
          $sql .= " ORDER BY c.timecreated DESC";
  
          $rs = $DB->get_recordset_sql($sql, $params);
          $comments = [];
          foreach ($rs as $record) {
              if ($record->userid != $user->id) {
                  // Clean HTML in comments that were added by other users.
                  $comment = ['content' => format_text($record->content, $record->format, ['context' => $context])];
              } else {
                  // Export comments made by this user as they are stored.
                  $comment = ['content' => $record->content, 'contentformat' => $record->format];
              }
              $comment += [
                  'time' => transform::datetime($record->timecreated),
                  'userid' => transform::user($record->userid),
              ];
              $comments[] = (object)$comment;
          }
          $rs->close();
          return $comments;
      }
code_tokens: protected static function get_page_comments ( $ user , \ context $ context , $ pageid , $ onlyforthisuser = true ) { global $ USER , $ DB ; $ params = [ 'contextid' => $ context -> id , 'commentarea' => 'wiki_page' , 'itemid' => $ pageid ] ; $ sql = "SELECT c.id, c.content, c.format, c.timecreated, c.userid
                    FROM {comments} c
                   WHERE c.contextid = :contextid AND
                         c.commentarea = :commentarea AND
                         c.itemid = :itemid" ; if ( $ onlyforthisuser ) { $ sql .= " AND c.userid = :userid" ; $ params [ 'userid' ] = $ USER -> id ; } $ sql .= " ORDER BY c.timecreated DESC" ; $ rs = $ DB -> get_recordset_sql ( $ sql , $ params ) ; $ comments = [ ] ; foreach ( $ rs as $ record ) { if ( $ record -> userid != $ user -> id ) { // Clean HTML in comments that were added by other users. $ comment = [ 'content' => format_text ( $ record -> content , $ record -> format , [ 'context' => $ context ] ) ] ; } else { // Export comments made by this user as they are stored. $ comment = [ 'content' => $ record -> content , 'contentformat' => $ record -> format ] ; } $ comment += [ 'time' => transform :: datetime ( $ record -> timecreated ) , 'userid' => transform :: user ( $ record -> userid ) , ] ; $ comments [ ] = ( object ) $ comment ; } $ rs -> close ( ) ; return $ comments ; }
docstring: Retrieves page comments
  
  We can not use \core_comment\privacy\provider::export_comments() because it expects each item to have a separate
  subcontext and we store wiki pages as related data to subwiki because the files are shared between pages.
  
  @param stdClass $user
  @param \context $context
  @param int $pageid
  @param bool $onlyforthisuser
  @return array
docstring_tokens: Retrieves page comments