r110763 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r110762‎ | r110763 | r110764 >
Date:17:37, 6 February 2012
Author:jeroendedauw
Status:deferred
Tags:
Comment:
work on article listing functionality
Modified paths:
  • /trunk/extensions/EducationProgram/EducationProgram.i18n.php (modified) (history)
  • /trunk/extensions/EducationProgram/EducationProgram.php (modified) (history)
  • /trunk/extensions/EducationProgram/actions/ViewCourseAction.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPArticle.php (added) (history)
  • /trunk/extensions/EducationProgram/includes/EPArticlePager.php (added) (history)
  • /trunk/extensions/EducationProgram/includes/EPCA.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPCourse.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPOA.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPRevision.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPStudent.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialStudent.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/EducationProgram.php
@@ -97,6 +97,8 @@
9898 $wgAutoloadClasses['EPIRole'] = dirname( __FILE__ ) . '/includes/EPIRole.php';
9999 $wgAutoloadClasses['EPRevisionedObject'] = dirname( __FILE__ ) . '/includes/EPRevisionedObject.php';
100100 $wgAutoloadClasses['EPRoleObject'] = dirname( __FILE__ ) . '/includes/EPRoleObject.php';
 101+$wgAutoloadClasses['EPArticle'] = dirname( __FILE__ ) . '/includes/EPArticle.php';
 102+$wgAutoloadClasses['EPArticlePager'] = dirname( __FILE__ ) . '/includes/EPArticlePager.php';
101103
102104 $wgAutoloadClasses['CoursePage'] = dirname( __FILE__ ) . '/pages/CoursePage.php';
103105 $wgAutoloadClasses['EPPage'] = dirname( __FILE__ ) . '/pages/EPPage.php';
@@ -153,6 +155,7 @@
154156 $egEPDBObjects['EPStudent'] = array( 'table' => 'ep_students', 'prefix' => 'student_' );
155157 $egEPDBObjects['EPOA'] = array( 'table' => 'ep_oas', 'prefix' => 'oa_' );
156158 $egEPDBObjects['EPCA'] = array( 'table' => 'ep_cas', 'prefix' => 'ca_' );
 159+$egEPDBObjects['EPArticle'] = array( 'table' => 'ep_articles', 'prefix' => 'article_' );
157160 $egEPDBObjects[] = array( 'table' => 'ep_students_per_course', 'prefix' => 'spc_' );
158161 $egEPDBObjects[] = array( 'table' => 'ep_oas_per_course', 'prefix' => 'opc_' );
159162 $egEPDBObjects[] = array( 'table' => 'ep_cas_per_course', 'prefix' => 'cpc_' );
Index: trunk/extensions/EducationProgram/actions/ViewCourseAction.php
@@ -39,6 +39,9 @@
4040 );
4141
4242 if ( count( $studentIds ) > 0 ) {
 43+ $out->addElement( 'h2', array(), wfMsg( 'ep-course-articles' ) );
 44+ EPArticle::displayPager( $this->getContext(), array( 'course_id' => $course->getId() ) );
 45+
4346 $out->addElement( 'h2', array(), wfMsg( 'ep-course-students' ) );
4447 EPStudent::displayPager( $this->getContext(), array( 'id' => $studentIds ) );
4548 }
Index: trunk/extensions/EducationProgram/specials/SpecialStudent.php
@@ -50,7 +50,7 @@
5151
5252 $this->displaySummary( $student );
5353
54 - $out->addElement( 'h2', array(), wfMsg( 'ep-student-terms' ) );
 54+ $out->addElement( 'h2', array(), wfMsg( 'ep-student-courses' ) );
5555
5656 $courseIds = array_map(
5757 function( EPCourse $course ) {
Index: trunk/extensions/EducationProgram/includes/EPArticle.php
@@ -0,0 +1,94 @@
 2+<?php
 3+
 4+/**
 5+ * Class representing a single single article being worked upon by a student,
 6+ * and can have zero or more associated reviewers.
 7+ *
 8+ * @since 0.1
 9+ *
 10+ * @file EPRevision.php
 11+ * @ingroup EducationProgram
 12+ *
 13+ * @licence GNU GPL v3 or later
 14+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
 15+ */
 16+class EPArticle extends EPDBObject {
 17+
 18+ /**
 19+ * Cached user object for this revision.
 20+ *
 21+ * @since 0.1
 22+ * @var User|false
 23+ */
 24+ protected $user = false;
 25+
 26+ /**
 27+ * @see parent::getFieldTypes
 28+ *
 29+ * @since 0.1
 30+ *
 31+ * @return array
 32+ */
 33+ protected static function getFieldTypes() {
 34+ return array(
 35+ 'id' => 'id',
 36+
 37+ 'course_id' => 'int',
 38+ 'user_id' => 'int',
 39+ 'page_id' => 'int',
 40+ 'reviewers' => 'array',
 41+ );
 42+ }
 43+
 44+ /**
 45+ * (non-PHPdoc)
 46+ * @see EPDBObject::getDefaults()
 47+ */
 48+ public static function getDefaults() {
 49+ return array(
 50+ 'reviewers' => array(),
 51+ );
 52+ }
 53+
 54+ /**
 55+ * Returns the user that authored this revision.
 56+ *
 57+ * @since 0.1
 58+ *
 59+ * @return User
 60+ */
 61+ public function getUser() {
 62+ if ( $this->user === false ) {
 63+ $this->user = User::newFromId( $this->loadAndGetField( 'user_id' ) );
 64+ }
 65+
 66+ return $this->user;
 67+ }
 68+
 69+ /**
 70+ * Display a pager with articles.
 71+ *
 72+ * @since 0.1
 73+ *
 74+ * @param IContextSource $context
 75+ * @param array $conditions
 76+ */
 77+ public static function displayPager( IContextSource $context, array $conditions = array() ) {
 78+ $pager = new EPArticlePager( $context, $conditions );
 79+
 80+ if ( $pager->getNumRows() ) {
 81+ $context->getOutput()->addHTML(
 82+ $pager->getFilterControl() .
 83+ $pager->getNavigationBar() .
 84+ $pager->getBody() .
 85+ $pager->getNavigationBar() .
 86+ $pager->getMultipleItemControl()
 87+ );
 88+ }
 89+ else {
 90+ $context->getOutput()->addHTML( $pager->getFilterControl( true ) );
 91+ $context->getOutput()->addWikiMsg( 'ep-articles-noresults' );
 92+ }
 93+ }
 94+
 95+}
Index: trunk/extensions/EducationProgram/includes/EPCA.php
@@ -23,8 +23,8 @@
2424 protected static function getFieldTypes() {
2525 return array(
2626 'id' => 'id',
27 - 'user_id' => 'id',
28 -
 27+
 28+ 'user_id' => 'int',
2929 'bio' => 'str',
3030 'photo' => 'str',
3131 );
Index: trunk/extensions/EducationProgram/includes/EPStudent.php
@@ -23,8 +23,8 @@
2424 protected static function getFieldTypes() {
2525 return array(
2626 'id' => 'id',
27 - 'user_id' => 'id',
2827
 28+ 'user_id' => 'int',
2929 'first_enroll' => 'str', // TS_MW
3030
3131 'last_active' => 'str', // TS_MW
Index: trunk/extensions/EducationProgram/includes/EPRevision.php
@@ -45,8 +45,8 @@
4646 return array(
4747 'id' => 'id',
4848
49 - 'object_id' => 'id',
50 - 'user_id' => 'id',
 49+ 'object_id' => 'int',
 50+ 'user_id' => 'int',
5151 'type' => 'str',
5252 'comment' => 'str',
5353 'user_text' => 'str',
Index: trunk/extensions/EducationProgram/includes/EPOA.php
@@ -23,8 +23,8 @@
2424 protected static function getFieldTypes() {
2525 return array(
2626 'id' => 'id',
27 - 'user_id' => 'id',
28 -
 27+
 28+ 'user_id' => 'int',
2929 'bio' => 'str',
3030 'photo' => 'str',
3131 );
Index: trunk/extensions/EducationProgram/includes/EPCourse.php
@@ -98,8 +98,8 @@
9999 protected static function getFieldTypes() {
100100 return array(
101101 'id' => 'id',
102 - 'org_id' => 'id',
103102
 103+ 'org_id' => 'int',
104104 'name' => 'str',
105105 'start' => 'str', // TS_MW
106106 'end' => 'str', // TS_MW
Index: trunk/extensions/EducationProgram/includes/EPArticlePager.php
@@ -0,0 +1,98 @@
 2+<?php
 3+
 4+/**
 5+ * Article pager which lists students and their associated articles reviewers for those if any.
 6+ *
 7+ * @since 0.1
 8+ *
 9+ * @file EPAticlePager.php
 10+ * @ingroup EductaionProgram
 11+ *
 12+ * @licence GNU GPL v3 or later
 13+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
 14+ */
 15+class EPArticlePager extends EPPager {
 16+
 17+ /**
 18+ * Constructor.
 19+ *
 20+ * @param IContextSource $context
 21+ * @param array $conds
 22+ */
 23+ public function __construct( IContextSource $context, array $conds = array() ) {
 24+ $this->mDefaultDirection = true;
 25+
 26+ // when MW 1.19 becomes min, we want to pass an IContextSource $context here.
 27+ parent::__construct( $context, $conds, 'EPArticle' );
 28+ }
 29+
 30+ /**
 31+ * (non-PHPdoc)
 32+ * @see EPPager::getFields()
 33+ */
 34+ public function getFields() {
 35+ return array(
 36+ 'id',
 37+ 'user_id',
 38+ 'course_id',
 39+ 'page_id',
 40+ 'reviewers',
 41+ );
 42+ }
 43+
 44+ /**
 45+ * (non-PHPdoc)
 46+ * @see TablePager::getRowClass()
 47+ */
 48+ function getRowClass( $row ) {
 49+ return 'ep-article-row';
 50+ }
 51+
 52+ /**
 53+ * (non-PHPdoc)
 54+ * @see TablePager::getTableClass()
 55+ */
 56+ public function getTableClass() {
 57+ return 'TablePager ep-articles';
 58+ }
 59+
 60+ /**
 61+ * (non-PHPdoc)
 62+ * @see EPPager::getFormattedValue()
 63+ */
 64+ protected function getFormattedValue( $name, $value ) {
 65+ switch ( $name ) {
 66+ case 'user_id':
 67+ $user = User::newFromId( $value );
 68+ $name = $user->getRealName() === '' ? $user->getName() : $user->getRealName();
 69+
 70+ $value = Linker::userLink( $value, $name ) . Linker::userToolLinks( $value, $name );
 71+ break;
 72+ }
 73+
 74+ return $value;
 75+ }
 76+
 77+ /**
 78+ * (non-PHPdoc)
 79+ * @see EPPager::getSortableFields()
 80+ */
 81+ protected function getSortableFields() {
 82+ return array(
 83+ );
 84+ }
 85+
 86+ /**
 87+ * (non-PHPdoc)
 88+ * @see EPPager::hasActionsColumn()
 89+ */
 90+ protected function hasActionsColumn() {
 91+ return false;
 92+ }
 93+
 94+ function getDefaultSort() {
 95+ $c = $this->className; // Yeah, this is needed in PHP 5.3 >_>
 96+ return $c::getPrefixedField( 'user_id' );
 97+ }
 98+
 99+}
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php
@@ -234,6 +234,10 @@
235235 'epstudentpager-yes' => 'Yes',
236236 'epstudentpager-no' => 'No',
237237
 238+ // Article pager
 239+ 'ep-articles-noresults' => 'There are no articles to list.',
 240+ 'ep-articles-noresults' => 'There are no articles to list.',
 241+
238242 // Campus ambassador pager
239243 'epcapager-header-photo' => 'Photo',
240244 'epcapager-header-user-id' => 'User',
@@ -314,6 +318,7 @@
315319 // Course viewing
316320 'ep-course-title' => 'Course: $1',
317321 'ep-course-students' => 'Students',
 322+ 'ep-course-articles' => 'Articles',
318323 'viewcourseaction-none' => 'There is no course with name "$1". See [[Special:Courses|here]] for a list of courses.',
319324 'ep-course-create' => 'There is no course with name "$1", but you can create a new one.',
320325 'ep-course-description' => 'Description',

Status & tagging log