forked from duncan-crane/TinyMCE
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTinyMCEAction.php
110 lines (93 loc) · 3.07 KB
/
TinyMCEAction.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
use MediaWiki\MediaWikiServices;
/**
* Handles the formedit action.
*
* @author Yaron Koren
* @author Stephan Gambke
* @file
* @ingroup PF
*/
class TinyMCEAction extends Action {
/**
* Return the name of the action this object responds to
* @return String lowercase
*/
public function getName() {
return 'tinymceedit';
}
/**
* The main action entry point.
* @throws ErrorPageError
*/
public function show() {
$title = $this->getTitle();
$context = $this->getContext();
$article = Article::newFromTitle( $title, $context );
$editPage = new EditPage( $article );
// Keep additional screens in this tab, instead of going to 'action=submit'.
$editPage->action = 'tinymceedit';
return $editPage->edit();
}
/**
* Execute the action in a silent fashion: do not display anything or release any errors.
* @return Bool whether execution was successful
*/
public function execute() {
return true;
}
/**
* Adds an "action" (i.e., a tab) to edit the current article with
* TinyMCE.
*/
static function displayTab( $obj, &$links ) {
global $wgRequest;
$content_actions = &$links['views'];
$title = $obj->getTitle();
$context = $obj->getContext();
if ( !isset( $title ) || !$title->userCan( 'edit' ) ) {
return true;
}
if ( !TinyMCEHooks::enableTinyMCE( $title, $context ) ) {
return true;
}
// Create the form edit tab, and apply whatever changes are
// specified by the edit-tab global variables.
if ( array_key_exists( 'edit', $content_actions ) ) {
$content_actions['edit']['text'] = wfMessage( 'tinymce-editsource' )->text();
}
$class_name = ( $wgRequest->getVal( 'action' ) == 'tinymceedit' ) ? 'selected' : '';
$tinyMCETab = array(
'class' => $class_name,
'text' => wfMessage( 'edit' )->text(),
'href' => $title->getLocalURL( 'action=tinymceedit' )
);
// Find the location of the 'edit' tab, and add 'edit
// with form' right before it.
// This is a "key-safe" splice - it preserves both the keys
// and the values of the array, by editing them separately
// and then rebuilding the array. Based on the example at
// http://us2.php.net/manual/en/function.array-splice.php#31234
$tab_keys = array_keys( $content_actions );
$tab_values = array_values( $content_actions );
$edit_tab_location = array_search( 'edit', $tab_keys );
// If there's no 'edit' tab, look for the 'view source' tab
// instead.
if ( $edit_tab_location == null ) {
$edit_tab_location = array_search( 'viewsource', $tab_keys );
}
// This should rarely happen, but if there was no edit *or*
// view source tab, set the location index to -1, so the
// tab shows up near the end.
if ( $edit_tab_location == null ) {
$edit_tab_location = - 1;
}
array_splice( $tab_keys, $edit_tab_location, 0, 'tinymceedit' );
array_splice( $tab_values, $edit_tab_location, 0, array( $tinyMCETab ) );
$content_actions = array();
for ( $i = 0; $i < count( $tab_keys ); $i++ ) {
$content_actions[$tab_keys[$i]] = $tab_values[$i];
}
return true; // always return true, in order not to stop MW's hook processing!
}
}