Index: trunk/extensions/EducationProgram/specials/SpecialMasterCourseHistory.php |
— | — | @@ -19,7 +19,7 @@ |
20 | 20 | * @since 0.1 |
21 | 21 | */ |
22 | 22 | public function __construct() { |
23 | | - parent::__construct( 'MasterCourseHistory', 'EPMC', 'name' ); |
| 23 | + parent::__construct( 'MasterCourseHistory', 'EPMC', 'name', 'MasterCourse' ); |
24 | 24 | } |
25 | 25 | |
26 | 26 | } |
Index: trunk/extensions/EducationProgram/specials/SpecialInstitutionHistory.php |
— | — | @@ -19,7 +19,7 @@ |
20 | 20 | * @since 0.1 |
21 | 21 | */ |
22 | 22 | public function __construct() { |
23 | | - parent::__construct( 'InstitutionHistory', 'EPMC', 'name' ); |
| 23 | + parent::__construct( 'InstitutionHistory', 'EPMC', 'name', 'Institution' ); |
24 | 24 | } |
25 | 25 | |
26 | 26 | } |
Index: trunk/extensions/EducationProgram/specials/SpecialCourseHistory.php |
— | — | @@ -19,7 +19,7 @@ |
20 | 20 | * @since 0.1 |
21 | 21 | */ |
22 | 22 | public function __construct() { |
23 | | - parent::__construct( 'CourseHistory', 'EPCourse', 'id' ); |
| 23 | + parent::__construct( 'CourseHistory', 'EPCourse', 'id', 'Course' ); |
24 | 24 | } |
25 | 25 | |
26 | 26 | } |
Index: trunk/extensions/EducationProgram/specials/SpecialEPHistory.php |
— | — | @@ -26,6 +26,12 @@ |
27 | 27 | protected $className; |
28 | 28 | |
29 | 29 | /** |
| 30 | + * @since 0.1 |
| 31 | + * @var string |
| 32 | + */ |
| 33 | + protected $itemPage; |
| 34 | + |
| 35 | + /** |
30 | 36 | * @see parent::__construct |
31 | 37 | * |
32 | 38 | * @since 0.1 |
— | — | @@ -35,9 +41,10 @@ |
36 | 42 | * @param string $identifierField |
37 | 43 | * @param string $restriction |
38 | 44 | */ |
39 | | - public function __construct( $name, $className, $identifierField, $restriction = '' ) { |
| 45 | + public function __construct( $name, $className, $identifierField, $itemPage, $restriction = '' ) { |
40 | 46 | $this->identifier = $identifierField; |
41 | 47 | $this->className = $className; |
| 48 | + $this->itemPage = $itemPage; |
42 | 49 | |
43 | 50 | parent::__construct( $name, $restriction, false ); |
44 | 51 | } |
— | — | @@ -129,7 +136,7 @@ |
130 | 137 | '</fieldset></form>' |
131 | 138 | ); |
132 | 139 | |
133 | | - $pager = new EPRevisionPager( $this->getContext(), $conditions ); |
| 140 | + $pager = new EPRevisionPager( $this->getContext(), $this->className, $this->itemPage, $conditions ); |
134 | 141 | |
135 | 142 | if ( $pager->getNumRows() ) { |
136 | 143 | $out->addHTML( |
Index: trunk/extensions/EducationProgram/includes/EPDBObject.php |
— | — | @@ -23,7 +23,7 @@ |
24 | 24 | * @since 0.1 |
25 | 25 | * |
26 | 26 | * @file EPDBObject.php |
27 | | - * @ingroup Review |
| 27 | + * @ingroup EducationProgram |
28 | 28 | * |
29 | 29 | * @licence GNU GPL v3 or later |
30 | 30 | * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
Index: trunk/extensions/EducationProgram/includes/EPRevisionPager.php |
— | — | @@ -21,15 +21,30 @@ |
22 | 22 | protected $context; |
23 | 23 | |
24 | 24 | /** |
| 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 | + /** |
25 | 37 | * Constructor. |
26 | 38 | * |
27 | 39 | * @param IContextSource $context |
| 40 | + * @param string $className |
| 41 | + * @param string $itemPage |
28 | 42 | * @param array $conds |
29 | | - * @param string $className |
30 | 43 | */ |
31 | | - public function __construct( IContextSource $context, array $conds ) { |
| 44 | + public function __construct( IContextSource $context, $className, $itemPage, array $conds = array() ) { |
32 | 45 | $this->conds = $conds; |
33 | 46 | $this->context = $context; |
| 47 | + $this->className = $className; |
| 48 | + $this->itemPage = $itemPage; |
34 | 49 | |
35 | 50 | $this->mDefaultDirection = true; |
36 | 51 | |
— | — | @@ -102,6 +117,14 @@ |
103 | 118 | } |
104 | 119 | |
105 | 120 | /** |
| 121 | + * @see parent::getStartBody |
| 122 | + * @since 0.1 |
| 123 | + */ |
| 124 | + function getStartBody() { |
| 125 | + return '<ul>'; |
| 126 | + } |
| 127 | + |
| 128 | + /** |
106 | 129 | * Abstract formatting function. This should return an HTML string |
107 | 130 | * representing the result row $row. Rows will be concatenated and |
108 | 131 | * returned by getBody() |
— | — | @@ -111,10 +134,35 @@ |
112 | 135 | * @return String |
113 | 136 | */ |
114 | 137 | 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>'; |
116 | 156 | } |
117 | 157 | |
118 | 158 | /** |
| 159 | + * @see parent::getEndBody |
| 160 | + * @since 0.1 |
| 161 | + */ |
| 162 | + function getEndBody() { |
| 163 | + return '</ul>'; |
| 164 | + } |
| 165 | + |
| 166 | + /** |
119 | 167 | * This function should be overridden to provide all parameters |
120 | 168 | * needed for the main paged query. It returns an associative |
121 | 169 | * array with the following elements: |
Index: trunk/extensions/EducationProgram/includes/EPOrg.php |
— | — | @@ -11,7 +11,7 @@ |
12 | 12 | * @licence GNU GPL v3 or later |
13 | 13 | * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
14 | 14 | */ |
15 | | -class EPOrg extends EPDBObject { |
| 15 | +class EPOrg extends EPPageObject { |
16 | 16 | |
17 | 17 | /** |
18 | 18 | * Cached array of the linked EPMC objects. |
— | — | @@ -290,29 +290,4 @@ |
291 | 291 | return $this->courses; |
292 | 292 | } |
293 | 293 | |
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 | | - |
319 | 294 | } |
Index: trunk/extensions/EducationProgram/includes/EPMC.php |
— | — | @@ -12,7 +12,7 @@ |
13 | 13 | * @licence GNU GPL v3 or later |
14 | 14 | * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
15 | 15 | */ |
16 | | -class EPMC extends EPDBObject { |
| 16 | +class EPMC extends EPPageObject { |
17 | 17 | |
18 | 18 | /** |
19 | 19 | * Field for caching the linked org. |
— | — | @@ -327,31 +327,6 @@ |
328 | 328 | } |
329 | 329 | |
330 | 330 | /** |
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 | | - /** |
356 | 331 | * Returns the instructors as a list of EPInstructor objects. |
357 | 332 | * |
358 | 333 | * @since 0.1 |
Index: trunk/extensions/EducationProgram/includes/EPCourse.php |
— | — | @@ -11,7 +11,7 @@ |
12 | 12 | * @licence GNU GPL v3 or later |
13 | 13 | * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
14 | 14 | */ |
15 | | -class EPCourse extends EPDBObject { |
| 15 | +class EPCourse extends EPPageObject { |
16 | 16 | |
17 | 17 | /** |
18 | 18 | * Field for caching the linked master course. |
— | — | @@ -466,18 +466,4 @@ |
467 | 467 | return $status; |
468 | 468 | } |
469 | 469 | |
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 | | - |
484 | 470 | } |
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 @@ |
84 | 84 | $wgAutoloadClasses['EPHTMLDateField'] = dirname( __FILE__ ) . '/includes/EPHTMLDateField.php'; |
85 | 85 | $wgAutoloadClasses['EPRevision'] = dirname( __FILE__ ) . '/includes/EPRevision.php'; |
86 | 86 | $wgAutoloadClasses['EPRevisionPager'] = dirname( __FILE__ ) . '/includes/EPRevisionPager.php'; |
| 87 | +$wgAutoloadClasses['EPPageObject'] = dirname( __FILE__ ) . '/includes/EPPageObject.php'; |
87 | 88 | |
88 | 89 | $wgAutoloadClasses['SpecialCourse'] = dirname( __FILE__ ) . '/specials/SpecialCourse.php'; |
89 | 90 | $wgAutoloadClasses['SpecialCourses'] = dirname( __FILE__ ) . '/specials/SpecialCourses.php'; |