Hypergrove has uploaded a new change for review.
https://gerrit.wikimedia.org/r/51843
Change subject: initial load
......................................................................
initial load
Change-Id: I277c1c153aeda2e6184d0cdf3dc64eda62e186f6
---
A .gitreview
A PopupPages.i18n.php
A PopupPages.php
A resources/PopupPages.css
A resources/PopupPages.js
5 files changed, 346 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/PopupPages
refs/changes/43/51843/1
diff --git a/.gitreview b/.gitreview
new file mode 100644
index 0000000..3f064bc
--- /dev/null
+++ b/.gitreview
@@ -0,0 +1,5 @@
+host=gerrit.wikimedia.org
+port=29418
+project=mediawiki/extensions/PopupPages.git
+defaultbranch=master
+
diff --git a/PopupPages.i18n.php b/PopupPages.i18n.php
new file mode 100644
index 0000000..a9ebd31
--- /dev/null
+++ b/PopupPages.i18n.php
@@ -0,0 +1,36 @@
+<?php
+/**
+ * Internationalisation file for the PopupPages extension
+ *
+ * @file
+ * @ingroup Extensions
+ */
+
+$magicWords = array();
+
+$magicWords['en'] = array(
+ 'popup' => array( 0, 'popup' ),
+ 'popupcloser' => array( 0, 'popup-closer' ),
+ 'popupputter' => array( 0, 'popup-putter' ),
+);
+
+$messages = array();
+
+/* English
+ * @author john mcclure
+ */
+$messages['en'] = array(
+ 'popuppages-desc' => 'Interstitial popup parser functions',
+ 'popuppages-nopage' => 'Page for interstitial popup not found',
+ 'popuppages-nopolicy' => 'Display policy for interstitial popup not
found',
+);
+
+/** Message documentation (Message documentation)
+ * @author your name
+ */
+$messages['qqq'] = array(
+ 'popuppages-desc' => '{{desc}}',
+ 'popuppages-nopage' => '{{no page found to display}}',
+ 'popuppages-nopolicy' => 'cookie-in, cookie-out, groups-in, groups-out',
+);
+
diff --git a/PopupPages.php b/PopupPages.php
new file mode 100644
index 0000000..5c347f2
--- /dev/null
+++ b/PopupPages.php
@@ -0,0 +1,210 @@
+<?php
+/*
+ * Copyright (C) OneOnOne Marketing.
+ *
+ * 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/>.
+ *
+ * Extension:PopupPages
+ * @author John McClure
+ */
+if ( !defined( 'MEDIAWIKI' ) ) die();
+if ( !defined( 'MW_SUPPORTS_RESOURCE_MODULES' ) ) die('wrong mw version');
+$popupDir = __DIR__ . '/';
+define('PPPAGE_VERSION','1.0');
+$wgExtensionCredits['parserhook'][] = array(
+ 'path' => __FILE__,
+ 'name' => 'PopupPages',
+ 'version' => PPPAGE_VERSION,
+ 'url' => 'http://www.mediawiki.org/wiki/Extension:PopupPages',
+ 'author' => 'John McClure',
+ 'descriptionmsg' => 'Interstitial popup parser functions',
+);
+$wgResourceModules += array(
+ 'ext.popuppages.popup' => array(
+ 'localBasePath' => $popupDir,
+ 'remoteExtPath' => 'PopupPages',
+ 'group' => 'ext.popuppages',
+ 'position' => 'top',
+ 'scripts' => array( 'resources/PopupPages.js' ),
+ 'styles' => array( 'resources/PopupPages.css'),
+ )
+);
+$wgHooks['ParserFirstCallInit'][] = 'wfPopupPageFunctions';
+function wfPopupPageFunctions( &$parser ) {
+ $wgPopupPageFunctions = new PopupPageFunctions();
+ $parser->setFunctionHook( 'popup', 'PopupPageFunctions::popup' );#,
SFH_OBJECT_ARGS );
+ $parser->setFunctionHook( 'popupcloser', 'PopupPageFunctions::closer' );#,
SFH_OBJECT_ARGS );
+ $parser->setFunctionHook( 'popupputter', 'PopupPageFunctions::putter' );#,
SFH_OBJECT_ARGS );
+ return true;
+}
+$wgExtensionMessagesFiles['PopupPagesExtension'] = $popupDir .
'PopupPages.i18n.php';
+
+##########################
+Class PopupPageFunctions {
+##########################
+public static function popup( $parser ) {
+ global $wgRequest;
+ $parms = self::getParms( 'page', func_get_args(),
+ array( //default values
+ 'page' => 'Mediawiki:PopupPage Default',
+ 'class' => 'popupPanel',
+ 'popupID' => '',
+ 'policy' => 'cookie-out, group-out',
+ 'cookieName' => 'PopupPage', //for testing per policy
+ 'cookieValue' => 'PopupPage',
+ ));
+ // USE __NOCACHE__ TO TURN OFF THE CACHE
+ // TURN OFF THE CACHE FOR THIS PAGE
+ //global $wgOut;
+ //$parser->disableCache();
+ //$wgOut->enableClientCache(false);
+ //
+ // EVALUATE WHETHER USER IS IN OR OUT OF POLICY
+ if( isset($parms['policy']) ) {
+ $policies = explode( ',', $parms['policy']);
+ foreach( $policies as $policy) {
+ switch( $policy )
+ {
+ case 'cookie-out': // if cookie exists, no-show popup
+ case 'cookie-in': // if cookie exists, show popup
+ if( isset($parms['cookieName']) ) {
+ $value = $wgRequest->getCookie( $parms['cookieName'], '' );
+ if( isset($value) ) {
+ if( !isset($parms['CookieValue']) ||
$value==$parms['CookieValue']) {
+ $bPolicyOut = $policy=='cookie-out';
+ $bPolicyIn = $policy=='cookie-in';
+ }
+ }
+ }
+ break;
+ case 'group-out': // if user within a group, no-show
+ case 'group-in': // if user within a group, show
+ if( isset($parms['groups']) ) {
+ global $wgUser;
+ $userGroups = $wgUser->getGroups();
+ if( isset($userGroups) ) {
+ $a = explode( ',', $parms['groups']);
+ foreach( $a as $group) {
+ if ( in_array ($group, $userGroups ) ) {
+ $bPolicyOut = $policy=='group-out';
+ $bPolicyIn = $policy=='group-in';
+ break;
+ }
+ }
+ }
+ }
+ else {
+ $bPolicyOut = $policy=='group-in';
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ }
+ // EVALUATE WHETHER USER IS TO SEE THE POPUP. IF SO, CREATE IT
+ $htmlPopup = '';
+ if( (!isset($bPolicyOut) && isset($bPolicyIn) && $bPolicyIn ) ||
+ ( isset($bPolicyOut) && !isset($bPolicyIn) && !$bPolicyOut ) ||
+ ( isset($bPolicyOut) && isset($bPolicyIn) && $bPolicyIn ) ||
+ (!isset($bPolicyOut) && !isset($bPolicyIn) ) )
+ {
+ $title = Title::newFromText($parms['page']);
+ if( !isset($title) ) {
+ $title = Title::newFromText('Mediawiki:PopupPage_Error');
+ !isset($title) ? die('no Mediawiki:PopupPage_Error?') : null;
+ }
+ $article = Revision::newFromTitle( $title );
+ if( isset($article) ) {
+ $raw = $article->getText(Revision::FOR_PUBLIC);
+ $parsed = $parser->parse( $raw, $parser->mTitle, new
ParserOptions() );
+ $body = '<div class="popupBody">' . $parsed->getText() . '</div>';
+ } else {
+ $body = '<div class="popupError">article missing: ' .
$parms['page'] . '</div>';
+ }
+ if( isset($parms['popupID']) ) {
+ $id = trim($parms['popupID']);
+ }
+ if( !isset($id) || !strlen($id) ) {
+ $id = str_replace(" ", "_", trim($parms['page']));
+ $id = str_replace(":", "_", $id);
+ }
+ $htmlPopup = '<div id="' . $id . '" class="' . $parms['class'] . '">'
. $body . '</div>';
+ $parser->getOutput()->addModules( array('ext.popuppages.popup') );
+ }
+ return array( $parser->insertStripItem( $htmlPopup, $parser->mStripState
), 'noparse' => true, 'isHTML' => true );
+}
+public static function closer( $parser ) {
+ $parms = self::getParms( 'label', func_get_args(),
+ array( //default values
+ 'label' => 'Close message', //text on close button
+ 'class' => 'popupCloseButton', //class for button
+ 'popupClass' => 'popupPanel', //class for the popupPanel
+ 'cookieName' => '', //cookie to set on close
+ 'cookieValue'=> '', //cookie value to set
+ 'cookieDays' => '1', //cookie days to set
+ ) );
+ if( !isset($parms['id']) ) {
+ $parms['id'] = '';
+ }
+ $onClick = !strlen($parms['cookieName'])
+ ? ' onClick="popupClose(this,\'' . $parms["popupClass"] .
'\');"'
+ : ' onClick="popupPutCookie(true,'
+ . "'" . $parms['cookieName'] . "'"
+ . ",'" . $parms['cookieValue'] . "'"
+ . ",'" . $parms['cookieDays'] . "'"
+ . ');popupClose(this,\'' . $parms["popupClass"] .
'\');"';
+ $html = '<button class="' . $parms['class'] . '" id="' . $parms['id'] . '"'
+ . $onClick . '>' . $parms['label'] . '</button>';
+ return array( $parser->insertStripItem( $html, $parser->mStripState ),
'noparse' => true, 'isHTML' => true );
+}
+public static function putter( $parser ) {
+ $parms = self::getParms( 'label', func_get_args(),
+ array( //default values
+ 'label' => "Opt-out of this message",//wiki-text on checkbox
+ 'class' => 'popupPutter', //class for checkbox
+ 'putterID' => "popupPutter", //id of putter span
+ 'cookieName' => 'PopupPage', //cookie to set
+ 'cookieValue' => 'PopupPage', //cookie value to set
+ 'cookieDays' => '1', //cookie days to set
+ ) );
+ $parsed = $parser->parse( $parms['label'], $parser->mTitle, new
ParserOptions() );
+ $textCheckbox = $parsed->getText(); //remove enclosing para tag
+ $textCheckbox = substr( $textCheckbox, 3, strlen($textCheckbox)-4 );
+ $onClick = !strlen($parms['cookieName']) ? ''
+ : ' onClick="popupPutCookie(this.checked,'
+ . "'" . $parms['cookieName'] . "'"
+ . ",'" . $parms['cookieValue'] . "'"
+ . ",'" . $parms['cookieDays'] . "'"
+ . ');"';
+ $html = "<span class='" . $parms['class'] . "'>"
+ . "<input id='" . $parms['putterID'] . '\' type="checkbox"' .
$onClick . ' value="false"></input>'
+ . '<label for="' . $parms['putterID'] . '">' . $textCheckbox .
'</label></span>';
+ return array( $parser->insertStripItem( $html, $parser->mStripState ),
'noparse' => true, 'isHTML' => true );
+}
+
+private static function getParms( $unnamed, $args, $parms ) {
+ if( count($args) > 1 && !strpos($args[1], '=') ) {
+ $parms[$unnamed] = trim($args[1]);
+ }
+ for ( $i = 2; $i < count($args); $i++ ) {
+ $pair = isset($args[$i]) ? explode("=", $args[$i] ) : array();
+ if ( count( $pair ) == 2 ) {
+ $parms[trim( $pair[0] )] = trim( $pair[1] );
+ }
+ }
+ return $parms;
+}
+
+} //class PopupPageFunctions
\ No newline at end of file
diff --git a/resources/PopupPages.css b/resources/PopupPages.css
new file mode 100644
index 0000000..df6070b
--- /dev/null
+++ b/resources/PopupPages.css
@@ -0,0 +1,51 @@
+
+@CHARSET "UTF-8";
+
+/* the overlayed element */
+.popupPanel { /* must be initially shown */
+ display: block;
+ /* place overlay on top of other elements */
+ z-index: 10000;
+ /* styling */
+ background-color: #a1a1a1;
+ width: 300px;
+ min-height: 100px;
+ border: 2px solid #333333;
+ /* CSS3 styling for latest browsers */
+ -moz-box-shadow: 0 0 30px 5px #000;
+ -webkit-box-shadow: 0 0 30px #000;
+}
+
+/* close button positioned on upper right corner */
+.popupPanel .close {
+ background-image: url(/icons/overlay/close.png);
+ position: absolute;
+ right: -15px;
+ top: -15px;
+ cursor: pointer;
+ height: 35px;
+ width: 35px;*/
+}
+
+/* styling for elements inside overlay */
+.popupPanelContent {
+ padding: 10px 0px;
+ font-size: 12px;
+ font-weight: bold;
+ color: #fff;
+ width: 100%;
+ text-align: center;
+}
+.popupPanelDeleteButtonDiv {
+ padding: 0 30px 10px 0;
+ float: right;
+}
+
+.popupPanelCancelButtonDiv {
+ padding: 0 0 10px 30px;
+ float:left;
+}
+.popupPanelCloseButtonDiv {
+ text-align: center;
+}
+
diff --git a/resources/PopupPages.js b/resources/PopupPages.js
new file mode 100644
index 0000000..6780bf5
--- /dev/null
+++ b/resources/PopupPages.js
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) OneOnOne Marketing.
+ *
+ * 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/>.
+ *
+ */
+
+function popupPutCookie(optingOut,name,value,days) {
+ if( $.type(name)=='string' ) {
+ if( optingOut ) {
+ if( $.type(days)=='string' ) {
+ /*$.cookie(name,value, { expires : days } );*/
+ var exdate=new Date();
+ exdate.setDate(exdate.getDate() + days);
+ var c_value=escape(value) + ((days==null) ? "" : ";
expires="+exdate.toUTCString())
+ + "; path=/";
+ document.cookie=name + "=" + c_value;
+ } else {
+ /*$.cookie(name,value);*/
+ document.cookie=name + "=" + escape(value);
+ }
+ } else {
+ $.cookie(name, null);
+ }
+ }
+}
+
+function popupClose(elem, popupClass) {
+ $(elem).closest('.'+popupClass).hide();
+}
+
+window.popupClose = popupClose;
+window.popupPutCookie = popupPutCookie;
\ No newline at end of file
--
To view, visit https://gerrit.wikimedia.org/r/51843
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I277c1c153aeda2e6184d0cdf3dc64eda62e186f6
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/PopupPages
Gerrit-Branch: master
Gerrit-Owner: Hypergrove <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits