https://www.mediawiki.org/wiki/Special:Code/MediaWiki/114077
Revision: 114077
Author: jeroendedauw
Date: 2012-03-17 21:52:55 +0000 (Sat, 17 Mar 2012)
Log Message:
-----------
identify students by user name rather then id
Modified Paths:
--------------
trunk/extensions/EducationProgram/EducationProgram.i18n.php
trunk/extensions/EducationProgram/includes/EPStudent.php
trunk/extensions/EducationProgram/includes/EPStudentActivityPager.php
trunk/extensions/EducationProgram/includes/EPStudentPager.php
trunk/extensions/EducationProgram/includes/EPUtils.php
trunk/extensions/EducationProgram/specials/SpecialStudent.php
Modified: trunk/extensions/EducationProgram/EducationProgram.i18n.php
===================================================================
--- trunk/extensions/EducationProgram/EducationProgram.i18n.php 2012-03-17
21:51:12 UTC (rev 114076)
+++ trunk/extensions/EducationProgram/EducationProgram.i18n.php 2012-03-17
21:52:55 UTC (rev 114077)
@@ -28,6 +28,7 @@
'ep-form-summary' => 'Summary:',
'ep-form-minor' => 'This is a minor edit',
'ep-move-error' => 'You are not allowed to move articles in or out of
the education namespaces.',
+ 'ep-student-view-profile' => 'student profile',
// Tabs
'ep-tab-view' => 'Read',
@@ -582,7 +583,7 @@
'ep-ambassador-title' => 'Ambassador: $1',
// Special:Student
- 'ep-student-none' => 'There is no student with id "$1". See
[[Special:Students|here]] for a list of students.',
+ 'ep-student-none' => 'There is no student with user name "$1". See
[[Special:Students|here]] for a list of all students.',
'ep-student-title' => 'Student: $1',
'ep-student-actively-enrolled' => 'Currently enrolled',
'ep-student-no-active-enroll' => 'Not currently enrolled',
Modified: trunk/extensions/EducationProgram/includes/EPStudent.php
===================================================================
--- trunk/extensions/EducationProgram/includes/EPStudent.php 2012-03-17
21:51:12 UTC (rev 114076)
+++ trunk/extensions/EducationProgram/includes/EPStudent.php 2012-03-17
21:52:55 UTC (rev 114077)
@@ -92,4 +92,46 @@
$this->getUser()->saveSettings();
}
+ /**
+ * Returns the view link for the student.
+ * These are the user page, contribs and student profile.
+ *
+ * @since 0.1
+ *
+ * @param IContextSource $context
+ *
+ * @return string
+ */
+ public function getViewLinks( IContextSource $context ) {
+ return self::getViewLinksFor(
+ $context,
+ $this->getUser()->getId(),
+ $this->getUser()->getName()
+ );
+ }
+
+ /**
+ * Returns the view links for the student with provided user id and
name.
+ * These are the user page, contribs and student profile.
+ *
+ * @since 0.1
+ *
+ * @param IContextSource $context
+ * @param integer $userId
+ * @param string $userName
+ *
+ * @return string
+ */
+ public static function getViewLinksFor( IContextSource $context,
$userId, $userName ) {
+ return EPUtils::getToolLinks(
+ $userId,
+ $userName,
+ $context,
+ array( Linker::link(
+ SpecialPage::getTitleFor( 'Student', $userName
),
+ $context->msg( 'ep-student-view-profile'
)->escaped()
+ ) )
+ );
+ }
+
}
Modified: trunk/extensions/EducationProgram/includes/EPStudentActivityPager.php
===================================================================
--- trunk/extensions/EducationProgram/includes/EPStudentActivityPager.php
2012-03-17 21:51:12 UTC (rev 114076)
+++ trunk/extensions/EducationProgram/includes/EPStudentActivityPager.php
2012-03-17 21:52:55 UTC (rev 114077)
@@ -99,7 +99,8 @@
case 'user_id':
if ( array_key_exists( $value, $this->userNames
) ) {
list( $userName, $realName ) =
$this->userNames[$value];
- $value = Linker::userLink( $value,
$userName, $realName ) . Linker::userToolLinks( $value, $userName );
+ $value = Linker::userLink( $value,
$userName, $realName )
+ . EPStudent::getViewLinksFor(
$this->getContext(), $value, $userName );
}
else {
wfWarn( 'User id not in
$this->userNames in ' . __METHOD__ );
Modified: trunk/extensions/EducationProgram/includes/EPStudentPager.php
===================================================================
--- trunk/extensions/EducationProgram/includes/EPStudentPager.php
2012-03-17 21:51:12 UTC (rev 114076)
+++ trunk/extensions/EducationProgram/includes/EPStudentPager.php
2012-03-17 21:52:55 UTC (rev 114077)
@@ -81,16 +81,11 @@
*/
protected function getFormattedValue( $name, $value ) {
switch ( $name ) {
- case 'id':
- $value = Linker::linkKnown(
- SpecialPage::getTitleFor( 'Student',
$value ),
- htmlspecialchars(
$this->getLanguage()->formatNum( $value, true ) )
- );
- break;
case 'user_id':
if ( array_key_exists( $value, $this->userNames
) ) {
list( $userName, $realName ) =
$this->userNames[$value];
- $value = Linker::userLink( $value,
$userName, $realName ) . Linker::userToolLinks( $value, $userName );
+ $value = Linker::userLink( $value,
$userName, $realName )
+ . EPStudent::getViewLinksFor(
$this->getContext(), $value, $userName );
}
else {
wfWarn( 'User id not in
$this->userNames in ' . __METHOD__ );
@@ -147,6 +142,8 @@
public function getFieldNames() {
$fields = parent::getFieldNames();
+ unset( $fields['id'] );
+
$fields['_courses_current'] = 'current-courses';
return $fields;
Modified: trunk/extensions/EducationProgram/includes/EPUtils.php
===================================================================
--- trunk/extensions/EducationProgram/includes/EPUtils.php 2012-03-17
21:51:12 UTC (rev 114076)
+++ trunk/extensions/EducationProgram/includes/EPUtils.php 2012-03-17
21:52:55 UTC (rev 114077)
@@ -108,13 +108,11 @@
public static function getRoleToolLinks( EPIRole $role, IContextSource
$context, EPCourse $course = null ) {
$roleName = $role->getRoleName();
$links = array();
-
- $links[] = Linker::userTalkLink( $role->getUser()->getId(),
$role->getUser()->getName() );
-
- $links[] = Linker::link( SpecialPage::getTitleFor(
'Contributions', $role->getUser()->getName() ), wfMsgHtml( 'contribslink' ) );
-
+
+ $user = $role->getUser();
+
if ( !is_null( $course ) &&
- ( $context->getUser()->isAllowed( 'ep-' . $roleName )
|| $role->getUser()->getId() == $context->getUser()->getId() ) ) {
+ ( $context->getUser()->isAllowed( 'ep-' . $roleName )
|| $user->getId() == $context->getUser()->getId() ) ) {
$links[] = Html::element(
'a',
array(
@@ -123,8 +121,8 @@
'data-role' => $roleName,
'data-courseid' => $course->getId(),
'data-coursename' => $course->getField(
'name' ),
- 'data-userid' =>
$role->getUser()->getId(),
- 'data-username' =>
$role->getUser()->getName(),
+ 'data-userid' => $user->getId(),
+ 'data-username' => $user->getName(),
'data-bestname' => $role->getName(),
),
wfMsg( 'ep-' . $roleName . '-remove' )
@@ -133,9 +131,21 @@
$context->getOutput()->addModules( 'ep.enlist' );
}
- return ' <span class="mw-usertoollinks">(' .
$context->getLanguage()->pipeList( $links ) . ')</span>';
+ return self::getToolLinks( $user->getId(), $user->getName(),
$context, $links );
}
+ /**
+ * Returns tool links for the provided user details plus any adittional
links.
+ *
+ * @since 0.1
+ *
+ * @param integer $userId
+ * @param string $userName
+ * @param IContextSource $context
+ * @param array $extraLinks
+ *
+ * @return string
+ */
public static function getToolLinks( $userId, $userName, IContextSource
$context, array $extraLinks = array() ) {
$links = array();
Modified: trunk/extensions/EducationProgram/specials/SpecialStudent.php
===================================================================
--- trunk/extensions/EducationProgram/specials/SpecialStudent.php
2012-03-17 21:51:12 UTC (rev 114076)
+++ trunk/extensions/EducationProgram/specials/SpecialStudent.php
2012-03-17 21:52:55 UTC (rev 114077)
@@ -40,8 +40,13 @@
else {
$this->displayNavigation();
- $student = EPStudents::singleton()->selectRow( null,
array( 'id' => $this->subPage ) );
+ $student = false;
+ $user = User::newFromName( $subPage );
+ if ( $user !== false && $user->getId() !== 0 ) {
+ $student = EPStudents::singleton()->selectRow(
null, array( 'user_id' => $user->getId() ) );
+ }
+
if ( $student === false ) {
$out->addWikiMsg( 'ep-student-none',
$this->subPage );
}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs