r114077 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r114076‎ | r114077 | r114078 >
Date:21:52, 17 March 2012
Author:jeroendedauw
Status:deferred (Comments)
Tags:
Comment:
identify students by user name rather then id
Modified paths:
  • /trunk/extensions/EducationProgram/EducationProgram.i18n.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPStudent.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPStudentActivityPager.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPStudentPager.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPUtils.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialStudent.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/specials/SpecialStudent.php
@@ -40,8 +40,13 @@
4141 else {
4242 $this->displayNavigation();
4343
44 - $student = EPStudents::singleton()->selectRow( null, array( 'id' => $this->subPage ) );
 44+ $student = false;
 45+ $user = User::newFromName( $subPage );
4546
 47+ if ( $user !== false && $user->getId() !== 0 ) {
 48+ $student = EPStudents::singleton()->selectRow( null, array( 'user_id' => $user->getId() ) );
 49+ }
 50+
4651 if ( $student === false ) {
4752 $out->addWikiMsg( 'ep-student-none', $this->subPage );
4853 }
Index: trunk/extensions/EducationProgram/includes/EPUtils.php
@@ -108,13 +108,11 @@
109109 public static function getRoleToolLinks( EPIRole $role, IContextSource $context, EPCourse $course = null ) {
110110 $roleName = $role->getRoleName();
111111 $links = array();
112 -
113 - $links[] = Linker::userTalkLink( $role->getUser()->getId(), $role->getUser()->getName() );
114 -
115 - $links[] = Linker::link( SpecialPage::getTitleFor( 'Contributions', $role->getUser()->getName() ), wfMsgHtml( 'contribslink' ) );
116 -
 112+
 113+ $user = $role->getUser();
 114+
117115 if ( !is_null( $course ) &&
118 - ( $context->getUser()->isAllowed( 'ep-' . $roleName ) || $role->getUser()->getId() == $context->getUser()->getId() ) ) {
 116+ ( $context->getUser()->isAllowed( 'ep-' . $roleName ) || $user->getId() == $context->getUser()->getId() ) ) {
119117 $links[] = Html::element(
120118 'a',
121119 array(
@@ -123,8 +121,8 @@
124122 'data-role' => $roleName,
125123 'data-courseid' => $course->getId(),
126124 'data-coursename' => $course->getField( 'name' ),
127 - 'data-userid' => $role->getUser()->getId(),
128 - 'data-username' => $role->getUser()->getName(),
 125+ 'data-userid' => $user->getId(),
 126+ 'data-username' => $user->getName(),
129127 'data-bestname' => $role->getName(),
130128 ),
131129 wfMsg( 'ep-' . $roleName . '-remove' )
@@ -133,9 +131,21 @@
134132 $context->getOutput()->addModules( 'ep.enlist' );
135133 }
136134
137 - return ' <span class="mw-usertoollinks">(' . $context->getLanguage()->pipeList( $links ) . ')</span>';
 135+ return self::getToolLinks( $user->getId(), $user->getName(), $context, $links );
138136 }
139137
 138+ /**
 139+ * Returns tool links for the provided user details plus any adittional links.
 140+ *
 141+ * @since 0.1
 142+ *
 143+ * @param integer $userId
 144+ * @param string $userName
 145+ * @param IContextSource $context
 146+ * @param array $extraLinks
 147+ *
 148+ * @return string
 149+ */
140150 public static function getToolLinks( $userId, $userName, IContextSource $context, array $extraLinks = array() ) {
141151 $links = array();
142152
Index: trunk/extensions/EducationProgram/includes/EPStudentPager.php
@@ -81,16 +81,11 @@
8282 */
8383 protected function getFormattedValue( $name, $value ) {
8484 switch ( $name ) {
85 - case 'id':
86 - $value = Linker::linkKnown(
87 - SpecialPage::getTitleFor( 'Student', $value ),
88 - htmlspecialchars( $this->getLanguage()->formatNum( $value, true ) )
89 - );
90 - break;
9185 case 'user_id':
9286 if ( array_key_exists( $value, $this->userNames ) ) {
9387 list( $userName, $realName ) = $this->userNames[$value];
94 - $value = Linker::userLink( $value, $userName, $realName ) . Linker::userToolLinks( $value, $userName );
 88+ $value = Linker::userLink( $value, $userName, $realName )
 89+ . EPStudent::getViewLinksFor( $this->getContext(), $value, $userName );
9590 }
9691 else {
9792 wfWarn( 'User id not in $this->userNames in ' . __METHOD__ );
@@ -147,6 +142,8 @@
148143 public function getFieldNames() {
149144 $fields = parent::getFieldNames();
150145
 146+ unset( $fields['id'] );
 147+
151148 $fields['_courses_current'] = 'current-courses';
152149
153150 return $fields;
Index: trunk/extensions/EducationProgram/includes/EPStudentActivityPager.php
@@ -99,7 +99,8 @@
100100 case 'user_id':
101101 if ( array_key_exists( $value, $this->userNames ) ) {
102102 list( $userName, $realName ) = $this->userNames[$value];
103 - $value = Linker::userLink( $value, $userName, $realName ) . Linker::userToolLinks( $value, $userName );
 103+ $value = Linker::userLink( $value, $userName, $realName )
 104+ . EPStudent::getViewLinksFor( $this->getContext(), $value, $userName );
104105 }
105106 else {
106107 wfWarn( 'User id not in $this->userNames in ' . __METHOD__ );
Index: trunk/extensions/EducationProgram/includes/EPStudent.php
@@ -92,4 +92,46 @@
9393 $this->getUser()->saveSettings();
9494 }
9595
 96+ /**
 97+ * Returns the view link for the student.
 98+ * These are the user page, contribs and student profile.
 99+ *
 100+ * @since 0.1
 101+ *
 102+ * @param IContextSource $context
 103+ *
 104+ * @return string
 105+ */
 106+ public function getViewLinks( IContextSource $context ) {
 107+ return self::getViewLinksFor(
 108+ $context,
 109+ $this->getUser()->getId(),
 110+ $this->getUser()->getName()
 111+ );
 112+ }
 113+
 114+ /**
 115+ * Returns the view links for the student with provided user id and name.
 116+ * These are the user page, contribs and student profile.
 117+ *
 118+ * @since 0.1
 119+ *
 120+ * @param IContextSource $context
 121+ * @param integer $userId
 122+ * @param string $userName
 123+ *
 124+ * @return string
 125+ */
 126+ public static function getViewLinksFor( IContextSource $context, $userId, $userName ) {
 127+ return EPUtils::getToolLinks(
 128+ $userId,
 129+ $userName,
 130+ $context,
 131+ array( Linker::link(
 132+ SpecialPage::getTitleFor( 'Student', $userName ),
 133+ $context->msg( 'ep-student-view-profile' )->escaped()
 134+ ) )
 135+ );
 136+ }
 137+
96138 }
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php
@@ -28,6 +28,7 @@
2929 'ep-form-summary' => 'Summary:',
3030 'ep-form-minor' => 'This is a minor edit',
3131 'ep-move-error' => 'You are not allowed to move articles in or out of the education namespaces.',
 32+ 'ep-student-view-profile' => 'student profile',
3233
3334 // Tabs
3435 'ep-tab-view' => 'Read',
@@ -582,7 +583,7 @@
583584 'ep-ambassador-title' => 'Ambassador: $1',
584585
585586 // Special:Student
586 - 'ep-student-none' => 'There is no student with id "$1". See [[Special:Students|here]] for a list of students.',
 587+ 'ep-student-none' => 'There is no student with user name "$1". See [[Special:Students|here]] for a list of all students.',
587588 'ep-student-title' => 'Student: $1',
588589 'ep-student-actively-enrolled' => 'Currently enrolled',
589590 'ep-student-no-active-enroll' => 'Not currently enrolled',

Comments

#Comment by Nikerabbit (talk | contribs)   09:00, 19 March 2012

Cannot review without message documentation.

Status & tagging log