r111504 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111503‎ | r111504 | r111505 >
Date:22:55, 14 February 2012
Author:jeroendedauw
Status:deferred
Tags:
Comment:
follow up to r111491, fix various issues due to refactoring
Modified paths:
  • /trunk/extensions/EducationProgram/EducationProgram.hooks.php (modified) (history)
  • /trunk/extensions/EducationProgram/EducationProgram.php (modified) (history)
  • /trunk/extensions/EducationProgram/actions/CourseHistoryAction.php (modified) (history)
  • /trunk/extensions/EducationProgram/actions/EPEditAction.php (modified) (history)
  • /trunk/extensions/EducationProgram/actions/EPHistoryAction.php (modified) (history)
  • /trunk/extensions/EducationProgram/actions/EPViewAction.php (modified) (history)
  • /trunk/extensions/EducationProgram/actions/EditCourseAction.php (modified) (history)
  • /trunk/extensions/EducationProgram/actions/EditOrgAction.php (modified) (history)
  • /trunk/extensions/EducationProgram/actions/OrgHistoryAction.php (modified) (history)
  • /trunk/extensions/EducationProgram/actions/ViewCourseAction.php (modified) (history)
  • /trunk/extensions/EducationProgram/actions/ViewOrgAction.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPArticle.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPArticlePager.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPArticles.php (added) (history)
  • /trunk/extensions/EducationProgram/includes/EPCourse.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPCoursePager.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPCourses.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPOrgPager.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPOrgs.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPPageObject.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPPageTable.php (added) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/EducationProgram.php
@@ -92,6 +92,7 @@
9393 $wgAutoloadClasses['EPRevision'] = dirname( __FILE__ ) . '/includes/EPRevision.php';
9494 $wgAutoloadClasses['EPRevisionPager'] = dirname( __FILE__ ) . '/includes/EPRevisionPager.php';
9595 $wgAutoloadClasses['EPPageObject'] = dirname( __FILE__ ) . '/includes/EPPageObject.php';
 96+$wgAutoloadClasses['EPPageTable'] = dirname( __FILE__ ) . '/includes/EPPageTable.php';
9697 $wgAutoloadClasses['EPFailForm'] = dirname( __FILE__ ) . '/includes/EPFailForm.php';
9798 $wgAutoloadClasses['EPIRole'] = dirname( __FILE__ ) . '/includes/EPIRole.php';
9899 $wgAutoloadClasses['EPRevisionedObject'] = dirname( __FILE__ ) . '/includes/EPRevisionedObject.php';
@@ -107,6 +108,7 @@
108109 $wgAutoloadClasses['EPCAs'] = dirname( __FILE__ ) . '/includes/EPCAs.php';
109110 $wgAutoloadClasses['EPInstructors'] = dirname( __FILE__ ) . '/includes/EPInstructors.php';
110111 $wgAutoloadClasses['EPRevisions'] = dirname( __FILE__ ) . '/includes/EPRevisions.php';
 112+$wgAutoloadClasses['EPArticles'] = dirname( __FILE__ ) . '/includes/EPArticles.php';
111113
112114 $wgAutoloadClasses['CoursePage'] = dirname( __FILE__ ) . '/pages/CoursePage.php';
113115 $wgAutoloadClasses['EPPage'] = dirname( __FILE__ ) . '/pages/EPPage.php';
Index: trunk/extensions/EducationProgram/actions/ViewCourseAction.php
@@ -13,15 +13,23 @@
1414 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1515 */
1616 class ViewCourseAction extends EPViewAction {
17 -
 17+
 18+ /**
 19+ * Constructor.
 20+ *
 21+ * @since 0.1
 22+ *
 23+ * @param Page $page
 24+ * @param IContextSource $context
 25+ */
 26+ protected function __construct( Page $page, IContextSource $context = null ) {
 27+ parent::__construct( $page, $context, EPCourses::singleton() );
 28+ }
 29+
1830 public function getName() {
1931 return 'viewcourse';
2032 }
2133
22 - protected function getItemClass() {
23 - return 'EPCourse';
24 - }
25 -
2634 protected function displayPage( DBDataObject $course ) {
2735 parent::displayPage( $course );
2836
@@ -62,8 +70,8 @@
6371 protected function getSummaryData( DBDataObject $course ) {
6472 $stats = array();
6573
66 - $orgName = EPOrg::selectFieldsRow( 'name', array( 'id' => $course->getField( 'org_id' ) ) );
67 - $stats['org'] = EPOrg::getLinkFor( $orgName );
 74+ $orgName = EPOrgs::singleton()->selectFieldsRow( 'name', array( 'id' => $course->getField( 'org_id' ) ) );
 75+ $stats['org'] = EPOrgs::singleton()->getLinkFor( $orgName );
6876
6977 $lang = $this->getLanguage();
7078
Index: trunk/extensions/EducationProgram/actions/EditOrgAction.php
@@ -13,8 +13,20 @@
1414 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1515 */
1616 class EditOrgAction extends EPEditAction {
17 -
 17+
1818 /**
 19+ * Constructor.
 20+ *
 21+ * @since 0.1
 22+ *
 23+ * @param Page $page
 24+ * @param IContextSource $context
 25+ */
 26+ protected function __construct( Page $page, IContextSource $context = null ) {
 27+ parent::__construct( $page, $context, EPOrgs::singleton() );
 28+ }
 29+
 30+ /**
1931 * (non-PHPdoc)
2032 * @see Action::getName()
2133 */
@@ -32,14 +44,6 @@
3345
3446 /**
3547 * (non-PHPdoc)
36 - * @see EPEditAction::getItemClass()
37 - */
38 - protected function getItemClass() {
39 - return 'EPOrg';
40 - }
41 -
42 - /**
43 - * (non-PHPdoc)
4448 * @see Action::getRestriction()
4549 */
4650 public function getRestriction() {
Index: trunk/extensions/EducationProgram/actions/EPViewAction.php
@@ -15,13 +15,24 @@
1616 abstract class EPViewAction extends FormlessAction {
1717
1818 /**
19 - * Returns the class name of the DBDataObject this action handles.
 19+ * @since 0.1
 20+ * @var DBTable
 21+ */
 22+ protected $table;
 23+
 24+ /**
 25+ * Constructor.
2026 *
2127 * @since 0.1
2228 *
23 - * @return string
 29+ * @param Page $page
 30+ * @param IContextSource $context
 31+ * @param DBTable $table
2432 */
25 - protected abstract function getItemClass();
 33+ protected function __construct( Page $page, IContextSource $context = null, DBTable $table ) {
 34+ $this->table = $table;
 35+ parent::__construct( $page, $context );
 36+ }
2637
2738 /**
2839 * (non-PHPdoc)
@@ -30,12 +41,11 @@
3142 public function onView() {
3243 $out = $this->getOutput();
3344 $name = $this->getTitle()->getText();
34 - $class = $this->getItemClass();
3545
3646 $object = false;
3747
3848 if ( $this->getRequest()->getCheck( 'revid' ) ) {
39 - $currentObject = $class::get( $name, 'id' );
 49+ $currentObject = $this->table->get( $name, 'id' );
4050
4151 if ( $currentObject !== false ) {
4252 $rev = EPRevision::selectRow( null, array(
@@ -54,19 +64,19 @@
5565 }
5666
5767 if ( $object === false ) {
58 - $object = $class::get( $name );
 68+ $object = $this->table->get( $name );
5969 }
6070
6171 if ( $object === false ) {
6272 $this->displayNavigation();
6373
64 - if ( $this->getUser()->isAllowed( $class::getEditRight() ) ) {
 74+ if ( $this->getUser()->isAllowed( $this->table->getEditRight() ) ) {
6575 $out->redirect( $this->getTitle()->getLocalURL( array( 'action' => 'edit' ) ) );
6676 }
6777 else {
6878 $out->addWikiMsg( strtolower( get_called_class() ) . '-none', $name );
69 -
70 - $class::displayDeletionLog(
 79+
 80+ $this->table->displayDeletionLog(
7181 $this->getContext(),
7282 'ep-' . strtolower( $this->getName() ) . '-deleted'
7383 );
Index: trunk/extensions/EducationProgram/actions/CourseHistoryAction.php
@@ -13,8 +13,19 @@
1414 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1515 */
1616 class CourseHistoryAction extends EPHistoryAction {
17 -
18 -
 17+
 18+ /**
 19+ * Constructor.
 20+ *
 21+ * @since 0.1
 22+ *
 23+ * @param Page $page
 24+ * @param IContextSource $context
 25+ */
 26+ protected function __construct( Page $page, IContextSource $context = null ) {
 27+ parent::__construct( $page, $context, EPCourses::singleton() );
 28+ }
 29+
1930 public function getName() {
2031 return 'coursehistory';
2132 }
@@ -27,9 +38,5 @@
2839 array( 'page' => $this->getTitle()->getPrefixedText() )
2940 );
3041 }
31 -
32 - protected function getItemClass() {
33 - return 'EPCourse';
34 - }
3542
3643 }
\ No newline at end of file
Index: trunk/extensions/EducationProgram/actions/ViewOrgAction.php
@@ -13,15 +13,23 @@
1414 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1515 */
1616 class ViewOrgAction extends EPViewAction {
17 -
 17+
 18+ /**
 19+ * Constructor.
 20+ *
 21+ * @since 0.1
 22+ *
 23+ * @param Page $page
 24+ * @param IContextSource $context
 25+ */
 26+ protected function __construct( Page $page, IContextSource $context = null ) {
 27+ parent::__construct( $page, $context, EPOrgs::singleton() );
 28+ }
 29+
1830 public function getName() {
1931 return 'vieworg';
2032 }
2133
22 - protected function getItemClass() {
23 - return 'EPOrg';
24 - }
25 -
2634 protected function displayPage( DBDataObject $org ) {
2735 parent::displayPage( $org );
2836
Index: trunk/extensions/EducationProgram/actions/EPHistoryAction.php
@@ -15,13 +15,24 @@
1616 abstract class EPHistoryAction extends FormlessAction {
1717
1818 /**
19 - * Returns the class name of the EPPageObject this action handles.
 19+ * @since 0.1
 20+ * @var DBTable
 21+ */
 22+ protected $table;
 23+
 24+ /**
 25+ * Constructor.
2026 *
2127 * @since 0.1
2228 *
23 - * @return string
 29+ * @param Page $page
 30+ * @param IContextSource $context
 31+ * @param DBTable $table
2432 */
25 - protected abstract function getItemClass();
 33+ protected function __construct( Page $page, IContextSource $context = null, DBTable $table ) {
 34+ $this->table = $table;
 35+ parent::__construct( $page, $context );
 36+ }
2637
2738 /**
2839 * (non-PHPdoc)
@@ -30,9 +41,7 @@
3142 public function onView() {
3243 $this->getOutput()->setPageTitle( $this->getPageTitle() );
3344
34 - $c = $this->getItemClass(); // Yeah, this is needed in PHP 5.3 >_>
35 -
36 - $object = $c::get( $this->getTitle()->getText() );
 45+ $object = $this->table->get( $this->getTitle()->getText() );
3746
3847 if ( $object === false ) {
3948 $this->displayNoRevisions();
@@ -47,9 +56,7 @@
4857 protected function displayNoRevisions() {
4958 $this->getOutput()->addWikiMsg( 'ep-' . strtolower( $this->getName() ) . '-norevs' );
5059
51 - $c = $this->getItemClass(); // Yeah, this is needed in PHP 5.3 >_>
52 -
53 - $c::displayDeletionLog(
 60+ $this->table->displayDeletionLog(
5461 $this->getContext(),
5562 'ep-' . strtolower( $this->getName() ) . '-deleted'
5663 );
Index: trunk/extensions/EducationProgram/actions/EditCourseAction.php
@@ -13,8 +13,20 @@
1414 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1515 */
1616 class EditCourseAction extends EPEditAction {
17 -
 17+
1818 /**
 19+ * Constructor.
 20+ *
 21+ * @since 0.1
 22+ *
 23+ * @param Page $page
 24+ * @param IContextSource $context
 25+ */
 26+ protected function __construct( Page $page, IContextSource $context = null ) {
 27+ parent::__construct( $page, $context, EPCourses::singleton() );
 28+ }
 29+
 30+ /**
1931 * (non-PHPdoc)
2032 * @see Action::getName()
2133 */
@@ -45,10 +57,8 @@
4658 public function onView() {
4759 $this->getOutput()->addModules( array( 'ep.datepicker', 'ep.combobox' ) );
4860
49 - $c = $this->getItemClass(); // Yeah, this is needed in PHP 5.3 >_>
50 -
51 - if ( !$this->isNewPost() && !$c::hasIdentifier( $this->getTitle()->getText() ) ) {
52 - $c::displayDeletionLog(
 61+ if ( !$this->isNewPost() && !$this->table->hasIdentifier( $this->getTitle()->getText() ) ) {
 62+ $this->table->displayDeletionLog(
5363 $this->getContext(),
5464 'ep-' . strtolower( $this->getName() ) . '-deleted'
5565 );
@@ -105,22 +115,13 @@
106116
107117 /**
108118 * (non-PHPdoc)
109 - * @see EPEditAction::getItemClass()
110 - * @return string
111 - */
112 - protected function getItemClass() {
113 - return 'EPCourse';
114 - }
115 -
116 - /**
117 - * (non-PHPdoc)
118119 * @see EPEditAction::getFormFields()
119120 * @return array
120121 */
121122 protected function getFormFields() {
122123 $fields = parent::getFormFields();
123124
124 - $orgOptions = EPOrg::getOrgOptions();
 125+ $orgOptions = EPOrgs::singleton()->getOrgOptions();
125126
126127 $fields['name'] = array (
127128 'type' => 'text',
@@ -128,7 +129,7 @@
129130 'required' => true,
130131 );
131132
132 - $mcs = EPCourse::selectFields( 'mc', array(), array( 'DISTINCT' ) );
 133+ $mcs = $this->table->selectFields( 'mc', array(), array( 'DISTINCT' ) );
133134
134135 if ( $this->getRequest()->getCheck( 'newname' ) ) {
135136 $newName = $this->getRequest()->getText( 'newname' );
@@ -138,7 +139,6 @@
139140 $mcs = array_merge( array( '' => '' ), $mcs );
140141 }
141142
142 -
143143 $fields['mc'] = array (
144144 'class' => 'EPHTMLCombobox',
145145 'label-message' => 'ep-course-edit-mc',
@@ -185,7 +185,7 @@
186186 'required' => true,
187187 );
188188
189 - $fieldFields = EPCourse::selectFields( 'field', array(), array( 'DISTINCT' ) );
 189+ $fieldFields = $this->table->selectFields( 'field', array(), array( 'DISTINCT' ) );
190190 $fieldFields = array_merge( array( '' => '' ), $fieldFields );
191191 $fields['field'] = array (
192192 'class' => 'EPHTMLCombobox',
@@ -194,7 +194,7 @@
195195 'options' => array_combine( $fieldFields, $fieldFields ),
196196 );
197197
198 - $levels = EPCourse::selectFields( 'level', array(), array( 'DISTINCT' ) );
 198+ $levels = $this->table->selectFields( 'level', array(), array( 'DISTINCT' ) );
199199 $levels = array_merge( array( '' => '' ), $levels );
200200 $fields['level'] = array (
201201 'class' => 'EPHTMLCombobox',
Index: trunk/extensions/EducationProgram/actions/OrgHistoryAction.php
@@ -13,8 +13,19 @@
1414 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1515 */
1616 class OrgHistoryAction extends EPHistoryAction {
 17+
 18+ /**
 19+ * Constructor.
 20+ *
 21+ * @since 0.1
 22+ *
 23+ * @param Page $page
 24+ * @param IContextSource $context
 25+ */
 26+ protected function __construct( Page $page, IContextSource $context = null ) {
 27+ parent::__construct( $page, $context, EPOrgs::singleton() );
 28+ }
1729
18 -
1930 public function getName() {
2031 return 'orghistory';
2132 }
@@ -28,8 +39,4 @@
2940 );
3041 }
3142
32 - protected function getItemClass() {
33 - return 'EPOrg';
34 - }
35 -
3643 }
\ No newline at end of file
Index: trunk/extensions/EducationProgram/actions/EPEditAction.php
@@ -31,14 +31,25 @@
3232 protected $isNew = null;
3333
3434 /**
35 - * Returns the class name of the EPPageObject this action handles.
 35+ * @since 0.1
 36+ * @var DBTable
 37+ */
 38+ protected $table;
 39+
 40+ /**
 41+ * Constructor.
3642 *
3743 * @since 0.1
3844 *
39 - * @return string
 45+ * @param Page $page
 46+ * @param IContextSource $context
 47+ * @param DBTable $table
4048 */
41 - protected abstract function getItemClass();
42 -
 49+ protected function __construct( Page $page, IContextSource $context = null, DBTable $table ) {
 50+ $this->table = $table;
 51+ parent::__construct( $page, $context );
 52+ }
 53+
4354 /**
4455 * (non-PHPdoc)
4556 * @see FormlessAction::onView()
@@ -80,24 +91,23 @@
8192 protected function showContent() {
8293 $out = $this->getOutput();
8394
84 - $c = $this->getItemClass(); // Yeah, this is needed in PHP 5.3 >_>
85 -
8695 $data = $this->getNewData();
8796
88 - $object = $c::selectRow( null, $data );
 97+ $object = $this->table->selectRow( null, $data );
8998
9099 if ( $object !== false && $this->getRequest()->getText( 'redlink' ) === '1' ) {
91100 $out->redirect( $this->getTitle()->getLocalURL() );
92101 }
93102 else {
94103 if ( $object === false ) {
 104+ $c = $this->table->getDataObjectClass();
95105 $c::displayDeletionLog(
96106 $this->getContext(),
97 - 'ep-' . strtolower( $this->getName() ) . '-deleted'
 107+ 'ep-' . strtolower( $this->getName() ) . '-deleted'
98108 );
99109
100110 $this->isNew = true;
101 - $object = new $c( $data, true );
 111+ $object = $this->table->newFromArray( $data, true );
102112 }
103113 elseif ( $this->isNewPost() ) {
104114 $this->showWarning( wfMessage( 'ep-' . strtolower( $this->getName() ) . '-exists-already' ) );
@@ -345,14 +355,14 @@
346356 return Title::newFromText( $this->getRequest()->getText( 'wpreturnto' ) );
347357 }
348358 elseif ( !$addedItem && $this->isNew() ) {
349 - $c = $this->getItemClass(); // Yeah, this is needed in PHP 5.3 >_>
 359+ $c = $this->table->getDataObjectClass(); // Yeah, this is needed in PHP 5.3 >_>
350360 return SpecialPage::getTitleFor( $c::getListPage() );
351361 }
352362 elseif ( $this->item !== false ) {
353363 return $this->item->getTitle();
354364 }
355365 else {
356 - $c = $this->getItemClass(); // Yeah, this is needed in PHP 5.3 >_>
 366+ $c = $this->table->getDataObjectClass(); // Yeah, this is needed in PHP 5.3 >_>
357367 $fieldName = 'wpitem-' . $c::getIdentifierField();
358368
359369 if ( $this->getRequest()->getCheck( $fieldName ) ) {
@@ -376,8 +386,6 @@
377387 $fields = array();
378388 $unknownValues = array();
379389
380 - $c = $this->getItemClass(); // Yeah, this is needed in PHP 5.3 >_>
381 -
382390 foreach ( $data as $name => $value ) {
383391 $matches = array();
384392
@@ -386,7 +394,7 @@
387395 $value = null;
388396 }
389397
390 - if ( $c::canHaveField( $matches[1] ) ) {
 398+ if ( $this->table->canHaveField( $matches[1] ) ) {
391399 $fields[$matches[1]] = $value;
392400 }
393401 else {
@@ -398,7 +406,7 @@
399407 $keys = array_keys( $fields );
400408 $fields = array_combine( $keys, array_map( array( $this, 'handleKnownField' ), $keys, $fields ) );
401409
402 - /* EPPageObject */ $item = new $c( $fields, is_null( $fields['id'] ) );
 410+ /* EPPageObject */ $item = $this->table->newFromArray( $fields, is_null( $fields['id'] ) );
403411
404412 foreach ( $unknownValues as $name => $value ) {
405413 $this->handleUnknownField( $item, $name, $value );
Index: trunk/extensions/EducationProgram/includes/EPOrgPager.php
@@ -62,7 +62,7 @@
6363 public function getFormattedValue( $name, $value ) {
6464 switch ( $name ) {
6565 case 'name':
66 - $value = EPOrg::getLinkFor( $value );
 66+ $value = EPOrgs::getLinkFor( $value );
6767 break;
6868 case 'country':
6969 $countries = array_flip( EPUtils::getCountryOptions( $this->getLanguage()->getCode() ) );
Index: trunk/extensions/EducationProgram/includes/EPArticles.php
@@ -0,0 +1,75 @@
 2+<?php
 3+
 4+/**
 5+ * Class representing the ep_articles table.
 6+ *
 7+ * @since 0.1
 8+ *
 9+ * @file EPArticles.php
 10+ * @ingroup EducationProgram
 11+ *
 12+ * @licence GNU GPL v3 or later
 13+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
 14+ */
 15+class EPArticles extends DBTable {
 16+
 17+ /**
 18+ * (non-PHPdoc)
 19+ * @see DBTable::getDBTable()
 20+ * @since 0.1
 21+ * @return string
 22+ */
 23+ public function getDBTable() {
 24+ return 'ep_articles';
 25+ }
 26+
 27+ /**
 28+ * (non-PHPdoc)
 29+ * @see DBTable::getFieldPrefix()
 30+ * @since 0.1
 31+ * @return string
 32+ */
 33+ public function getFieldPrefix() {
 34+ return 'article_';
 35+ }
 36+
 37+ /**
 38+ * (non-PHPdoc)
 39+ * @see DBTable::getDataObjectClass()
 40+ * @since 0.1
 41+ * @return string
 42+ */
 43+ public function getDataObjectClass() {
 44+ return 'EPArticle';
 45+ }
 46+
 47+ /**
 48+ * (non-PHPdoc)
 49+ * @see DBTable::getFieldTypes()
 50+ * @since 0.1
 51+ * @return array
 52+ */
 53+ public function getFieldTypes() {
 54+ return array(
 55+ 'id' => 'id',
 56+
 57+ 'course_id' => 'int',
 58+ 'user_id' => 'int',
 59+ 'page_id' => 'int',
 60+ 'reviewers' => 'array',
 61+ );
 62+ }
 63+
 64+ /**
 65+ * (non-PHPdoc)
 66+ * @see DBTable::getDefaults()
 67+ * @since 0.1
 68+ * @return array
 69+ */
 70+ public function getDefaults() {
 71+ return array(
 72+ 'reviewers' => array(),
 73+ );
 74+ }
 75+
 76+}
Index: trunk/extensions/EducationProgram/includes/EPOrgs.php
@@ -11,7 +11,7 @@
1212 * @licence GNU GPL v3 or later
1313 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1414 */
15 -class EPOrgs extends DBTable {
 15+class EPOrgs extends EPPageTable {
1616
1717 /**
1818 * (non-PHPdoc)
Index: trunk/extensions/EducationProgram/includes/EPPageTable.php
@@ -0,0 +1,160 @@
 2+<?php
 3+
 4+/**
 5+ * Abstract base class DBDataObjects that have associated page views.
 6+ *
 7+ * @since 0.1
 8+ *
 9+ * @file EPPageTable.php
 10+ * @ingroup EducationProgram
 11+ *
 12+ * @licence GNU GPL v3 or later
 13+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
 14+ */
 15+abstract class EPPageTable extends DBTable {
 16+
 17+ protected static $info = array(
 18+ 'EPCourses' => array(
 19+ 'ns' => EP_NS_COURSE,
 20+ 'actions' => array(
 21+ 'view' => false,
 22+ 'edit' => 'ep-course',
 23+ 'history' => false,
 24+ 'enroll' => 'ep-enroll',
 25+ ),
 26+ 'edit-right' => 'ep-course',
 27+ 'identifier' => 'name',
 28+ 'list' => 'Courses',
 29+ 'log-type' => 'course',
 30+ ),
 31+ 'EPOrgs' => array(
 32+ 'ns' => EP_NS_INSTITUTION,
 33+ 'actions' => array(
 34+ 'view' => false,
 35+ 'edit' => 'ep-org',
 36+ 'history' => false,
 37+ ),
 38+ 'edit-right' => 'ep-org',
 39+ 'identifier' => 'name',
 40+ 'list' => 'Institutions',
 41+ 'log-type' => 'institution',
 42+ ),
 43+ );
 44+
 45+ public function getIdentifierField() {
 46+ return self::$info[get_called_class()]['identifier'];
 47+ }
 48+
 49+ public function getEditRight() {
 50+ return self::$info[get_called_class()]['edit-right'];
 51+ }
 52+
 53+ public static function getTitleFor( $identifierValue ) {
 54+ return Title::newFromText(
 55+ $identifierValue,
 56+ self::$info[get_called_class()]['ns']
 57+ );
 58+ }
 59+
 60+ public static function getLinkFor( $identifierValue, $action = 'view', $html = null, $customAttribs = array(), $query = array() ) {
 61+ if ( $action !== 'view' ) {
 62+ $query['action'] = $action;
 63+ }
 64+
 65+ return Linker::linkKnown( // Linker has no hook that allows us to figure out if the page actually exists :(
 66+ self::getTitleFor( $identifierValue, $action ),
 67+ is_null( $html ) ? htmlspecialchars( $identifierValue ) : $html,
 68+ $customAttribs,
 69+ $query
 70+ );
 71+ }
 72+
 73+ public function hasIdentifier( $identifier ) {
 74+ return $this->has( array( $this->getIdentifierField() => $identifier ) );
 75+ }
 76+
 77+ public function get( $identifier, $fields = null ) {
 78+ return static::selectRow( $fields, array( $this->getIdentifierField() => $identifier ) );
 79+ }
 80+
 81+ public function getListPage() {
 82+ return self::$info[get_called_class()]['list'];
 83+ }
 84+
 85+ /**
 86+ * Delete all objects matching the provided condirions.
 87+ *
 88+ * @since 0.1
 89+ *
 90+ * @param EPRevisionAction $revAction
 91+ * @param array $conditions
 92+ *
 93+ * @return boolean
 94+ */
 95+ public function deleteAndLog( EPRevisionAction $revAction, array $conditions ) {
 96+ $objects = $this->select(
 97+ null,
 98+ $conditions
 99+ );
 100+
 101+ $success = true;
 102+
 103+ if ( count( $objects ) > 0 ) {
 104+ $revAction->setDelete( true );
 105+
 106+ foreach ( $objects as /* EPPageObject */ $object ) {
 107+ $success = $object->revisionedRemove( $revAction ) && $success;
 108+ }
 109+ }
 110+
 111+ return $success;
 112+ }
 113+
 114+ /**
 115+ * (non-PHPdoc)
 116+ * @see EPRevisionedObject::getLogInfo()
 117+ */
 118+ protected function getLogInfoForTitle( Title $title ) {
 119+ return array(
 120+ 'type' => self::$info[get_called_class()]['log-type'],
 121+ 'title' => $title,
 122+ );
 123+ }
 124+
 125+ public static function getTypeForNS( $ns ) {
 126+ foreach ( self::$info as $type => $info ) {
 127+ if ( $info['ns'] === $ns ) {
 128+ return $type;
 129+ }
 130+ }
 131+
 132+ throw new MWException( 'Unknown EPPageObject ns' );
 133+ }
 134+
 135+ public static function getLatestRevForTitle( Title $title, $conditions = array() ) {
 136+ $conds = array(
 137+ 'type' => self::getTypeForNS( $title->getNamespace() ),
 138+ 'object_identifier' => $title->getText(),
 139+ );
 140+
 141+ return EPRevision::getLastRevision( array_merge( $conds, $conditions ) );
 142+ }
 143+
 144+ public static function displayDeletionLog( IContextSource $context, $messageKey ) {
 145+ $out = $context->getOutput();
 146+
 147+ LogEventsList::showLogExtract(
 148+ $out,
 149+ array( self::$info[get_called_class()]['log-type'] ),
 150+ $context->getTitle(),
 151+ '',
 152+ array(
 153+ 'lim' => 10,
 154+ 'conds' => array( 'log_action' => 'remove' ),
 155+ 'showIfEmpty' => false,
 156+ 'msgKey' => array( $messageKey )
 157+ )
 158+ );
 159+ }
 160+
 161+}
Index: trunk/extensions/EducationProgram/includes/EPPageObject.php
@@ -13,55 +13,16 @@
1414 */
1515 abstract class EPPageObject extends EPRevisionedObject {
1616
17 - protected static $info = array(
18 - 'EPCourse' => array(
19 - 'ns' => EP_NS_COURSE,
20 - 'actions' => array(
21 - 'view' => false,
22 - 'edit' => 'ep-course',
23 - 'history' => false,
24 - 'enroll' => 'ep-enroll',
25 - ),
26 - 'edit-right' => 'ep-course',
27 - 'identifier' => 'name',
28 - 'list' => 'Courses',
29 - 'log-type' => 'course',
30 - ),
31 - 'EPOrg' => array(
32 - 'ns' => EP_NS_INSTITUTION,
33 - 'actions' => array(
34 - 'view' => false,
35 - 'edit' => 'ep-org',
36 - 'history' => false,
37 - ),
38 - 'edit-right' => 'ep-org',
39 - 'identifier' => 'name',
40 - 'list' => 'Institutions',
41 - 'log-type' => 'institution',
42 - ),
43 - );
44 -
45 - public static function getIdentifierField() {
46 - return self::$info[get_called_class()]['identifier'];
47 - }
48 -
4917 public function getIdentifier() {
50 - return $this->getField( self::$info[get_called_class()]['identifier'] );
 18+ return $this->getField( $this->table->getIdentifierField() );
5119 }
5220
53 - public static function getEditRight() {
54 - return self::$info[get_called_class()]['edit-right'];
55 - }
56 -
5721 public function getTitle() {
58 - return Title::newFromText(
59 - $this->getIdentifier(),
60 - self::$info[get_called_class()]['ns']
61 - );
 22+ return $this->table->getTitleFor( $this->getIdentifier() );
6223 }
6324
6425 public function getLink( $action = 'view', $html = null, $customAttribs = array(), $query = array() ) {
65 - return self::getLinkFor(
 26+ return $this->table->getLinkFor(
6627 $this->getIdentifier(),
6728 $action,
6829 $html,
@@ -70,112 +31,12 @@
7132 );
7233 }
7334
74 - public static function getTitleFor( $identifierValue ) {
75 - return Title::newFromText(
76 - $identifierValue,
77 - self::$info[get_called_class()]['ns']
78 - );
79 - }
80 -
81 - public static function getLinkFor( $identifierValue, $action = 'view', $html = null, $customAttribs = array(), $query = array() ) {
82 - if ( $action !== 'view' ) {
83 - $query['action'] = $action;
84 - }
85 -
86 - return Linker::linkKnown( // Linker has no hook that allows us to figure out if the page actually exists :(
87 - self::getTitleFor( $identifierValue, $action ),
88 - is_null( $html ) ? htmlspecialchars( $identifierValue ) : $html,
89 - $customAttribs,
90 - $query
91 - );
92 - }
93 -
94 - public static function hasIdentifier( $identifier ) {
95 - return static::has( array( static::getIdentifierField() => $identifier ) );
96 - }
97 -
98 - public static function get( $identifier, $fields = null ) {
99 - return static::selectRow( $fields, array( static::getIdentifierField() => $identifier ) );
100 - }
101 -
102 - public static function getListPage() {
103 - return self::$info[get_called_class()]['list'];
104 - }
105 -
10635 /**
107 - * Delete all objects matching the provided condirions.
108 - *
109 - * @since 0.1
110 - *
111 - * @param EPRevisionAction $revAction
112 - * @param array $conditions
113 - *
114 - * @return boolean
115 - */
116 - public static function deleteAndLog( EPRevisionAction $revAction, array $conditions ) {
117 - $objects = static::select(
118 - null,
119 - $conditions
120 - );
121 -
122 - $success = true;
123 -
124 - if ( count( $objects ) > 0 ) {
125 - $revAction->setDelete( true );
126 -
127 - foreach ( $objects as /* EPPageObject */ $object ) {
128 - $success = $object->revisionedRemove( $revAction ) && $success;
129 - }
130 - }
131 -
132 - return $success;
133 - }
134 -
135 - /**
13636 * (non-PHPdoc)
13737 * @see EPRevisionedObject::getLogInfo()
13838 */
13939 protected function getLogInfo( $subType ) {
140 - return array(
141 - 'type' => self::$info[get_called_class()]['log-type'],
142 - 'title' => $this->getTitle(),
143 - );
 40+ return $this->table->getLogInfoForTitle( $this->getTitle() );
14441 }
14542
146 - public static function getTypeForNS( $ns ) {
147 - foreach ( self::$info as $type => $info ) {
148 - if ( $info['ns'] === $ns ) {
149 - return $type;
150 - }
151 - }
152 -
153 - throw new MWException( 'Unknown EPPageObject ns' );
154 - }
155 -
156 - public static function getLatestRevForTitle( Title $title, $conditions = array() ) {
157 - $conds = array(
158 - 'type' => self::getTypeForNS( $title->getNamespace() ),
159 - 'object_identifier' => $title->getText(),
160 - );
161 -
162 - return EPRevision::getLastRevision( array_merge( $conds, $conditions ) );
163 - }
164 -
165 - public static function displayDeletionLog( IContextSource $context, $messageKey ) {
166 - $out = $context->getOutput();
167 -
168 - LogEventsList::showLogExtract(
169 - $out,
170 - array( self::$info[get_called_class()]['log-type'] ),
171 - $context->getTitle(),
172 - '',
173 - array(
174 - 'lim' => 10,
175 - 'conds' => array( 'log_action' => 'remove' ),
176 - 'showIfEmpty' => false,
177 - 'msgKey' => array( $messageKey )
178 - )
179 - );
180 - }
181 -
18243 }
Index: trunk/extensions/EducationProgram/includes/EPCoursePager.php
@@ -72,7 +72,7 @@
7373 public function getFormattedValue( $name, $value ) {
7474 switch ( $name ) {
7575 case 'name':
76 - $value = EPCourse::getLinkFor( $value );
 76+ $value = EPCourses::getLinkFor( $value );
7777 break;
7878 case 'org_id':
7979 $org = EPOrgs::singleton()->selectRow( 'name', array( 'id' => $value ) );
Index: trunk/extensions/EducationProgram/includes/EPCourses.php
@@ -11,7 +11,7 @@
1212 * @licence GNU GPL v3 or later
1313 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1414 */
15 -class EPCourses extends DBTable {
 15+class EPCourses extends EPPageTable {
1616
1717 /**
1818 * (non-PHPdoc)
Index: trunk/extensions/EducationProgram/includes/EPArticle.php
@@ -23,50 +23,6 @@
2424 protected $user = false;
2525
2626 /**
27 - * (non-PHPdoc)
28 - * @see DBDataObject::getDBTable()
29 - */
30 - public static function getDBTable() {
31 - return 'ep_articles';
32 - }
33 -
34 - /**
35 - * (non-PHPdoc)
36 - * @see DBDataObject::getFieldPrefix()
37 - */
38 - public static function getFieldPrefix() {
39 - return 'article_';
40 - }
41 -
42 - /**
43 - * @see parent::getFieldTypes
44 - *
45 - * @since 0.1
46 - *
47 - * @return array
48 - */
49 - protected static function getFieldTypes() {
50 - return array(
51 - 'id' => 'id',
52 -
53 - 'course_id' => 'int',
54 - 'user_id' => 'int',
55 - 'page_id' => 'int',
56 - 'reviewers' => 'array',
57 - );
58 - }
59 -
60 - /**
61 - * (non-PHPdoc)
62 - * @see DBDataObject::getDefaults()
63 - */
64 - public static function getDefaults() {
65 - return array(
66 - 'reviewers' => array(),
67 - );
68 - }
69 -
70 - /**
7127 * Returns the user that authored this revision.
7228 *
7329 * @since 0.1
Index: trunk/extensions/EducationProgram/includes/EPCourse.php
@@ -305,7 +305,7 @@
306306 'form',
307307 array(
308308 'method' => 'post',
309 - 'action' => self::getTitleFor( 'NAME_PLACEHOLDER' )->getLocalURL( array( 'action' => 'edit' ) ),
 309+ 'action' => EPCourses::singleton()->getTitleFor( 'NAME_PLACEHOLDER' )->getLocalURL( array( 'action' => 'edit' ) ),
310310 )
311311 ) );
312312
@@ -705,7 +705,7 @@
706706 public static function hasActiveName( $courseName ) {
707707 $now = wfGetDB( DB_SLAVE )->addQuotes( wfTimestampNow() );
708708
709 - return self::has( array(
 709+ return EPCourses::singleton()->has( array(
710710 'name' => $courseName,
711711 'end >= ' . $now,
712712 'start <= ' . $now,
Index: trunk/extensions/EducationProgram/includes/EPArticlePager.php
@@ -23,7 +23,7 @@
2424 $this->mDefaultDirection = true;
2525
2626 // when MW 1.19 becomes min, we want to pass an IContextSource $context here.
27 - parent::__construct( $context, $conds, 'EPArticle' );
 27+ parent::__construct( $context, $conds, EPArticles::singleton() );
2828 }
2929
3030 /**
@@ -91,8 +91,7 @@
9292 }
9393
9494 function getDefaultSort() {
95 - $c = $this->className; // Yeah, this is needed in PHP 5.3 >_>
96 - return $c::getPrefixedField( 'user_id' );
 95+ return $this->table->getPrefixedField( 'user_id' );
9796 }
9897
9998 }
Index: trunk/extensions/EducationProgram/EducationProgram.hooks.php
@@ -228,8 +228,8 @@
229229 */
230230 protected static function displayTabs( SkinTemplate &$sktemplate, array &$links, Title $title ) {
231231 $classes = array(
232 - EP_NS_INSTITUTION => 'EPOrg',
233 - EP_NS_COURSE => 'EPCourse',
 232+ EP_NS_INSTITUTION => 'EPOrgs',
 233+ EP_NS_COURSE => 'EPCourses',
234234 );
235235
236236 $exists = null;
@@ -240,7 +240,7 @@
241241
242242 $user = $sktemplate->getUser();
243243 $class = $classes[$title->getNamespace()];
244 - $exists = $class::hasIdentifier( $title->getText() );
 244+ $exists = $class::singleton()->hasIdentifier( $title->getText() );
245245 $type = $sktemplate->getRequest()->getText( 'action' );
246246 $isSpecial = $sktemplate->getTitle()->isSpecialPage();
247247
@@ -252,7 +252,7 @@
253253 );
254254 }
255255
256 - if ( $user->isAllowed( $class::getEditRight() ) ) {
 256+ if ( $user->isAllowed( $class::singleton()->getEditRight() ) ) {
257257 $links['views']['edit'] = array(
258258 'class' => $type === 'edit' ? 'selected' : false,
259259 'text' => wfMsg( $exists ? 'ep-tab-edit' : 'ep-tab-create' ),
@@ -307,11 +307,11 @@
308308 public static function onTitleIsAlwaysKnown( Title $title, &$isKnown ) {
309309 if ( in_array( $title->getNamespace(), array( EP_NS_COURSE, EP_NS_INSTITUTION ) ) ) {
310310 $classes = array(
311 - EP_NS_COURSE => 'EPCourse',
312 - EP_NS_INSTITUTION => 'EPOrg',
 311+ EP_NS_COURSE => 'EPCourses',
 312+ EP_NS_INSTITUTION => 'EPOrgs',
313313 );
314314
315 - $isKnown = $classes[$title->getNamespace()]::hasIdentifier( $title->getText() );
 315+ $isKnown = $classes[$title->getNamespace()]::singleton()->hasIdentifier( $title->getText() );
316316 }
317317
318318 return true;

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r111491follow up to r111469 - pass instance of table instead of DBDataObject class n...jeroendedauw21:17, 14 February 2012

Status & tagging log