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
cde2f673
Commit
cde2f673
authored
Apr 23, 2020
by
Markus Koller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use accessors in WikiPage
This is preferred over using instance variables, to avoid e.g. typos.
parent
62518064
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 @
cde2f673
...
@@ -95,29 +95,29 @@ class WikiPage
...
@@ -95,29 +95,29 @@ class WikiPage
# The escaped URL path of this page.
# The escaped URL path of this page.
def
slug
def
slug
@
attributes
[
:slug
].
presence
||
wiki
.
wiki
.
preview_slug
(
title
,
format
)
attributes
[
:slug
].
presence
||
wiki
.
wiki
.
preview_slug
(
title
,
format
)
end
end
alias_method
:to_param
,
:slug
alias_method
:to_param
,
:slug
def
human_title
def
human_title
return
'Home'
if
title
==
'home'
return
'Home'
if
title
==
Wiki
::
HOMEPAGE
title
title
end
end
# The formatted title of this page.
# The formatted title of this page.
def
title
def
title
@
attributes
[
:title
]
||
''
attributes
[
:title
]
||
''
end
end
# Sets the title of this page.
# Sets the title of this page.
def
title
=
(
new_title
)
def
title
=
(
new_title
)
@
attributes
[
:title
]
=
new_title
attributes
[
:title
]
=
new_title
end
end
def
raw_content
def
raw_content
@attributes
[
:content
]
||=
@
page
&
.
text_data
attributes
[
:content
]
||=
page
&
.
text_data
end
end
# The hierarchy of the directory this page is contained in.
# The hierarchy of the directory this page is contained in.
...
@@ -127,7 +127,7 @@ class WikiPage
...
@@ -127,7 +127,7 @@ class WikiPage
# The markup format for the page.
# The markup format for the page.
def
format
def
format
@
attributes
[
:format
]
||
:markdown
attributes
[
:format
]
||
:markdown
end
end
# The commit message for this page version.
# The commit message for this page version.
...
@@ -151,13 +151,13 @@ class WikiPage
...
@@ -151,13 +151,13 @@ class WikiPage
def
versions
(
options
=
{})
def
versions
(
options
=
{})
return
[]
unless
persisted?
return
[]
unless
persisted?
wiki
.
wiki
.
page_versions
(
@
page
.
path
,
options
)
wiki
.
wiki
.
page_versions
(
page
.
path
,
options
)
end
end
def
count_versions
def
count_versions
return
[]
unless
persisted?
return
[]
unless
persisted?
wiki
.
wiki
.
count_page_versions
(
@
page
.
path
)
wiki
.
wiki
.
count_page_versions
(
page
.
path
)
end
end
def
last_version
def
last_version
...
@@ -173,7 +173,7 @@ class WikiPage
...
@@ -173,7 +173,7 @@ class WikiPage
def
historical?
def
historical?
return
false
unless
last_commit_sha
&&
version
return
false
unless
last_commit_sha
&&
version
@
page
.
historical?
&&
last_commit_sha
!=
version
.
sha
page
.
historical?
&&
last_commit_sha
!=
version
.
sha
end
end
# Returns boolean True or False if this instance
# Returns boolean True or False if this instance
...
@@ -185,7 +185,7 @@ class WikiPage
...
@@ -185,7 +185,7 @@ class WikiPage
# Returns boolean True or False if this instance
# Returns boolean True or False if this instance
# has been fully created on disk or not.
# has been fully created on disk or not.
def
persisted?
def
persisted?
@
page
.
present?
page
.
present?
end
end
# Creates a new Wiki Page.
# Creates a new Wiki Page.
...
@@ -232,13 +232,13 @@ class WikiPage
...
@@ -232,13 +232,13 @@ class WikiPage
update_attributes
(
attrs
)
update_attributes
(
attrs
)
if
title
.
present?
&&
title_changed?
&&
wiki
.
find_page
(
title
).
present?
if
title
.
present?
&&
title_changed?
&&
wiki
.
find_page
(
title
).
present?
@attributes
[
:title
]
=
@
page
.
title
attributes
[
:title
]
=
page
.
title
raise
PageRenameError
raise
PageRenameError
end
end
save
do
save
do
wiki
.
update_page
(
wiki
.
update_page
(
@
page
,
page
,
content:
raw_content
,
content:
raw_content
,
format:
format
,
format:
format
,
message:
attrs
[
:message
],
message:
attrs
[
:message
],
...
@@ -251,7 +251,7 @@ class WikiPage
...
@@ -251,7 +251,7 @@ class WikiPage
#
#
# Returns boolean True or False.
# Returns boolean True or False.
def
delete
def
delete
if
wiki
.
delete_page
(
@
page
)
if
wiki
.
delete_page
(
page
)
true
true
else
else
false
false
...
@@ -271,7 +271,7 @@ class WikiPage
...
@@ -271,7 +271,7 @@ class WikiPage
def
title_changed?
def
title_changed?
if
persisted?
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
,
new_dir
=
wiki
.
page_title_and_dir
(
self
.
class
.
unhyphenize
(
title
))
new_title
!=
old_title
||
(
title
.
include?
(
'/'
)
&&
new_dir
!=
old_dir
)
new_title
!=
old_title
||
(
title
.
include?
(
'/'
)
&&
new_dir
!=
old_dir
)
...
@@ -288,7 +288,7 @@ class WikiPage
...
@@ -288,7 +288,7 @@ class WikiPage
attrs
.
slice!
(
:content
,
:format
,
:message
,
:title
)
attrs
.
slice!
(
:content
,
:format
,
:message
,
:title
)
clear_memoization
(
:parsed_content
)
if
attrs
.
has_key?
(
:content
)
clear_memoization
(
:parsed_content
)
if
attrs
.
has_key?
(
:content
)
@
attributes
.
merge!
(
attrs
)
attributes
.
merge!
(
attrs
)
end
end
def
to_ability_name
def
to_ability_name
...
@@ -326,7 +326,7 @@ class WikiPage
...
@@ -326,7 +326,7 @@ class WikiPage
title
=
deep_title_squish
(
title
)
title
=
deep_title_squish
(
title
)
current_dirname
=
File
.
dirname
(
title
)
current_dirname
=
File
.
dirname
(
title
)
if
@page
.
present
?
if
persisted
?
return
title
[
1
..-
1
]
if
current_dirname
==
'/'
return
title
[
1
..-
1
]
if
current_dirname
==
'/'
return
File
.
join
([
directory
.
presence
,
title
].
compact
)
if
current_dirname
==
'.'
return
File
.
join
([
directory
.
presence
,
title
].
compact
)
if
current_dirname
==
'.'
end
end
...
@@ -363,9 +363,11 @@ class WikiPage
...
@@ -363,9 +363,11 @@ class WikiPage
end
end
def
validate_path_limits
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"
)
%
{
errors
.
add
(
:title
,
_
(
"exceeds the limit of %{bytes} bytes"
)
%
{
bytes:
Gitlab
::
WikiPages
::
MAX_TITLE_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