Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

* Fixing getTimestamp function.

* Moving each message class in its own file.
* New function fnEditWarning_getSection.
* Now anonymous users only get a message if there is a lock on the article/section.
  (showing an info message makes no sense, because there won't be a lock created
  for them).
* Because of that the extension now doesn't hide elements for anonymous users.
* Bugfixes in fnEditWarning_edit function.
* Smaller fixes in Messages.i18n.php
* New css style for messages.
* Change licence of unit tests.
  • Loading branch information...
commit d28a0f6d93bd55d15e5d12e373feadce060ddb1b 1 parent 78fd5df
Thomas David authored
View
14 EditWarning.class.php
@@ -89,9 +89,6 @@ public function load( $dbr ) {
// Build conditions for select operation.
$conditions = sprintf( "`article_id` = '%s'", $this->getArticleID() );
$conditions .= sprintf( " AND `timestamp` >= '%s'", $this->getTimestamp( TIMESTAMP_EXPIRED ) );
- if ( $this->getSection() != null ) {
- $conditions .= sprintf( " AND `section` = '%s'", $this->getSection() );
- }
$result = $dbr->select( "editwarning_locks", "*", $conditions );
// Create lock objects for every valid lock.
@@ -112,13 +109,20 @@ public function load( $dbr ) {
*/
public function getTimestamp( $type ) {
global $EditWarning_Timeout;
+
+ // Default timeout is 10 minutes.
+ if ( $EditWarning_Timeout <= 0 || $EditWarning_Timeout == "" || $EditWarning_Timeout == null ) {
+ $timeout = 10;
+ } else {
+ $timeout = $EditWarning_Timeout;
+ }
switch ( $type ) {
case TIMESTAMP_NEW:
- return mktime( date("H"), date("i") + $EditWarning_Timeout, date("s"), date("m"), date("d"), date("Y") );
+ return mktime( date("H"), date("i") + $timeout, date("s"), date("m"), date("d"), date("Y") );
break;
case TIMESTAMP_EXPIRED:
- return mktime( date("H"), date("i") - $EditWarning_Timeout, date("s"), date("m"), date("d"), date("Y") );
+ return mktime( date("H"), date("i") - $timeout, date("s"), date("m"), date("d"), date("Y") );
break;
default:
throw new InvalidTypeArgumentException( "Invalid argument for type. Use TIMESTAMP_NEW or TIMESTAMP_EXPIRED constant.");
View
223 EditWarning.php
@@ -30,18 +30,16 @@
if ( !defined( 'MEDIAWIKI' ) && !defined( 'EDITWARNING_UNITTEST' ) ) {
echo <<<EOT
-To install this extension, put the following line in LocalSettings.php:\n
-require_once "\$IP/extensions/EditWarning/EditWarning.php";\n\n
+<p>To install this extension, put the following line in LocalSettings.php:\n
+<pre>require_once "\$IP/extensions/EditWarning/EditWarning.php";</pre></p>\n\n
-See http://www.mediawiki.org/wiki/Extension:EditWarning for more information.
+<p>See <a href="http://www.mediawiki.org/wiki/Extension:EditWarning">http://www.mediawiki.org/wiki/Extension:EditWarning</a> for more information.</p>
EOT;
exit(1);
}
$extension_dir = dirname(__FILE__) . "/";
-require_once $extension_dir . 'EditWarningMessage.class.php';
-
$wgExtensionCredits['EditWarning'][] = array(
'name' => "EditWarning",
'author' => "Thomas David",
@@ -50,6 +48,7 @@
);
$wgAutoloadClasses['EditWarning'] = $extension_dir . 'EditWarning.class.php';
+$wgAutoloadClasses['EditWarningMsg'] = $extension_dir . 'EditWarningMsg.class.php';
$wgExtensionMessagesFiles['EditWarning'] = $extension_dir . 'Messages.i18n.php';
$wgExtensionFunctions[] = 'fnEditWarning_init';
@@ -58,10 +57,23 @@
}
// Assign hooks to functions
-$wgHooks['AlternateEdit'][] = array( 'fnEditWarning_edit', $editwarning ); // On article edit.
-$wgHooks['ArticleSave'][] = array( 'fnEditWarning_remove', $editwarning ); // On article save.
-$wgHooks['UserLogout'][] = array( 'fnEditWarning_logout', $editwarning ); // On user logout.
-$wgHooks['ArticleViewHeader'][] = array( 'fnEditWarning_abort', $editwarning ); // On editing abort.
+$wgHooks['AlternateEdit'][] = array( 'fnEditWarning_edit', $editwarning ); // On article edit.
+$wgHooks['ArticleSave'][] = array( 'fnEditWarning_remove', $editwarning ); // On article save.
+$wgHooks['UserLogout'][] = array( 'fnEditWarning_logout', $editwarning ); // On user logout.
+$wgHooks['ArticleViewHeader'][] = array( 'fnEditWarning_abort', $editwarning ); // On editing abort.
+
+/**
+ * Gets the section id from GET or POST
+ *
+ * @return int Section id.
+ */
+function fnEditWarning_getSection() {
+ if ( isset( $_GET['section'] ) && !isset( $_POST['wpSection'] ) ) {
+ return intval( $_GET['section'] );
+ } else {
+ return intval( $_POST['wpSection'] );
+ }
+}
/**
* Setup EditWarning extension
@@ -69,11 +81,13 @@
* @return boolean Returns always true.
*/
function fnEditWarning_init() {
- global $wgRequest, $wgOut, $EditWarning_OnlyEditor;
+ global $wgRequest, $wgOut, $wgUser, $EditWarning_OnlyEditor;
// Add CSS styles to header
- if ( ( $wgRequest->getVal('action') == 'edit' || $wgRequest->getVal('action') == 'submit' ) && $EditWarning_OnlyEditor != "false" ) {
- $wgOut->addHeadItem('edit_css', ' <link href="extensions/EditWarning/article_edit.css" rel="stylesheet" type="text/css" />');
+ if ( ( $wgRequest->getVal('action') == 'edit' || $wgRequest->getVal('action') == 'submit' )
+ && $EditWarning_OnlyEditor != "false"
+ && $wgUser->getID() >= 1 ) {
+ $wgOut->addHeadItem('edit_css', ' <link href="extensions/EditWarning/article_edit.css" rel="tylesheet" type="text/css" />');
}
$wgOut->addHeadItem('EditWarning', ' <link href="extensions/EditWarning/style.css" rel="stylesheet" type="text/css" />');
@@ -93,16 +107,16 @@ function fnEditWarning_init() {
* environment, else true.
*/
function fnEditWarning_edit(&$ew, &$editpage) {
- global $wgRequest, $wgUser, $wgScriptPath, $wgScriptExtension;
+ global $wgUser, $wgScriptPath, $wgScriptExtension, $PHP_SELF;
- // Abort on nonexisting pages or anonymous users.
- if ( $editpage->mArticle->getID() < 1 || $wgUser->getID() < 1 ) {
+ // Abort on nonexisting pages
+ if ( $editpage->mArticle->getID() < 1 ) {
return true;
}
$ew->setUserID( $wgUser->getID() );
$ew->setArticleID( $editpage->mArticle->getID() );
- $section = (int) $wgRequest->getVal( 'section' );
+ $section = fnEditWarning_getSection();
$dbr =& wfGetDB( DB_SLAVE );
$dbw =& wfGetDB( DB_MASTER );
$msg_params = array();
@@ -114,7 +128,7 @@ function fnEditWarning_edit(&$ew, &$editpage) {
$article_title = $editpage->mArticle->mTitle->getNsText() . ":" . $editpage->mArticle->mTitle->getPartialURL();
}
- $url = $wgScriptPath . "/index" . $wgScriptExtension . "?title=" . $article_title;
+ $url = $PHP_SELF . "?title=" . $article_title . "&cancel=true";
// Check request values
if ( $section > 0 ) {
@@ -123,7 +137,8 @@ function fnEditWarning_edit(&$ew, &$editpage) {
$ew->load( $dbr );
if ( $ew->anyLock() ) {
- if ( $lock = $ew->sectionLock() ) {
+ $lock = $ew->sectionLock();
+ if ( $lock ) {
if ( $ew->sectionUserLock() ) {
// User itself has lock on that section.
$ew->updateLock( $dbw, $wgUser->getID(), $wgUser->getName(), $section );
@@ -131,7 +146,7 @@ function fnEditWarning_edit(&$ew, &$editpage) {
// Show info message with updated timestamp.
$msg_params[] = date( "Y-m-d", $ew->getTimestamp( TIMESTAMP_NEW ) );
$msg_params[] = date( "H:i", $ew->getTimestamp( TIMESTAMP_NEW ) );
- $msg = EWMsg::getInstance( "SectionNotice", $url, $msg_params );
+ $msg = EditWarningMsg::getInstance( "SectionNotice", $url, $msg_params );
$msg->show();
unset( $ew );
unset( $msg );
@@ -141,7 +156,7 @@ function fnEditWarning_edit(&$ew, &$editpage) {
} else {
return true;
}
- } else {
+ } elseif( $lock->getSection() == $section ) {
// Someone else is already working on this section.
// Calculate time to wait
@@ -156,12 +171,12 @@ function fnEditWarning_edit(&$ew, &$editpage) {
// Use minutes or seconds string?
if ($time_to_wait > 1 || $difference > 60) {
- $msg_params[] = wfMsg( 'minutes' );
+ $msg_params[] = wfMsg( 'ew-minutes' );
} else {
- $msg_params[] = wfMsg( 'seconds' );
+ $msg_params[] = wfMsg( 'ew-seconds' );
}
- $msg = EWMsg::getInstance( "SectionWarning", $url, $msg_params );
+ $msg = EditWarningMsg::getInstance( "SectionWarning", $url, $msg_params );
$msg->show();
unset( $ew );
unset( $msg );
@@ -171,6 +186,25 @@ function fnEditWarning_edit(&$ew, &$editpage) {
} else {
return true;
}
+ } else {
+ // Someone else is working on another section.
+
+ // Don't save locks for anonymous users
+ if ( $wgUser->getID() < 1 ) {
+ return true;
+ }
+
+ $ew->saveLock( $dbw, $wgUser->getID(), $wgUser->getName(), $section );
+
+ // Show info message.
+ $msg_params[] = date( "Y-m-d", $ew->getTimestamp( TIMESTAMP_NEW ) );
+ $msg_params[] = date( "H:i", $ew->getTimestamp( TIMESTAMP_NEW ) );
+ $msg = EditWarningMsg::getInstance( "SectionNotice", $url, $msg_params );
+ $msg->show();
+ unset( $ew );
+ unset( $msg );
+
+ return true;
}
} else {
// Someone else is working on the whole article.
@@ -179,25 +213,20 @@ function fnEditWarning_edit(&$ew, &$editpage) {
// Calculate time to wait
$difference = floatval( abs( time() - $lock->getTimestamp() ) );
$time_to_wait = bcdiv( $difference, 60, 0 );
-
- // Show warning.
- $msg = new EditWarningMessage( 'warning' );
- $msg->setLabel( 'MSG', 'ew-warning-article' );
- $msg->setLabel( 'URL', $url );
- $msg->setLabel( 'BUTTON_CANCEL', 'ew-button-cancel' );
- $msg->addValue( $lock->getUserName() );
- $msg->addValue( date( "Y-m-d", $lock->getTimestamp() ) );
- $msg->addValue( date( "H:i", $lock->getTimestamp() ) );
- $msg->addValue( $time_to_wait );
-
+ $msg_params[] = $lock->getUserName();
+ $msg_params[] = date( "Y-m-d", $lock->getTimestamp() );
+ $msg_params[] = date( "H:i", $lock->getTimestamp() );
+ $msg_params[] = $time_to_wait;
+
// Use minutes or seconds string?
if ($time_to_wait > 1 || $difference > 60) {
- $msg->addValue( wfMsg( 'minutes' ) );
+ $msg_params[] = wfMsg( 'ew-minutes' );
} else {
- $msg->addValue( wfMsg( 'seconds' ) );
+ $msg_params[] = wfMsg( 'ew-seconds' );
}
- $msg->addValue( wfMsg( 'ew-leave' ) );
+ // Show warning.
+ $msg = EditWarningMsg::getInstance( "ArticleWarning", $url, $msg_params );
$msg->show();
unset( $ew );
unset( $msg );
@@ -209,19 +238,20 @@ function fnEditWarning_edit(&$ew, &$editpage) {
}
}
} else {
+ // Don't save locks for anonymous users
+ if ( $wgUser->getID() < 1 ) {
+ return true;
+ }
+
$ew->saveLock( $dbw, $wgUser->getID(), $wgUser->getName(), $section );
// Show info message.
-// $msg = new EditWarningMessage( 'notice' );
-// $msg->setLabel( 'MSG', 'ew-notice-section' );
-// $msg->setLabel( 'URL', $url );
-// $msg->setLabel( 'BUTTON_CANCEL', 'ew-button-cancel' );
-// $msg->addValue( date( "Y-m-d", $ew->getTimestamp( TIMESTAMP_NEW ) ) );
-// $msg->addValue( date( "H:i", $ew->getTimestamp( TIMESTAMP_NEW ) ) );
-// $msg->addValue( wfMsg( 'ew-leave' ) );
-// $msg->show();
-// unset( $ew );
-// unset( $msg );
+ $msg_params[] = date( "Y-m-d", $ew->getTimestamp( TIMESTAMP_NEW ) );
+ $msg_params[] = date( "H:i", $ew->getTimestamp( TIMESTAMP_NEW ) );
+ $msg = EditWarningMsg::getInstance( "SectionNotice", $url, $msg_params );
+ $msg->show();
+ unset( $ew );
+ unset( $msg );
if ( defined( 'EDITWARNING_UNITTEST' ) ) {
return EDIT_SECTION_NEW;
@@ -234,22 +264,19 @@ function fnEditWarning_edit(&$ew, &$editpage) {
$ew->load( $dbr );
if ( $ew->anyLock() ) {
- if ( $lock = $ew->articleLock() ) {
+ $lock = $ew->articleLock();
+ if ( $lock ) {
if ( $ew->articleUserLock() ) {
// User itself has lock on that article.
$ew->updateLock( $dbw, $wgUser->getID(), $wgUser->getName() );
// Show info message with updated timestamp.
-// $msg = new EditWarningMessage( 'notice' );
-// $msg->setLabel( 'MSG', 'ew-notice-article');
-// $msg->setLabel( 'URL', $url );
-// $msg->setLabel( 'BUTTON_CANCEL', 'ew-button-cancel' );
-// $msg->addValue( date( "Y-m-d", $ew->getTimestamp( TIMESTAMP_NEW ) ) );
-// $msg->addValue( date( "H:i", $ew->getTimestamp( TIMESTAMP_NEW ) ) );
-// $msg->addValue( wfMsg( 'ew-leave' ) );
-// $msg->show();
-// unset( $ew );
-// unset( $msg );
+ $msg_params[] = date( "Y-m-d", $ew->getTimestamp( TIMESTAMP_NEW ) );
+ $msg_params[] = date( "H:i", $ew->getTimestamp( TIMESTAMP_NEW ) );
+ $msg = EditWarningMsg::getInstance( "ArticleNotice", $url, $msg_params );
+ $msg->show();
+ unset( $ew );
+ unset( $msg );
if ( defined( 'EDITWARNING_UNITTEST' ) ) {
return EDIT_ARTICLE_USER;
@@ -262,28 +289,23 @@ function fnEditWarning_edit(&$ew, &$editpage) {
// Calculate time to wait
$difference = floatval( abs( time() - $lock->getTimestamp() ) );
$time_to_wait = bcdiv( $difference, 60, 0 );
+ $msg_params[] = $lock->getUserName();
+ $msg_params[] = date( "Y-m-d", $lock->getTimestamp() );
+ $msg_params[] = date( "H:i", $lock->getTimestamp() );
+ $msg_params[] = $time_to_wait;
+
+ // Use minutes or seconds string?
+ if ($time_to_wait > 1 || $difference > 60) {
+ $msg_params[] = wfMsg( 'ew-minutes' );
+ } else {
+ $msg_params[] = wfMsg( 'ew-seconds' );
+ }
-// // Show warning.
-// $msg = new EditWarningMessage( 'warning' );
-// $msg->setLabel( 'MSG', 'ew-warning-article' );
-// $msg->setLabel( 'URL', $url );
-// $msg->setLabel( 'BUTTON_CANCEL', 'ew-button-cancel' );
-// $msg->addValue( $lock->getUserName() );
-// $msg->addValue( date( "Y-m-d", $lock->getTimestamp() ) );
-// $msg->addValue( date( "H:i", $lock->getTimestamp() ) );
-// $msg->addValue( $time_to_wait );
-//
-// // Use minutes or seconds string?
-// if ($time_to_wait > 1 || $difference > 60) {
-// $msg->addValue( wfMsg( 'minutes' ) );
-// } else {
-// $msg->addValue( wfMsg( 'seconds' ) );
-// }
-//
-// $msg->addValue( 'ew-leave' );
-// $msg->show();
-// unset( $ew );
-// unset( $msg);
+ // Show warning
+ $msg = EditWarningMsg::getInstance( "ArticleWarning", $url, $msg_params );
+ $msg->show();
+ unset( $ew );
+ unset( $msg);
if ( defined( 'EDITWARNING_UNITTEST' ) ) {
return EDIT_ARTICLE_OTHER;
@@ -298,25 +320,19 @@ function fnEditWarning_edit(&$ew, &$editpage) {
// Calculate time to wait
$difference = floatval( abs( time() - $lock->getTimestamp() ) );
$time_to_wait = bcdiv( $difference, 60, 0 );
+ $msg_params[] = $time_to_wait;
+
+ // Use minutes or seconds string?
+ if ($time_to_wait > 1 || $difference > 60) {
+ $msg_params[] = wfMsg( 'ew-minutes' );
+ } else {
+ $msg_params[] = wfMsg( 'ew-seconds' );
+ }
-// // Show warning.
-// $msg = new EditWarningMessage( 'warning' );
-// $msg->setLabel( 'MSG', 'ew-warning-sectionedit' );
-// $msg->setLabel( 'URL', $url );
-// $msg->setLabel( 'BUTTON_CANCEL' );
-// $msg->addValue( $time_to_wait );
-//
-// // Use minutes or seconds string?
-// if ($time_to_wait > 1 || $difference > 60) {
-// $msg->addValue( wfMsg( 'minutes' ) );
-// } else {
-// $msg->addValue( wfMsg( 'seconds' ) );
-// }
-//
-// $msg->addValue( 'ew-leave' );
-// $msg->show();
-// unset( $ew );
-// unset( $msg );
+ $msg = EditWarningMsg::getInstance( "ArticleSectionWarning", $url, $msg_params );
+ $msg->show();
+ unset( $ew );
+ unset( $msg );
if ( defined( 'EDITWARNING_UNITTEST' ) ) {
return EDIT_ARTICLE_SECTION;
@@ -326,12 +342,18 @@ function fnEditWarning_edit(&$ew, &$editpage) {
}
} else {
// There are no locks.
+
+ // Don't save locks for anonymous users.
+ if ( $wgUser->getID() < 1 ) {
+ return true;
+ }
+
$ew->saveLock( $dbw, $wgUser->getID(), $wgUser->getName() );
// Show info message.
$msg_params[] = date( "Y-m-d", $ew->getTimestamp( TIMESTAMP_NEW ) );
$msg_params[] = date( "H:i", $ew->getTimestamp( TIMESTAMP_NEW ) );
- $msg = EWMsg::getInstance( "ArticleNotice", $url, $msg_params );
+ $msg = EditWarningMsg::getInstance( "ArticleNotice", $url, $msg_params );
$msg->show();
unset( $ew );
unset( $msg );
@@ -382,6 +404,11 @@ function fnEditWarning_abort( $ew, &$article, &$outputDone, &$pcache ) {
$dbw =& wfGetDB( DB_MASTER );
$ew->setArticleID( $article->getID() );
$ew->removeLock( $dbw, $wgUser->getID(), $wgUser->getName() );
+
+ $msg = EditWarningMsg::getInstance( "Cancel" );
+ $msg->show();
+ unset( $ew );
+ unset( $msg );
}
return true;
View
38 EditWarningCancelMsg.class.php
@@ -0,0 +1,38 @@
+<?php
+
+/**
+ * Implementation of EditWarningCancelMsg class.
+ *
+ * This file is part of the MediaWiki extension EditWarning. It contains
+ * the EditWarningMessage subclass EditWarningCancelMessage representing
+ * the cancel message.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @author Thomas David <ThomasDavid@gmx.de>
+ * @copyright 2007-2009 Thomas David <ThomasDavid@gmx.de>
+ * @license http://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2.0 or later
+ * @version 0.4-prealpha
+ * @category Extensions
+ * @package EditWarning
+ */
+
+require_once( "EditWarningMessage.class.php" );
+
+class EditWarningCancelMsg extends EditWarningMessage {
+ public function __construct( $path ) {
+ $this->loadTemplate( $path . "/canceled.html" );
+ $this->addLabel( 'CANCELED', wfMsg( 'ew-canceled' ) );
+ }
+}
View
39 EditWarningInfoMsg.class.php
@@ -0,0 +1,39 @@
+<?php
+
+/**
+ * Implementation of EditWarningInfoMsg class.
+ *
+ * This file is part of the MediaWiki extension EditWarning. It contains
+ * the EditWarningMessage subclass EditWarningInfoMessage representing a
+ * info message.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @author Thomas David <ThomasDavid@gmx.de>
+ * @copyright 2007-2009 Thomas David <ThomasDavid@gmx.de>
+ * @license http://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2.0 or later
+ * @version 0.4-prealpha
+ * @category Extensions
+ * @package EditWarning
+ */
+
+require_once( "EditWarningMessage.class.php" );
+
+class EditWarningInfoMsg extends EditWarningMessage {
+ public function __construct( $path, $url ) {
+ $this->loadTemplate( $path . "/notice.html" );
+ $this->addLabel( 'URL', $url );
+ $this->addLabel( 'BUTTON_CANCEL', wfMsg( 'ew-button-cancel' ) );
+ }
+}
View
226 EditWarningMessage.class.php
@@ -34,7 +34,7 @@
class LoadTemplateException extends Exception {}
class NoTemplateContentFoundException extends Exception {}
-abstract class EWMessage {
+abstract class EditWarningMessage {
private $_content;
private $_labels = array();
@@ -106,228 +106,12 @@ public function show() {
}
}
-class EWInfoMessage extends EWMessage {
- public function __construct( $path, $url ) {
- $this->loadTemplate( $path . "/notice.html" );
- $this->addLabel( 'URL', $url );
- $this->addLabel( 'BUTTON_CANCEL', wfMsg( 'ew-button-cancel' ) );
- }
-}
-class EWCancelMessage extends EWMessage {
- public function __construct( $path ) {
- $this->loadTemplate( $path . "/cancel.html" );
- }
-}
-class EWWarningMessage extends EWMessage {
- public function __construct( $path, $url ) {
- $this->loadTemplate( $path . "/warning.html" );
- $this->addLabel( 'URL', $url );
- $this->addLabel( 'BUTTON_CANCEL', wfMsg( 'ew-button-cancel' ) );
- }
-}
-interface EWMessageFactory {
- public static function getInstance( $type, $url, $params );
-}
-class EWMsg implements EWMessageFactory {
- private static $instance = array();
-
- private function __construct() {}
-
- public static function getInstance( $type, $url, $params ) {
- global $IP;
-
- $path = $IP . "/extensions/EditWarning/templates";
-
- if ( $self->instance[$type] === null ) {
- switch ( $type ) {
- case "ArticleNotice":
- $params[] = wfMsg( 'ew-leave' );
- self::$instance[$type] = new EWInfoMessage( $path, $url );
- self::$instance[$type]->setMsg( 'ew-notice-article', $params );
- break;
- case "ArticleWarning":
- $params[] = wfMsg( 'ew-leave' );
- self::$instance[$type] = new EWWarningMessage( $path, $url );
- self::$instance[$type]->setMsg( 'ew-warning-article', $params );
- break;
- case "ArticleSectionWarning":
- $params[] = wfMsg( 'ew-leave' );
- self::$instance[$type] = new EWWarningMessage( $path, $url );
- self::$instance[$type]->setMsg( 'ew-warning-sectionedit', $params );
- break;
- case "SectionNotice":
- $params[] = wfMsg( 'ew-leave' );
- self::$instance[$type] = new EWInfoMessage( $path, $url );
- self::$instance[$type]->setMsg( 'ew-notice-section', $params );
- break;
- case "SectionWarning":
- $params[] = wfMsg( 'ew-leave' );
- self::$instance[$type] = new EWWarningMessage( $path, $url );
- self::$instance[$type]->setMsg( 'ew-warning-section', $params );
- break;
- case "Cancel":
- self::$instance[$type] = new EWCancelMessage( $path );
- self::$instance[$type]->setMsg( 'ew-canceled' );
- break;
- default:
- throw new IllegalArgumentException( "Unknown message type." );
- }
- }
-
- return self::$instance[$type];
- }
-}
-//class EditWarningMessage {
-// /**
-// * @access private
-// * @var string Holds the type of the message (eg. notice). It is used to
-// * determine the template file to load.
-// */
-// private $_msg_type;
-//
-// /**
-// * @access private
-// * @var array Array of labels and associated values.
-// */
-// private $_labels = array();
-//
-// /**
-// * @access private
-// * @var array Array of values used in message strings.
-// */
-// private $_values = array();
-//
-// /**
-// * @access private
-// * @var string Template content read from template file.
-// */
-// private $_tpl_content;
-//
-// /**
-// * @access public
-// * @param string $msg_type Type of message (eg. notice).
-// */
-// public function __construct( $msg_type ) {
-// $this->setMsgType( strtolower( $msg_type ) );
-// }
-//
-// /**
-// * @access public
-// * @param string $msg_type Type of message (eg. notice).
-// */
-// public function setMsgType( $msg_type ) {
-// $this->_msg_type = $msg_type;
-// }
-//
-// /**
-// * @access public
-// * @return string Type of message (eg. notice).
-// */
-// public function getMsgType() {
-// return $this->_msg_type;
-// }
-//
-// /**
-// * @access public
-// * @param string $label Label that should be replaced in template.
-// * @param mixed $value Associated value.
-// */
-// public function setLabel( $label, $value ) {
-// $this->_labels[$label] = $value;
-// }
-//
-// /**
-// * @access public
-// * @return array Array of labels and associated values.
-// */
-// public function getLabels() {
-// return $this->_labels;
-// }
-//
-// /**
-// * @access public
-// * @param mixed $value Value that should be inserted in message string.
-// */
-// public function addValue( $value ) {
-// $this->_values[] = $value;
-// }
-//
-// /**
-// * @access public
-// * @return array Array of values used in message strings.
-// */
-// public function getValues() {
-// return $this->values;
-// }
-//
-// /**
-// * @access public
-// * @param string $content Template content.
-// */
-// public function setContent( $content ) {
-// $this->_tpl_content = $content;
-// }
-//
-// /**
-// * @access public
-// * @param string Template content.
-// */
-// public function getContent() {
-// return $this->_tpl_content;
-// }
-//
-// /**
-// * Loads template content from file.
-// *
-// * @access public
-// * @param string $file_name Name of the template file.
-// */
-// public function loadTemplate( $file_name ) {
-// try {
-// $file = fopen( $file_name, "r" );
-// $this->setContent( fread( $file, filesize( $file_name ) ) );
-// } catch( Exception $e ) {
-// throw new LoadTemplateException( $e );
-// }
-// fclose( $file );
-// }
-//
-// /**
-// * Replaces labels in template content with associated values.
-// *
-// * @access public
-// */
-// public function processTemplate() {
-// if ( $this->getContent() == null ) {
-// throw new NoTemplateContentFoundException(
-// "No template content found. You should load a template first."
-// );
-// }
-//
-// foreach( $this->getLabels() as $label => $value ) {
-// $this->setContent( preg_replace(
-// "/{{{" . $label . "}}}/",
-// wfMsgReal( $value, $this->getValues(), true ),
-// $this->getContent()
-// ) );
-// }
-// }
-//
-// /**
-// * Output the HTML code.
-// *
-// * @access public
-// */
-// public function show() {
-// global $IP, $wgOut;
-//
-// $this->loadTemplate( $IP . "/extensions/EditWarning/templates/" . $this->getMsgType() . ".html" );
-// $this->processTemplate();
-// $wgOut->addHtml( $this->getContent() );
-// }
-//}
+
+
+
+
View
87 EditWarningMsg.class.php
@@ -0,0 +1,87 @@
+<?php
+
+/**
+ * Implementation of EditWarningMsg class.
+ *
+ * This file is part of the MediaWiki extension EditWarning. It contains
+ * the implementation of EditWarningMsg class responsible for creating
+ * EditWarningMessage subclasses.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @author Thomas David <ThomasDavid@gmx.de>
+ * @copyright 2007-2009 Thomas David <ThomasDavid@gmx.de>
+ * @license http://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2.0 or later
+ * @version 0.4-prealpha
+ * @category Extensions
+ * @package EditWarning
+ */
+
+require_once( "EditWarningMsgFactory.class.php" );
+require_once( "EditWarningInfoMsg.class.php" );
+require_once( "EditWarningWarnMsg.class.php" );
+require_once( "EditWarningCancelMsg.class.php" );
+
+/**
+ * Singleton factory for EditWarningMessage subclasses.
+ */
+class EditWarningMsg implements EditWarningMsgFactory {
+ private static $instance = array();
+
+ private function __construct() {}
+ private function __clone() {}
+
+ public static function getInstance( $type, $url = null, $params = null ) {
+ global $IP;
+
+ $path = $IP . "/extensions/EditWarning/templates";
+
+ if ( $self->instance[$type] === null ) {
+ switch ( $type ) {
+ case "ArticleNotice":
+ $params[] = wfMsg( 'ew-leave' );
+ self::$instance[$type] = new EditWarningInfoMsg( $path, $url );
+ self::$instance[$type]->setMsg( 'ew-notice-article', $params );
+ break;
+ case "ArticleWarning":
+ $params[] = wfMsg( 'ew-leave' );
+ self::$instance[$type] = new EditWarningWarnMsg( $path, $url );
+ self::$instance[$type]->setMsg( 'ew-warning-article', $params );
+ break;
+ case "ArticleSectionWarning":
+ $params[] = wfMsg( 'ew-leave' );
+ self::$instance[$type] = new EditWarningWarnMsg( $path, $url );
+ self::$instance[$type]->setMsg( 'ew-warning-sectionedit', $params );
+ break;
+ case "SectionNotice":
+ $params[] = wfMsg( 'ew-leave' );
+ self::$instance[$type] = new EditWarningInfoMsg( $path, $url );
+ self::$instance[$type]->setMsg( 'ew-notice-section', $params );
+ break;
+ case "SectionWarning":
+ $params[] = wfMsg( 'ew-leave' );
+ self::$instance[$type] = new EditWarningWarnMsg( $path, $url );
+ self::$instance[$type]->setMsg( 'ew-warning-section', $params );
+ break;
+ case "Cancel":
+ self::$instance[$type] = new EditWarningCancelMsg( $path );
+ break;
+ default:
+ throw new IllegalArgumentException( "Unknown message type." );
+ }
+ }
+
+ return self::$instance[$type];
+ }
+}
View
32 EditWarningMsgFactory.class.php
@@ -0,0 +1,32 @@
+<?php
+
+/**
+ * EditWarningMsgFactory interface
+ *
+ * This file is part of the MediaWiki extension EditWarning. It contains
+ * the interface for EditWarningMessage subclass factories.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @author Thomas David <ThomasDavid@gmx.de>
+ * @copyright 2007-2009 Thomas David <ThomasDavid@gmx.de>
+ * @license http://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2.0 or later
+ * @version 0.4-prealpha
+ * @category Extensions
+ * @package EditWarning
+ */
+
+interface EditWarningMsgFactory {
+ public static function getInstance( $type, $url = null, $params = null );
+}
View
39 EditWarningWarnMsg.class.php
@@ -0,0 +1,39 @@
+<?php
+
+/**
+ * Implementation of EditWarningWarnMsg class.
+ *
+ * This file is part of the MediaWiki extension EditWarning. It contains
+ * the EditWarningMessage subclass EditWarningWarnMessage representing a
+ * warning message.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @author Thomas David <ThomasDavid@gmx.de>
+ * @copyright 2007-2009 Thomas David <ThomasDavid@gmx.de>
+ * @license http://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2.0 or later
+ * @version 0.4-prealpha
+ * @category Extensions
+ * @package EditWarning
+ */
+
+require_once( "EditWarningMessage.class.php" );
+
+class EditWarningWarnMsg extends EditWarningMessage {
+ public function __construct( $path, $url ) {
+ $this->loadTemplate( $path . "/warning.html" );
+ $this->addLabel( 'URL', $url );
+ $this->addLabel( 'BUTTON_CANCEL', wfMsg( 'ew-button-cancel' ) );
+ }
+}
View
4 Messages.i18n.php
@@ -61,7 +61,7 @@
'ew-warning-section' => "User <strong>$1</strong> opened this section for editing on <strong>$2 $3</strong>. " .
"You shouldn't make any changes for the next <strong>$4 $5</strong> to avoid edit conflicts.<br />$6",
'ew-warning-sectionedit' => "One or more sections of this article are edited currently. " .
- "Please edit a specific section or wait $1 $2 for bigger changes of this article, to avoid edit conflicts.<br />$3",
+ "Please edit a specific section or wait <strong>$1 $2</strong> for bigger changes of this article, to avoid edit conflicts.<br />$3",
'ew-leave' => "You can leave this screen by clicking <em>Cancel</em>.",
'ew-canceled' => "Canceled editing.",
'ew-minute' => "minute",
@@ -102,7 +102,7 @@
'ew-warning-section' => "User <strong>$1</strong> opened this section for editing on <strong>$2 $3</strong>. " .
"Vous devriez eviter de faire des modifications jusqu'au <strong>$4 $5</strong>, afin d'eviter des conflits de version.<br />$6",
'ew-warning-sectionedit' => "One or more sections of this article are edited currently. " .
- "Please edit a specific section or wait $1 $2 for bigger changes of this article, to avoid edit conflicts.<br />$3",
+ "Please edit a specific section or wait <strong>$1 $2</strong> for bigger changes of this article, to avoid edit conflicts.<br />$3",
'ew-leave' => "Vous pouvez quitter cette page en cliquant sur le bouton <em>Annuler</em>.",
'ew-canceled' => "Modification interrompue.",
'ew-minute' => "minute",
View
10 style.css
@@ -26,17 +26,17 @@
*/
.note {
- background: #dfd;
+ text-align: center;
+ background: #ddffdd;
padding: .5em;
margin: 1em 0 1em 0;
- border-top: 1px #bdb dotted;
- border-bottom: 1px #bdb dotted;
+ border: 2px solid #008000;
}
.warning {
+ text-align: center;
background: #fdd;
padding: .5em;
margin: 1em 0 1em 0;
- border-top: 1px #dbb dotted;
- border-bottom: 1px #dbb dotted;
+ border: 2px solid #b80000;
}
View
3  templates/notice.html
@@ -1,7 +1,6 @@
<div class="note">
- <p>{{{MSG}}}</p>
+ <p style="text-align: left;">{{{MSG}}}</p>
<p><form action="{{{URL}}}" method="post">
- <input type="hidden" name="cancel" value="true" />
<input type="submit" value="{{{BUTTON_CANCEL}}}" /></form></p>
</div>
View
5 templates/warning.html
@@ -1,7 +1,6 @@
<div class="warning">
- <p>{{{MSG}}}</p>
+ <p style="text-align: left">{{{MSG}}}</p>
- <p><form action="{{{URL}}}" method="post">
- <input type="hidden" name="cancel" value="true" />
+ <p style="text-align: center;"><form action="{{{URL}}}" method="post">
<input type="submit" value="{{{BUTTON_CANCEL}}}" /></form></p>
</div>
View
11 tests/AllTests.php
@@ -4,7 +4,7 @@
* SimpleTest testgroup: All tests.
*
* This file is part of the MediaWiki extension EditWarning. It contains
- * all SimpleTest unit tests.
+ * a SimpleTest testsuite running all EditWarning unit tests.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -21,7 +21,7 @@
*
* @author Thomas David <ThomasDavid@gmx.de>
* @copyright 2007-2009 Thomas David <ThomasDavid@gmx.de>
- * @license http://www.gnu.org/licenses/gpl-howto.html GNU AGPL 3.0 or later
+ * @license http://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2.0 or later
* @version 0.4-prealpha
* @category Extensions
* @package EditWarning
@@ -32,6 +32,11 @@
$suite = &new TestSuite( "All EditWarning Tests" );
$suite->addTestFile( "EditWarningClassTest.php" );
$suite->addTestFile( "EditWarningHookTest.php" );
-$suite->run(new HtmlReporter());
+
+if ( isset( $_SERVER['SERVER_SOFTWARE'] ) ) {
+ $suite->run( new HtmlReporter() );
+} else {
+ $suite->run( new TextReporter() );
+}
?>
View
2  tests/EditWarningClassTest.php
@@ -21,7 +21,7 @@
*
* @author Thomas David <ThomasDavid@gmx.de>
* @copyright 2007-2009 Thomas David <ThomasDavid@gmx.de>
- * @license http://www.gnu.org/licenses/gpl-howto.html GNU AGPL 3.0 or later
+ * @license http://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2.0 or later
* @version 0.4-prealpha
* @category Extensions
* @package EditWarning
View
2  tests/EditWarningHookTest.php
@@ -21,7 +21,7 @@
*
* @author Thomas David <ThomasDavid@gmx.de>
* @copyright 2007-2009 Thomas David <ThomasDavid@gmx.de>
- * @license http://www.gnu.org/licenses/gpl-howto.html GNU AGPL 3.0 or later
+ * @license http://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2.0 or later
* @version 0.4-prealpha
* @category Extensions
* @package EditWarning
View
2  tests/EditWarningWebTest.php
@@ -21,7 +21,7 @@
*
* @author Thomas David <ThomasDavid@gmx.de>
* @copyright 2007-2009 Thomas David <ThomasDavid@gmx.de>
- * @license http://www.gnu.org/licenses/gpl-howto.html GNU AGPL 3.0 or later
+ * @license http://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2.0 or later
* @version 0.4-prealpha
* @category Extensions
* @package EditWarning
View
2  tests/Mock_DatabaseConnection.php
@@ -21,7 +21,7 @@
*
* @author Thomas David <ThomasDavid@gmx.de>
* @copyright 2007-2009 Thomas David <ThomasDavid@gmx.de>
- * @license http://www.gnu.org/licenses/gpl-howto.html GNU AGPL 3.0 or later
+ * @license http://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2.0 or later
* @version 0.4-prealpha
* @category Extensions
* @package EditWarning
Please sign in to comment.
Something went wrong with that request. Please try again.