r114739 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r114738‎ | r114739 | r114740 >
Date:14:34, 5 April 2012
Author:jeroendedauw
Status:deferred
Tags:
Comment:
split logic from display
Modified paths:
  • /trunk/extensions/EducationProgram/EducationProgram.php (modified) (history)
  • /trunk/extensions/EducationProgram/actions/EPRestoreAction.php (modified) (history)
  • /trunk/extensions/EducationProgram/actions/EPUndoAction.php (modified) (history)
  • /trunk/extensions/EducationProgram/actions/EditCourseAction.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPDiffTable.php (added) (history)
  • /trunk/extensions/EducationProgram/includes/EPMenu.php (added) (history)
  • /trunk/extensions/EducationProgram/includes/EPRevisionDiff.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/EducationProgram.php
@@ -122,6 +122,8 @@
123123 $wgAutoloadClasses['EPArticles'] = dirname( __FILE__ ) . '/includes/EPArticles.php';
124124 $wgAutoloadClasses['EPStudentActivityPager'] = dirname( __FILE__ ) . '/includes/EPStudentActivityPager.php';
125125 $wgAutoloadClasses['EPRevisionDiff'] = dirname( __FILE__ ) . '/includes/EPRevisionDiff.php';
 126+$wgAutoloadClasses['EPDiffTable'] = dirname( __FILE__ ) . '/includes/EPDiffTable.php';
 127+$wgAutoloadClasses['EPMenu'] = dirname( __FILE__ ) . '/includes/EPMenu.php';
126128
127129 $wgAutoloadClasses['CoursePage'] = dirname( __FILE__ ) . '/pages/CoursePage.php';
128130 $wgAutoloadClasses['EPPage'] = dirname( __FILE__ ) . '/pages/EPPage.php';
@@ -146,12 +148,12 @@
147149
148150 // Compat classes
149151 foreach ( array(
150 - 'ORMResult' => 'ORMResult.php',
151 - 'ORMRow' => 'ORMRow.php',
152 - 'ORMTable' => 'ORMTable.php',
153 - 'CacheHelper' => 'CacheHelper.php',
154 - 'ICacheHelper' => 'CacheHelper.php',
155 - 'CachedAction' => 'CachedAction.php',
 152+ 'ORMResult' => 'ORMResult.php', // MW < 1.20
 153+ 'ORMRow' => 'ORMRow.php', // MW < 1.20
 154+ 'ORMTable' => 'ORMTable.php', // MW < 1.20
 155+ 'CacheHelper' => 'CacheHelper.php', // MW < 1.20
 156+ 'ICacheHelper' => 'CacheHelper.php', // MW < 1.20
 157+ 'CachedAction' => 'CachedAction.php', // MW < 1.20
156158 'SpecialCachedPage' => 'SpecialCachedPage.php' // MW < 1.20
157159 ) as $className => $fileName ) {
158160
Index: trunk/extensions/EducationProgram/actions/EditCourseAction.php
@@ -208,7 +208,7 @@
209209 'required' => true,
210210 'options' => array_combine( $levels, $levels ),
211211 );
212 -XML::languageSelector()
 212+
213213 $langOptions = EPUtils::getLanguageOptions( $this->getLanguage()->getCode() );
214214 $fields['lang'] = array (
215215 'type' => 'select',
Index: trunk/extensions/EducationProgram/actions/EPRestoreAction.php
@@ -68,8 +68,8 @@
6969
7070 if ( $diff->isValid() ) {
7171 if ( $diff->hasChanges() ) {
72 - $diff->setContext( $this->getContext() );
73 - $diff->display();
 72+ $diffTable = new EPDiffTable( $this->getContext(), $diff );
 73+ $diffTable->display();
7474
7575 $this->displayForm( $object, $revision );
7676 }
Index: trunk/extensions/EducationProgram/actions/EPUndoAction.php
@@ -68,8 +68,8 @@
6969
7070 if ( $diff->isValid() ) {
7171 if ( $diff->hasChanges() ) {
72 - $diff->setContext( $this->getContext() );
73 - $diff->display();
 72+ $diffTable = new EPDiffTable( $this->getContext(), $diff );
 73+ $diffTable->display();
7474
7575 $this->displayForm( $object, $revision );
7676 }
Index: trunk/extensions/EducationProgram/includes/EPMenu.php
@@ -0,0 +1,30 @@
 2+<?php
 3+
 4+/**
 5+ * Education Program menu.
 6+ * @since 0.1
 7+ *
 8+ * @file EPMenu.php
 9+ * @ingroup EducationProgram
 10+ *
 11+ * @licence GNU GPL v2+
 12+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
 13+ */
 14+class EPMenu extends ContextSource {
 15+
 16+ /**
 17+ * Constructor.
 18+ *
 19+ * @since 0.1
 20+ *
 21+ * @param IContextSource $context
 22+ */
 23+ public function __construct( IContextSource $context ) {
 24+ $this->setContext( $context );
 25+ }
 26+
 27+ public function display() {
 28+ // TODO
 29+ }
 30+
 31+}
Index: trunk/extensions/EducationProgram/includes/EPDiffTable.php
@@ -0,0 +1,72 @@
 2+<?php
 3+
 4+/**
 5+ * Utility for visualizing diffs between two revisions.
 6+ *
 7+ * @since 0.1
 8+ *
 9+ * @file EPDiffTable.php
 10+ * @ingroup EducationProgram
 11+ *
 12+ * @licence GNU GPL v2+
 13+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
 14+ */
 15+class EPDiffTable extends ContextSource {
 16+
 17+ /**
 18+ * @since 0.1
 19+ * @var EPRevisionDiff
 20+ */
 21+ protected $diff;
 22+
 23+ /**
 24+ * Constructor.
 25+ *
 26+ * @since 0.1
 27+ *
 28+ * @param IContextSource $context
 29+ * @param EPRevisionDiff $diff
 30+ */
 31+ public function __construct( IContextSource $context, EPRevisionDiff $diff ) {
 32+ if ( !$diff->isValid() ) {
 33+ throw new MWException( 'Ivalid EPRevisionDiff passed to EPDiffTable.' );
 34+ }
 35+
 36+ $this->diff = $diff;
 37+
 38+ $this->setContext( $context );
 39+ }
 40+
 41+ /**
 42+ * Display the diff as a table.
 43+ *
 44+ * @since 0.1
 45+ */
 46+ public function display() {
 47+ $out = $this->getOutput();
 48+
 49+ $out->addHTML( '<table class="wikitable sortable"><tr>' );
 50+
 51+ $out->addElement( 'th', array(), '' );
 52+ $out->addElement( 'th', array(), $this->msg( 'ep-diff-old' )->plain() );
 53+ $out->addElement( 'th', array(), $this->msg( 'ep-diff-new' )->plain() );
 54+
 55+ $out->addHTML( '</tr>' );
 56+
 57+ foreach ( $this->diff->getChangedFields() as $field => $values ) {
 58+ $out->addHtml( '<tr>' );
 59+
 60+ $source = array_key_exists( 'source', $values ) ? $values['source'] : '';
 61+ $target = array_key_exists( 'target', $values ) ? $values['target'] : '';
 62+
 63+ $out->addElement( 'th', array(), $field );
 64+ $out->addElement( 'td', array(), $source );
 65+ $out->addElement( 'td', array(), $target );
 66+
 67+ $out->addHtml( '</tr>' );
 68+ }
 69+
 70+ $out->addHTML( '</table>' );
 71+ }
 72+
 73+}
\ No newline at end of file
Index: trunk/extensions/EducationProgram/includes/EPRevisionDiff.php
@@ -1,7 +1,7 @@
22 <?php
33
44 /**
5 - * Utility for visualizing diffs between two revisions.
 5+ * Repserents a diff between two revisions.
66 *
77 * @since 0.1
88 *
@@ -11,10 +11,8 @@
1212 * @licence GNU GPL v2+
1313 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1414 */
15 -class EPRevisionDiff extends ContextSource {
 15+class EPRevisionDiff {
1616
17 - protected $context;
18 -
1917 protected $changedFields = array();
2018
2119 protected $isValid = true;
@@ -92,33 +90,6 @@
9391 $this->changedFields = $changedFields;
9492 }
9593
96 - public function display() {
97 - $out = $this->getOutput();
98 -
99 - $out->addHTML( '<table class="wikitable sortable"><tr>' );
100 -
101 - $out->addElement( 'th', array(), '' );
102 - $out->addElement( 'th', array(), $this->msg( 'ep-diff-old' )->plain() );
103 - $out->addElement( 'th', array(), $this->msg( 'ep-diff-new' )->plain() );
104 -
105 - $out->addHTML( '</tr>' );
106 -
107 - foreach ( $this->changedFields as $field => $values ) {
108 - $out->addHtml( '<tr>' );
109 -
110 - $source = array_key_exists( 'source', $values ) ? $values['source'] : '';
111 - $target = array_key_exists( 'target', $values ) ? $values['target'] : '';
112 -
113 - $out->addElement( 'th', array(), $field );
114 - $out->addElement( 'td', array(), $source );
115 - $out->addElement( 'td', array(), $target );
116 -
117 - $out->addHtml( '</tr>' );
118 - }
119 -
120 - $out->addHTML( '</table>' );
121 - }
122 -
12394 /**
12495 * @return array
12596 */

Status & tagging log