Merge "Documentation improvements in includes/actions"
[lhc/web/wiklou.git] / includes / actions / EditAction.php
1 <?php
2 /**
3 * action=edit / action=submit handler
4 *
5 * Copyright © 2012 Timo Tijhof
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
20 *
21 * @file
22 * @ingroup Actions
23 * @author Timo Tijhof
24 */
25
26 /**
27 * Page edition handler
28 *
29 * This is a wrapper that will call the EditPage class, or ExternalEdit
30 * if $wgUseExternalEditor is set to true and requested by the user.
31 *
32 * @ingroup Actions
33 */
34 class EditAction extends FormlessAction {
35
36 public function getName() {
37 return 'edit';
38 }
39
40 public function onView() {
41 return null;
42 }
43
44 public function show() {
45 $page = $this->page;
46 $request = $this->getRequest();
47 $user = $this->getUser();
48 $context = $this->getContext();
49
50 if ( wfRunHooks( 'CustomEditor', array( $page, $user ) ) ) {
51 if ( ExternalEdit::useExternalEngine( $context, 'edit' )
52 && $this->getName() == 'edit' && !$request->getVal( 'section' )
53 && !$request->getVal( 'oldid' ) )
54 {
55 $extedit = new ExternalEdit( $context );
56 $extedit->execute();
57 } else {
58 $editor = new EditPage( $page );
59 $editor->edit();
60 }
61 }
62
63 }
64
65 }
66
67 /**
68 * Edit submission handler
69 *
70 * This is the same as EditAction; except that it sets the session cookie.
71 *
72 * @ingroup Actions
73 */
74 class SubmitAction extends EditAction {
75
76 public function getName() {
77 return 'submit';
78 }
79
80 public function show() {
81 if ( session_id() == '' ) {
82 // Send a cookie so anons get talk message notifications
83 wfSetupSession();
84 }
85
86 parent::show();
87 }
88
89 }