original_string: protected static function export_subwiki($user, context $context, $subwiki, $wikimode) {
          if (empty($subwiki)) {
              return;
          }
          $subwikiid = key($subwiki);
          $pages = $subwiki[$subwikiid]['pages'];
          unset($subwiki[$subwikiid]['pages']);
          writer::with_context($context)->export_data([$subwikiid], (object)$subwiki[$subwikiid]);
          $allfiles = $wikimode === 'individual'; // Whether to export all files or only the ones that are used.
  
          $alltexts = ''; // Store all texts that reference files to search which files are used.
          foreach ($pages as $page => $entry) {
              // Preprocess current page contents.
              if (!$allfiles && self::text_has_files($entry['page']['cachedcontent'])) {
                  $alltexts .= $entry['page']['cachedcontent'];
              }
              $entry['page']['cachedcontent'] = format_text(writer::with_context($context)
                  ->rewrite_pluginfile_urls([$subwikiid], 'mod_wiki', 'attachments',
                      $subwikiid, $entry['page']['cachedcontent']), FORMAT_HTML, ['context' => $context]);
              // Add page tags.
              $pagetags = \core_tag_tag::get_item_tags_array('mod_wiki', 'page', $entry['page']['id']);
              if ($pagetags) {
                  $entry['page']['tags'] = $pagetags;
              }
  
              // Preprocess revisions.
              if (!empty($entry['revisions'])) {
                  // For each revision this user has made preprocess the contents.
                  foreach ($entry['revisions'] as &$revision) {
                      if ((!$allfiles && self::text_has_files($revision['content']))) {
                          $alltexts .= $revision['content'];
                      }
                      $revision['content'] = writer::with_context($context)
                          ->rewrite_pluginfile_urls([$subwikiid], 'mod_wiki', 'attachments', $subwikiid, $revision['content']);
                  }
              }
              $comments = self::get_page_comments($user, $context, $entry['page']['id'], !array_key_exists('userid', $entry['page']));
              if ($comments) {
                  $entry['page']['comments'] = $comments;
              }
              writer::with_context($context)->export_related_data([$subwikiid], $page, $entry);
          }
  
          if ($allfiles) {
              // Export all files.
              writer::with_context($context)->export_area_files([$subwikiid], 'mod_wiki', 'attachments', $subwikiid);
          } else {
              // Analyze which files are used in the texts.
              self::export_used_files($context, $subwikiid, $alltexts);
          }
      }
code: protected static function export_subwiki($user, context $context, $subwiki, $wikimode) {
          if (empty($subwiki)) {
              return;
          }
          $subwikiid = key($subwiki);
          $pages = $subwiki[$subwikiid]['pages'];
          unset($subwiki[$subwikiid]['pages']);
          writer::with_context($context)->export_data([$subwikiid], (object)$subwiki[$subwikiid]);
          $allfiles = $wikimode === 'individual'; // Whether to export all files or only the ones that are used.
  
          $alltexts = ''; // Store all texts that reference files to search which files are used.
          foreach ($pages as $page => $entry) {
              // Preprocess current page contents.
              if (!$allfiles && self::text_has_files($entry['page']['cachedcontent'])) {
                  $alltexts .= $entry['page']['cachedcontent'];
              }
              $entry['page']['cachedcontent'] = format_text(writer::with_context($context)
                  ->rewrite_pluginfile_urls([$subwikiid], 'mod_wiki', 'attachments',
                      $subwikiid, $entry['page']['cachedcontent']), FORMAT_HTML, ['context' => $context]);
              // Add page tags.
              $pagetags = \core_tag_tag::get_item_tags_array('mod_wiki', 'page', $entry['page']['id']);
              if ($pagetags) {
                  $entry['page']['tags'] = $pagetags;
              }
  
              // Preprocess revisions.
              if (!empty($entry['revisions'])) {
                  // For each revision this user has made preprocess the contents.
                  foreach ($entry['revisions'] as &$revision) {
                      if ((!$allfiles && self::text_has_files($revision['content']))) {
                          $alltexts .= $revision['content'];
                      }
                      $revision['content'] = writer::with_context($context)
                          ->rewrite_pluginfile_urls([$subwikiid], 'mod_wiki', 'attachments', $subwikiid, $revision['content']);
                  }
              }
              $comments = self::get_page_comments($user, $context, $entry['page']['id'], !array_key_exists('userid', $entry['page']));
              if ($comments) {
                  $entry['page']['comments'] = $comments;
              }
              writer::with_context($context)->export_related_data([$subwikiid], $page, $entry);
          }
  
          if ($allfiles) {
              // Export all files.
              writer::with_context($context)->export_area_files([$subwikiid], 'mod_wiki', 'attachments', $subwikiid);
          } else {
              // Analyze which files are used in the texts.
              self::export_used_files($context, $subwikiid, $alltexts);
          }
      }
code_tokens: protected static function export_subwiki ( $ user , context $ context , $ subwiki , $ wikimode ) { if ( empty ( $ subwiki ) ) { return ; } $ subwikiid = key ( $ subwiki ) ; $ pages = $ subwiki [ $ subwikiid ] [ 'pages' ] ; unset ( $ subwiki [ $ subwikiid ] [ 'pages' ] ) ; writer :: with_context ( $ context ) -> export_data ( [ $ subwikiid ] , ( object ) $ subwiki [ $ subwikiid ] ) ; $ allfiles = $ wikimode === 'individual' ; // Whether to export all files or only the ones that are used. $ alltexts = '' ; // Store all texts that reference files to search which files are used. foreach ( $ pages as $ page => $ entry ) { // Preprocess current page contents. if ( ! $ allfiles && self :: text_has_files ( $ entry [ 'page' ] [ 'cachedcontent' ] ) ) { $ alltexts .= $ entry [ 'page' ] [ 'cachedcontent' ] ; } $ entry [ 'page' ] [ 'cachedcontent' ] = format_text ( writer :: with_context ( $ context ) -> rewrite_pluginfile_urls ( [ $ subwikiid ] , 'mod_wiki' , 'attachments' , $ subwikiid , $ entry [ 'page' ] [ 'cachedcontent' ] ) , FORMAT_HTML , [ 'context' => $ context ] ) ; // Add page tags. $ pagetags = \ core_tag_tag :: get_item_tags_array ( 'mod_wiki' , 'page' , $ entry [ 'page' ] [ 'id' ] ) ; if ( $ pagetags ) { $ entry [ 'page' ] [ 'tags' ] = $ pagetags ; } // Preprocess revisions. if ( ! empty ( $ entry [ 'revisions' ] ) ) { // For each revision this user has made preprocess the contents. foreach ( $ entry [ 'revisions' ] as & $ revision ) { if ( ( ! $ allfiles && self :: text_has_files ( $ revision [ 'content' ] ) ) ) { $ alltexts .= $ revision [ 'content' ] ; } $ revision [ 'content' ] = writer :: with_context ( $ context ) -> rewrite_pluginfile_urls ( [ $ subwikiid ] , 'mod_wiki' , 'attachments' , $ subwikiid , $ revision [ 'content' ] ) ; } } $ comments = self :: get_page_comments ( $ user , $ context , $ entry [ 'page' ] [ 'id' ] , ! array_key_exists ( 'userid' , $ entry [ 'page' ] ) ) ; if ( $ comments ) { $ entry [ 'page' ] [ 'comments' ] = $ comments ; } writer :: with_context ( $ context ) -> export_related_data ( [ $ subwikiid ] , $ page , $ entry ) ; } if ( $ allfiles ) { // Export all files. writer :: with_context ( $ context ) -> export_area_files ( [ $ subwikiid ] , 'mod_wiki' , 'attachments' , $ subwikiid ) ; } else { // Analyze which files are used in the texts. self :: export_used_files ( $ context , $ subwikiid , $ alltexts ) ; } }
docstring: Add one subwiki to the export
  
  Each page is added as related data because all pages in one subwiki share the same filearea
  
  @param stdClass $user
  @param context $context
  @param array $subwiki
  @param string $wikimode
docstring_tokens: Add one subwiki to the export