r110293 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r110292‎ | r110293 | r110294 >
Date:15:09, 30 January 2012
Author:jeroendedauw
Status:deferred
Tags:educationprogram 
Comment:
work on revision display
Modified paths:
  • /trunk/extensions/EducationProgram/EducationProgram.hooks.php (modified) (history)
  • /trunk/extensions/EducationProgram/EducationProgram.settings.php (modified) (history)
  • /trunk/extensions/EducationProgram/actions/EPEditAction.php (modified) (history)
  • /trunk/extensions/EducationProgram/actions/EPViewAction.php (modified) (history)
  • /trunk/extensions/EducationProgram/actions/ViewCourseAction.php (modified) (history)
  • /trunk/extensions/EducationProgram/actions/ViewOrgAction.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPCourse.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPOrg.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPRevision.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialEPPage.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialOAProfile.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/EducationProgram.settings.php
@@ -29,6 +29,9 @@
3030 protected static function getDefaultSettings() {
3131 return array(
3232 'enableTopLink' => true,
 33+ 'ambassadorPictureDomains' => array(
 34+ 'wikimedia.org'
 35+ ),
3336 );
3437 }
3538
Index: trunk/extensions/EducationProgram/actions/ViewCourseAction.php
@@ -18,56 +18,35 @@
1919 return 'viewcourse';
2020 }
2121
22 - /**
23 - *
24 - *
25 - * @return String HTML
26 - */
27 - public function onView() {
28 - $out = $this->getOutput();
29 -
30 - $name = $this->getTitle()->getText();
31 -
32 - $course = EPCourse::get( $name );
 22+ protected function getItemClass() {
 23+ return 'EPCourse';
 24+ }
3325
34 - if ( $course === false ) {
35 - $this->displayNavigation();
 26+ protected function displayPage( EPDBObject $course ) {
 27+ parent::displayPage( $course );
3628
37 - if ( $this->getUser()->isAllowed( 'ep-course' ) ) {
38 - $out->redirect( $this->getTitle()->getLocalURL( array( 'action' => 'edit' ) ) );
39 - }
40 - else {
41 - $out->addWikiMsg( 'ep-course-none', $name );
42 - }
43 - }
44 - else {
45 - $this->displayNavigation();
 29+ $out = $this->getOutput();
4630
47 - $this->displaySummary( $course );
 31+ $out->addHTML( Html::element( 'h2', array(), wfMsg( 'ep-course-description' ) ) );
4832
49 - $out->addHTML( Html::element( 'h2', array(), wfMsg( 'ep-course-description' ) ) );
 33+ $out->addHTML( $this->getOutput()->parse( $course->getField( 'description' ) ) );
5034
51 - $out->addHTML( $this->getOutput()->parse( $course->getField( 'description' ) ) );
 35+ $studentIds = array_map(
 36+ function( EPStudent $student ) {
 37+ return $student->getId();
 38+ },
 39+ $course->getStudents( 'id' )
 40+ );
5241
53 - $studentIds = array_map(
54 - function( EPStudent $student ) {
55 - return $student->getId();
56 - },
57 - $course->getStudents( 'id' )
58 - );
59 -
60 - if ( count( $studentIds ) > 0 ) {
61 - $out->addHTML( Html::element( 'h2', array(), wfMsg( 'ep-course-students' ) ) );
62 - EPStudent::displayPager( $this->getContext(), array( 'id' => $studentIds ) );
63 - }
64 - else {
65 - // TODO
66 - }
 42+ if ( count( $studentIds ) > 0 ) {
 43+ $out->addHTML( Html::element( 'h2', array(), wfMsg( 'ep-course-students' ) ) );
 44+ EPStudent::displayPager( $this->getContext(), array( 'id' => $studentIds ) );
6745 }
68 -
69 - return '';
 46+ else {
 47+ // TODO
 48+ }
7049 }
71 -
 50+
7251 /**
7352 * Gets the summary data.
7453 *
Index: trunk/extensions/EducationProgram/actions/EPViewAction.php
@@ -19,6 +19,97 @@
2020 }
2121
2222 /**
 23+ * Returns the class name of the EPDBObject this action handles.
 24+ *
 25+ * @since 0.1
 26+ *
 27+ * @return string
 28+ */
 29+ protected abstract function getItemClass();
 30+
 31+ /**
 32+ *
 33+ *
 34+ * @return String HTML
 35+ */
 36+ public function onView() {
 37+ $out = $this->getOutput();
 38+ $name = $this->getTitle()->getText();
 39+ $class = $this->getItemClass();
 40+
 41+ $object = false;
 42+
 43+ if ( $this->getRequest()->getCheck( 'revid' ) ) {
 44+ $currentObject = $class::get( $name, 'id' );
 45+
 46+ if ( $currentObject !== false ) {
 47+ $rev = EPRevision::selectRow( null, array(
 48+ 'id' => $this->getRequest()->getInt( 'revid' ),
 49+ 'object_id' => $currentObject->getField( 'id' )
 50+ ) );
 51+
 52+ if ( $rev === false ) {
 53+ // TODO
 54+ }
 55+ else {
 56+ $object = $rev->getObject();
 57+
 58+ $lang = $this->getLanguage();
 59+
 60+ $current = false; // TODO
 61+ $td = $lang->timeanddate( $rev->getField( 'time' ), true );
 62+ $tddate = $lang->date( $rev->getField( 'time' ), true );
 63+ $tdtime = $lang->time( $rev->getField( 'time' ), true );
 64+
 65+ $userToolLinks = Linker::userLink( $rev->getUser()->getId(), $rev->getUser()->getName() )
 66+ . Linker::userToolLinks( $rev->getUser()->getId(), $rev->getUser()->getName() );
 67+
 68+ $infomsg = $current && !wfMessage( 'revision-info-current' )->isDisabled()
 69+ ? 'revision-info-current'
 70+ : 'revision-info';
 71+
 72+ $out->setSubtitle(
 73+ "<div id=\"mw-{$infomsg}\">" .
 74+ wfMessage( $infomsg, $td )->rawParams( $userToolLinks )->params(
 75+ $rev->getId(),
 76+ $tddate,
 77+ $tdtime,
 78+ $rev->getUser()
 79+ )->parse() .
 80+ "</div>"
 81+ );
 82+ }
 83+ }
 84+ }
 85+
 86+ if ( $object === false ) {
 87+ $object = $class::get( $name );
 88+ }
 89+
 90+ if ( $object === false ) {
 91+ $this->displayNavigation();
 92+
 93+ if ( $this->getUser()->isAllowed( $class::getEditRight() ) ) {
 94+ $out->redirect( $this->getTitle()->getLocalURL( array( 'action' => 'edit' ) ) );
 95+ }
 96+ else {
 97+ $out->addWikiMsg( strtolower( get_called_class() ) . '-none', $name );
 98+ }
 99+ }
 100+ else {
 101+ $this->displayPage( $object );
 102+ }
 103+
 104+ return '';
 105+ }
 106+
 107+ protected function displayPage( EPDBObject $object ) {
 108+ $this->displayNavigation();
 109+
 110+ $this->displaySummary( $object );
 111+ }
 112+
 113+ /**
23114 * Adds a navigation menu with the provided links.
24115 * Links should be provided in an array with:
25116 * label => Title (object)
Index: trunk/extensions/EducationProgram/actions/ViewOrgAction.php
@@ -18,47 +18,26 @@
1919 return 'vieworg';
2020 }
2121
22 - /**
23 - *
24 - *
25 - * @return String HTML
26 - */
27 - public function onView() {
28 - $out = $this->getOutput();
29 -
30 - $name = $this->getTitle()->getText();
31 -
32 - $out->setPageTitle( wfMsgExt( 'ep-institution-title', 'parsemag', $name ) );
 22+ protected function getItemClass() {
 23+ return 'EPOrg';
 24+ }
3325
34 - $org = EPOrg::get( $name );
 26+ protected function displayPage( EPDBObject $org ) {
 27+ parent::displayPage( $org );
3528
36 - if ( $org === false ) {
37 - if ( $this->getUser()->isAllowed( 'ep-org' ) ) {
38 - $out->redirect( $this->getTitle()->getLocalURL( array( 'action' => 'edit' ) ) );
39 - }
40 - else {
41 - $out->addWikiMsg( 'ep-institution-none', $name );
42 - }
43 - }
44 - else {
45 - $this->displayNavigation();
 29+ $out = $this->getOutput();
4630
47 - $this->displaySummary( $org );
 31+ $out->addHTML( Html::element( 'h2', array(), wfMsg( 'ep-institution-courses' ) ) );
4832
49 - $out->addHTML( Html::element( 'h2', array(), wfMsg( 'ep-institution-courses' ) ) );
 33+ EPCourse::displayPager( $this->getContext(), array( 'org_id' => $org->getId() ) );
5034
51 - EPCourse::displayPager( $this->getContext(), array( 'org_id' => $org->getId() ) );
 35+ if ( $this->getUser()->isAllowed( 'ep-course' ) ) {
 36+ $out->addHTML( Html::element( 'h2', array(), wfMsg( 'ep-institution-add-course' ) ) );
5237
53 - if ( $this->getUser()->isAllowed( 'ep-course' ) ) {
54 - $out->addHTML( Html::element( 'h2', array(), wfMsg( 'ep-institution-add-course' ) ) );
55 -
56 - EPCourse::displayAddNewControl( $this->getContext(), array( 'org' => $org->getId() ) );
57 - }
 38+ EPCourse::displayAddNewControl( $this->getContext(), array( 'org' => $org->getId() ) );
5839 }
59 -
60 - return '';
6140 }
62 -
 41+
6342 /**
6443 * Gets the summary data.
6544 *
Index: trunk/extensions/EducationProgram/actions/EPEditAction.php
@@ -166,6 +166,8 @@
167167 else {
168168 $data['name'] = $this->getTitle()->getText();
169169 }
 170+
 171+ $data['name'] = $this->getLanguage()->ucfirst( $data['name'] );
170172
171173 return $data;
172174 }
Index: trunk/extensions/EducationProgram/specials/SpecialOAProfile.php
@@ -11,7 +11,7 @@
1212 * @licence GNU GPL v3 or later
1313 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1414 */
15 -class SpecialOAProfile extends SpecialEPPage {
 15+class SpecialOAProfile extends FormSpecialPage {
1616
1717 /**
1818 * Constructor.
@@ -31,9 +31,67 @@
3232 */
3333 public function execute( $subPage ) {
3434 parent::execute( $subPage );
 35+ }
3536
 37+ /**
 38+ * (non-PHPdoc)
 39+ * @see FormSpecialPage::getFormFields()
 40+ * @return array
 41+ */
 42+ protected function getFormFields() {
 43+ $fields = array();
3644
 45+ $fields['bio'] = array(
 46+ 'type' => 'textarea',
 47+ 'label-message' => 'ep-oa-profile-bio',
 48+ 'required' => true,
 49+ 'validation-callback' => function ( $value, array $alldata = null ) {
 50+ return strlen( $value ) < 10 ? wfMsgExt( 'ep-oa-profile-invalid-bio', 'parsemag', 10 ) : true;
 51+ },
 52+ 'rows' => 10,
 53+ 'id' => 'wpTextbox1',
 54+ );
3755
 56+ $lang = $this->getLanguage();
 57+
 58+ $fields['photo'] = array(
 59+ 'type' => 'text',
 60+ 'label-message' => 'ep-oa-profile-photo',
 61+ 'validation-callback' => function ( $value, array $alldata = null ) use ( $lang ) {
 62+ foreach ( EPSettings::get( 'ambassadorPictureDomains' ) as $domain ) {
 63+ $pattern = '@^https?://(([a-z0-9]+)\.)?' . str_replace( '.', '\.', $domain ) . '/.*$@i';
 64+
 65+ if ( preg_match( $pattern, $value ) ) {
 66+ return true;
 67+ }
 68+ }
 69+
 70+ return wfMsgExt( 'ep-oa-profile-invalid-photo', 'parsemag', $lang->listToText( $domain ) );
 71+ },
 72+ );
 73+
 74+ return $fields;
3875 }
3976
 77+ /**
 78+ * Gets called after the form is saved.
 79+ *
 80+ * @since 0.1
 81+ */
 82+ public function onSuccess() {
 83+ // $this->getOutput()->redirect( $this->getReturnToTitle( true )->getLocalURL() );
 84+ }
 85+
 86+ /**
 87+ * Process the form. At this point we know that the user passes all the criteria in
 88+ * userCanExecute().
 89+ *
 90+ * @param array $data
 91+ *
 92+ * @return Bool|Array
 93+ */
 94+ public function onSubmit( array $data ) {
 95+
 96+ }
 97+
4098 }
\ No newline at end of file
Index: trunk/extensions/EducationProgram/specials/SpecialEPPage.php
@@ -113,7 +113,7 @@
114114
115115 /**
116116 * Get the Language being used for this instance.
117 - * getLang was deprecated in 1.19, getLanguage was introduces in the same version.
 117+ * getLang was deprecated in 1.19, getLanguage was introduced in the same version.
118118 *
119119 * @since 0.1
120120 *
Index: trunk/extensions/EducationProgram/includes/EPOrg.php
@@ -170,6 +170,18 @@
171171 }
172172
173173 /**
 174+ * (non-PHPdoc)
 175+ * @see EPDBObject::writeToDB()
 176+ */
 177+ public function writeToDB() {
 178+ if ( $this->hasField( 'name' ) ) {
 179+ $this->setField( 'name', $GLOBALS['wgLang']->ucfirst( $this->getField( 'name' ) ) );
 180+ }
 181+
 182+ return parent::writeToDB();
 183+ }
 184+
 185+ /**
174186 * Returns a list of orgs in an array that can be fed to select inputs.
175187 *
176188 * @since 0.1
Index: trunk/extensions/EducationProgram/includes/EPRevision.php
@@ -14,6 +14,15 @@
1515 class EPRevision extends EPDBObject {
1616
1717 /**
 18+ * Cached user object for this revision.
 19+ *
 20+ * @since 0.1
 21+ * @var User|false
 22+ */
 23+ protected $user = false;
 24+
 25+
 26+ /**
1827 * @see parent::__construct
1928 *
2029 * @since 0.1
@@ -76,5 +85,61 @@
7786 return new static( $fields );
7887 }
7988
 89+ /**
 90+ * Return the object as it was at this revision.
 91+ *
 92+ * @since 0,1
 93+ *
 94+ * @return EPDBObject
 95+ */
 96+ public function getObject() {
 97+ $class = $this->getField( 'type' );
 98+ return $class::newFromArray( $this->getField( 'data' ) );
 99+ }
80100
 101+ /**
 102+ * Returns the the object stored in the revision with the provided id,
 103+ * or false if there is no matching object.
 104+ *
 105+ * @since 0.1
 106+ *
 107+ * @param integer $revId
 108+ * @param integer|null $objectId
 109+ *
 110+ * @return EPDBObject|false
 111+ */
 112+ public static function getObjectFromRevId( $revId, $objectId = null ) {
 113+ $conditions = array(
 114+ 'id' => $revId
 115+ );
 116+
 117+ if ( !is_null( $objectId ) ) {
 118+ $conditions['object_id'] = $objectId;
 119+ }
 120+
 121+ $rev = EPRevision::selectRow( array( 'type', 'data' ), $conditions );
 122+
 123+ if ( $rev === false ) {
 124+ return false;
 125+ }
 126+ else {
 127+ return $rev->getDataObject();
 128+ }
 129+ }
 130+
 131+ /**
 132+ * Returns the user that authored this revision.
 133+ *
 134+ * @since 0.1
 135+ *
 136+ * @return User
 137+ */
 138+ public function getUser() {
 139+ if ( $this->user === false ) {
 140+ $this->user = User::newFromId( $this->loadAndGetField( 'user_id' ) );
 141+ }
 142+
 143+ return $this->user;
 144+ }
 145+
81146 }
Index: trunk/extensions/EducationProgram/includes/EPCourse.php
@@ -270,6 +270,18 @@
271271 }
272272
273273 /**
 274+ * (non-PHPdoc)
 275+ * @see EPDBObject::writeToDB()
 276+ */
 277+ public function writeToDB() {
 278+ if ( $this->hasField( 'name' ) ) {
 279+ $this->setField( 'name', $GLOBALS['wgLang']->ucfirst( $this->getField( 'name' ) ) );
 280+ }
 281+
 282+ return parent::writeToDB();
 283+ }
 284+
 285+ /**
274286 * Returns the org associated with this term.
275287 *
276288 * @since 0.1
Index: trunk/extensions/EducationProgram/EducationProgram.hooks.php
@@ -253,7 +253,7 @@
254254 if ( array_key_exists( $title->getNamespace(), $classes ) ) {
255255 $links['views'] = array();
256256 $links['actions'] = array();
257 -
 257+
258258 $user = $sktemplate->getUser();
259259 $class = $classes[$title->getNamespace()];
260260 $exists = $class::hasIdentifier( $title->getText() );

Status & tagging log