tosfos has uploaded a new change for review.
https://gerrit.wikimedia.org/r/156729
Change subject: allow ads in content area
......................................................................
allow ads in content area
Change-Id: Ibef0a5bc5b2ab434c381a0fb33e0f37c21485188
---
M AdManager.class.php
M AdManager.hooks.php
M AdManager.php
M ext.adManager.css
4 files changed, 57 insertions(+), 20 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/AdManager
refs/changes/29/156729/1
diff --git a/AdManager.class.php b/AdManager.class.php
index dc23d6b..08b1a7d 100644
--- a/AdManager.class.php
+++ b/AdManager.class.php
@@ -202,6 +202,27 @@
self::$catList[$catName] = $count;
}
+ public static function getAdOutputFor( Title $title ) {
+ if ( !AdManager::tableExists() ) {
+ return false;
+ }
+ $adManagerCode = AdManager::getAdManagerCode();
+ if ( !isset( $adManagerCode ) ) {
+ return false; // TODO: show error
+ }
+
+ $thisPageAdZones = AdManager::getAdZonesFor( $title );
+ if ( empty( $thisPageAdZones ) ) { // No zone set for this page
or its categories
+ return array();
+ }
+
+ $adsOut = array();
+ foreach ( $thisPageAdZones as $thisPageAdZone ) {
+ $adsOut[] = str_replace( '$1', $thisPageAdZone,
$adManagerCode );
+ }
+ return $adsOut;
+ }
+
/**
* Get all the ad slot ids that should be displayed for this title
*
diff --git a/AdManager.hooks.php b/AdManager.hooks.php
index 88d24f0..07a79c6 100644
--- a/AdManager.hooks.php
+++ b/AdManager.hooks.php
@@ -18,39 +18,48 @@
/**
* Pop some ads at the bottom of the sidebar
*
- * @global string $wgAdManagerService
- * @global string $wgAdManagerCode
+ * @global string $wgAdManagerPlacement
* @param Skin $skin
* @param array $sidebar
* @return boolean
*/
public static function SkinBuildSidebar( $skin, &$sidebar ) {
- if ( !AdManager::tableExists() ) {
+ global $wgAdManagerPlacement;
+
+ if ( $wgAdManagerPlacement != 'sidebar' ) {
return true;
}
- $thisPageAdZones = AdManager::getAdZonesFor( $skin->getTitle()
);
-
- if ( empty( $thisPageAdZones ) ) { // No zone set for this page
or its categories
- return true;
- }
-
- $adManagerCode = AdManager::getAdManagerCode();
- if ( !isset( $adManagerCode ) ) {
- return true; // TODO: show error
- }
-
- $adNumber = 0;
- foreach ( $thisPageAdZones as $thisPageAdZone ) {
- $adNumber++;
- $out = str_replace( '$1', $thisPageAdZone,
$adManagerCode );
- $sidebar["AdManager$adNumber"] = $out;
+ $adsOut = AdManager::getAdOutputFor( $skin->getTitle() );
+ foreach ( $adsOut as $adNumber => $adOut ) {
+ $sidebar["AdManager$adNumber"] = $adOut;
}
return true;
}
+ /**
+ * Pop some ads into the start of the content area
+ *
+ * @global string $wgAdManagerPlacement
+ * @param OutputPage $out
+ * @param Skin $skin
+ * @return boolean
+ */
public static function onBeforePageDisplay( OutputPage &$out, Skin
&$skin ) {
$out->addModules( 'ext.adManager' );
+
+ global $wgAdManagerPlacement;
+ if ( $wgAdManagerPlacement != 'content' ) {
+ return true;
+ }
+
+ $adsOut = AdManager::getAdOutputFor( $skin->getTitle() );
+ foreach ( $adsOut as $adNumber => $adOut ) {
+ $out->prependHTML( Html::rawelement( 'div',
+ array( 'id' =>
"AdManager-content-$adNumber", 'class' => 'AdManager-content' ), $adOut ) );
+ }
+
+ return true;
}
}
diff --git a/AdManager.php b/AdManager.php
index fc91278..0da10d9 100644
--- a/AdManager.php
+++ b/AdManager.php
@@ -21,7 +21,7 @@
$wgExtensionCredits['specialpage'][] = array(
'path' => __FILE__,
'name' => 'AdManager',
- 'version' => '0.4.0',
+ 'version' => '0.5.0',
'author' => 'Ike Hecht for WikiWorks',
'url' => 'https://www.mediawiki.org/wiki/Extension:AdManager',
'descriptionmsg' => 'admanager-desc',
@@ -32,6 +32,9 @@
$wgAdManagerService = null;
// For custom code. Insert $1 anywhere that the ad zone should be inserted.
$wgAdManagerCode = null;
+// Where should the ads be outputted?
+// Allowed values: 'sidebar', 'content'
+$wgAdManagerPlacement = 'sidebar';
$wgMessagesDirs['AdManager'] = __DIR__ . '/i18n';
$wgExtensionMessagesFiles['AdManager'] = __DIR__ . 'AdManager.i18n.php';
diff --git a/ext.adManager.css b/ext.adManager.css
index 8fb2bad..6c3c77d 100644
--- a/ext.adManager.css
+++ b/ext.adManager.css
@@ -7,6 +7,10 @@
margin-left: 0!important;
}
+div.AdManager-content {
+ float: right;
+}
+
body.mw-special-AdManager legend {
display: none;
}
--
To view, visit https://gerrit.wikimedia.org/r/156729
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibef0a5bc5b2ab434c381a0fb33e0f37c21485188
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/AdManager
Gerrit-Branch: master
Gerrit-Owner: tosfos <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits