Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Stud.IP
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Marcus Eibrink-Lunzenauer
Stud.IP
Commits
44b518ce
Commit
44b518ce
authored
5 months ago
by
Moritz Strohm
Browse files
Options
Downloads
Patches
Plain Diff
added wiki.php as redirection script, fixes #4996
Closes #4996 Merge request
studip/studip!3749
parent
837d45b6
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
public/wiki.php
+127
-0
127 additions, 0 deletions
public/wiki.php
with
127 additions
and
0 deletions
public/wiki.php
0 → 100644
+
127
−
0
View file @
44b518ce
<?php
/**
* wiki.php
*
* This script is needed to redirect wiki pages referenced by an URL to the old wiki
* (before Stud.IP 5.5) to the controller of the new wiki (Stud.IP 5.5 and newer).
*
* @author Jan-Hendrik Willms <tleilax+studip@gmail.com>
* @author Moritz Strohm <strohm@data-quest.de>
* @license http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
* @category Stud.IP
* @since 5.5
*/
// Set up a minimal Stud.IP environment:
require_once
__DIR__
.
'/../lib/bootstrap.php'
;
URLHelper
::
setBaseUrl
(
$GLOBALS
[
'ABSOLUTE_URI_STUDIP'
]);
// Set exception handler which outputs the message of the exception.
// In case the Stud.IP is in development mode, the stack trace
// is also printed before halting execution.
set_exception_handler
(
function
(
Throwable
$exception
)
{
header
(
'Content-Type: text/plain'
);
echo
$exception
->
getMessage
();
if
(
Studip\ENV
===
'development'
)
{
echo
"
\n
"
.
$exception
->
getTraceAsString
();
}
die
;
});
// Handle URL parameters:
$course_id
=
Request
::
option
(
'cid'
);
$keyword
=
Request
::
get
(
'keyword'
);
$version
=
Request
::
int
(
'version'
);
if
(
!
$course_id
)
{
// Invalid wiki page.
die
(
sprintf
(
_
(
'Fehlender URL-Parameter: %s'
),
'cid'
));
}
// Load the wiki page or a version of it:
$page
=
null
;
$page_version
=
null
;
if
(
!
$keyword
||
$keyword
===
'WikiWikiWeb'
)
{
// Load the start page for the course:
$page_id
=
CourseConfig
::
get
(
$course_id
)
->
getValue
(
'WIKI_STARTPAGE_ID'
);
$load_newest_version
=
true
;
if
(
$version
)
{
// Check if the requested version is the newest version.
// In that case, the wiki_pages table instead of the wiki_versions
// table must be used to get the correct version of the page.
$newest_version
=
1
+
WikiVersion
::
countByPage_id
(
$page_id
);
$load_newest_version
=
$version
===
$newest_version
;
}
if
(
$load_newest_version
)
{
// Load the newest version:
$page
=
WikiPage
::
find
(
$page_id
);
}
else
{
// Load the requested version:
$page_version
=
WikiVersion
::
findOneBySQL
(
'`page_id` = :page_id
ORDER BY `mkdate` ASC
LIMIT 1 OFFSET :version'
,
[
'page_id'
=>
$page_id
,
'version'
=>
$version
-
1
]
);
}
}
else
{
// Load the page by its keyword and course-ID:
$load_newest_version
=
true
;
if
(
$version
)
{
// Check if the requested version is the newest version.
// In that case, the wiki_pages table instead of the wiki_versions
// table must be used to get the correct version of the page.
$newest_version
=
1
+
WikiVersion
::
countBySql
(
'JOIN `wiki_pages` USING (`page_id`)
WHERE `wiki_pages`.`range_id` = :course_id AND `wiki_pages`.`name` = :keyword'
,
[
'course_id'
=>
$course_id
,
'keyword'
=>
$keyword
]
);
$load_newest_version
=
$version
===
$newest_version
;
}
if
(
$load_newest_version
)
{
// Load the newest version:
$page
=
WikiPage
::
findOneBySQL
(
'`range_id` = :course_id AND `name` = :keyword'
,
[
'course_id'
=>
$course_id
,
'keyword'
=>
$keyword
]
);
}
else
{
// Load the requested version:
$page_version
=
WikiVersion
::
findOneBySQL
(
'JOIN `wiki_pages` USING (`page_id`)
WHERE `wiki_pages`.`range_id` = :course_id AND `wiki_pages`.`name` = :keyword
ORDER BY `wiki_versions`.`mkdate` ASC
LIMIT 1 OFFSET :version'
,
[
'course_id'
=>
$course_id
,
'keyword'
=>
$keyword
,
'version'
=>
$version
-
1
]
);
}
}
if
(
!
$page
&&
!
$page_version
)
{
// Page not found:
die
(
sprintf
(
_
(
'Die Wikiseite mit dem Schlagwort "%s" wurde nicht gefunden.'
),
$keyword
));
}
// Everything went well: Redirect permanently to the new wiki page.
// Assume that the optional version parameter is not set and redirect to the newest
// version of the wiki page, which should be the usual case.
$url
=
URLHelper
::
getURL
(
'dispatch.php/course/wiki/page/'
.
$page
->
id
,
[
'cid'
=>
$course_id
]);
if
(
$page_version
)
{
//Redirect to the specific version of the wiki page instead of the newest version:
$url
=
URLHelper
::
getURL
(
'dispatch.php/course/wiki/version/'
.
$page_version
->
id
,
[
'cid'
=>
$course_id
]);
}
header
(
'Location: '
.
$url
,
true
,
301
);
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment