r106910 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106909‎ | r106910 | r106911 >
Date:01:03, 21 December 2011
Author:preilly
Status:deferred (Comments)
Tags:mobile 
Comment:
add base template class
Modified paths:
  • /trunk/extensions/ZeroRatedMobileAccess/ZeroRatedMobileAccess.php (modified) (history)
  • /trunk/extensions/ZeroRatedMobileAccess/ZeroRatedMobileAccessTemplate.php (added) (history)

Diff [purge]

Index: trunk/extensions/ZeroRatedMobileAccess/ZeroRatedMobileAccess.php
@@ -28,12 +28,22 @@
2929 $cwd = dirname( __FILE__ ) . DIRECTORY_SEPARATOR;
3030 $wgExtensionMessagesFiles['ZeroRatedMobileAccess'] = $cwd . 'ZeroRatedMobileAccess.i18n.php';
3131
 32+// autoload extension classes
 33+
 34+$autoloadClasses = array (
 35+ 'ZeroRatedMobileAccessTemplate',
 36+);
 37+
 38+foreach ( $autoloadClasses as $class ) {
 39+ $wgAutoloadClasses[$class] = $cwd . $class . '.php';
 40+}
 41+
3242 $wgExtZeroRatedMobileAccess = new ExtZeroRatedMobileAccess();
3343
3444 $wgHooks['BeforePageDisplay'][] = array( &$wgExtZeroRatedMobileAccess, 'beforePageDisplayHTML' );
3545
3646 class ExtZeroRatedMobileAccess {
37 - const VERSION = '0.0.1';
 47+ const VERSION = '0.0.2';
3848
3949 public static $renderZeroRatedLandingPage;
4050
Index: trunk/extensions/ZeroRatedMobileAccess/ZeroRatedMobileAccessTemplate.php
@@ -0,0 +1,51 @@
 2+<?php
 3+
 4+if( !defined( 'MEDIAWIKI' ) ) {
 5+ die( -1 );
 6+}
 7+
 8+abstract class ZeroRatedMobileAccessTemplate {
 9+ public $data;
 10+
 11+ /**
 12+ * Constructor
 13+ */
 14+ public function __construct() {
 15+ $this->data = array();
 16+ }
 17+
 18+ /**
 19+ * Sets the value $value to $name
 20+ * @param $name
 21+ * @param $value
 22+ */
 23+ public function set( $name, $value ) {
 24+ $this->data[$name] = $value;
 25+ }
 26+
 27+ /**
 28+ * Sets the value $value to $name
 29+ * @param $name
 30+ * @param $value
 31+ */
 32+ public function setByArray( $options ) {
 33+ foreach ($options as $name => $value ) {
 34+ $this->set( $name, $value );
 35+ }
 36+ }
 37+
 38+ /**
 39+ * Gets the value of $name
 40+ * @param $name
 41+ * @return string
 42+ */
 43+ public function get( $name ) {
 44+ return $this->data[$name];
 45+ }
 46+
 47+ /**
 48+ * Main function, used by classes that subclass ZeroRatedMobileAccessTemplate
 49+ * to show the actual HTML output
 50+ */
 51+ abstract public function getHTML();
 52+}
Property changes on: trunk/extensions/ZeroRatedMobileAccess/ZeroRatedMobileAccessTemplate.php
___________________________________________________________________
Added: svn:eol-style
153 + native

Comments

#Comment by 😂 (talk | contribs)   15:59, 24 December 2011
  • If this constructor isn't going to do any other work, you can just move the array initialization up to the top like public $data = array();
  • Having set() and setByArray() is kind of redundant. Why not just call it set() and always use the array syntax

Status & tagging log