Index: trunk/extensions/ForcePreview/ForcePreview.i18n.php |
— | — | @@ -9,10 +9,10 @@ |
10 | 10 | $messages = array(); |
11 | 11 | |
12 | 12 | /** English |
13 | | - @author Ryan Schmidt |
| 13 | + * @author Ryan Schmidt |
14 | 14 | */ |
15 | 15 | $messages['en'] = array( |
16 | | - 'forcepreview' => 'Save page (use preview first)', |
| 16 | + 'forcepreview' => 'Save page (use preview first)', |
17 | 17 | 'forcepreview-desc' => 'Force preview for unprivileged users', |
18 | 18 | 'right-forcepreviewexempt' => 'May save without using Show preview', |
19 | 19 | ); |
Index: trunk/extensions/ForcePreview/ForcePreview.php |
— | — | @@ -1,13 +1,21 @@ |
2 | 2 | <?php |
3 | 3 | /** |
4 | | -* ForcePreview extension by Ryan Schmidt |
5 | | -*/ |
| 4 | + * ForcePreview extension -- forces unprivileged users to preview before saving |
| 5 | + * |
| 6 | + * @file |
| 7 | + * @ingroup Extensions |
| 8 | + * @author Ryan Schmidt |
| 9 | + * @version 1.2 |
| 10 | + * @license http://en.wikipedia.org/wiki/Public_domain Public domain |
| 11 | + * @link http://www.mediawiki.org/wiki/Extension:ForcePreview Documentation |
| 12 | + */ |
6 | 13 | |
7 | | -if(!defined('MEDIAWIKI')) { |
8 | | - echo("This file is an extension to the MediaWiki software and is not a valid access point"); |
9 | | - die(1); |
| 14 | +if( !defined( 'MEDIAWIKI' ) ) { |
| 15 | + echo( "This file is an extension to the MediaWiki software and is not a valid access point" ); |
| 16 | + die( 1 ); |
10 | 17 | } |
11 | 18 | |
| 19 | +// Extension credits that will show up on Special:Version |
12 | 20 | $wgExtensionCredits['other'][] = array( |
13 | 21 | 'path' => __FILE__, |
14 | 22 | 'name' => 'Force Preview', |
— | — | @@ -17,9 +25,14 @@ |
18 | 26 | 'url' => 'http://www.mediawiki.org/wiki/Extension:ForcePreview', |
19 | 27 | ); |
20 | 28 | |
21 | | -$dir = dirname(__FILE__) . '/'; |
22 | | -$wgExtensionMessagesFiles['ForcePreview'] = $dir .'ForcePreview.i18n.php'; |
| 29 | +// i18n file |
| 30 | +$dir = dirname( __FILE__ ) . '/'; |
| 31 | +$wgExtensionMessagesFiles['ForcePreview'] = $dir . 'ForcePreview.i18n.php'; |
| 32 | + |
| 33 | +// New user right, allows users to bypass the requirement of previewing before |
| 34 | +// saving the page |
23 | 35 | $wgAvailableRights[] = 'forcepreviewexempt'; |
| 36 | + |
24 | 37 | $wgHooks['EditPageBeforeEditButtons'][] = 'efForcePreview'; |
25 | 38 | $wgHooks['BeforePageDisplay'][] = 'efForcePreviewLivePreview'; |
26 | 39 | |
— | — | @@ -28,15 +41,36 @@ |
29 | 42 | |
30 | 43 | function efForcePreview( &$editpage, &$buttons ) { |
31 | 44 | global $wgUser; |
32 | | - if( !$wgUser->isAllowed( 'forcepreviewexempt' ) && !$editpage->preview && empty( $editpage->save ) ) { |
33 | | - |
34 | | - $buttons['save'] = str_replace( '/>', 'disabled="disabled" />', $buttons['save'] ); |
35 | | - $buttons['save'] = preg_replace( '/value="' . wfMsg('savearticle') . '"/i', 'value="' . wfMsg('forcepreview') . '"', $buttons['save'] ); |
| 45 | + if( |
| 46 | + !$wgUser->isAllowed( 'forcepreviewexempt' ) && |
| 47 | + !$editpage->preview && empty( $editpage->save ) |
| 48 | + ) |
| 49 | + { |
| 50 | + $buttons['save'] = str_replace( |
| 51 | + '/>', 'disabled="disabled" />', $buttons['save'] |
| 52 | + ); |
| 53 | + $buttons['save'] = preg_replace( |
| 54 | + '/value="' . wfMsg( 'savearticle' ) . '"/i', |
| 55 | + 'value="' . wfMsg( 'forcepreview' ) . '"', |
| 56 | + $buttons['save'] |
| 57 | + ); |
36 | 58 | if( $buttons['live'] !== '' ) { |
37 | | - $buttons['preview'] = preg_replace( '/style="(.*?);?"/', 'style="$1; font-weight: bold;"', $buttons['preview'] ); #in case something else made it visible |
38 | | - $buttons['live'] = str_replace( '/>', 'style="font-weight: bold" />', $buttons['live'] ); |
| 59 | + $buttons['preview'] = preg_replace( |
| 60 | + '/style="(.*?);?"/', |
| 61 | + 'style="$1; font-weight: bold;"', |
| 62 | + $buttons['preview'] |
| 63 | + ); # in case something else made it visible |
| 64 | + $buttons['live'] = str_replace( |
| 65 | + '/>', |
| 66 | + 'style="font-weight: bold" />', |
| 67 | + $buttons['live'] |
| 68 | + ); |
39 | 69 | } else { |
40 | | - $buttons['preview'] = str_replace( '/>', 'style="font-weight: bold" />', $buttons['preview'] ); |
| 70 | + $buttons['preview'] = str_replace( |
| 71 | + '/>', |
| 72 | + 'style="font-weight: bold" />', |
| 73 | + $buttons['preview'] |
| 74 | + ); |
41 | 75 | } |
42 | 76 | } |
43 | 77 | return true; |
— | — | @@ -44,31 +78,49 @@ |
45 | 79 | |
46 | 80 | function efForcePreviewLivePreview( &$out, $sk = null ) { |
47 | 81 | global $wgUser, $wgRequest, $wgLivePreview, $wgTitle; |
48 | | - if(!$wgLivePreview || !$wgTitle->userCan('edit', true) ) |
| 82 | + if( !$wgLivePreview || !$wgTitle->userCan( 'edit', true ) ) { |
49 | 83 | return true; |
50 | | - if($wgUser->isAllowed('forcepreviewexempt') || !$wgUser->getBoolOption('uselivepreview') ) |
| 84 | + } |
| 85 | + if( |
| 86 | + $wgUser->isAllowed( 'forcepreviewexempt' ) || |
| 87 | + !$wgUser->getBoolOption( 'uselivepreview' ) |
| 88 | + ) |
| 89 | + { |
51 | 90 | return true; |
52 | | - if(!$wgRequest->getVal('action') == 'edit' || !$wgRequest->getVal('action') == 'submit') |
| 91 | + } |
| 92 | + if( |
| 93 | + !$wgRequest->getVal( 'action' ) == 'edit' || |
| 94 | + !$wgRequest->getVal( 'action' ) == 'submit' |
| 95 | + ) |
| 96 | + { |
53 | 97 | return true; |
54 | | - $out->addHTML("<script type=\"text/javascript\"> |
55 | | - var liveButton = document.getElementById('wpLivePreview'); |
56 | | - var msg = \"".wfMsg('savearticle')."\"; |
| 98 | + } |
| 99 | + $out->addHTML( |
| 100 | + "<script type=\"text/javascript\"> |
| 101 | + var liveButton = document.getElementById( 'wpLivePreview' ); |
| 102 | + var msg = \"" . wfMsg( 'savearticle' ) . "\"; |
57 | 103 | function enableSave() { |
58 | | - if(!liveButton) return; |
| 104 | + if( !liveButton ) { |
| 105 | + return; |
| 106 | + } |
59 | 107 | liveButton.style.fontWeight = 'normal'; |
60 | | - var previewButton = document.getElementById('wpPreview'); |
61 | | - if(previewButton) |
| 108 | + var previewButton = document.getElementById( 'wpPreview' ); |
| 109 | + if( previewButton ) { |
62 | 110 | previewButton.style.fontWeight = 'normal'; |
63 | | - var saveButton = document.getElementById('wpSave'); |
64 | | - if(!saveButton) return; |
| 111 | + } |
| 112 | + var saveButton = document.getElementById( 'wpSave' ); |
| 113 | + if( !saveButton ) { |
| 114 | + return; |
| 115 | + } |
65 | 116 | saveButton.disabled = false; |
66 | 117 | saveButton.value = msg; |
67 | 118 | } |
68 | | - if(window.addEventListener) { |
69 | | - liveButton.addEventListener('click', enableSave, false); |
70 | | - } else if(window.attachEvent) { |
71 | | - liveButton.attachEvent('onclick', enableSave); |
| 119 | + if( window.addEventListener ) { |
| 120 | + liveButton.addEventListener( 'click', enableSave, false ); |
| 121 | + } else if( window.attachEvent ) { |
| 122 | + liveButton.attachEvent( 'onclick', enableSave ); |
72 | 123 | } |
73 | | - </script>"); |
| 124 | + </script>" |
| 125 | + ); |
74 | 126 | return true; |
75 | 127 | } |