r109724 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r109723‎ | r109724 | r109725 >
Date:06:22, 22 January 2012
Author:jeroendedauw
Status:deferred
Tags:
Comment:
work on edit/view navigation of org and course management
Modified paths:
  • /trunk/extensions/EducationProgram/EducationProgram.hooks.php (modified) (history)
  • /trunk/extensions/EducationProgram/EducationProgram.i18n.alias.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPCoursePager.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPMCPager.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPOrgPager.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialCourse.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialEPFormPage.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialEditCourse.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialEditInstitution.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialEditMasterCourse.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialInstitution.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialMasterCourse.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/EducationProgram.i18n.alias.php
@@ -35,3 +35,8 @@
3636 'CampusAmbassador' => array( 'CampusAmbassador' ),
3737 'OnlineAmbassador' => array( 'OnlineAmbassador' ),
3838 );
 39+
 40+/** Dutch (Nederlands) */
 41+$specialPageAliases['nl'] = array(
 42+ 'MyCourses' => array( 'MijnCursusen' ),
 43+);
\ No newline at end of file
Index: trunk/extensions/EducationProgram/specials/SpecialInstitution.php
@@ -55,16 +55,8 @@
5656 }
5757 }
5858 else {
59 - $links = array();
 59+ $this->displayNavigation();
6060
61 - if ( $this->getUser()->isAllowed( 'ep-org' ) ) {
62 - $links[wfMsg( 'ep-institution-nav-edit' )] =
63 - array( SpecialPage::getTitleFor( 'EditInstitution', $this->subPage ) )
64 - + Linker::tooltipAndAccesskeyAttribs( 'ep-edit-institution' );
65 - }
66 -
67 - $this->displayNavigation( $links );
68 -
6961 $this->displaySummary( $org );
7062
7163 $out->addHTML( Html::element( 'h2', array(), wfMsg( 'ep-institution-courses' ) ) );
Index: trunk/extensions/EducationProgram/specials/SpecialEditInstitution.php
@@ -19,7 +19,7 @@
2020 * @since 0.1
2121 */
2222 public function __construct() {
23 - parent::__construct( 'EditInstitution', 'ep-org', 'EPOrg', 'Institutions' );
 23+ parent::__construct( 'EditInstitution', 'ep-org', 'EPOrg', 'Institutions', 'Institution' );
2424 }
2525
2626 /**
Index: trunk/extensions/EducationProgram/specials/SpecialCourse.php
@@ -55,16 +55,8 @@
5656 }
5757 }
5858 else {
59 - $links = array();
 59+ $this->displayNavigation();
6060
61 - if ( $this->getUser()->isAllowed( 'ep-course' ) ) {
62 - $links[wfMsg( 'ep-course-nav-edit' )] =
63 - array( SpecialPage::getTitleFor( 'EditCourse', $this->subPage ) )
64 - + Linker::tooltipAndAccesskeyAttribs( 'ep-edit-course' );
65 - }
66 -
67 - $this->displayNavigation( $links );
68 -
6961 $this->displaySummary( $course );
7062
7163 $out->addHTML( Html::element( 'h2', array(), wfMsg( 'ep-course-description' ) ) );
Index: trunk/extensions/EducationProgram/specials/SpecialEditCourse.php
@@ -19,7 +19,7 @@
2020 * @since 0.1
2121 */
2222 public function __construct() {
23 - parent::__construct( 'EditCourse', 'ep-course', 'EPCourse', 'Courses' );
 23+ parent::__construct( 'EditCourse', 'ep-course', 'EPCourse', 'Courses', 'Course' );
2424
2525 $this->getOutput()->addModules( 'ep.datepicker' );
2626 }
Index: trunk/extensions/EducationProgram/specials/SpecialMasterCourse.php
@@ -55,16 +55,8 @@
5656 }
5757 }
5858 else {
59 - $links = array();
 59+ $this->displayNavigation();
6060
61 - if ( $this->getUser()->isAllowed( 'ep-mc' ) ) {
62 - $links[wfMsg( 'ep-mc-nav-edit' )] =
63 - array( SpecialPage::getTitleFor( 'EditMasterCourse', $this->subPage ) )
64 - + Linker::tooltipAndAccesskeyAttribs( 'ep-edit-mc' );
65 - }
66 -
67 - $this->displayNavigation( $links );
68 -
6961 $this->displaySummary( $masterCourse );
7062
7163 $out->addHTML( Html::element( 'h2', array(), wfMsg( 'ep-mc-description' ) ) );
Index: trunk/extensions/EducationProgram/specials/SpecialEditMasterCourse.php
@@ -19,7 +19,7 @@
2020 * @since 0.1
2121 */
2222 public function __construct() {
23 - parent::__construct( 'EditMasterCourse', 'ep-mc', 'EPMC', 'MasterCourses' );
 23+ parent::__construct( 'EditMasterCourse', 'ep-mc', 'EPMC', 'MasterCourses', 'MasterCourse' );
2424 }
2525
2626 /**
Index: trunk/extensions/EducationProgram/specials/SpecialEPFormPage.php
@@ -39,6 +39,15 @@
4040 protected $listPage;
4141
4242 /**
 43+ * Name of the special page displaying individual items.
 44+ * For example, for "EditLolcat", it could be "Lolcat".
 45+ *
 46+ * @since 0.1
 47+ * @var string
 48+ */
 49+ protected $itemPage;
 50+
 51+ /**
4352 * Constructor.
4453 *
4554 * @since 0.1
@@ -47,10 +56,12 @@
4857 * @param string $right Right needed to access the page
4958 * @param string $itemClass Name of the item class
5059 * @param string $listPage Name of the page listing the items
 60+ * @param string $itemPage Name of the page displaying individual items
5161 */
52 - public function __construct( $name, $right, $itemClass, $listPage ) {
 62+ public function __construct( $name, $right, $itemClass, $listPage, $itemPage ) {
5363 $this->itemClass = $itemClass;
5464 $this->listPage = $listPage;
 65+ $this->itemPage = $itemPage;
5566
5667 parent::__construct( $name, $right, false );
5768
@@ -210,10 +221,17 @@
211222 if ( $this->isNew() ) {
212223 $fields['isnew'] = array(
213224 'type' => 'hidden',
214 - 'default' => 1
 225+ 'default' => 1,
215226 );
216227 }
217228
 229+ if ( $this->getRequest()->getCheck( 'wpreturnto' ) ) {
 230+ $fields['returnto'] = array(
 231+ 'type' => 'hidden',
 232+ 'default' => $this->getRequest()->getText( 'wpreturnto' ),
 233+ );
 234+ }
 235+
218236 $form = new HTMLForm( $fields, $this->getContext() );
219237
220238 $form->setSubmitCallback( array( $this, 'handleSubmission' ) );
@@ -318,7 +336,15 @@
319337 * @since 0.1
320338 */
321339 public function onSuccess() {
322 - $this->getOutput()->redirect( SpecialPage::getTitleFor( $this->listPage )->getLocalURL() );
 340+ if ( $this->getRequest()->getCheck( 'wpreturnto' ) ) {
 341+ $parts = explode( '/', $this->getRequest()->getText( 'wpreturnto' ), 2 );
 342+ $title = SpecialPage::getTitleFor( $parts[0], count( $parts ) === 2 ? $parts[1] : false )->getLocalURL();
 343+ }
 344+ else {
 345+ $title = SpecialPage::getTitleFor( $this->itemPage )->getLocalURL();
 346+ }
 347+
 348+ $this->getOutput()->redirect( $title );
323349 }
324350
325351 /**
Index: trunk/extensions/EducationProgram/includes/EPOrgPager.php
@@ -152,7 +152,9 @@
153153 if ( $this->getUser()->isAllowed( 'ep-org' ) ) {
154154 $links[] = $value = Linker::linkKnown(
155155 SpecialPage::getTitleFor( 'EditInstitution', $item->getField( 'name' ) ),
156 - wfMsgHtml( 'edit' )
 156+ wfMsgHtml( 'edit' ),
 157+ array(),
 158+ array( 'wpreturnto' => $this->getTitle()->getText() )
157159 );
158160
159161 $links[] = $this->getDeletionLink( 'org', $item->getId() );
Index: trunk/extensions/EducationProgram/includes/EPMCPager.php
@@ -142,7 +142,9 @@
143143 if ( $this->getUser()->isAllowed( 'ep-mc' ) ) {
144144 $links[] = $value = Linker::linkKnown(
145145 SpecialPage::getTitleFor( 'EditMasterCourse', $item->getField( 'name' ) ),
146 - wfMsgHtml( 'edit' )
 146+ wfMsgHtml( 'edit' ),
 147+ array(),
 148+ array( 'wpreturnto' => $this->getTitle()->getText() )
147149 );
148150
149151 $links[] = $this->getDeletionLink( 'course', $item->getId() );
Index: trunk/extensions/EducationProgram/includes/EPCoursePager.php
@@ -187,7 +187,9 @@
188188 if ( $this->getUser()->isAllowed( 'ep-course' ) ) {
189189 $links[] = $value = Linker::linkKnown(
190190 SpecialPage::getTitleFor( 'EditCourse', $item->getId() ),
191 - wfMsgHtml( 'edit' )
 191+ wfMsgHtml( 'edit' ),
 192+ array(),
 193+ array( 'wpreturnto' => $this->getTitle()->getText() )
192194 );
193195
194196 $links[] = $this->getDeletionLink( 'course', $item->getId() );
Index: trunk/extensions/EducationProgram/EducationProgram.hooks.php
@@ -153,16 +153,75 @@
154154
155155 $title = $sktemplate->getTitle();
156156
157 - switch ( $title->getBaseText() ) {
158 - case 'Institution': case 'EditInstitution':
159 - $editTitle = SpecialPage::getTitleFor( 'EditInstitution', $title->getSubpageText() );
 157+ // The Title getBaseText and getSubpageText methods only do what we want when
 158+ // the special pages NS is in teh list of NS with subpages.
 159+ $textParts = SpecialPageFactory::resolveAlias( $sktemplate->getTitle()->getText() );
 160+ $baseText = $textParts[0];
 161+
 162+ $specials = array(
 163+ array(
 164+ 'view' => 'Institution',
 165+ 'edit' => 'EditInstitution',
 166+ //'history' => 'InstitutionHistory',
 167+ ),
 168+ array(
 169+ 'view' => 'MasterCourse',
 170+ 'edit' => 'EditMasterCourse',
 171+ //'history' => 'MasterCourseHistory',
 172+ ),
 173+ array(
 174+ 'view' => 'Course',
 175+ 'edit' => 'EditCourse',
 176+ //'history' => 'CourseHistory',
 177+ ),
 178+ );
 179+
 180+ $editRights = array(
 181+ 'EditInstitution' => 'ep-org',
 182+ 'EditMasterCourse' => 'ep-mc',
 183+ 'EditCourse' => 'ep-course',
 184+ );
 185+
 186+ $specialSet = false;
 187+ $type = false;
 188+
 189+ foreach ( $specials as $set ) {
 190+ if ( in_array( $baseText, $set ) ) {
 191+ $specialSet = $set;
 192+ $flipped = array_flip( $set );
 193+ $type = $flipped[$baseText];
 194+ break;
 195+ }
 196+ }
 197+
 198+ // TODO: messages
 199+ if ( $specialSet !== false ) {
 200+ $editRight = $editRights[$specialSet['edit']];
 201+
 202+ foreach ( $specialSet as &$special ) {
 203+ $special = SpecialPageFactory::getLocalNameFor( $special );
 204+ }
 205+
 206+ $viewLinks['view'] = array(
 207+ 'class' => $type === 'view' ? 'selected' : false,
 208+ 'text' => wfMsg( 'vector-view-view' ),
 209+ 'href' => SpecialPage::getTitleFor( $specialSet['view'], $textParts[1] )->getLocalUrl()
 210+ );
 211+
 212+ if ( $sktemplate->getUser()->isAllowed( $editRight ) ) {
160213 $viewLinks['edit'] = array(
161 - 'class' => $title->getBaseText() == 'EditInstitution' ? 'selected' : false,
162 - 'text' => wfMsg( 'edit' ),
163 - 'href' => $editTitle->getLocalUrl()
 214+ 'class' => $type === 'edit' ? 'selected' : false,
 215+ 'text' => wfMsg( 'vector-view-edit' ),
 216+ 'href' => SpecialPage::getTitleFor( $specialSet['edit'], $textParts[1] )->getLocalUrl()
164217 );
165 - break;
166 - // TODO: test & add other links
 218+ }
 219+
 220+ $viewLinks['history'] = array(
 221+ 'class' => $type === 'history' ? 'selected' : false,
 222+ 'text' => wfMsg( 'vector-view-history' ),
 223+ 'href' => '' // TODO
 224+ //SpecialPage::getTitleFor( $specialSet['history'], $textParts[1] )->getLocalUrl()
 225+ );
167226 }
168227
169228 $links['views'] = $viewLinks;

Status & tagging log