Method: Wiki#find_page

Defined in:
app/models/wiki.rb

#find_page(title, version = nil, load_content: true) ⇒ Object

Finds a page within the repository based on a title or slug.

title - The human readable or parameterized title of

the page.

Returns an initialized WikiPage instance or nil



256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
# File 'app/models/wiki.rb', line 256

def find_page(title, version = nil, load_content: true)
  return unless title.present?

  capture_git_error(:find, response_on_error: nil) do
    create_wiki_repository unless repository_exists?

    version = version.presence || default_branch
    path = find_matched_file(title, version)
    next if path.blank?

    path = Gitlab::EncodingHelper.encode_utf8_no_detect(path)
    blob_options = load_content ? {} : { limit: 0 }
    blob = repository.blob_at(version, path, **blob_options)
    commit = repository.commit(blob.commit_id)
    format = find_page_format(path)

    page = Gitlab::Git::WikiPage.new(
      url_path: strip_extension(path),
      title: canonicalize_filename(path),
      format: format,
      path: path,
      raw_data: blob.data,
      name: canonicalize_filename(path),
      historical: version == default_branch ? false : check_page_historical(path, commit),
      version: Gitlab::Git::WikiPageVersion.new(commit, format)
    )
    WikiPage.new(self, page)
  end
end