r109955 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r109954‎ | r109955 | r109956 >
Date:21:27, 24 January 2012
Author:jeroendedauw
Status:deferred
Tags:
Comment:
some initial work towars cleaning up linking to orgs/mcs/courses
Modified paths:
  • /trunk/extensions/EducationProgram/EducationProgram.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPCourse.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPDBObject.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPMC.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPOrg.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPPageObject.php (added) (history)
  • /trunk/extensions/EducationProgram/includes/EPRevisionPager.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialCourseHistory.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialEPHistory.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialInstitutionHistory.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialMasterCourseHistory.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/specials/SpecialMasterCourseHistory.php
@@ -19,7 +19,7 @@
2020 * @since 0.1
2121 */
2222 public function __construct() {
23 - parent::__construct( 'MasterCourseHistory', 'EPMC', 'name' );
 23+ parent::__construct( 'MasterCourseHistory', 'EPMC', 'name', 'MasterCourse' );
2424 }
2525
2626 }
Index: trunk/extensions/EducationProgram/specials/SpecialInstitutionHistory.php
@@ -19,7 +19,7 @@
2020 * @since 0.1
2121 */
2222 public function __construct() {
23 - parent::__construct( 'InstitutionHistory', 'EPMC', 'name' );
 23+ parent::__construct( 'InstitutionHistory', 'EPMC', 'name', 'Institution' );
2424 }
2525
2626 }
Index: trunk/extensions/EducationProgram/specials/SpecialCourseHistory.php
@@ -19,7 +19,7 @@
2020 * @since 0.1
2121 */
2222 public function __construct() {
23 - parent::__construct( 'CourseHistory', 'EPCourse', 'id' );
 23+ parent::__construct( 'CourseHistory', 'EPCourse', 'id', 'Course' );
2424 }
2525
2626 }
Index: trunk/extensions/EducationProgram/specials/SpecialEPHistory.php
@@ -26,6 +26,12 @@
2727 protected $className;
2828
2929 /**
 30+ * @since 0.1
 31+ * @var string
 32+ */
 33+ protected $itemPage;
 34+
 35+ /**
3036 * @see parent::__construct
3137 *
3238 * @since 0.1
@@ -35,9 +41,10 @@
3642 * @param string $identifierField
3743 * @param string $restriction
3844 */
39 - public function __construct( $name, $className, $identifierField, $restriction = '' ) {
 45+ public function __construct( $name, $className, $identifierField, $itemPage, $restriction = '' ) {
4046 $this->identifier = $identifierField;
4147 $this->className = $className;
 48+ $this->itemPage = $itemPage;
4249
4350 parent::__construct( $name, $restriction, false );
4451 }
@@ -129,7 +136,7 @@
130137 '</fieldset></form>'
131138 );
132139
133 - $pager = new EPRevisionPager( $this->getContext(), $conditions );
 140+ $pager = new EPRevisionPager( $this->getContext(), $this->className, $this->itemPage, $conditions );
134141
135142 if ( $pager->getNumRows() ) {
136143 $out->addHTML(
Index: trunk/extensions/EducationProgram/includes/EPDBObject.php
@@ -23,7 +23,7 @@
2424 * @since 0.1
2525 *
2626 * @file EPDBObject.php
27 - * @ingroup Review
 27+ * @ingroup EducationProgram
2828 *
2929 * @licence GNU GPL v3 or later
3030 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
Index: trunk/extensions/EducationProgram/includes/EPRevisionPager.php
@@ -21,15 +21,30 @@
2222 protected $context;
2323
2424 /**
 25+ * @since 0.1
 26+ * @var string
 27+ */
 28+ protected $className;
 29+
 30+ /**
 31+ * @since 0.1
 32+ * @var string
 33+ */
 34+ protected $itemPage;
 35+
 36+ /**
2537 * Constructor.
2638 *
2739 * @param IContextSource $context
 40+ * @param string $className
 41+ * @param string $itemPage
2842 * @param array $conds
29 - * @param string $className
3043 */
31 - public function __construct( IContextSource $context, array $conds ) {
 44+ public function __construct( IContextSource $context, $className, $itemPage, array $conds = array() ) {
3245 $this->conds = $conds;
3346 $this->context = $context;
 47+ $this->className = $className;
 48+ $this->itemPage = $itemPage;
3449
3550 $this->mDefaultDirection = true;
3651
@@ -102,6 +117,14 @@
103118 }
104119
105120 /**
 121+ * @see parent::getStartBody
 122+ * @since 0.1
 123+ */
 124+ function getStartBody() {
 125+ return '<ul>';
 126+ }
 127+
 128+ /**
106129 * Abstract formatting function. This should return an HTML string
107130 * representing the result row $row. Rows will be concatenated and
108131 * returned by getBody()
@@ -111,10 +134,35 @@
112135 * @return String
113136 */
114137 function formatRow( $row ) {
115 - return json_encode( $row ); // TODO
 138+ $revision = EPRevision::newFromDBResult( $row );
 139+
 140+ $c = $this->className; // Yeah, this is needed in PHP 5.3 >_>
 141+ $object = $c::newFromArray( $revision->getField( 'data' ) );
 142+
 143+ $html = '';
 144+
 145+ $html .= Html::element(
 146+ 'a',
 147+ array(
 148+ 'href' => SpecialPage::getTitleFor( $this->itemPage, $object->getIdentifier() )->getLocalURL( array(
 149+ 'revid' => $revision->getId(),
 150+ ) ),
 151+ ),
 152+ $this->getLanguage()->timeanddate( $revision->getField( 'time' ) )
 153+ );
 154+
 155+ return '<li>' . $html . '</li>';
116156 }
117157
118158 /**
 159+ * @see parent::getEndBody
 160+ * @since 0.1
 161+ */
 162+ function getEndBody() {
 163+ return '</ul>';
 164+ }
 165+
 166+ /**
119167 * This function should be overridden to provide all parameters
120168 * needed for the main paged query. It returns an associative
121169 * array with the following elements:
Index: trunk/extensions/EducationProgram/includes/EPOrg.php
@@ -11,7 +11,7 @@
1212 * @licence GNU GPL v3 or later
1313 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1414 */
15 -class EPOrg extends EPDBObject {
 15+class EPOrg extends EPPageObject {
1616
1717 /**
1818 * Cached array of the linked EPMC objects.
@@ -290,29 +290,4 @@
291291 return $this->courses;
292292 }
293293
294 - /**
295 - * Get the title of Special:Institution/name.
296 - *
297 - * @since 0.1
298 - *
299 - * @return Title
300 - */
301 - public function getTitle() {
302 - return SpecialPage::getTitleFor( 'Institution', $this->getField( 'name' ) );
303 - }
304 -
305 - /**
306 - * Get a link to Special:Institution/name.
307 - *
308 - * @since 0.1
309 - *
310 - * @return string
311 - */
312 - public function getLink() {
313 - return Linker::linkKnown(
314 - $this->getTitle(),
315 - htmlspecialchars( $this->getField( 'name' ) )
316 - );
317 - }
318 -
319294 }
Index: trunk/extensions/EducationProgram/includes/EPMC.php
@@ -12,7 +12,7 @@
1313 * @licence GNU GPL v3 or later
1414 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1515 */
16 -class EPMC extends EPDBObject {
 16+class EPMC extends EPPageObject {
1717
1818 /**
1919 * Field for caching the linked org.
@@ -327,31 +327,6 @@
328328 }
329329
330330 /**
331 - * Get a link to Special:Course/name.
332 - *
333 - * @since 0.1
334 - *
335 - * @return string
336 - */
337 - public function getLink() {
338 - return Linker::linkKnown(
339 - $this->getTitle(),
340 - htmlspecialchars( $this->getField( 'name' ) )
341 - );
342 - }
343 -
344 - /**
345 - * Get the title of Special:Course/name.
346 - *
347 - * @since 0.1
348 - *
349 - * @return Title
350 - */
351 - public function getTitle() {
352 - return SpecialPage::getTitleFor( 'MasterCourse', $this->getField( 'name' ) );
353 - }
354 -
355 - /**
356331 * Returns the instructors as a list of EPInstructor objects.
357332 *
358333 * @since 0.1
Index: trunk/extensions/EducationProgram/includes/EPCourse.php
@@ -11,7 +11,7 @@
1212 * @licence GNU GPL v3 or later
1313 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1414 */
15 -class EPCourse extends EPDBObject {
 15+class EPCourse extends EPPageObject {
1616
1717 /**
1818 * Field for caching the linked master course.
@@ -466,18 +466,4 @@
467467 return $status;
468468 }
469469
470 - /**
471 - * Get a link to Special:Course/id.
472 - *
473 - * @since 0.1
474 - *
475 - * @return string
476 - */
477 - public function getLink() {
478 - return Linker::linkKnown(
479 - SpecialPage::getTitleFor( 'Course', $this->getId() ),
480 - htmlspecialchars( $this->getId() )
481 - );
482 - }
483 -
484470 }
Index: trunk/extensions/EducationProgram/includes/EPPageObject.php
@@ -0,0 +1,73 @@
 2+<?php
 3+
 4+/**
 5+ * Abstract base class for EPDBObjects that have associated view, edit and history pages
 6+ *
 7+ * @since 0.1
 8+ *
 9+ * @file EPPageObject.php
 10+ * @ingroup EducationProgram
 11+ *
 12+ * @licence GNU GPL v3 or later
 13+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
 14+ */
 15+abstract class EPPageObject extends EPDBObject {
 16+
 17+ protected static $info = array(
 18+ 'EPCourse' => array(
 19+ 'pages' => array(
 20+ 'view' => 'Course',
 21+ 'edit' => 'EditCourse',
 22+ 'history' => 'CourseHistory',
 23+ ),
 24+ 'edit-right' => 'ep-course',
 25+ 'identifier' => 'id',
 26+ ),
 27+ 'EPMC' => array(
 28+ 'pages' => array(
 29+ 'view' => 'MasterCourse',
 30+ 'edit' => 'EditMasterCourse',
 31+ 'history' => 'MasterCourseHistory',
 32+ ),
 33+ 'edit-right' => 'ep-mc',
 34+ 'identifier' => 'name',
 35+ ),
 36+ 'EPOrg' => array(
 37+ 'pages' => array(
 38+ 'view' => 'Institution',
 39+ 'edit' => 'EditInstitution',
 40+ 'history' => 'InstitutionHistory',
 41+ ),
 42+ 'edit-right' => 'ep-org',
 43+ 'identifier' => 'name',
 44+ ),
 45+ );
 46+
 47+ public static function getIdentifierField() {
 48+ return self::$info[get_called_class()]['identifier'];
 49+ }
 50+
 51+ public function getIdentifier() {
 52+ return $this->getField( self::$info[get_called_class()]['identifier'] );
 53+ }
 54+
 55+ public static function getEditRight() {
 56+ return self::$info[get_called_class()]['edit-right'];
 57+ }
 58+
 59+ public static function getTitleText( $action = 'view' ) {
 60+ return self::$info[get_called_class()]['pages'][$action];
 61+ }
 62+
 63+ public function getTitle( $action = 'view' ) {
 64+ return SpecialPage::getTitleFor( self::getTitleText( $action ), $this->getIdentifier() );
 65+ }
 66+
 67+ public function getLink( $action = 'view' ) {
 68+ return Linker::link(
 69+ self::getTitle( $action ),
 70+ htmlspecialchars( $this->getIdentifier() )
 71+ );
 72+ }
 73+
 74+}
\ No newline at end of file
Index: trunk/extensions/EducationProgram/EducationProgram.php
@@ -83,6 +83,7 @@
8484 $wgAutoloadClasses['EPHTMLDateField'] = dirname( __FILE__ ) . '/includes/EPHTMLDateField.php';
8585 $wgAutoloadClasses['EPRevision'] = dirname( __FILE__ ) . '/includes/EPRevision.php';
8686 $wgAutoloadClasses['EPRevisionPager'] = dirname( __FILE__ ) . '/includes/EPRevisionPager.php';
 87+$wgAutoloadClasses['EPPageObject'] = dirname( __FILE__ ) . '/includes/EPPageObject.php';
8788
8889 $wgAutoloadClasses['SpecialCourse'] = dirname( __FILE__ ) . '/specials/SpecialCourse.php';
8990 $wgAutoloadClasses['SpecialCourses'] = dirname( __FILE__ ) . '/specials/SpecialCourses.php';

Status & tagging log