r90533 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r90532‎ | r90533 | r90534 >
Date:16:39, 21 June 2011
Author:zhenya
Status:deferred (Comments)
Tags:
Comment:
Class
Modified paths:
  • /trunk/extensions/SocialProfile/UserStatus/UserStatusClass.php (added) (history)

Diff [purge]

Index: trunk/extensions/SocialProfile/UserStatus/UserStatusClass.php
@@ -0,0 +1,104 @@
 2+<?php
 3+
 4+class UserStatusClass {
 5+
 6+ /* private */ function __construct($u_id) {
 7+ global $wgOut, $wgScriptPath;
 8+ $wgOut->addScriptFile($wgScriptPath.'/extensions/SocialProfile/UserStatus/UserStatus.js' ); //Does not work
 9+ }
 10+
 11+ public function getStatus($u_id) {
 12+ $dbr = wfGetDB(DB_SLAVE);
 13+ $res = $dbr->select('user_status', '*', array('us_user_id' => $u_id), __METHOD__);
 14+ $message = array();
 15+ if (empty($res)) {
 16+ $message = '';
 17+ } else {
 18+ foreach ($res as $row) {
 19+ $message = array(
 20+ 'us_user_id' => $row->us_user_id,
 21+ 'us_status' => htmlspecialchars($row->us_status),
 22+ );
 23+ }
 24+ }
 25+ return $message;
 26+ }
 27+
 28+ /*
 29+ *
 30+ */
 31+
 32+ public function setStatus($u_id, $message) {
 33+ if (mb_strlen($message) > 140) { // change
 34+ //ERROR. Message lenth is too long
 35+ return;
 36+ }
 37+ $dbw = wfGetDB(DB_MASTER);
 38+ $res = $dbw->select('user_status', '*', array('us_user_id' => $u_id), __METHOD__);
 39+ $i = 0;
 40+ foreach ($res as $row)
 41+ $i++;
 42+ if ($i == 0) {
 43+ $dbw->insert(
 44+ 'user_status',
 45+ /* SET */ array(
 46+ 'us_user_id' => $u_id,
 47+ 'us_status' => $message,), __METHOD__
 48+ );
 49+ } else {
 50+ $dbw->update(
 51+ 'user_status',
 52+ /* SET */ array('us_status' => $message),
 53+ /* WHERE */ array('us_user_id' => $u_id), __METHOD__
 54+ );
 55+ }
 56+ $this->useStatusHistory('insert',$u_id);
 57+ return;
 58+ }
 59+
 60+ /*
 61+ * Method that manipulates the user_status_history table
 62+ * $mode - varieble for realization of two methods.
 63+ * Variants:
 64+ * 'insert'
 65+ * 'select'
 66+ */
 67+ public function useStatusHistory($mode,$u_id) {
 68+ $dbw = wfGetDB(DB_MASTER);
 69+ $userHistory = $dbw->select('user_status_history', '*', array('ush_user_id' => $u_id), __METHOD__, array('ORDER BY' => 'ush_timestamp ASC'));
 70+ $i = 0;
 71+ $history = array();
 72+ foreach ($userHistory as $row) {
 73+ $i++;
 74+ $history[] = array(
 75+ 'ush_id' => $row->ush_id,
 76+ 'ush_user_id' => $row->ush_user_id,
 77+ 'ush_timestamp' => $row->ush_timestamp,
 78+ 'ush_status' => $row->ush_status,
 79+ );
 80+ }
 81+ if ($mode=='select') return $history;
 82+ if ($mode=='insert'){
 83+ $currentStuts = $this->getStatus($u_id);
 84+
 85+ if ($i < 4) {
 86+ $dbw->insert(
 87+ 'user_status_history',
 88+ /* SET */ array(
 89+ 'ush_user_id' => $u_id,
 90+ 'ush_status' => $currentStuts['us_status']), __METHOD__
 91+ );
 92+ } else {
 93+ $dbw->update(
 94+ 'user_status_history',
 95+ /* SET */ array('ush_status' => $currentStuts['us_status']),
 96+ /*WHERE*/ array('ush_user_id' => $u_id,
 97+ 'ush_timestamp' => $history[0]['ush_timestamp']),
 98+ __METHOD__);
 99+ }
 100+ return;
 101+ }
 102+ }
 103+}
 104+
 105+?>
\ No newline at end of file
Property changes on: trunk/extensions/SocialProfile/UserStatus/UserStatusClass.php
___________________________________________________________________
Added: svn:eol-style
1106 + native

Comments

#Comment by Nikerabbit (talk | contribs)   17:55, 21 June 2011

We don't end PHP files with ?> anymore.

Status & tagging log