r85215 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r85214‎ | r85215 | r85216 >
Date:22:24, 2 April 2011
Author:ashley
Status:deferred
Tags:
Comment:
ForcePreview: coding style tweaks, broke some long lines, added docs
Modified paths:
  • /trunk/extensions/ForcePreview/ForcePreview.i18n.php (modified) (history)
  • /trunk/extensions/ForcePreview/ForcePreview.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ForcePreview/ForcePreview.i18n.php
@@ -9,10 +9,10 @@
1010 $messages = array();
1111
1212 /** English
13 - @author Ryan Schmidt
 13+ * @author Ryan Schmidt
1414 */
1515 $messages['en'] = array(
16 - 'forcepreview' => 'Save page (use preview first)',
 16+ 'forcepreview' => 'Save page (use preview first)',
1717 'forcepreview-desc' => 'Force preview for unprivileged users',
1818 'right-forcepreviewexempt' => 'May save without using Show preview',
1919 );
Index: trunk/extensions/ForcePreview/ForcePreview.php
@@ -1,13 +1,21 @@
22 <?php
33 /**
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+ */
613
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 );
1017 }
1118
 19+// Extension credits that will show up on Special:Version
1220 $wgExtensionCredits['other'][] = array(
1321 'path' => __FILE__,
1422 'name' => 'Force Preview',
@@ -17,9 +25,14 @@
1826 'url' => 'http://www.mediawiki.org/wiki/Extension:ForcePreview',
1927 );
2028
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
2335 $wgAvailableRights[] = 'forcepreviewexempt';
 36+
2437 $wgHooks['EditPageBeforeEditButtons'][] = 'efForcePreview';
2538 $wgHooks['BeforePageDisplay'][] = 'efForcePreviewLivePreview';
2639
@@ -28,15 +41,36 @@
2942
3043 function efForcePreview( &$editpage, &$buttons ) {
3144 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+ );
3658 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+ );
3969 } 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+ );
4175 }
4276 }
4377 return true;
@@ -44,31 +78,49 @@
4579
4680 function efForcePreviewLivePreview( &$out, $sk = null ) {
4781 global $wgUser, $wgRequest, $wgLivePreview, $wgTitle;
48 - if(!$wgLivePreview || !$wgTitle->userCan('edit', true) )
 82+ if( !$wgLivePreview || !$wgTitle->userCan( 'edit', true ) ) {
4983 return true;
50 - if($wgUser->isAllowed('forcepreviewexempt') || !$wgUser->getBoolOption('uselivepreview') )
 84+ }
 85+ if(
 86+ $wgUser->isAllowed( 'forcepreviewexempt' ) ||
 87+ !$wgUser->getBoolOption( 'uselivepreview' )
 88+ )
 89+ {
5190 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+ {
5397 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' ) . "\";
57103 function enableSave() {
58 - if(!liveButton) return;
 104+ if( !liveButton ) {
 105+ return;
 106+ }
59107 liveButton.style.fontWeight = 'normal';
60 - var previewButton = document.getElementById('wpPreview');
61 - if(previewButton)
 108+ var previewButton = document.getElementById( 'wpPreview' );
 109+ if( previewButton ) {
62110 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+ }
65116 saveButton.disabled = false;
66117 saveButton.value = msg;
67118 }
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 );
72123 }
73 - </script>");
 124+ </script>"
 125+ );
74126 return true;
75127 }

Status & tagging log