Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
eba6affb
Commit
eba6affb
authored
Apr 24, 2020
by
James Lopez
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'wiki-page-accessors' into 'master'
Use accessors in WikiPage See merge request gitlab-org/gitlab!30326
parents
a66557e0
cde2f673
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
18 deletions
+20
-18
app/models/wiki_page.rb
app/models/wiki_page.rb
+20
-18
No files found.
app/models/wiki_page.rb
View file @
eba6affb
...
...
@@ -95,29 +95,29 @@ class WikiPage
# The escaped URL path of this page.
def
slug
@
attributes
[
:slug
].
presence
||
wiki
.
wiki
.
preview_slug
(
title
,
format
)
attributes
[
:slug
].
presence
||
wiki
.
wiki
.
preview_slug
(
title
,
format
)
end
alias_method
:to_param
,
:slug
def
human_title
return
'Home'
if
title
==
'home'
return
'Home'
if
title
==
Wiki
::
HOMEPAGE
title
end
# The formatted title of this page.
def
title
@
attributes
[
:title
]
||
''
attributes
[
:title
]
||
''
end
# Sets the title of this page.
def
title
=
(
new_title
)
@
attributes
[
:title
]
=
new_title
attributes
[
:title
]
=
new_title
end
def
raw_content
@attributes
[
:content
]
||=
@
page
&
.
text_data
attributes
[
:content
]
||=
page
&
.
text_data
end
# The hierarchy of the directory this page is contained in.
...
...
@@ -127,7 +127,7 @@ class WikiPage
# The markup format for the page.
def
format
@
attributes
[
:format
]
||
:markdown
attributes
[
:format
]
||
:markdown
end
# The commit message for this page version.
...
...
@@ -151,13 +151,13 @@ class WikiPage
def
versions
(
options
=
{})
return
[]
unless
persisted?
wiki
.
wiki
.
page_versions
(
@
page
.
path
,
options
)
wiki
.
wiki
.
page_versions
(
page
.
path
,
options
)
end
def
count_versions
return
[]
unless
persisted?
wiki
.
wiki
.
count_page_versions
(
@
page
.
path
)
wiki
.
wiki
.
count_page_versions
(
page
.
path
)
end
def
last_version
...
...
@@ -173,7 +173,7 @@ class WikiPage
def
historical?
return
false
unless
last_commit_sha
&&
version
@
page
.
historical?
&&
last_commit_sha
!=
version
.
sha
page
.
historical?
&&
last_commit_sha
!=
version
.
sha
end
# Returns boolean True or False if this instance
...
...
@@ -185,7 +185,7 @@ class WikiPage
# Returns boolean True or False if this instance
# has been fully created on disk or not.
def
persisted?
@
page
.
present?
page
.
present?
end
# Creates a new Wiki Page.
...
...
@@ -232,13 +232,13 @@ class WikiPage
update_attributes
(
attrs
)
if
title
.
present?
&&
title_changed?
&&
wiki
.
find_page
(
title
).
present?
@attributes
[
:title
]
=
@
page
.
title
attributes
[
:title
]
=
page
.
title
raise
PageRenameError
end
save
do
wiki
.
update_page
(
@
page
,
page
,
content:
raw_content
,
format:
format
,
message:
attrs
[
:message
],
...
...
@@ -251,7 +251,7 @@ class WikiPage
#
# Returns boolean True or False.
def
delete
if
wiki
.
delete_page
(
@
page
)
if
wiki
.
delete_page
(
page
)
true
else
false
...
...
@@ -271,7 +271,7 @@ class WikiPage
def
title_changed?
if
persisted?
old_title
,
old_dir
=
wiki
.
page_title_and_dir
(
self
.
class
.
unhyphenize
(
@
page
.
url_path
))
old_title
,
old_dir
=
wiki
.
page_title_and_dir
(
self
.
class
.
unhyphenize
(
page
.
url_path
))
new_title
,
new_dir
=
wiki
.
page_title_and_dir
(
self
.
class
.
unhyphenize
(
title
))
new_title
!=
old_title
||
(
title
.
include?
(
'/'
)
&&
new_dir
!=
old_dir
)
...
...
@@ -288,7 +288,7 @@ class WikiPage
attrs
.
slice!
(
:content
,
:format
,
:message
,
:title
)
clear_memoization
(
:parsed_content
)
if
attrs
.
has_key?
(
:content
)
@
attributes
.
merge!
(
attrs
)
attributes
.
merge!
(
attrs
)
end
def
to_ability_name
...
...
@@ -326,7 +326,7 @@ class WikiPage
title
=
deep_title_squish
(
title
)
current_dirname
=
File
.
dirname
(
title
)
if
@page
.
present
?
if
persisted
?
return
title
[
1
..-
1
]
if
current_dirname
==
'/'
return
File
.
join
([
directory
.
presence
,
title
].
compact
)
if
current_dirname
==
'.'
end
...
...
@@ -363,9 +363,11 @@ class WikiPage
end
def
validate_path_limits
*
dirnames
,
title
=
@attributes
[
:title
].
split
(
'/'
)
return
unless
title
.
present?
*
dirnames
,
filename
=
title
.
split
(
'/'
)
if
title
&&
titl
e
.
bytesize
>
Gitlab
::
WikiPages
::
MAX_TITLE_BYTES
if
filename
&&
filenam
e
.
bytesize
>
Gitlab
::
WikiPages
::
MAX_TITLE_BYTES
errors
.
add
(
:title
,
_
(
"exceeds the limit of %{bytes} bytes"
)
%
{
bytes:
Gitlab
::
WikiPages
::
MAX_TITLE_BYTES
})
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment