r107179 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107178‎ | r107179 | r107180 >
Date:20:40, 23 December 2011
Author:jeroendedauw
Status:deferred
Tags:educationprogram 
Comment:
restructuring some stuff and initial work on display of cousres, orgs and terms. also follow up to r107107
Modified paths:
  • /trunk/extensions/EducationProgram/EducationProgram.i18n.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPCourse.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPCoursePager.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPOrg.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/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)

Diff [purge]

Index: trunk/extensions/EducationProgram/includes/EPOrgPager.php
@@ -63,7 +63,7 @@
6464 case 'name':
6565 $value = Linker::linkKnown(
6666 SpecialPage::getTitleFor( 'Institution', $value ),
67 - $value
 67+ htmlspecialchars( $value )
6868 );
6969 break;
7070 case 'country':
@@ -118,13 +118,13 @@
119119
120120 $links[] = $value = Linker::linkKnown(
121121 SpecialPage::getTitleFor( 'Institution', $item->getField( 'name' ) ),
122 - wfMsg( 'view' )
 122+ wfMsgHtml( 'view' )
123123 );
124124
125125 if ( $this->getUser()->isAllowed( 'epadmin' ) ) {
126126 $links[] = $value = Linker::linkKnown(
127127 SpecialPage::getTitleFor( 'EditInstitution', $item->getField( 'name' ) ),
128 - wfMsg( 'edit' )
 128+ wfMsgHtml( 'edit' )
129129 );
130130
131131 $links[] = $this->getDeletionLink( 'org', $item->getId() );
Index: trunk/extensions/EducationProgram/includes/EPTermPager.php
@@ -65,7 +65,7 @@
6666 case 'id':
6767 $value = Linker::linkKnown(
6868 SpecialPage::getTitleFor( 'Term', $value ),
69 - $value
 69+ htmlspecialchars( $value )
7070 );
7171 break;
7272 case 'course_id':
@@ -73,7 +73,7 @@
7474
7575 $value = Linker::linkKnown(
7676 SpecialPage::getTitleFor( 'Course', $value ),
77 - $value
 77+ htmlspecialchars( $value )
7878 );
7979 break;
8080 case 'year':
@@ -140,13 +140,13 @@
141141
142142 $links[] = $value = Linker::linkKnown(
143143 SpecialPage::getTitleFor( 'Term', $item->getId() ),
144 - wfMsg( 'view' )
 144+ wfMsgHtml( 'view' )
145145 );
146146
147147 if ( $this->getUser()->isAllowed( 'epadmin' ) ) {
148148 $links[] = $value = Linker::linkKnown(
149149 SpecialPage::getTitleFor( 'EditTerm', $item->getId() ),
150 - wfMsg( 'edit' )
 150+ wfMsgHtml( 'edit' )
151151 );
152152
153153 $links[] = $this->getDeletionLink( 'term', $item->getId() );
Index: trunk/extensions/EducationProgram/includes/EPOrg.php
@@ -111,5 +111,35 @@
112112 return array();
113113 }
114114 }
 115+
 116+ public static function displayAddNewControl( IContextSource $context, $name = false ) {
 117+ $out = $context->getOutput();
 118+
 119+ $out->addHTML( Html::openElement(
 120+ 'form',
 121+ array(
 122+ 'method' => 'post',
 123+ 'action' => SpecialPage::getTitleFor( 'EditInstitution' )->getLocalURL(),
 124+ )
 125+ ) );
115126
 127+ $out->addHTML( '<fieldset>' );
 128+
 129+ $out->addHTML( '<legend>' . wfMsgHtml( 'ep-institutions-addnew' ) . '</legend>' );
 130+
 131+ $out->addHTML( Html::element( 'p', array(), wfMsg( 'ep-institutions-namedoc' ) ) );
 132+
 133+ $out->addHTML( Xml::inputLabel( wfMsg( 'ep-institutions-newname' ), 'newname', 'newname', false, $name ) );
 134+
 135+ $out->addHTML( '&#160;' . Html::input(
 136+ 'addneworg',
 137+ wfMsg( 'ep-institutions-add' ),
 138+ 'submit'
 139+ ) );
 140+
 141+ $out->addHTML( Html::hidden( 'newEditToken', $context->getUser()->editToken() ) );
 142+
 143+ $out->addHTML( '</fieldset></form>' );
 144+ }
 145+
116146 }
Index: trunk/extensions/EducationProgram/includes/EPPager.php
@@ -245,6 +245,12 @@
246246 public function getFilterControl( $hideWhenNoResults = true ) {
247247 $filterOptions = $this->getFilterOptions();
248248
 249+ foreach ( $this->conds as $name => $value ) {
 250+ if ( array_key_exists( $name, $filterOptions ) ) {
 251+ unset( $filterOptions[$name] );
 252+ }
 253+ }
 254+
249255 if ( count( $filterOptions ) < 1 ) {
250256 return '';
251257 }
Index: trunk/extensions/EducationProgram/includes/EPCoursePager.php
@@ -62,7 +62,7 @@
6363 case 'name':
6464 $value = Linker::linkKnown(
6565 SpecialPage::getTitleFor( 'Course', $value ),
66 - $value
 66+ htmlspecialchars( $value )
6767 );
6868 break;
6969 case 'org_id':
@@ -70,7 +70,7 @@
7171
7272 $value = Linker::linkKnown(
7373 SpecialPage::getTitleFor( 'Institution', $value ),
74 - $value
 74+ htmlspecialchars( $value )
7575 );
7676 break;
7777 }
@@ -119,13 +119,13 @@
120120
121121 $links[] = $value = Linker::linkKnown(
122122 SpecialPage::getTitleFor( 'Course', $item->getField( 'name' ) ),
123 - wfMsg( 'view' )
 123+ wfMsgHtml( 'view' )
124124 );
125125
126126 if ( $this->getUser()->isAllowed( 'epadmin' ) ) {
127127 $links[] = $value = Linker::linkKnown(
128128 SpecialPage::getTitleFor( 'EditCourse', $item->getField( 'name' ) ),
129 - wfMsg( 'edit' )
 129+ wfMsgHtml( 'edit' )
130130 );
131131
132132 $links[] = $this->getDeletionLink( 'term', $item->getId() );
@@ -133,5 +133,24 @@
134134
135135 return $links;
136136 }
 137+
 138+ public static function displayWithAddControl( IContextSource $context, array $conditions = array() ) {
137139
 140+
 141+ $pager = new self( $this->getContext() );
 142+
 143+ if ( $pager->getNumRows() ) {
 144+ $this->getOutput()->addHTML(
 145+ $pager->getFilterControl() .
 146+ $pager->getNavigationBar() .
 147+ $pager->getBody() .
 148+ $pager->getNavigationBar()
 149+ );
 150+ }
 151+ else {
 152+ $this->getOutput()->addHTML( $pager->getFilterControl( true ) );
 153+ $this->getOutput()->addWikiMsg( 'ep-courses-noresults' );
 154+ }
 155+ }
 156+
138157 }
Index: trunk/extensions/EducationProgram/includes/EPCourse.php
@@ -121,5 +121,115 @@
122122
123123 return $cache[$userId];
124124 }
 125+
 126+ /**
 127+ * Adds a control to add a new course to the provided context.
 128+ * An org id can be provided to set the initially selected org.
 129+ *
 130+ * @since 0.1
 131+ *
 132+ * @param IContextSource $context
 133+ * @param array $args
 134+ */
 135+ public static function displayAddNewControl( IContextSource $context, array $args = array() ) {
 136+ $out = $this->getOutput();
125137
 138+ $out->addHTML( Html::openElement(
 139+ 'form',
 140+ array(
 141+ 'method' => 'post',
 142+ 'action' => SpecialPage::getTitleFor( 'EditCourse' )->getLocalURL(),
 143+ )
 144+ ) );
 145+
 146+ $out->addHTML( '<fieldset>' );
 147+
 148+ $out->addHTML( '<legend>' . wfMsgHtml( 'ep-courses-addnew' ) . '</legend>' );
 149+
 150+ $out->addHTML( Html::element( 'p', array(), wfMsg( 'ep-courses-namedoc' ) ) );
 151+
 152+ $out->addHTML( Html::element( 'label', array( 'for' => 'neworg' ), wfMsg( 'ep-courses-neworg' ) ) );
 153+
 154+ $out->addHTML( '&#160;' );
 155+
 156+ $select = new XmlSelect(
 157+ 'neworg',
 158+ 'neworg',
 159+ array_key_exists( 'org', $args ) ? $args['org'] : false
 160+ );
 161+
 162+ $select->addOptions( EPOrg::getOrgOptions( EPOrg::getEditableOrgs( $context->getUser() ) ) );
 163+ $out->addHTML( $select->getHTML() );
 164+
 165+ $out->addHTML( '&#160;' );
 166+
 167+ $out->addHTML( Xml::inputLabel(
 168+ wfMsg( 'ep-courses-newname' ),
 169+ 'newname',
 170+ 'newname',
 171+ false,
 172+ array_key_exists( 'name', $args ) ? $args['name'] : false
 173+ ) );
 174+
 175+ $out->addHTML( '&#160;' );
 176+
 177+ $out->addHTML( Html::input(
 178+ 'addneworg',
 179+ wfMsg( 'ep-courses-add' ),
 180+ 'submit'
 181+ ) );
 182+
 183+ $out->addHTML( Html::hidden( 'newEditToken', $this->getUser()->editToken() ) );
 184+
 185+ $out->addHTML( '</fieldset></form>' );
 186+ }
 187+
 188+ /**
 189+ * Adds a control to add a new course to the provided context
 190+ * or show a message if this is not possible for some reason.
 191+ *
 192+ * @since 0.1
 193+ *
 194+ * @param IContextSource $context
 195+ * @param array $args
 196+ */
 197+ public static function displayAddNewRegion( IContextSource $context, array $args = array() ) {
 198+ $orgs = EPOrg::getEditableOrgs( $context->getUser() );
 199+
 200+ if ( count( $orgs ) > 0 ) {
 201+ EPCourse::displayAddNewControl( $context, $args );
 202+ }
 203+ elseif ( $context->getUser()->isAllowed( 'epadmin' ) ) {
 204+ $context->getOutput()->addWikiMsg( 'ep-courses-noorgs' );
 205+ }
 206+ elseif ( $context->getUser()->isAllowed( 'epmentor' ) ) {
 207+ $context->getOutput()->addWikiMsg( 'ep-courses-addorgfirst' );
 208+ }
 209+ }
 210+
 211+ /**
 212+ * Display a pager with courses.
 213+ *
 214+ * @since 0.1
 215+ *
 216+ * @param IContextSource $context
 217+ * @param array $conditions
 218+ */
 219+ public static function displayPager( IContextSource $context, array $conditions = array() ) {
 220+ $pager = new EPCoursePager( $context, $conditions );
 221+
 222+ if ( $pager->getNumRows() ) {
 223+ $context->getOutput()->addHTML(
 224+ $pager->getFilterControl() .
 225+ $pager->getNavigationBar() .
 226+ $pager->getBody() .
 227+ $pager->getNavigationBar()
 228+ );
 229+ }
 230+ else {
 231+ $context->getOutput()->addHTML( $pager->getFilterControl( true ) );
 232+ $context->getOutput()->addWikiMsg( 'ep-courses-noresults' );
 233+ }
 234+ }
 235+
126236 }
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php
@@ -150,6 +150,12 @@
151151 // ep.pager
152152 'ep-pager-confirm-delete' => 'Are you sure you want to delete this item?',
153153 'ep-pager-delete-fail' => 'Could not delete this item.',
 154+
 155+ // Special:Institution
 156+ 'ep-institution-none' => 'There is no institution with name "$1".',
 157+ 'ep-institution-create' => 'There is no institution with name "$1" yet, but you can create it.',
 158+ 'ep-institution-title' => 'Institution: $1',
 159+ 'ep-institution-courses' => 'Courses',
154160 );
155161
156162 /** Message documentation (Message documentation)
Index: trunk/extensions/EducationProgram/specials/SpecialInstitution.php
@@ -14,6 +14,8 @@
1515 */
1616 class SpecialInstitution extends SpecialEPPage {
1717
 18+ protected $org;
 19+
1820 /**
1921 * Constructor.
2022 *
@@ -34,8 +36,40 @@
3537 parent::execute( $subPage );
3638
3739 $out = $this->getOutput();
38 -
39 - // TODO: AUTH
 40+
 41+ $out->setPageTitle( wfMsgExt( 'ep-institution-title', 'parsemag', $this->subPage ) );
 42+
 43+ $org = EPOrg::selectRow( null, array( 'name' => $this->subPage ) );
 44+
 45+ if ( $org === false ) {
 46+ if ( $this->getUser()->isAllowed( 'epadmin' ) ) {
 47+ $out->addWikiMsg( 'ep-institution-create', 'parsemag', $this->subPage );
 48+ EPOrg::displayAddNewControl( $this->getContext(), $this->subPage );
 49+ }
 50+ else {
 51+ $out->addWikiMsg( 'ep-institution-none', 'parsemag', $this->subPage );
 52+ }
 53+ }
 54+ else {
 55+ $this->displayInfo( $org );
 56+
 57+ $out->addHTML( Html::element( 'h2', array(), wfMsg( 'ep-institution-courses' ) ) );
 58+
 59+ EPCourse::displayPager( $this->getContext(), array( 'org_id' => $org->getId() ) );
 60+ }
4061 }
41 -
 62+
 63+ /**
 64+ * Display the orgs info.
 65+ *
 66+ * @since 0.1
 67+ *
 68+ * @param EPOrg $org
 69+ */
 70+ protected function displayInfo( EPOrg $org ) {
 71+ $out = $this->getOutput();
 72+
 73+
 74+ }
 75+
4276 }
Index: trunk/extensions/EducationProgram/specials/SpecialInstitutions.php
@@ -57,59 +57,7 @@
5858 * @since 0.1
5959 */
6060 protected function displayPage() {
61 - if ( $this->getUser()->isAllowed( 'epadmin' ) ) {
62 - $this->displayAddNewControl();
63 - }
64 -
65 - $pager = new EPOrgPager( $this->getContext() );
66 -
67 - if ( $pager->getNumRows() ) {
68 - $this->getOutput()->addHTML(
69 - $pager->getFilterControl() .
70 - $pager->getNavigationBar() .
71 - $pager->getBody() .
72 - $pager->getNavigationBar()
73 - );
74 - }
75 - else {
76 - $this->getOutput()->addHTML( $pager->getFilterControl( true ) );
77 - $this->getOutput()->addWikiMsg( 'ep-institutions-noresults' );
78 - }
79 - }
80 -
81 - /**
82 - * Displays a small form to add a new institution.
83 - *
84 - * @since 0.1
85 - */
86 - protected function displayAddNewControl() {
87 - $out = $this->getOutput();
8861
89 - $out->addHTML( Html::openElement(
90 - 'form',
91 - array(
92 - 'method' => 'post',
93 - 'action' => SpecialPage::getTitleFor( 'EditInstitution' )->getLocalURL(),
94 - )
95 - ) );
96 -
97 - $out->addHTML( '<fieldset>' );
98 -
99 - $out->addHTML( '<legend>' . wfMsgHtml( 'ep-institutions-addnew' ) . '</legend>' );
100 -
101 - $out->addHTML( Html::element( 'p', array(), wfMsg( 'ep-institutions-namedoc' ) ) );
102 -
103 - $out->addHTML( Xml::inputLabel( wfMsg( 'ep-institutions-newname' ), 'newname', 'newname' ) );
104 -
105 - $out->addHTML( '&#160;' . Html::input(
106 - 'addneworg',
107 - wfMsg( 'ep-institutions-add' ),
108 - 'submit'
109 - ) );
110 -
111 - $out->addHTML( Html::hidden( 'newEditToken', $this->getUser()->editToken() ) );
112 -
113 - $out->addHTML( '</fieldset></form>' );
11462 }
11563
11664 }
Index: trunk/extensions/EducationProgram/specials/SpecialEPPage.php
@@ -41,7 +41,6 @@
4242 public function setHeaders() {
4343 $out = $this->getOutput();
4444 $out->setArticleRelated( false );
45 - $out->setRobotPolicy( 'noindex,nofollow' );
4645 $out->setPageTitle( $this->getDescription() );
4746 }
4847
Index: trunk/extensions/EducationProgram/specials/SpecialCourses.php
@@ -36,14 +36,14 @@
3737 $out = $this->getOutput();
3838
3939 if ( $this->subPage === '' ) {
40 - $this->displayPage();
 40+ EPCourse::displayPager()
4141 }
4242 else {
4343 $org = EPOrg::has( array( 'name' => $this->subPage ) );
4444
4545 if ( $org === false ) {
4646 $this->showError( wfMessage( 'ep-courses-nosuchcourses', $this->subPage ) );
47 - $this->displayPage();
 47+ EPCourse::displayAddNewRegion( $this->getContext() );
4848 }
4949 else {
5050 $out->redirect( SpecialPage::getTitleFor( 'Course', $this->subPage )->getLocalURL() );
@@ -51,89 +51,4 @@
5252 }
5353 }
5454
55 - /**
56 - * Display all the stuff that should be on the page.
57 - *
58 - * @since 0.1
59 - */
60 - protected function displayPage() {
61 - $user = $this->getUser();
62 -
63 - $orgs = EPOrg::getEditableOrgs( $this->getUser() );
64 -
65 - if ( count( $orgs ) > 0 ) {
66 - $this->displayAddNewControl( $orgs );
67 - }
68 - elseif ( $user->isAllowed( 'epadmin' ) ) {
69 - $this->getOutput()->addWikiMsg( 'ep-courses-noorgs' );
70 - }
71 - elseif ( $user->isAllowed( 'epmentor' ) ) {
72 - $this->getOutput()->addWikiMsg( 'ep-courses-addorgfirst' );
73 - }
74 -
75 - $pager = new EPCoursePager( $this->getContext() );
76 -
77 - if ( $pager->getNumRows() ) {
78 - $this->getOutput()->addHTML(
79 - $pager->getFilterControl() .
80 - $pager->getNavigationBar() .
81 - $pager->getBody() .
82 - $pager->getNavigationBar()
83 - );
84 - }
85 - else {
86 - $this->getOutput()->addHTML( $pager->getFilterControl( true ) );
87 - $this->getOutput()->addWikiMsg( 'ep-courses-noresults' );
88 - }
89 - }
90 -
91 - /**
92 - * Displays a small form to add a new institution.
93 - *
94 - * @since 0.1
95 - *
96 - * @param array $orgs
97 - */
98 - protected function displayAddNewControl( array /* of EPOrg */ $orgs ) {
99 - $out = $this->getOutput();
100 -
101 - $out->addHTML( Html::openElement(
102 - 'form',
103 - array(
104 - 'method' => 'post',
105 - 'action' => SpecialPage::getTitleFor( 'EditCourse' )->getLocalURL(),
106 - )
107 - ) );
108 -
109 - $out->addHTML( '<fieldset>' );
110 -
111 - $out->addHTML( '<legend>' . wfMsgHtml( 'ep-courses-addnew' ) . '</legend>' );
112 -
113 - $out->addHTML( Html::element( 'p', array(), wfMsg( 'ep-courses-namedoc' ) ) );
114 -
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 -
125 - $out->addHTML( Xml::inputLabel( wfMsg( 'ep-courses-newname' ), 'newname', 'newname' ) );
126 -
127 - $out->addHTML( '&#160;' );
128 -
129 - $out->addHTML( Html::input(
130 - 'addneworg',
131 - wfMsg( 'ep-courses-add' ),
132 - 'submit'
133 - ) );
134 -
135 - $out->addHTML( Html::hidden( 'newEditToken', $this->getUser()->editToken() ) );
136 -
137 - $out->addHTML( '</fieldset></form>' );
138 - }
139 -
14055 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r107181Follow up to r107179; fixes and cleanupjeroendedauw21:06, 23 December 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r107107finished up some stuffjeroendedauw20:17, 22 December 2011

Status & tagging log