r107200 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107199‎ | r107200 | r107201 >
Date:01:47, 24 December 2011
Author:jeroendedauw
Status:deferred
Tags:educationprogram 
Comment:
work on nav links
Modified paths:
  • /trunk/extensions/EducationProgram/EducationProgram.i18n.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPStudent.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialCourse.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialCourses.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialEPPage.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialInstitution.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialInstitutions.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialTerm.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialTerms.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/includes/EPStudent.php
@@ -26,5 +26,19 @@
2727 'user_id' => 'id',
2828 );
2929 }
30 -
 30+
 31+ /**
 32+ * Get the student object of a user, or false if there is none.
 33+ *
 34+ * @since 0.1
 35+ *
 36+ * @param User $user
 37+ * @param string|array|null $fields
 38+ *
 39+ * @return EPStudent|false
 40+ */
 41+ public static function newFromUser( User $user, $fields = null ) {
 42+ return self::selectRow( $fields, array( 'user_id' => $user->getId() ) );
 43+ }
 44+
3145 }
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php
@@ -168,6 +168,12 @@
169169 'ep-term-students' => 'Students',
170170 'ep-term-none' => 'There is no term with id "$1". See [[Special:Terms|here]] for a list of terms.',
171171 'ep-term-create' => 'There is no term with id "$1", but you can create a new one.',
 172+
 173+ // Navigation links
 174+ 'ep-nav-orgs' => 'Institution list',
 175+ 'ep-nav-courses' => 'Courses list',
 176+ 'ep-nav-terms' => 'Terms list',
 177+ 'ep-nav-mycourses' => 'My courses',
172178 );
173179
174180 /** Message documentation (Message documentation)
Index: trunk/extensions/EducationProgram/specials/SpecialTerm.php
@@ -41,6 +41,8 @@
4242 else {
4343 $out->setPageTitle( wfMsgExt( 'ep-term-title', 'parsemag', $this->subPage ) );
4444
 45+ $this->displayNavigation();
 46+
4547 $term = EPTerm::selectRow( null, array( 'id' => $this->subPage ) );
4648
4749 if ( $term === false ) {
Index: trunk/extensions/EducationProgram/specials/SpecialInstitution.php
@@ -41,6 +41,8 @@
4242 else {
4343 $out->setPageTitle( wfMsgExt( 'ep-institution-title', 'parsemag', $this->subPage ) );
4444
 45+ $this->displayNavigation();
 46+
4547 $org = EPOrg::selectRow( null, array( 'name' => $this->subPage ) );
4648
4749 if ( $org === false ) {
Index: trunk/extensions/EducationProgram/specials/SpecialTerms.php
@@ -34,6 +34,7 @@
3535 parent::execute( $subPage );
3636
3737 if ( $this->subPage === '' ) {
 38+ $this->displayNavigation();
3839 EPTerm::displayAddNewRegion( $this->getContext() );
3940 EPTerm::displayPager( $this->getContext() );
4041 }
@@ -41,40 +42,5 @@
4243 $this->getOutput()->redirect( SpecialPage::getTitleFor( 'Term', $this->subPage )->getLocalURL() );
4344 }
4445 }
45 -
46 - /**
47 - * Display all the stuff that should be on the page.
48 - *
49 - * @since 0.1
50 - */
51 - protected function displayPage() {
52 - $user = $this->getUser();
53 -
54 - $courses = EPCourse::getEditableCourses( $this->getUser() );
55 -
56 - if ( count( $courses ) > 0 ) {
57 - $this->displayAddNewControl( $courses );
58 - }
59 - elseif ( $user->isAllowed( 'epmentor' ) ) {
60 - $this->getOutput()->addWikiMsg( 'ep-terms-addcoursefirst' );
61 - }
62 -
63 - $pager = new EPTermPager( $this->getContext() );
64 -
65 - if ( $pager->getNumRows() ) {
66 - $this->getOutput()->addHTML(
67 - $pager->getFilterControl() .
68 - $pager->getNavigationBar() .
69 - $pager->getBody() .
70 - $pager->getNavigationBar()
71 - );
72 - }
73 - else {
74 - $this->getOutput()->addHTML( $pager->getFilterControl( true ) );
75 - $this->getOutput()->addWikiMsg( 'ep-terms-noresults' );
76 - }
77 - }
7846
79 -
80 -
8147 }
Index: trunk/extensions/EducationProgram/specials/SpecialInstitutions.php
@@ -34,6 +34,7 @@
3535 parent::execute( $subPage );
3636
3737 if ( $this->subPage === '' ) {
 38+ $this->displayNavigation();
3839 EPOrg::displayAddNewControl( $this->getContext() );
3940 EPOrg::displayPager( $this->getContext() );
4041 }
Index: trunk/extensions/EducationProgram/specials/SpecialCourse.php
@@ -41,6 +41,8 @@
4242 else {
4343 $out->setPageTitle( wfMsgExt( 'ep-course-title', 'parsemag', $this->subPage ) );
4444
 45+ $this->displayNavigation();
 46+
4547 $course = EPCourse::selectRow( null, array( 'name' => $this->subPage ) );
4648
4749 if ( $course === false ) {
Index: trunk/extensions/EducationProgram/specials/SpecialEPPage.php
@@ -120,5 +120,51 @@
121121 public function getLanguage() {
122122 return method_exists( get_parent_class(), 'getLanguage' ) ? parent::getLanguage() : $this->getLang();
123123 }
 124+
 125+ /**
 126+ * Adds a navigation menu with the provided links.
 127+ * Links should be provided in an array with:
 128+ * label => Title (object)
 129+ *
 130+ * @since 0.1
 131+ *
 132+ * @param array $links
 133+ */
 134+ protected function displayNavigation( array $items = array() ) {
 135+ $links = array();
 136+ $items = array_merge( $this->getDefaultNavigationItems(), $items );
 137+
 138+ foreach ( $items as $label => $target ) {
 139+ $links[] = Linker::linkKnown(
 140+ $target,
 141+ htmlspecialchars( $label )
 142+ );
 143+ }
 144+
 145+ $this->getOutput()->addHTML(
 146+ Html::rawElement( 'p', array(), $this->getLang()->pipeList( $links ) )
 147+ );
 148+ }
 149+
 150+ /**
 151+ * Returns the default nav items for @see displayNavigation.
 152+ *
 153+ * @since 0.1
 154+ *
 155+ * @return array
 156+ */
 157+ protected function getDefaultNavigationItems() {
 158+ $items = array(
 159+ wfMsg( 'ep-nav-orgs' ) => SpecialPage::getTitleFor( 'Institutions' ),
 160+ wfMsg( 'ep-nav-courses' ) => SpecialPage::getTitleFor( 'Courses' ),
 161+ wfMsg( 'ep-nav-terms' ) => SpecialPage::getTitleFor( 'Terms' ),
 162+ );
 163+
 164+ if ( $this->getUser()->isAllowed( 'epmentor' ) || EPStudent::has( array( 'user_id' => $this->getUser()->getId() ) ) ) {
 165+ $items[wfMsg( 'ep-nav-mycourses' )] = SpecialPage::getTitleFor( 'MyCourses' );
 166+ }
 167+
 168+ return $items;
 169+ }
124170
125171 }
Index: trunk/extensions/EducationProgram/specials/SpecialCourses.php
@@ -34,6 +34,7 @@
3535 parent::execute( $subPage );
3636
3737 if ( $this->subPage === '' ) {
 38+ $this->displayNavigation();
3839 EPCourse::displayAddNewRegion( $this->getContext() );
3940 EPCourse::displayPager( $this->getContext() );
4041 }

Status & tagging log