r107107 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107106‎ | r107107 | r107108 >
Date:20:17, 22 December 2011
Author:jeroendedauw
Status:deferred (Comments)
Tags:educationprogram 
Comment:
finished up some stuff
Modified paths:
  • /trunk/extensions/EducationProgram/EducationProgram.i18n.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPCoursePager.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPOrgPager.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPPager.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPTermPager.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialCourse.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialCourses.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialEditCourse.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialInstitution.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialTerm.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/specials/SpecialInstitution.php
@@ -1,7 +1,8 @@
22 <?php
33
44 /**
5 - *
 5+ * Shows the info for a single institution, with management and
 6+ * enrollment controls depending on the user and his rights.
67 *
78 * @since 0.1
89 *
Index: trunk/extensions/EducationProgram/specials/SpecialCourse.php
@@ -1,7 +1,8 @@
22 <?php
33
44 /**
5 - *
 5+ * Shows the info for a single course, with management and
 6+ * enrollment controls depending on the user and his rights.
67 *
78 * @since 0.1
89 *
Index: trunk/extensions/EducationProgram/specials/SpecialCourses.php
@@ -59,15 +59,16 @@
6060 protected function displayPage() {
6161 $user = $this->getUser();
6262
63 - if ( $user->isAllowed( 'epadmin' ) ) {
64 - $this->displayAddNewControl();
 63+ $orgs = EPOrg::getEditableOrgs( $this->getUser() );
 64+
 65+ if ( count( $orgs ) > 0 ) {
 66+ $this->displayAddNewControl( $orgs );
6567 }
 68+ elseif ( $user->isAllowed( 'epadmin' ) ) {
 69+ $this->getOutput()->addWikiMsg( 'ep-courses-noorgs' );
 70+ }
6671 elseif ( $user->isAllowed( 'epmentor' ) ) {
67 - $mentor = EPMentor::select( array( 'user_id' => $user->getId() ) );
68 -
69 - if ( $mentor !== false && count( $mentor->getOrgs() ) > 0 ) {
70 - $this->displayAddNewControl();
71 - }
 72+ $this->getOutput()->addWikiMsg( 'ep-courses-addorgfirst' );
7273 }
7374
7475 $pager = new EPCoursePager( $this->getContext() );
@@ -90,8 +91,10 @@
9192 * Displays a small form to add a new institution.
9293 *
9394 * @since 0.1
 95+ *
 96+ * @param array $orgs
9497 */
95 - protected function displayAddNewControl() {
 98+ protected function displayAddNewControl( array /* of EPOrg */ $orgs ) {
9699 $out = $this->getOutput();
97100
98101 $out->addHTML( Html::openElement(
@@ -108,9 +111,21 @@
109112
110113 $out->addHTML( Html::element( 'p', array(), wfMsg( 'ep-courses-namedoc' ) ) );
111114
 115+ $out->addHTML( Html::element( 'label', array( 'for' => 'neworg' ), wfMsg( 'ep-courses-neworg' ) ) );
 116+
 117+ $out->addHTML( '&#160;' );
 118+
 119+ $select = new XmlSelect( 'neworg', 'neworg' );
 120+ $select->addOptions( EPOrg::getOrgOptions( $orgs ) );
 121+ $out->addHTML( $select->getHTML() );
 122+
 123+ $out->addHTML( '&#160;' );
 124+
112125 $out->addHTML( Xml::inputLabel( wfMsg( 'ep-courses-newname' ), 'newname', 'newname' ) );
113126
114 - $out->addHTML( '&#160;' . Html::input(
 127+ $out->addHTML( '&#160;' );
 128+
 129+ $out->addHTML( Html::input(
115130 'addneworg',
116131 wfMsg( 'ep-courses-add' ),
117132 'submit'
Index: trunk/extensions/EducationProgram/specials/SpecialEditCourse.php
@@ -64,4 +64,15 @@
6565 return $this->processFormFields( $fields );
6666 }
6767
 68+ /**
 69+ * (non-PHPdoc)
 70+ * @see SpecialEPFormPage::getNewData()
 71+ */
 72+ protected function getNewData() {
 73+ return array(
 74+ 'org_id' => $this->getRequest()->getVal( 'neworg' ),
 75+ 'name' => $this->getRequest()->getVal( 'newname' ),
 76+ );
 77+ }
 78+
6879 }
Index: trunk/extensions/EducationProgram/specials/SpecialTerm.php
@@ -0,0 +1,41 @@
 2+<?php
 3+
 4+/**
 5+ * Shows the info for a single term, with management and
 6+ * enrollment controls depending on the user and his rights.
 7+ *
 8+ * @since 0.1
 9+ *
 10+ * @file SpecialTerm.php
 11+ * @ingroup EducationProgram
 12+ *
 13+ * @licence GNU GPL v3 or later
 14+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
 15+ */
 16+class SpecialTerm extends SpecialEPPage {
 17+
 18+ /**
 19+ * Constructor.
 20+ *
 21+ * @since 0.1
 22+ */
 23+ public function __construct() {
 24+ parent::__construct( 'Term' );
 25+ }
 26+
 27+ /**
 28+ * Main method.
 29+ *
 30+ * @since 0.1
 31+ *
 32+ * @param string $arg
 33+ */
 34+ public function execute( $subPage ) {
 35+ parent::execute( $subPage );
 36+
 37+ $out = $this->getOutput();
 38+
 39+ // TODO: AUTH
 40+ }
 41+
 42+}
Index: trunk/extensions/EducationProgram/includes/EPOrgPager.php
@@ -20,9 +20,6 @@
2121 * @param array $conds
2222 */
2323 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.
2724 parent::__construct( $context, $conds, 'EPOrg' );
2825 }
2926
@@ -130,16 +127,7 @@
131128 wfMsg( 'edit' )
132129 );
133130
134 - $links[] = $value = Html::element(
135 - 'a',
136 - array(
137 - 'href' => '#',
138 - 'class' => 'ep-pager-delete',
139 - 'data-id' => $item->getId(),
140 - 'data-type' => 'org',
141 - ),
142 - wfMsg( 'delete' )
143 - );
 131+ $links[] = $this->getDeletionLink( 'org', $item->getId() );
144132 }
145133
146134 return $links;
Index: trunk/extensions/EducationProgram/includes/EPTermPager.php
@@ -20,9 +20,6 @@
2121 * @param array $conds
2222 */
2323 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.
2724 parent::__construct( $context, $conds, 'EPTerm' );
2825 }
2926
@@ -142,11 +139,18 @@
143140 $links = parent::getControlLinks( $item );
144141
145142 $links[] = $value = Linker::linkKnown(
146 - SpecialPage::getTitleFor( 'EditTerm', $item->getId() ),
147 - wfMsg( 'edit' )
 143+ SpecialPage::getTitleFor( 'Term', $item->getId() ),
 144+ wfMsg( 'view' )
148145 );
149146
150 - // TODO
 147+ if ( $this->getUser()->isAllowed( 'epadmin' ) ) {
 148+ $links[] = $value = Linker::linkKnown(
 149+ SpecialPage::getTitleFor( 'EditTerm', $item->getId() ),
 150+ wfMsg( 'edit' )
 151+ );
 152+
 153+ $links[] = $this->getDeletionLink( 'term', $item->getId() );
 154+ }
151155
152156 return $links;
153157 }
Index: trunk/extensions/EducationProgram/includes/EPPager.php
@@ -54,6 +54,8 @@
5555 $this->className = $className;
5656 $this->context = $context;
5757
 58+ $this->mDefaultDirection = true;
 59+
5860 if ( version_compare( $GLOBALS['wgVersion'], '1.18c', '>' ) ) {
5961 parent::__construct( $context );
6062 }
@@ -377,5 +379,28 @@
378380 protected function getControlLinks( EPDBObject $item ) {
379381 return array();
380382 }
 383+
 384+ /**
 385+ * Returns a deletion link.
 386+ *
 387+ * @since 0.1
 388+ *
 389+ * @param string $type
 390+ * @paran integer $id
 391+ *
 392+ * @return string
 393+ */
 394+ protected function getDeletionLink( $type, $id ) {
 395+ return Html::element(
 396+ 'a',
 397+ array(
 398+ 'href' => '#',
 399+ 'class' => 'ep-pager-delete',
 400+ 'data-id' => $id,
 401+ 'data-type' => $type,
 402+ ),
 403+ wfMsg( 'delete' )
 404+ );
 405+ }
381406
382407 }
Index: trunk/extensions/EducationProgram/includes/EPCoursePager.php
@@ -20,9 +20,6 @@
2121 * @param array $conds
2222 */
2323 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.
2724 parent::__construct( $context, $conds, 'EPCourse' );
2825 }
2926
@@ -121,11 +118,18 @@
122119 $links = parent::getControlLinks( $item );
123120
124121 $links[] = $value = Linker::linkKnown(
125 - SpecialPage::getTitleFor( 'EditCourse', $item->getField( 'name' ) ),
126 - wfMsg( 'edit' )
 122+ SpecialPage::getTitleFor( 'Course', $item->getField( 'name' ) ),
 123+ wfMsg( 'view' )
127124 );
128125
129 - // TODO
 126+ if ( $this->getUser()->isAllowed( 'epadmin' ) ) {
 127+ $links[] = $value = Linker::linkKnown(
 128+ SpecialPage::getTitleFor( 'EditCourse', $item->getField( 'name' ) ),
 129+ wfMsg( 'edit' )
 130+ );
 131+
 132+ $links[] = $this->getDeletionLink( 'term', $item->getId() );
 133+ }
130134
131135 return $links;
132136 }
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php
@@ -77,6 +77,9 @@
7878 'ep-courses-namedoc' => 'Enter the name for the new course (which should be unique) and hit the button.',
7979 'ep-courses-newname' => 'Course name:',
8080 'ep-courses-add' => 'Add course',
 81+ 'ep-courses-addorgfirst' => 'You need to [[Special:Institutions|add an institution]] before you can create any courses.',
 82+ 'ep-courses-noorgs' => 'You are not a mentor of any insitutions yet, so cannot add any courses.',
 83+ 'ep-courses-neworg' => 'Institution',
8184
8285 // Special:Terms
8386 'ep-terms-nosuchterm' => 'There is no term with id "$1". Existing terms are listed below.',

Follow-up revisions

RevisionCommit summaryAuthorDate
r107179restructuring some stuff and initial work on display of cousres, orgs and ter...jeroendedauw20:40, 23 December 2011

Comments

#Comment by Nikerabbit (talk | contribs)   09:04, 23 December 2011
+			$links[] = $value = Linker::linkKnown(
+				SpecialPage::getTitleFor( 'EditTerm', $item->getId() ),
+				wfMsg( 'edit' )
+			);

$value looks unused. Should not reuse messages. The message should be escaped. Two instances.

#Comment by Jeroen De Dauw (talk | contribs)   18:49, 23 December 2011

Good catch, did not realize I had to escape this arg (even though it's sort of obvious), and so did not do that anywhere in the extension :) Will be fixed in next commit.

Status & tagging log