r107185 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107184‎ | r107185 | r107186 >
Date:21:42, 23 December 2011
Author:jeroendedauw
Status:deferred
Tags:educationprogram 
Comment:
work on item pages
Modified paths:
  • /trunk/extensions/EducationProgram/EducationProgram.i18n.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPCourse.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPTerm.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialCourse.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialCourses.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialInstitution.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialInstitutions.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialTerms.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/specials/SpecialInstitution.php
@@ -14,8 +14,6 @@
1515 */
1616 class SpecialInstitution extends SpecialEPPage {
1717
18 - protected $org;
19 -
2018 /**
2119 * Constructor.
2220 *
Index: trunk/extensions/EducationProgram/specials/SpecialTerms.php
@@ -33,21 +33,12 @@
3434 public function execute( $subPage ) {
3535 parent::execute( $subPage );
3636
37 - $out = $this->getOutput();
38 -
3937 if ( $this->subPage === '' ) {
40 - $this->displayPage();
 38+ EPTerm::displayAddNewRegion( $this->getContext() );
 39+ EPTerm::displayPager( $this->getContext() );
4140 }
4241 else {
43 - $org = EPOrg::has( array( 'name' => $this->subPage ) );
44 -
45 - if ( $org === false ) {
46 - $this->showError( wfMessage( 'ep-terms-nosuchcourses', $this->subPage ) );
47 - $this->displayPage();
48 - }
49 - else {
50 - $out->redirect( SpecialPage::getTitleFor( 'Term', $this->subPage )->getLocalURL() );
51 - }
 42+ $this->getOutput()->redirect( SpecialPage::getTitleFor( 'Term', $this->subPage )->getLocalURL() );
5243 }
5344 }
5445
@@ -83,50 +74,7 @@
8475 $this->getOutput()->addWikiMsg( 'ep-terms-noresults' );
8576 }
8677 }
87 -
88 - /**
89 - * Displays a small form to add a new institution.
90 - *
91 - * @since 0.1
92 - *
93 - * @param array $courses
94 - */
95 - protected function displayAddNewControl( array $courses ) {
96 - $out = $this->getOutput();
9778
98 - $out->addHTML( Html::openElement(
99 - 'form',
100 - array(
101 - 'method' => 'post',
102 - 'action' => SpecialPage::getTitleFor( 'EditTerm' )->getLocalURL(),
103 - )
104 - ) );
10579
106 - $out->addHTML( '<fieldset>' );
10780
108 - $out->addHTML( '<legend>' . wfMsgHtml( 'ep-terms-addnew' ) . '</legend>' );
109 -
110 - $out = $this->getOutput();
111 -
112 - $out->addHTML( Html::element( 'p', array(), wfMsg( 'ep-terms-namedoc' ) ) );
113 -
114 - $out->addHTML( Html::element( 'label', array( 'for' => 'newcourse' ), wfMsg( 'ep-terms-newcourse' ) ) );
115 -
116 - $select = new XmlSelect( 'newcourse', 'newcourse' );
117 - $select->addOptions( EPCourse::getCourseOptions( $courses ) );
118 - $out->addHTML( $select->getHTML() );
119 -
120 - $out->addHTML( '&#160;' . Xml::inputLabel( wfMsg( 'ep-terms-newyear' ), 'newyear', 'newyear', 10 ) );
121 -
122 - $out->addHTML( '&#160;' . Html::input(
123 - 'addnewterm',
124 - wfMsg( 'ep-terms-add' ),
125 - 'submit'
126 - ) );
127 -
128 - $out->addHTML( Html::hidden( 'newEditToken', $this->getUser()->editToken() ) );
129 -
130 - $out->addHTML( '</fieldset></form>' );
131 - }
132 -
13381 }
Index: trunk/extensions/EducationProgram/specials/SpecialInstitutions.php
@@ -33,14 +33,12 @@
3434 public function execute( $subPage ) {
3535 parent::execute( $subPage );
3636
37 - $out = $this->getOutput();
38 -
3937 if ( $this->subPage === '' ) {
4038 EPOrg::displayAddNewControl( $this->getContext() );
4139 EPOrg::displayPager( $this->getContext() );
4240 }
4341 else {
44 - $out->redirect( SpecialPage::getTitleFor( 'Institution', $this->subPage )->getLocalURL() );
 42+ $this->getOutput()->redirect( SpecialPage::getTitleFor( 'Institution', $this->subPage )->getLocalURL() );
4543 }
4644 }
4745
Index: trunk/extensions/EducationProgram/specials/SpecialCourse.php
@@ -34,8 +34,40 @@
3535 parent::execute( $subPage );
3636
3737 $out = $this->getOutput();
38 -
39 - // TODO: AUTH
 38+
 39+ $out->setPageTitle( wfMsgExt( 'ep-course-title', 'parsemag', $this->subPage ) );
 40+
 41+ $course = EPCourse::selectRow( null, array( 'name' => $this->subPage ) );
 42+
 43+ if ( $course === false ) {
 44+ if ( $this->getUser()->isAllowed( 'epadmin' ) || $this->getUser()->isAllowed( 'epmentor' ) ) {
 45+ $out->addWikiMsg( 'ep-course-create', 'parsemag', $this->subPage );
 46+ EPCourse::displayAddNewRegion( $this->getContext(), array( 'name' => $this->subPage ) );
 47+ }
 48+ else {
 49+ $out->addWikiMsg( 'ep-course-none', 'parsemag', $this->subPage );
 50+ }
 51+ }
 52+ else {
 53+ $this->displayInfo( $course );
 54+
 55+ $out->addHTML( Html::element( 'h2', array(), wfMsg( 'ep-course-terms' ) ) );
 56+
 57+ EPTerm::displayPager( $this->getContext(), array( 'course_id' => $course->getId() ) );
 58+ }
4059 }
 60+
 61+ /**
 62+ * Display the orgs info.
 63+ *
 64+ * @since 0.1
 65+ *
 66+ * @param EPCourse $course
 67+ */
 68+ protected function displayInfo( EPCourse $course ) {
 69+ $out = $this->getOutput();
 70+
 71+
 72+ }
4173
4274 }
Index: trunk/extensions/EducationProgram/specials/SpecialCourses.php
@@ -33,22 +33,12 @@
3434 public function execute( $subPage ) {
3535 parent::execute( $subPage );
3636
37 - $out = $this->getOutput();
38 -
3937 if ( $this->subPage === '' ) {
4038 EPCourse::displayAddNewRegion( $this->getContext() );
4139 EPCourse::displayPager( $this->getContext() );
4240 }
4341 else {
44 - $org = EPOrg::has( array( 'name' => $this->subPage ) );
45 -
46 - if ( $org === false ) {
47 - $this->showError( wfMessage( 'ep-courses-nosuchcourses', $this->subPage ) );
48 - EPCourse::displayAddNewRegion( $this->getContext(), array( 'name' => $this->subPage ) );
49 - }
50 - else {
51 - $out->redirect( SpecialPage::getTitleFor( 'Course', $this->subPage )->getLocalURL() );
52 - }
 42+ $this->getOutput()->redirect( SpecialPage::getTitleFor( 'Course', $this->subPage )->getLocalURL() );
5343 }
5444 }
5545
Index: trunk/extensions/EducationProgram/includes/EPTerm.php
@@ -59,5 +59,98 @@
6060
6161 return $success;
6262 }
 63+
 64+ /**
 65+ * Display a pager with terms.
 66+ *
 67+ * @since 0.1
 68+ *
 69+ * @param IContextSource $context
 70+ * @param array $conditions
 71+ */
 72+ public static function displayPager( IContextSource $context, array $conditions = array() ) {
 73+ $pager = new EPTermPager( $context, $conditions );
 74+
 75+ if ( $pager->getNumRows() ) {
 76+ $context->getOutput()->addHTML(
 77+ $pager->getFilterControl() .
 78+ $pager->getNavigationBar() .
 79+ $pager->getBody() .
 80+ $pager->getNavigationBar()
 81+ );
 82+ }
 83+ else {
 84+ $context->getOutput()->addHTML( $pager->getFilterControl( true ) );
 85+ $context->getOutput()->addWikiMsg( 'ep-terms-noresults' );
 86+ }
 87+ }
 88+
 89+ /**
 90+ * Adds a control to add a term org to the provided context.
 91+ * Adittional arguments can be provided to set the default values for the control fields.
 92+ *
 93+ * @since 0.1
 94+ *
 95+ * @param IContextSource $context
 96+ * @param array $args
 97+ */
 98+ public static function displayAddNewControl( IContextSource $context, array $courses ) {
 99+ $out = $context->getOutput();
63100
 101+ $out->addHTML( Html::openElement(
 102+ 'form',
 103+ array(
 104+ 'method' => 'post',
 105+ 'action' => SpecialPage::getTitleFor( 'EditTerm' )->getLocalURL(),
 106+ )
 107+ ) );
 108+
 109+ $out->addHTML( '<fieldset>' );
 110+
 111+ $out->addHTML( '<legend>' . wfMsgHtml( 'ep-terms-addnew' ) . '</legend>' );
 112+
 113+ $out->addHTML( Html::element( 'p', array(), wfMsg( 'ep-terms-namedoc' ) ) );
 114+
 115+ $out->addHTML( Html::element( 'label', array( 'for' => 'newcourse' ), wfMsg( 'ep-terms-newcourse' ) ) );
 116+
 117+ $select = new XmlSelect( 'newcourse', 'newcourse' );
 118+ $select->addOptions( EPCourse::getCourseOptions( $courses ) );
 119+ $out->addHTML( $select->getHTML() );
 120+
 121+ $out->addHTML( '&#160;' . Xml::inputLabel( wfMsg( 'ep-terms-newyear' ), 'newyear', 'newyear', 10 ) );
 122+
 123+ $out->addHTML( '&#160;' . Html::input(
 124+ 'addnewterm',
 125+ wfMsg( 'ep-terms-add' ),
 126+ 'submit'
 127+ ) );
 128+
 129+ $out->addHTML( Html::hidden( 'newEditToken', $context->getUser()->editToken() ) );
 130+
 131+ $out->addHTML( '</fieldset></form>' );
 132+ }
 133+
 134+ /**
 135+ * Adds a control to add a new term to the provided context
 136+ * or show a message if this is not possible for some reason.
 137+ *
 138+ * @since 0.1
 139+ *
 140+ * @param IContextSource $context
 141+ * @param array $args
 142+ */
 143+ public static function displayAddNewRegion( IContextSource $context, array $args = array() ) {
 144+ $courses = EPCourse::getEditableCourses( $context->getUser() );
 145+
 146+ if ( count( $courses ) > 0 ) {
 147+ EPTerm::displayAddNewControl( $context, $args );
 148+ }
 149+ elseif ( $context->getUser()->isAllowed( 'epadmin' ) ) {
 150+ $context->getOutput()->addWikiMsg( 'ep-terms-nocourses' );
 151+ }
 152+ elseif ( $context->getUser()->isAllowed( 'epmentor' ) ) {
 153+ $context->getOutput()->addWikiMsg( 'ep-terms-addcoursefirst' );
 154+ }
 155+ }
 156+
64157 }
Index: trunk/extensions/EducationProgram/includes/EPCourse.php
@@ -132,7 +132,7 @@
133133 * @param array $args
134134 */
135135 public static function displayAddNewControl( IContextSource $context, array $args = array() ) {
136 - $out = $this->getOutput();
 136+ $out = $context->getOutput();
137137
138138 $out->addHTML( Html::openElement(
139139 'form',
@@ -179,7 +179,7 @@
180180 'submit'
181181 ) );
182182
183 - $out->addHTML( Html::hidden( 'newEditToken', $this->getUser()->editToken() ) );
 183+ $out->addHTML( Html::hidden( 'newEditToken', $context->getUser()->editToken() ) );
184184
185185 $out->addHTML( '</fieldset></form>' );
186186 }
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php
@@ -152,10 +152,16 @@
153153 'ep-pager-delete-fail' => 'Could not delete this item.',
154154
155155 // Special:Institution
156 - 'ep-institution-none' => 'There is no institution with name "$1".',
 156+ 'ep-institution-none' => 'There is no institution with name "$1". See [[Special:Institution|here]] for a list of institutions.',
157157 'ep-institution-create' => 'There is no institution with name "$1" yet, but you can create it.',
158158 'ep-institution-title' => 'Institution: $1',
159159 'ep-institution-courses' => 'Courses',
 160+
 161+ // Special:Course
 162+ 'ep-course-title' => 'Course: $1',
 163+ 'ep-course-terms' => 'Terms',
 164+ 'ep-course-none' => 'There is no course with name "$1". See [[Special:Course|here]] for a list of courses.',
 165+ 'ep-course-create' => 'There is no course with name "$1" yet, but you can create it.',
160166 );
161167
162168 /** Message documentation (Message documentation)

Status & tagging log