Sumit has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/208096

Change subject: PageBanner: Static banner placeholder created
......................................................................

PageBanner: Static banner placeholder created

A static banner placeholder created on top of each Article page(Pages in the
'Main' namespace). Other pages remain unaffected. To achieve this, the extension
hides main h1 heading using custom css, and then adds banner placehold along
lines of http://en.wikivoyage.org/wiki/Template:Pagebanner. The custom html
code is inserted using 'ArticleViewHeader' hook.

Bug: T94772
Change-Id: Iba7cea63902e67e195f4c2a3484d85cbcdf203b6
---
D BoilerPlate.php
A WikidataPageBanner.class.php
R WikidataPageBanner.i18n.alias.php
A WikidataPageBanner.php
D modules/ext.BoilerPlate.foo.css
A modules/ext.WikidataPageBanner.css
R modules/ext.WikidataPageBanner.js
7 files changed, 155 insertions(+), 68 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikidataPageBanner 
refs/changes/96/208096/1

diff --git a/BoilerPlate.php b/BoilerPlate.php
deleted file mode 100644
index b8daf3e..0000000
--- a/BoilerPlate.php
+++ /dev/null
@@ -1,59 +0,0 @@
-<?php
-/**
- * BoilerPlate extension - the thing that needs you.
- *
- * For more info see http://mediawiki.org/wiki/Extension:BoilerPlate
- *
- * @file
- * @ingroup Extensions
- * @author John Doe, 2014
- * @license GNU General Public Licence 2.0 or later
- */
-
-$wgExtensionCredits['other'][] = array(
-       'path' => __FILE__,
-       'name' => 'BoilerPlate',
-       'author' => array(
-               'John Doe',
-       ),
-       'version'  => '0.2.0',
-       'url' => 'https://www.mediawiki.org/wiki/Extension:BoilerPlate',
-       'descriptionmsg' => 'boilerplate-desc',
-);
-
-/* Setup */
-
-// Register files
-$wgAutoloadClasses['BoilerPlateHooks'] = __DIR__ . '/BoilerPlate.hooks.php';
-$wgAutoloadClasses['SpecialHelloWorld'] = __DIR__ . 
'/specials/SpecialHelloWorld.php';
-$wgMessagesDirs['BoilerPlate'] = __DIR__ . '/i18n';
-$wgExtensionMessagesFiles['BoilerPlateAlias'] = __DIR__ . 
'/BoilerPlate.i18n.alias.php';
-
-// Register hooks
-#$wgHooks['NameOfHook'][] = 'BoilerPlateHooks::onNameOfHook';
-
-// Register special pages
-$wgSpecialPages['HelloWorld'] = 'SpecialHelloWorld';
-
-// Register modules
-$wgResourceModules['ext.BoilerPlate.foo'] = array(
-       'scripts' => array(
-               'modules/ext.BoilerPlate.foo.js',
-       ),
-       'styles' => array(
-               'modules/ext.BoilerPlate.foo.css',
-       ),
-       'messages' => array(
-       ),
-       'dependencies' => array(
-       ),
-
-       'localBasePath' => __DIR__,
-       'remoteExtPath' => 'examples/BoilerPlate',
-);
-
-
-/* Configuration */
-
-// Enable Foo
-#$wgBoilerPlateEnableFoo = true;
diff --git a/WikidataPageBanner.class.php b/WikidataPageBanner.class.php
new file mode 100644
index 0000000..76e8f35
--- /dev/null
+++ b/WikidataPageBanner.class.php
@@ -0,0 +1,54 @@
+<?php
+class WikidataPageBanner {
+       /**
+        * WikidataPageBanner::viewBanner
+        *
+        * @param Article $article
+        * @return bool
+        */
+       public static function viewBanner( $article ) {
+               global $wgOut, $wgPBImage, $wgIsMainPage;
+               $bannerurl = $wgPBImage;
+               $title = $article->getTitle();
+               $ns = $title->getNamespace();
+               // banner only on main namespace
+               if ( MWNamespace::equals( $ns, 0 ) ) {
+                       $banner = Html::openElement( 'div', array( 'class' => 
'noprint' ) ) .
+                       Html::openElement( 'div', array( 'class' => 
'mf-pagebanner',
+                                                                       'style' 
=> 'background-image:url('.$bannerurl.');'
+                                                               )
+                                                       ) .
+                       Html::openElement( 'div', array( 'class' => 'topbanner' 
) ) .
+                       Html::element( 'div',
+                               array( 'class' => 'name' ),
+                               $title
+                       ) .
+                       Html::element( 'div',
+                               array( 'class' => 'iconbox' )
+                       ) .
+                       Html::closeElement( 'div' ) .
+                       Html::closeElement( 'div' ) .
+                       Html::closeElement( 'div' ) . "\n";
+                       $wgOut->addHtml( $banner );
+                       $wgIsMainPage = true;
+               } else {
+                       $wgIsMainPage = false;
+               }
+               return true;
+       }
+
+       /**
+        * WikidataPageBanner::loadBanner
+        *
+        * @param $out OutputPage
+        * @param $parserOutput ParserOutput
+        * @return  bool
+        */
+       public static function loadModules( $out, $parserOutput ) {
+               global $wgIsMainPage;
+               if ( $wgIsMainPage === true ) {
+                       // Setup banner styling, only if main namespace
+                       $out->addModuleStyles( 'ext.WikidataPageBanner' );
+               }
+       }
+}
diff --git a/BoilerPlate.i18n.alias.php b/WikidataPageBanner.i18n.alias.php
similarity index 82%
rename from BoilerPlate.i18n.alias.php
rename to WikidataPageBanner.i18n.alias.php
index 9a0511a..3f02d9f 100644
--- a/BoilerPlate.i18n.alias.php
+++ b/WikidataPageBanner.i18n.alias.php
@@ -9,6 +9,6 @@
 $specialPageAliases = array();
 
 /** English (English) */
-$specialPageAliases['en'] = array(
+/*$specialPageAliases['en'] = array(
        'HelloWorld' => array( 'HelloWorld' ),
-);
+);*/
diff --git a/WikidataPageBanner.php b/WikidataPageBanner.php
new file mode 100644
index 0000000..16f4eea
--- /dev/null
+++ b/WikidataPageBanner.php
@@ -0,0 +1,67 @@
+<?php
+/**
+ * Wikidata PageBanner Extension
+ *
+ * For more info see http://mediawiki.org/wiki/Extension:WikidataPageBanner
+ * @author Sumit Asthana, 2015
+ * @license GNU General Public Licence 2.0 or later
+ */
+if ( !defined( 'MEDIAWIKI' ) ) {
+       die( 'This file is a MediaWiki extension, it is not a valid entry 
point' );
+}
+
+$wgExtensionCredits['other'][] = array(
+       'path'           => __FILE__,
+       'name'           => 'WikidataPageBanner',
+       'namemsg'        => "WikidataPageBanner",
+       'description'    => "Render banners on wikivoyage",
+       'descriptionmsg' => 'Display pagewide banners on wikivoyage',
+       'author'         => array( 'Sumit Asthana' ),
+       'version'        => '0.0.0',
+       'url'            => 
'https://www.mediawiki.org/wiki/Extension:WikidataPageBanner',
+       'license-name'   => 'GPL-2.0+',
+);
+
+/**
+ * Options:
+ *
+ * $wgPBImage - static pagebanner image url
+ */
+$wgPBImage = 
"http://upload.wikimedia.org/wikipedia/commons/a/a0/South_America_Wikivoyage_banner.jpg";;
+
+/* Setup */
+// autoloader
+$wgAutoloadClasses['WikidataPageBanner'] = __DIR__ . 
'/WikidataPageBanner.class.php';
+
+// Register files
+$wgMessagesDirs['WikidataPageBanner'] = __DIR__ . '/i18n';
+$wgExtensionMessagesFiles['WikidataPageBannerAlias'] = __DIR__ . 
'/WikidataPageBanner.i18n.alias.php';
+
+// Register hooks
+// Hook to inject banner code
+$wgHooks['ArticleViewHeader'][] = 'WikidataPageBanner::viewBanner';
+// Load Banner modules, styles
+$wgHooks['BeforePageDisplay'][] = 'WikidataPageBanner::loadModules';
+
+// include WikidataPageBanner class file
+require_once( 'WikidataPageBanner.class.php' );
+
+// Register modules
+$wgResourceModules['ext.WikidataPageBanner'] = array(
+       'scripts' => array(
+               'modules/ext.WikidataPageBanner.js',
+       ),
+       'styles' => array(
+               'modules/ext.WikidataPageBanner.css',
+       ),
+       'messages' => array(
+       ),
+       'dependencies' => array(
+       ),
+
+       'localBasePath' => __DIR__,
+       'remoteExtPath' => 'WikidataPageBanner',
+);
+
+// to test if the page is Main Namespace page
+$wgIsMainPage = false;
diff --git a/modules/ext.BoilerPlate.foo.css b/modules/ext.BoilerPlate.foo.css
deleted file mode 100644
index 4ec947d..0000000
--- a/modules/ext.BoilerPlate.foo.css
+++ /dev/null
@@ -1,7 +0,0 @@
-/**
- * Stylesheet for Foo in BoilerPlate.
- */
-
-.mw-boilerplate-foo {
-       display: block;
-}
diff --git a/modules/ext.WikidataPageBanner.css 
b/modules/ext.WikidataPageBanner.css
new file mode 100644
index 0000000..bf736e2
--- /dev/null
+++ b/modules/ext.WikidataPageBanner.css
@@ -0,0 +1,32 @@
+/**
+ * Stylesheet for page-wide Banner in WikidataPageBanner extension.
+ */
+
+.mf-pagebanner {
+       width:100%;
+       height:200px;
+       -webkit-background-size: cover;
+       -moz-background-size: cover;
+       -o-background-size: cover;
+       background-size: cover;
+       background-repeat: no-repeat;
+       background-position: center center;
+}
+
+.topbanner .name {
+       position: absolute;
+       z-index: 2;
+       margin: 0.6em 0 0 0.4em;
+       padding: 8px 7px;
+       font-size: 2.2em;
+       font-weight: bold;
+       background: none repeat scroll 0% 0% rgba(0, 0, 0, 0.3);
+       border-radius: 4px;
+       color: white;
+       white-space: no-wrap;
+       line-height: 0.9em;
+}
+
+h1.firstHeading {
+       display: none;
+}
diff --git a/modules/ext.BoilerPlate.foo.js b/modules/ext.WikidataPageBanner.js
similarity index 100%
rename from modules/ext.BoilerPlate.foo.js
rename to modules/ext.WikidataPageBanner.js

-- 
To view, visit https://gerrit.wikimedia.org/r/208096
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iba7cea63902e67e195f4c2a3484d85cbcdf203b6
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikidataPageBanner
Gerrit-Branch: master
Gerrit-Owner: Sumit <asthana.sumi...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to