r110242 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r110241‎ | r110242 | r110243 >
Date:14:13, 29 January 2012
Author:jeroendedauw
Status:deferred
Tags:
Comment:
improvements to editing and creating of courses and orgs
Modified paths:
  • /trunk/extensions/EducationProgram/EducationProgram.hooks.php (modified) (history)
  • /trunk/extensions/EducationProgram/actions/EPEditAction.php (modified) (history)
  • /trunk/extensions/EducationProgram/actions/ViewCourseAction.php (modified) (history)
  • /trunk/extensions/EducationProgram/actions/ViewOrgAction.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/actions/ViewCourseAction.php
@@ -28,10 +28,23 @@
2929 if ( $this->getUser()->isAllowed( 'ep-course' ) ) {
3030 $out->addWikiMsg( 'ep-course-create', $name );
3131
 32+ $bracketPos = strpos( $name, '(' );
 33+
 34+ if ( $bracketPos !== false ) {
 35+ if ( $bracketPos > 0 && in_array( $name{$bracketPos - 1}, array( ' ', '_' ) ) ) {
 36+ $bracketPos -= 1;
 37+ }
 38+
 39+ $newName = substr( $name, 0, $bracketPos );
 40+ }
 41+
3242 EPCourse::displayAddNewRegion(
3343 $this->getContext(),
3444 array(
35 - 'name' => $this->getRequest()->getText( 'newname', '' ),
 45+ 'name' => $this->getRequest()->getText(
 46+ 'newname',
 47+ $newName
 48+ ),
3649 'term' => $this->getRequest()->getText( 'newterm', '' ),
3750 )
3851 );
Index: trunk/extensions/EducationProgram/actions/ViewOrgAction.php
@@ -25,11 +25,8 @@
2626 $org = EPOrg::get( $name );
2727
2828 if ( $org === false ) {
29 - $this->displayNavigation();
30 -
3129 if ( $this->getUser()->isAllowed( 'ep-org' ) ) {
32 - $out->addWikiMsg( 'ep-institution-create', $name );
33 - EPOrg::displayAddNewControl( $this->getContext(), array( 'name' => $name ) );
 30+ $out->redirect( $this->getTitle()->getLocalURL( array( 'action' => 'edit' ) ) );
3431 }
3532 else {
3633 $out->addWikiMsg( 'ep-institution-none', $name );
Index: trunk/extensions/EducationProgram/actions/EPEditAction.php
@@ -45,35 +45,20 @@
4646 protected function showContent() {
4747 $c = $this->getItemClass(); // Yeah, this is needed in PHP 5.3 >_>
4848
49 - if ( $this->isNew() ) {
50 - $data = $this->getNewData();
51 -
52 - $object = $c::selectRow( null, $data );
53 -
54 - if ( $object === false ) {
55 - $object = new $c( $data, true );
56 - }
57 - else {
58 - $this->showWarning( wfMessage( 'educationprogram-' . strtolower( $this->getName() ) . '-exists-already' ) );
59 - }
60 - }
61 - else {
62 - $object = $c::selectRow( null, $this->getTitleConditions() );
63 - }
64 -
 49+ $data = $this->getNewData();
 50+
 51+ $object = $c::selectRow( null, $data );
 52+
6553 if ( $object === false ) {
66 - $this->getOutput()->redirect( SpecialPage::getTitleFor( $c::getListPage() )->getLocalURL() );
 54+ $this->isNew = true;
 55+ $object = new $c( $data, true );
6756 }
6857 else {
69 -// if ( !$this->isNew() ) {
70 -// $this->getOutput()->addHTML(
71 -// SpecialContestPage::getNavigation( $contest->getField( 'name' ), $this->getUser(), $this->getLanguage(), $this->getName() )
72 -// );
73 -// }
74 -
75 - $this->item = $object;
76 - $this->showForm();
 58+ $this->showWarning( wfMessage( 'educationprogram-' . strtolower( $this->getName() ) . '-exists-already' ) );
7759 }
 60+
 61+ $this->item = $object;
 62+ $this->showForm();
7863 }
7964
8065 /**
@@ -84,15 +69,17 @@
8570 * @return boolean
8671 */
8772 protected function isNew() {
88 - static $isNew = null;
89 -
90 - if ( is_null( $isNew ) ) {
91 - $isNew = $this->getRequest()->wasPosted() &&
92 - ( $this->getRequest()->getCheck( 'isnew' ) || $this->getRequest()->getCheck( 'wpisnew' ) );
 73+ if ( is_null( $this->isNew ) ) {
 74+ $isNew = $this->isNewPost();
9375 }
9476
95 - return $isNew;
 77+ return $this->isNew;
9678 }
 79+
 80+ protected function isNewPost() {
 81+ return $this->getRequest()->wasPosted() &&
 82+ ( $this->getRequest()->getCheck( 'isnew' ) || $this->getRequest()->getCheck( 'wpisnew' ) );
 83+ }
9784
9885 /**
9986 * Show the form.
@@ -123,7 +110,16 @@
124111 * @return array
125112 */
126113 protected function getNewData() {
127 - return array( 'name' => $this->getRequest()->getVal( 'newname' ) );
 114+ $data = array();
 115+
 116+ if ( $this->isNewPost() ) {
 117+ $data['name'] = $this->getRequest()->getVal( 'newname' );
 118+ }
 119+ else {
 120+ $data['name'] = $this->getTitle()->getText();
 121+ }
 122+
 123+ return $data;
128124 }
129125
130126 /**
@@ -268,13 +264,13 @@
269265 $this->getOutput()->redirect( $this->getReturnToTitle( true )->getLocalURL() );
270266 }
271267
272 - protected function getReturnToTitle( $newToItem = false ) {
 268+ protected function getReturnToTitle( $addedItem = false ) {
273269 if ( $this->getRequest()->getCheck( 'wpreturnto' ) ) {
274270 return Title::newFromText( $this->getRequest()->getText( 'wpreturnto' ) );
275271 }
276 - elseif ( $newToItem && $this->isNew() ) {
 272+ elseif ( !$addedItem && $this->isNew() ) {
277273 $c = $this->getItemClass(); // Yeah, this is needed in PHP 5.3 >_>
278 - return $c::getTitleFor( $this->getRequest()->getText( 'wpitem-' . $c::getIdentifierField() ) );
 274+ return SpecialPage::getTitleFor( $c::getListPage() );
279275 }
280276 else {
281277 return $this->getTitle();
Index: trunk/extensions/EducationProgram/EducationProgram.hooks.php
@@ -251,11 +251,13 @@
252252 $type = $sktemplate->getRequest()->getText( 'action' );
253253 $isSpecial = $sktemplate->getTitle()->isSpecialPage();
254254
255 - $links['views']['view'] = array(
256 - 'class' => ( !$isSpecial && $type === '' ) ? 'selected' : false,
257 - 'text' => wfMsg( 'ep-tab-view' ),
258 - 'href' => $title->getLocalUrl()
259 - );
 255+ if ( $type !== 'edit' || $exists ) {
 256+ $links['views']['view'] = array(
 257+ 'class' => ( !$isSpecial && $type === '' ) ? 'selected' : false,
 258+ 'text' => wfMsg( 'ep-tab-view' ),
 259+ 'href' => $title->getLocalUrl()
 260+ );
 261+ }
260262
261263 if ( $user->isAllowed( $class::getEditRight() ) ) {
262264 $links['views']['edit'] = array(

Status & tagging log