|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @package net.nemein.wiki |
|
4
|
|
|
* @author The Midgard Project, http://www.midgard-project.org |
|
5
|
|
|
* @copyright The Midgard Project, http://www.midgard-project.org |
|
6
|
|
|
* @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Wikipage "page not found" handler |
|
13
|
|
|
* |
|
14
|
|
|
* @package net.nemein.wiki |
|
15
|
|
|
*/ |
|
16
|
|
|
class net_nemein_wiki_handler_notfound extends midcom_baseclasses_components_handler |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @param string $wikiword The page's name |
|
20
|
|
|
* @param array $data The local request data. |
|
21
|
|
|
*/ |
|
22
|
1 |
|
public function _handler_notfound($wikiword, array &$data) |
|
23
|
|
|
{ |
|
24
|
1 |
|
$data['wikiword'] = $wikiword; |
|
25
|
1 |
|
$qb = net_nemein_wiki_wikipage::new_query_builder(); |
|
26
|
1 |
|
$qb->add_constraint('topic', '=', $this->_topic->id); |
|
27
|
1 |
|
$qb->add_constraint('title', '=', $wikiword); |
|
28
|
1 |
|
$result = $qb->execute(); |
|
29
|
1 |
|
if (!empty($result)) { |
|
30
|
|
|
// This wiki page actually exists, so go there as "Permanent Redirect" |
|
31
|
|
|
return new midcom_response_relocate("{$result[0]->name}/", 301); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
1 |
|
midcom::get()->head->set_pagetitle(sprintf($this->_l10n->get('"%s" not found'), $wikiword)); |
|
35
|
|
|
|
|
36
|
|
|
// TODO: List pages containing the wikiword via indexer |
|
37
|
|
|
|
|
38
|
1 |
|
$data['wiki_name'] = $this->_topic->extra; |
|
39
|
|
|
|
|
40
|
|
|
// Populate toolbar for actions available |
|
41
|
1 |
|
$data['wiki_tools'] = new midcom_helper_toolbar(); |
|
42
|
1 |
|
$workflow = $this->get_workflow('datamanager'); |
|
43
|
1 |
|
$buttons = []; |
|
44
|
1 |
|
if ($this->_topic->can_do('midgard:create')) { |
|
45
|
|
|
$buttons[] = $workflow->get_button('create/?wikiword=' . rawurlencode($wikiword), [ |
|
46
|
|
|
MIDCOM_TOOLBAR_LABEL => sprintf($this->_l10n->get('create page %s'), $wikiword), |
|
47
|
|
|
MIDCOM_TOOLBAR_GLYPHICON => 'file-o', |
|
48
|
|
|
MIDCOM_TOOLBAR_ENABLED => $this->_topic->can_do('midgard:create'), |
|
49
|
|
|
]); |
|
50
|
|
|
$buttons[] = $workflow->get_button('create/redirect/?wikiword=' . rawurlencode($wikiword), [ |
|
51
|
|
|
MIDCOM_TOOLBAR_LABEL => sprintf($this->_l10n->get('create redirection page %s'), $wikiword), |
|
52
|
|
|
MIDCOM_TOOLBAR_GLYPHICON => 'file-o', |
|
53
|
|
|
MIDCOM_TOOLBAR_ENABLED => $this->_topic->can_do('midgard:create'), |
|
54
|
|
|
]); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
1 |
|
$buttons[] = [ |
|
58
|
1 |
|
MIDCOM_TOOLBAR_URL => 'http://' . $this->_i18n->get_current_language() . '.wikipedia.org/wiki/' . rawurlencode($wikiword), |
|
59
|
1 |
|
MIDCOM_TOOLBAR_LABEL => sprintf($this->_l10n->get('look for %s in wikipedia'), $wikiword), |
|
60
|
1 |
|
MIDCOM_TOOLBAR_GLYPHICON => 'search', |
|
61
|
|
|
MIDCOM_TOOLBAR_OPTIONS => [ |
|
62
|
|
|
'rel' => 'directlink', |
|
63
|
|
|
] |
|
64
|
|
|
]; |
|
65
|
1 |
|
$data['wiki_tools']->add_items($buttons); |
|
66
|
1 |
|
$this->add_breadcrumb('notfound/' . rawurlencode($wikiword), $wikiword); |
|
67
|
|
|
|
|
68
|
1 |
|
$response = $this->show('view-notfound'); |
|
69
|
|
|
// This is a custom "not found" page, send appropriate headers to prevent indexing |
|
70
|
1 |
|
$response->setStatusCode(Response::HTTP_NOT_FOUND); |
|
71
|
1 |
|
return $response; |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|