r109851 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r109850‎ | r109851 | r109852 >
Date:20:51, 23 January 2012
Author:jeroendedauw
Status:deferred
Tags:
Comment:
added extra fields and table
Modified paths:
  • /trunk/extensions/EducationProgram/EducationProgram.hooks.php (modified) (history)
  • /trunk/extensions/EducationProgram/EducationProgram.i18n.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPCourse.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPMC.php (modified) (history)
  • /trunk/extensions/EducationProgram/sql/AddExtraFields.sql (added) (history)
  • /trunk/extensions/EducationProgram/sql/EducationProgram.sql (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/sql/AddExtraFields.sql
@@ -0,0 +1,32 @@
 2+-- SQL for the Education Program extension.
 3+-- Adds additional fields.
 4+-- Licence: GNU GPL v3+
 5+-- Author: Jeroen De Dauw < jeroendedauw@gmail.com >
 6+
 7+ALTER TABLE /*_*/ep_courses ADD COLUMN course_name VARCHAR(255) NOT NULL;
 8+CREATE INDEX /*i*/ep_course_name ON /*_*/ep_courses (course_name);
 9+
 10+ALTER TABLE /*_*/ep_courses ADD COLUMN course_timeline TEXT NOT NULL;
 11+ALTER TABLE /*_*/ep_mcs ADD COLUMN mc_timeline TEXT NOT NULL;
 12+
 13+-- Articles students are working on.
 14+CREATE TABLE IF NOT EXISTS /*_*/ep_articles (
 15+ article_id INT unsigned NOT NULL auto_increment PRIMARY KEY,
 16+
 17+ article_user_id INT unsigned NOT NULL, -- Foreign key on user.user_id
 18+ article_course_id INT unsigned NOT NULL, -- Foreign key on ep_courses.course_id
 19+ article_page_id INT unsigned NOT NULL, -- Foreign key on page.page_id
 20+
 21+ article_reviewers BLOB NOT NULL -- List of reviewers for this article (linking user.user_id)
 22+) /*$wgDBTableOptions*/;
 23+
 24+CREATE INDEX /*i*/ep_articles_user_id ON /*_*/ep_articles (article_user_id);
 25+CREATE INDEX /*i*/ep_articles_course_id ON /*_*/ep_articles (article_course_id);
 26+CREATE INDEX /*i*/ep_articles_page_id ON /*_*/ep_articles (article_page_id);
 27+CREATE UNIQUE INDEX /*i*/ep_articles_course_page ON /*_*/ep_articles (article_course_id, article_page_id);
 28+
 29+ALTER TABLE /*_*/ep_cas ADD COLUMN ca_bio TEXT NOT NULL;
 30+ALTER TABLE /*_*/ep_cas ADD COLUMN ca_photo VARCHAR(255) NOT NULL;
 31+
 32+ALTER TABLE /*_*/ep_oas ADD COLUMN oa_bio TEXT NOT NULL;
 33+ALTER TABLE /*_*/ep_oas ADD COLUMN oa_photo VARCHAR(255) NOT NULL;
\ No newline at end of file
Index: trunk/extensions/EducationProgram/sql/EducationProgram.sql
@@ -29,8 +29,9 @@
3030 mc_id INT unsigned NOT NULL auto_increment PRIMARY KEY,
3131
3232 mc_org_id INT unsigned NOT NULL, -- Foreign key on ep_orgs.org_id
33 - mc_name VARCHAR(255) NOT NULL, -- Name of the course
34 - mc_description TEXT NOT NULL, -- Description of the course
 33+ mc_name VARCHAR(255) NOT NULL, -- Name of the master course
 34+ mc_description TEXT NOT NULL, -- Description of the master course
 35+ mc_timeline TEXT NOT NULL, -- Timeline for the master course
3536 mc_lang VARCHAR(10) NOT NULL, -- Language (code)
3637 mc_instructors BLOB NOT NULL, -- List of associated instructors
3738
@@ -57,21 +58,39 @@
5859 course_start varbinary(14) NOT NULL, -- Start time of the course
5960 course_end varbinary(14) NOT NULL, -- End time of the course
6061 course_description TEXT NOT NULL, -- Description of the course
61 - course_online_ambs BLOB NOT NULL, -- List of associated online ambassadors
62 - course_campus_ambs BLOB NOT NULL, -- List of associated campus ambassadors
 62+ course_timeline TEXT NOT NULL, -- Timeline for the course
 63+ course_online_ambs BLOB NOT NULL, -- List of associated online ambassadors (linking ep_oas.oa_id)
 64+ course_campus_ambs BLOB NOT NULL, -- List of associated campus ambassadors (linking ep_cas.ca_id)
6365 course_token VARCHAR(255) NOT NULL, -- Token needed to enroll
6466
6567 course_students SMALLINT unsigned NOT NULL -- Amount of students
6668 ) /*$wgDBTableOptions*/;
6769
 70+CREATE INDEX /*i*/ep_course_name ON /*_*/ep_courses (course_name);
6871 CREATE INDEX /*i*/ep_course_year ON /*_*/ep_courses (course_year);
6972 CREATE INDEX /*i*/ep_course_start ON /*_*/ep_courses (course_start);
7073 CREATE INDEX /*i*/ep_course_end ON /*_*/ep_courses (course_end);
71 -CREATE INDEX /*i*/ep_trem_period ON /*_*/ep_courses (course_org_id, course_start, course_end);
 74+CREATE INDEX /*i*/ep_course_period ON /*_*/ep_courses (course_org_id, course_start, course_end);
7275 CREATE INDEX /*i*/ep_course_students ON /*_*/ep_courses (course_students);
7376
7477
7578
 79+-- Articles students are working on.
 80+CREATE TABLE IF NOT EXISTS /*_*/ep_articles (
 81+ article_id INT unsigned NOT NULL auto_increment PRIMARY KEY,
 82+
 83+ article_user_id INT unsigned NOT NULL, -- Foreign key on user.user_id
 84+ article_course_id INT unsigned NOT NULL, -- Foreign key on ep_courses.course_id
 85+ article_page_id INT unsigned NOT NULL, -- Foreign key on page.page_id
 86+
 87+ article_reviewers BLOB NOT NULL -- List of reviewers for this article (linking user.user_id)
 88+) /*$wgDBTableOptions*/;
 89+
 90+CREATE INDEX /*i*/ep_articles_user_id ON /*_*/ep_articles (article_user_id);
 91+CREATE INDEX /*i*/ep_articles_course_id ON /*_*/ep_articles (article_course_id);
 92+CREATE INDEX /*i*/ep_articles_page_id ON /*_*/ep_articles (article_page_id);
 93+CREATE UNIQUE INDEX /*i*/ep_articles_course_page ON /*_*/ep_articles (article_course_id, article_page_id);
 94+
7695 -- Students. In essence this is an extension to the user table.
7796 CREATE TABLE IF NOT EXISTS /*_*/ep_students (
7897 student_id INT unsigned NOT NULL auto_increment PRIMARY KEY,
@@ -111,7 +130,10 @@
112131 -- Campus ambassadors. In essence this is an extension to the user table.
113132 CREATE TABLE IF NOT EXISTS /*_*/ep_cas (
114133 ca_id INT unsigned NOT NULL auto_increment PRIMARY KEY,
115 - ca_user_id INT unsigned NOT NULL -- Foreign key on user.user_id
 134+ ca_user_id INT unsigned NOT NULL, -- Foreign key on user.user_id
 135+
 136+ ca_bio TEXT NOT NULL, -- Bio of the ambassador
 137+ ca_photo VARCHAR(255) NOT NULL -- Name of a photo of the ambassador on commons
116138 ) /*$wgDBTableOptions*/;
117139
118140 CREATE UNIQUE INDEX /*i*/ep_cas_user_id ON /*_*/ep_cas (ca_user_id);
@@ -130,6 +152,9 @@
131153 CREATE TABLE IF NOT EXISTS /*_*/ep_oas (
132154 oa_id INT unsigned NOT NULL auto_increment PRIMARY KEY,
133155 oa_user_id INT unsigned NOT NULL -- Foreign key on user.user_id
 156+
 157+ oa_bio TEXT NOT NULL, -- Bio of the ambassador
 158+ oa_photo VARCHAR(255) NOT NULL -- Name of a photo of the ambassador on commons
134159 ) /*$wgDBTableOptions*/;
135160
136161 CREATE UNIQUE INDEX /*i*/ep_oas_user_id ON /*_*/ep_oas (oa_user_id);
Index: trunk/extensions/EducationProgram/includes/EPMC.php
@@ -44,6 +44,7 @@
4545
4646 'name' => 'str',
4747 'description' => 'str',
 48+ 'timeline' => 'str',
4849 'lang' => 'str',
4950 'instructors' => 'array',
5051
@@ -59,6 +60,7 @@
6061 public static function getDefaults() {
6162 return array(
6263 'description' => '',
 64+ 'timeline' => '',
6365
6466 'active' => false,
6567 'students' => 0,
Index: trunk/extensions/EducationProgram/includes/EPCourse.php
@@ -85,10 +85,12 @@
8686 'mc_id' => 'id',
8787 'org_id' => 'id',
8888
 89+ 'name' => 'str',
8990 'year' => 'int',
9091 'start' => 'str', // TS_MW
9192 'end' => 'str', // TS_MW
9293 'description' => 'str',
 94+ 'timeline' => 'str',
9395 'token' => 'str',
9496 'online_ambs' => 'array',
9597 'campus_ambs' => 'array',
@@ -103,10 +105,12 @@
104106 */
105107 public static function getDefaults() {
106108 return array(
 109+ 'name' => '',
107110 'year' => substr( wfTimestamp( TS_MW ), 0, 4 ),
108111 'start' => wfTimestamp( TS_MW ),
109112 'end' => wfTimestamp( TS_MW ),
110113 'description' => '',
 114+ 'timeline' => '',
111115 'token' => '',
112116 'online_ambs' => array(),
113117 'campus_ambs' => array(),
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php
@@ -254,6 +254,12 @@
255255 'epstudentpager-yes' => 'Yes',
256256 'epstudentpager-no' => 'No',
257257
 258+ // Campus ambassador pager
 259+ 'eppager-header-user-id' => 'User',
 260+
 261+ // Online ambassador pager
 262+ 'epstudentpager-header-user-id' => 'User',
 263+
258264 // Special:EditInstitution
259265 'editinstitution-text' => 'Enter the institution details below and click submit to save your changes.',
260266 'educationprogram-org-edit-name' => 'Institution name',
Index: trunk/extensions/EducationProgram/EducationProgram.hooks.php
@@ -28,6 +28,15 @@
2929 'ep_orgs',
3030 dirname( __FILE__ ) . '/sql/EducationProgram.sql'
3131 );
 32+
 33+ $updater->addExtensionUpdate( array(
 34+ 'addField',
 35+ 'ep_courses',
 36+ 'course_name',
 37+ dirname( __FILE__ ) . '/sql/AddExtraFields.sql',
 38+ true
 39+ ) );
 40+
3241 return true;
3342 }
3443
@@ -181,6 +190,12 @@
182191 'EditCourse' => 'ep-course',
183192 );
184193
 194+ $classes = array(
 195+ 'Institution' => 'EPOrg',
 196+ 'Course' => 'EPCourse',
 197+ 'MasterCourse' => 'EPMC',
 198+ );
 199+
185200 $specialSet = false;
186201 $type = false;
187202
@@ -201,39 +216,44 @@
202217 $special = SpecialPageFactory::getLocalNameFor( $special );
203218 }
204219
 220+ $identifier = $canonicalSet['view'] === 'Course' ? 'id' : 'name';
 221+ $exists = $classes[$canonicalSet['view']]::has( array( $identifier => $textParts[1] ) );
 222+
205223 $viewLinks['view'] = array(
206224 'class' => $type === 'view' ? 'selected' : false,
207225 'text' => wfMsg( 'ep-tab-view' ),
208226 'href' => SpecialPage::getTitleFor( $specialSet['view'], $textParts[1] )->getLocalUrl()
209227 );
210228
211 - if ( $sktemplate->getUser()->isAllowed( $editRights[$canonicalSet['edit']] ) ) {
212 - $viewLinks['edit'] = array(
213 - 'class' => $type === 'edit' ? 'selected' : false,
214 - 'text' => wfMsg( 'ep-tab-edit' ),
215 - 'href' => SpecialPage::getTitleFor( $specialSet['edit'], $textParts[1] )->getLocalUrl()
 229+ if ( $exists ) {
 230+ if ( $sktemplate->getUser()->isAllowed( $editRights[$canonicalSet['edit']] ) ) {
 231+ $viewLinks['edit'] = array(
 232+ 'class' => $type === 'edit' ? 'selected' : false,
 233+ 'text' => wfMsg( 'ep-tab-edit' ),
 234+ 'href' => SpecialPage::getTitleFor( $specialSet['edit'], $textParts[1] )->getLocalUrl()
 235+ );
 236+ }
 237+
 238+ $viewLinks['history'] = array(
 239+ 'class' => $type === 'history' ? 'selected' : false,
 240+ 'text' => wfMsg( 'ep-tab-history' ),
 241+ 'href' => '' // TODO
 242+ //SpecialPage::getTitleFor( $specialSet['history'], $textParts[1] )->getLocalUrl()
216243 );
217 - }
218244
219 - $viewLinks['history'] = array(
220 - 'class' => $type === 'history' ? 'selected' : false,
221 - 'text' => wfMsg( 'ep-tab-history' ),
222 - 'href' => '' // TODO
223 - //SpecialPage::getTitleFor( $specialSet['history'], $textParts[1] )->getLocalUrl()
224 - );
 245+ if ( $canonicalSet['view'] === 'Course' ) {
 246+ $user = $sktemplate->getUser();
225247
226 - if ( $canonicalSet['view'] === 'Course' ) {
227 - $user = $sktemplate->getUser();
 248+ if ( $user->isAllowed( 'ep-enroll' ) ) {
 249+ $student = EPStudent::newFromUser( $user );
228250
229 - if ( $user->isAllowed( 'ep-enroll' ) ) {
230 - $student = EPStudent::newFromUser( $user );
231 -
232 - if ( $student === false || !$student->hasCourse( array( 'id' => $textParts[1] ) ) ) {
233 - $viewLinks['enroll'] = array(
234 - 'class' => $type === 'enroll' ? 'selected' : false,
235 - 'text' => wfMsg( 'ep-tab-enroll' ),
236 - 'href' => SpecialPage::getTitleFor( 'Enroll', $textParts[1] )->getLocalUrl()
237 - );
 251+ if ( $student === false || !$student->hasCourse( array( 'id' => $textParts[1] ) ) ) {
 252+ $viewLinks['enroll'] = array(
 253+ 'class' => $type === 'enroll' ? 'selected' : false,
 254+ 'text' => wfMsg( 'ep-tab-enroll' ),
 255+ 'href' => SpecialPage::getTitleFor( 'Enroll', $textParts[1] )->getLocalUrl()
 256+ );
 257+ }
238258 }
239259 }
240260 }

Status & tagging log