RecentChange.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  1. <?php
  2. /**
  3. * Utility class for creating new RC entries
  4. * mAttribs:
  5. * rc_id id of the row in the recentchanges table
  6. * rc_timestamp time the entry was made
  7. * rc_cur_time timestamp on the cur row
  8. * rc_namespace namespace #
  9. * rc_title non-prefixed db key
  10. * rc_type is new entry, used to determine whether updating is necessary
  11. * rc_minor is minor
  12. * rc_cur_id page_id of associated page entry
  13. * rc_user user id who made the entry
  14. * rc_user_text user name who made the entry
  15. * rc_comment edit summary
  16. * rc_this_oldid rev_id associated with this entry (or zero)
  17. * rc_last_oldid rev_id associated with the entry before this one (or zero)
  18. * rc_bot is bot, hidden
  19. * rc_ip IP address of the user in dotted quad notation
  20. * rc_new obsolete, use rc_type==RC_NEW
  21. * rc_patrolled boolean whether or not someone has marked this edit as patrolled
  22. * rc_old_len integer byte length of the text before the edit
  23. * rc_new_len the same after the edit
  24. * rc_deleted partial deletion
  25. * rc_logid the log_id value for this log entry (or zero)
  26. * rc_log_type the log type (or null)
  27. * rc_log_action the log action (or null)
  28. * rc_params log params
  29. *
  30. * mExtra:
  31. * prefixedDBkey prefixed db key, used by external app via msg queue
  32. * lastTimestamp timestamp of previous entry, used in WHERE clause during update
  33. * lang the interwiki prefix, automatically set in save()
  34. * oldSize text size before the change
  35. * newSize text size after the change
  36. *
  37. * temporary: not stored in the database
  38. * notificationtimestamp
  39. * numberofWatchingusers
  40. *
  41. * @todo document functions and variables
  42. */
  43. class RecentChange
  44. {
  45. var $mAttribs = array(), $mExtra = array();
  46. var $mTitle = false, $mMovedToTitle = false;
  47. var $numberofWatchingusers = 0 ; # Dummy to prevent error message in SpecialRecentchangeslinked
  48. # Factory methods
  49. public static function newFromRow( $row ) {
  50. $rc = new RecentChange;
  51. $rc->loadFromRow( $row );
  52. return $rc;
  53. }
  54. public static function newFromCurRow( $row ) {
  55. $rc = new RecentChange;
  56. $rc->loadFromCurRow( $row );
  57. $rc->notificationtimestamp = false;
  58. $rc->numberofWatchingusers = false;
  59. return $rc;
  60. }
  61. /**
  62. * Obtain the recent change with a given rc_id value
  63. *
  64. * @param $rcid rc_id value to retrieve
  65. * @return RecentChange
  66. */
  67. public static function newFromId( $rcid ) {
  68. $dbr = wfGetDB( DB_SLAVE );
  69. $res = $dbr->select( 'recentchanges', '*', array( 'rc_id' => $rcid ), __METHOD__ );
  70. if( $res && $dbr->numRows( $res ) > 0 ) {
  71. $row = $dbr->fetchObject( $res );
  72. $dbr->freeResult( $res );
  73. return self::newFromRow( $row );
  74. } else {
  75. return NULL;
  76. }
  77. }
  78. /**
  79. * Find the first recent change matching some specific conditions
  80. *
  81. * @param array $conds Array of conditions
  82. * @param mixed $fname Override the method name in profiling/logs
  83. * @return RecentChange
  84. */
  85. public static function newFromConds( $conds, $fname = false ) {
  86. if( $fname === false )
  87. $fname = __METHOD__;
  88. $dbr = wfGetDB( DB_SLAVE );
  89. $res = $dbr->select(
  90. 'recentchanges',
  91. '*',
  92. $conds,
  93. $fname
  94. );
  95. if( $res instanceof ResultWrapper && $res->numRows() > 0 ) {
  96. $row = $res->fetchObject();
  97. $res->free();
  98. return self::newFromRow( $row );
  99. }
  100. return null;
  101. }
  102. # Accessors
  103. public function setAttribs( $attribs ) {
  104. $this->mAttribs = $attribs;
  105. }
  106. public function setExtra( $extra ) {
  107. $this->mExtra = $extra;
  108. }
  109. public function &getTitle() {
  110. if( $this->mTitle === false ) {
  111. $this->mTitle = Title::makeTitle( $this->mAttribs['rc_namespace'], $this->mAttribs['rc_title'] );
  112. }
  113. return $this->mTitle;
  114. }
  115. public function getMovedToTitle() {
  116. if( $this->mMovedToTitle === false ) {
  117. $this->mMovedToTitle = Title::makeTitle( $this->mAttribs['rc_moved_to_ns'],
  118. $this->mAttribs['rc_moved_to_title'] );
  119. }
  120. return $this->mMovedToTitle;
  121. }
  122. # Writes the data in this object to the database
  123. public function save() {
  124. global $wgLocalInterwiki, $wgPutIPinRC, $wgRC2UDPAddress, $wgRC2UDPOmitBots;
  125. $fname = 'RecentChange::save';
  126. $dbw = wfGetDB( DB_MASTER );
  127. if( !is_array($this->mExtra) ) {
  128. $this->mExtra = array();
  129. }
  130. $this->mExtra['lang'] = $wgLocalInterwiki;
  131. if( !$wgPutIPinRC ) {
  132. $this->mAttribs['rc_ip'] = '';
  133. }
  134. # If our database is strict about IP addresses, use NULL instead of an empty string
  135. if( $dbw->strictIPs() and $this->mAttribs['rc_ip'] == '' ) {
  136. unset( $this->mAttribs['rc_ip'] );
  137. }
  138. # Fixup database timestamps
  139. $this->mAttribs['rc_timestamp'] = $dbw->timestamp($this->mAttribs['rc_timestamp']);
  140. $this->mAttribs['rc_cur_time'] = $dbw->timestamp($this->mAttribs['rc_cur_time']);
  141. $this->mAttribs['rc_id'] = $dbw->nextSequenceValue( 'rc_rc_id_seq' );
  142. ## If we are using foreign keys, an entry of 0 for the page_id will fail, so use NULL
  143. if( $dbw->cascadingDeletes() and $this->mAttribs['rc_cur_id']==0 ) {
  144. unset ( $this->mAttribs['rc_cur_id'] );
  145. }
  146. # Insert new row
  147. $dbw->insert( 'recentchanges', $this->mAttribs, $fname );
  148. # Set the ID
  149. $this->mAttribs['rc_id'] = $dbw->insertId();
  150. # Notify extensions
  151. wfRunHooks( 'RecentChange_save', array( &$this ) );
  152. # Notify external application via UDP
  153. if( $wgRC2UDPAddress && ( !$this->mAttribs['rc_bot'] || !$wgRC2UDPOmitBots ) ) {
  154. self::sendToUDP( $this->getIRCLine() );
  155. }
  156. # E-mail notifications
  157. global $wgUseEnotif, $wgShowUpdatedMarker, $wgUser;
  158. if( $wgUseEnotif || $wgShowUpdatedMarker ) {
  159. // Users
  160. if( $this->mAttribs['rc_user'] ) {
  161. $editor = ($wgUser->getId() == $this->mAttribs['rc_user']) ?
  162. $wgUser : User::newFromID( $this->mAttribs['rc_user'] );
  163. // Anons
  164. } else {
  165. $editor = ($wgUser->getName() == $this->mAttribs['rc_user_text']) ?
  166. $wgUser : User::newFromName( $this->mAttribs['rc_user_text'], false );
  167. }
  168. # FIXME: this would be better as an extension hook
  169. $enotif = new EmailNotification();
  170. $title = Title::makeTitle( $this->mAttribs['rc_namespace'], $this->mAttribs['rc_title'] );
  171. $enotif->notifyOnPageChange( $editor, $title,
  172. $this->mAttribs['rc_timestamp'],
  173. $this->mAttribs['rc_comment'],
  174. $this->mAttribs['rc_minor'],
  175. $this->mAttribs['rc_last_oldid'] );
  176. }
  177. }
  178. public function notifyRC2UDP() {
  179. global $wgRC2UDPAddress, $wgRC2UDPOmitBots;
  180. # Notify external application via UDP
  181. if( $wgRC2UDPAddress && ( !$this->mAttribs['rc_bot'] || !$wgRC2UDPOmitBots ) ) {
  182. self::sendToUDP( $this->getIRCLine() );
  183. }
  184. }
  185. /**
  186. * Send some text to UDP
  187. * @param string $line
  188. * @param string $prefix
  189. * @param string $address
  190. * @return bool success
  191. */
  192. public static function sendToUDP( $line, $address = '', $prefix = '' ) {
  193. global $wgRC2UDPAddress, $wgRC2UDPPrefix, $wgRC2UDPPort;
  194. # Assume default for standard RC case
  195. $address = $address ? $address : $wgRC2UDPAddress;
  196. $prefix = $prefix ? $prefix : $wgRC2UDPPrefix;
  197. # Notify external application via UDP
  198. if( $address ) {
  199. $conn = socket_create( AF_INET, SOCK_DGRAM, SOL_UDP );
  200. if( $conn ) {
  201. $line = $prefix . $line;
  202. wfDebug( __METHOD__ . ": sending UDP line: $line\n" );
  203. socket_sendto( $conn, $line, strlen($line), 0, $address, $wgRC2UDPPort );
  204. socket_close( $conn );
  205. return true;
  206. } else {
  207. wfDebug( __METHOD__ . ": failed to create UDP socket\n" );
  208. }
  209. }
  210. return false;
  211. }
  212. /**
  213. * Remove newlines, carriage returns and decode html entites
  214. * @param string $line
  215. * @return string
  216. */
  217. public static function cleanupForIRC( $text ) {
  218. return Sanitizer::decodeCharReferences( str_replace( array( "\n", "\r" ), array( "", "" ), $text ) );
  219. }
  220. /**
  221. * Mark a given change as patrolled
  222. *
  223. * @param mixed $change RecentChange or corresponding rc_id
  224. * @param bool $auto for automatic patrol
  225. * @return See doMarkPatrolled(), or null if $change is not an existing rc_id
  226. */
  227. public static function markPatrolled( $change, $auto = false ) {
  228. $change = $change instanceof RecentChange
  229. ? $change
  230. : RecentChange::newFromId($change);
  231. if( !$change instanceof RecentChange ) {
  232. return null;
  233. }
  234. return $change->doMarkPatrolled( $auto );
  235. }
  236. /**
  237. * Mark this RecentChange as patrolled
  238. *
  239. * NOTE: Can also return 'rcpatroldisabled', 'hookaborted' and 'markedaspatrollederror-noautopatrol' as errors
  240. * @param bool $auto for automatic patrol
  241. * @return array of permissions errors, see Title::getUserPermissionsErrors()
  242. */
  243. public function doMarkPatrolled( $auto = false ) {
  244. global $wgUser, $wgUseRCPatrol, $wgUseNPPatrol;
  245. $errors = array();
  246. // If recentchanges patrol is disabled, only new pages
  247. // can be patrolled
  248. if( !$wgUseRCPatrol && ( !$wgUseNPPatrol || $this->getAttribute('rc_type') != RC_NEW ) ) {
  249. $errors[] = array('rcpatroldisabled');
  250. }
  251. // Automatic patrol needs "autopatrol", ordinary patrol needs "patrol"
  252. $right = $auto ? 'autopatrol' : 'patrol';
  253. $errors = array_merge( $errors, $this->getTitle()->getUserPermissionsErrors( $right, $wgUser ) );
  254. if( !wfRunHooks('MarkPatrolled', array($this->getAttribute('rc_id'), &$wgUser, false)) ) {
  255. $errors[] = array('hookaborted');
  256. }
  257. // Users without the 'autopatrol' right can't patrol their
  258. // own revisions
  259. if( $wgUser->getName() == $this->getAttribute('rc_user_text') && !$wgUser->isAllowed('autopatrol') ) {
  260. $errors[] = array('markedaspatrollederror-noautopatrol');
  261. }
  262. if( $errors ) {
  263. return $errors;
  264. }
  265. // If the change was patrolled already, do nothing
  266. if( $this->getAttribute('rc_patrolled') ) {
  267. return array();
  268. }
  269. // Actually set the 'patrolled' flag in RC
  270. $this->reallyMarkPatrolled();
  271. // Log this patrol event
  272. PatrolLog::record( $this, $auto );
  273. wfRunHooks( 'MarkPatrolledComplete', array($this->getAttribute('rc_id'), &$wgUser, false) );
  274. return array();
  275. }
  276. /**
  277. * Mark this RecentChange patrolled, without error checking
  278. * @return int Number of affected rows
  279. */
  280. public function reallyMarkPatrolled() {
  281. $dbw = wfGetDB( DB_MASTER );
  282. $dbw->update(
  283. 'recentchanges',
  284. array(
  285. 'rc_patrolled' => 1
  286. ),
  287. array(
  288. 'rc_id' => $this->getAttribute('rc_id')
  289. ),
  290. __METHOD__
  291. );
  292. return $dbw->affectedRows();
  293. }
  294. # Makes an entry in the database corresponding to an edit
  295. public static function notifyEdit( $timestamp, &$title, $minor, &$user, $comment, $oldId,
  296. $lastTimestamp, $bot, $ip='', $oldSize=0, $newSize=0, $newId=0, $patrol=0 )
  297. {
  298. if( !$ip ) {
  299. $ip = wfGetIP();
  300. if( !$ip ) $ip = '';
  301. }
  302. $rc = new RecentChange;
  303. $rc->mAttribs = array(
  304. 'rc_timestamp' => $timestamp,
  305. 'rc_cur_time' => $timestamp,
  306. 'rc_namespace' => $title->getNamespace(),
  307. 'rc_title' => $title->getDBkey(),
  308. 'rc_type' => RC_EDIT,
  309. 'rc_minor' => $minor ? 1 : 0,
  310. 'rc_cur_id' => $title->getArticleID(),
  311. 'rc_user' => $user->getId(),
  312. 'rc_user_text' => $user->getName(),
  313. 'rc_comment' => $comment,
  314. 'rc_this_oldid' => $newId,
  315. 'rc_last_oldid' => $oldId,
  316. 'rc_bot' => $bot ? 1 : 0,
  317. 'rc_moved_to_ns' => 0,
  318. 'rc_moved_to_title' => '',
  319. 'rc_ip' => $ip,
  320. 'rc_patrolled' => intval($patrol),
  321. 'rc_new' => 0, # obsolete
  322. 'rc_old_len' => $oldSize,
  323. 'rc_new_len' => $newSize,
  324. 'rc_deleted' => 0,
  325. 'rc_logid' => 0,
  326. 'rc_log_type' => null,
  327. 'rc_log_action' => '',
  328. 'rc_params' => ''
  329. );
  330. $rc->mExtra = array(
  331. 'prefixedDBkey' => $title->getPrefixedDBkey(),
  332. 'lastTimestamp' => $lastTimestamp,
  333. 'oldSize' => $oldSize,
  334. 'newSize' => $newSize,
  335. );
  336. $rc->save();
  337. return $rc;
  338. }
  339. /**
  340. * Makes an entry in the database corresponding to page creation
  341. * Note: the title object must be loaded with the new id using resetArticleID()
  342. * @todo Document parameters and return
  343. */
  344. public static function notifyNew( $timestamp, &$title, $minor, &$user, $comment, $bot,
  345. $ip='', $size=0, $newId=0, $patrol=0 )
  346. {
  347. if( !$ip ) {
  348. $ip = wfGetIP();
  349. if( !$ip ) $ip = '';
  350. }
  351. $rc = new RecentChange;
  352. $rc->mAttribs = array(
  353. 'rc_timestamp' => $timestamp,
  354. 'rc_cur_time' => $timestamp,
  355. 'rc_namespace' => $title->getNamespace(),
  356. 'rc_title' => $title->getDBkey(),
  357. 'rc_type' => RC_NEW,
  358. 'rc_minor' => $minor ? 1 : 0,
  359. 'rc_cur_id' => $title->getArticleID(),
  360. 'rc_user' => $user->getId(),
  361. 'rc_user_text' => $user->getName(),
  362. 'rc_comment' => $comment,
  363. 'rc_this_oldid' => $newId,
  364. 'rc_last_oldid' => 0,
  365. 'rc_bot' => $bot ? 1 : 0,
  366. 'rc_moved_to_ns' => 0,
  367. 'rc_moved_to_title' => '',
  368. 'rc_ip' => $ip,
  369. 'rc_patrolled' => intval($patrol),
  370. 'rc_new' => 1, # obsolete
  371. 'rc_old_len' => 0,
  372. 'rc_new_len' => $size,
  373. 'rc_deleted' => 0,
  374. 'rc_logid' => 0,
  375. 'rc_log_type' => null,
  376. 'rc_log_action' => '',
  377. 'rc_params' => ''
  378. );
  379. $rc->mExtra = array(
  380. 'prefixedDBkey' => $title->getPrefixedDBkey(),
  381. 'lastTimestamp' => 0,
  382. 'oldSize' => 0,
  383. 'newSize' => $size
  384. );
  385. $rc->save();
  386. return $rc;
  387. }
  388. # Makes an entry in the database corresponding to a rename
  389. public static function notifyMove( $timestamp, &$oldTitle, &$newTitle, &$user, $comment, $ip='', $overRedir = false )
  390. {
  391. global $wgRequest;
  392. if( !$ip ) {
  393. $ip = wfGetIP();
  394. if( !$ip ) $ip = '';
  395. }
  396. $rc = new RecentChange;
  397. $rc->mAttribs = array(
  398. 'rc_timestamp' => $timestamp,
  399. 'rc_cur_time' => $timestamp,
  400. 'rc_namespace' => $oldTitle->getNamespace(),
  401. 'rc_title' => $oldTitle->getDBkey(),
  402. 'rc_type' => $overRedir ? RC_MOVE_OVER_REDIRECT : RC_MOVE,
  403. 'rc_minor' => 0,
  404. 'rc_cur_id' => $oldTitle->getArticleID(),
  405. 'rc_user' => $user->getId(),
  406. 'rc_user_text' => $user->getName(),
  407. 'rc_comment' => $comment,
  408. 'rc_this_oldid' => 0,
  409. 'rc_last_oldid' => 0,
  410. 'rc_bot' => $user->isAllowed( 'bot' ) ? $wgRequest->getBool( 'bot' , true ) : 0,
  411. 'rc_moved_to_ns' => $newTitle->getNamespace(),
  412. 'rc_moved_to_title' => $newTitle->getDBkey(),
  413. 'rc_ip' => $ip,
  414. 'rc_new' => 0, # obsolete
  415. 'rc_patrolled' => 1,
  416. 'rc_old_len' => NULL,
  417. 'rc_new_len' => NULL,
  418. 'rc_deleted' => 0,
  419. 'rc_logid' => 0, # notifyMove not used anymore
  420. 'rc_log_type' => null,
  421. 'rc_log_action' => '',
  422. 'rc_params' => ''
  423. );
  424. $rc->mExtra = array(
  425. 'prefixedDBkey' => $oldTitle->getPrefixedDBkey(),
  426. 'lastTimestamp' => 0,
  427. 'prefixedMoveTo' => $newTitle->getPrefixedDBkey()
  428. );
  429. $rc->save();
  430. }
  431. public static function notifyMoveToNew( $timestamp, &$oldTitle, &$newTitle, &$user, $comment, $ip='' ) {
  432. RecentChange::notifyMove( $timestamp, $oldTitle, $newTitle, $user, $comment, $ip, false );
  433. }
  434. public static function notifyMoveOverRedirect( $timestamp, &$oldTitle, &$newTitle, &$user, $comment, $ip='' ) {
  435. RecentChange::notifyMove( $timestamp, $oldTitle, $newTitle, $user, $comment, $ip, true );
  436. }
  437. public static function notifyLog( $timestamp, &$title, &$user, $actionComment, $ip='', $type,
  438. $action, $target, $logComment, $params, $newId=0 )
  439. {
  440. global $wgLogRestrictions;
  441. # Don't add private logs to RC!
  442. if( isset($wgLogRestrictions[$type]) && $wgLogRestrictions[$type] != '*' ) {
  443. return false;
  444. }
  445. $rc = self::newLogEntry( $timestamp, $title, $user, $actionComment, $ip, $type, $action,
  446. $target, $logComment, $params, $newId );
  447. $rc->save();
  448. return true;
  449. }
  450. public static function newLogEntry( $timestamp, &$title, &$user, $actionComment, $ip='',
  451. $type, $action, $target, $logComment, $params, $newId=0 )
  452. {
  453. global $wgRequest;
  454. if( !$ip ) {
  455. $ip = wfGetIP();
  456. if( !$ip ) $ip = '';
  457. }
  458. $rc = new RecentChange;
  459. $rc->mAttribs = array(
  460. 'rc_timestamp' => $timestamp,
  461. 'rc_cur_time' => $timestamp,
  462. 'rc_namespace' => $target->getNamespace(),
  463. 'rc_title' => $target->getDBkey(),
  464. 'rc_type' => RC_LOG,
  465. 'rc_minor' => 0,
  466. 'rc_cur_id' => $target->getArticleID(),
  467. 'rc_user' => $user->getId(),
  468. 'rc_user_text' => $user->getName(),
  469. 'rc_comment' => $logComment,
  470. 'rc_this_oldid' => 0,
  471. 'rc_last_oldid' => 0,
  472. 'rc_bot' => $user->isAllowed( 'bot' ) ? $wgRequest->getBool( 'bot', true ) : 0,
  473. 'rc_moved_to_ns' => 0,
  474. 'rc_moved_to_title' => '',
  475. 'rc_ip' => $ip,
  476. 'rc_patrolled' => 1,
  477. 'rc_new' => 0, # obsolete
  478. 'rc_old_len' => NULL,
  479. 'rc_new_len' => NULL,
  480. 'rc_deleted' => 0,
  481. 'rc_logid' => $newId,
  482. 'rc_log_type' => $type,
  483. 'rc_log_action' => $action,
  484. 'rc_params' => $params
  485. );
  486. $rc->mExtra = array(
  487. 'prefixedDBkey' => $title->getPrefixedDBkey(),
  488. 'lastTimestamp' => 0,
  489. 'actionComment' => $actionComment, // the comment appended to the action, passed from LogPage
  490. );
  491. return $rc;
  492. }
  493. # Initialises the members of this object from a mysql row object
  494. public function loadFromRow( $row ) {
  495. $this->mAttribs = get_object_vars( $row );
  496. $this->mAttribs['rc_timestamp'] = wfTimestamp(TS_MW, $this->mAttribs['rc_timestamp']);
  497. $this->mAttribs['rc_deleted'] = $row->rc_deleted; // MUST be set
  498. }
  499. # Makes a pseudo-RC entry from a cur row
  500. public function loadFromCurRow( $row ) {
  501. $this->mAttribs = array(
  502. 'rc_timestamp' => wfTimestamp(TS_MW, $row->rev_timestamp),
  503. 'rc_cur_time' => $row->rev_timestamp,
  504. 'rc_user' => $row->rev_user,
  505. 'rc_user_text' => $row->rev_user_text,
  506. 'rc_namespace' => $row->page_namespace,
  507. 'rc_title' => $row->page_title,
  508. 'rc_comment' => $row->rev_comment,
  509. 'rc_minor' => $row->rev_minor_edit ? 1 : 0,
  510. 'rc_type' => $row->page_is_new ? RC_NEW : RC_EDIT,
  511. 'rc_cur_id' => $row->page_id,
  512. 'rc_this_oldid' => $row->rev_id,
  513. 'rc_last_oldid' => isset($row->rc_last_oldid) ? $row->rc_last_oldid : 0,
  514. 'rc_bot' => 0,
  515. 'rc_moved_to_ns' => 0,
  516. 'rc_moved_to_title' => '',
  517. 'rc_ip' => '',
  518. 'rc_id' => $row->rc_id,
  519. 'rc_patrolled' => $row->rc_patrolled,
  520. 'rc_new' => $row->page_is_new, # obsolete
  521. 'rc_old_len' => $row->rc_old_len,
  522. 'rc_new_len' => $row->rc_new_len,
  523. 'rc_params' => isset($row->rc_params) ? $row->rc_params : '',
  524. 'rc_log_type' => isset($row->rc_log_type) ? $row->rc_log_type : null,
  525. 'rc_log_action' => isset($row->rc_log_action) ? $row->rc_log_action : null,
  526. 'rc_log_id' => isset($row->rc_log_id) ? $row->rc_log_id: 0,
  527. 'rc_deleted' => $row->rc_deleted // MUST be set
  528. );
  529. }
  530. /**
  531. * Get an attribute value
  532. *
  533. * @param $name Attribute name
  534. * @return mixed
  535. */
  536. public function getAttribute( $name ) {
  537. return isset( $this->mAttribs[$name] ) ? $this->mAttribs[$name] : NULL;
  538. }
  539. /**
  540. * Gets the end part of the diff URL associated with this object
  541. * Blank if no diff link should be displayed
  542. */
  543. public function diffLinkTrail( $forceCur ) {
  544. if( $this->mAttribs['rc_type'] == RC_EDIT ) {
  545. $trail = "curid=" . (int)($this->mAttribs['rc_cur_id']) .
  546. "&oldid=" . (int)($this->mAttribs['rc_last_oldid']);
  547. if( $forceCur ) {
  548. $trail .= '&diff=0' ;
  549. } else {
  550. $trail .= '&diff=' . (int)($this->mAttribs['rc_this_oldid']);
  551. }
  552. } else {
  553. $trail = '';
  554. }
  555. return $trail;
  556. }
  557. public function getIRCLine() {
  558. global $wgUseRCPatrol, $wgUseNPPatrol, $wgRC2UDPInterwikiPrefix, $wgLocalInterwiki;
  559. // FIXME: Would be good to replace these 2 extract() calls with something more explicit
  560. // e.g. list ($rc_type, $rc_id) = array_values ($this->mAttribs); [or something like that]
  561. extract($this->mAttribs);
  562. extract($this->mExtra);
  563. if( $rc_type == RC_LOG ) {
  564. $titleObj = Title::newFromText( "Log/$rc_log_type", NS_SPECIAL );
  565. } else {
  566. $titleObj =& $this->getTitle();
  567. }
  568. $title = $titleObj->getPrefixedText();
  569. $title = self::cleanupForIRC( $title );
  570. if( $rc_type == RC_LOG ) {
  571. $url = '';
  572. } else {
  573. if( $rc_type == RC_NEW ) {
  574. $url = "oldid=$rc_this_oldid";
  575. } else {
  576. $url = "diff=$rc_this_oldid&oldid=$rc_last_oldid";
  577. }
  578. if( $wgUseRCPatrol || ($rc_type == RC_NEW && $wgUseNPPatrol) ) {
  579. $url .= "&rcid=$rc_id";
  580. }
  581. // XXX: *HACK* this should use getFullURL(), hacked for SSL madness --brion 2005-12-26
  582. // XXX: *HACK^2* the preg_replace() undoes much of what getInternalURL() does, but we
  583. // XXX: need to call it so that URL paths on the Wikimedia secure server can be fixed
  584. // XXX: by a custom GetInternalURL hook --vyznev 2008-12-10
  585. $url = preg_replace( '/title=[^&]*&/', '', $titleObj->getInternalURL( $url ) );
  586. }
  587. if( isset( $oldSize ) && isset( $newSize ) ) {
  588. $szdiff = $newSize - $oldSize;
  589. if($szdiff < -500) {
  590. $szdiff = "\002$szdiff\002";
  591. } elseif($szdiff >= 0) {
  592. $szdiff = '+' . $szdiff ;
  593. }
  594. $szdiff = '(' . $szdiff . ')' ;
  595. } else {
  596. $szdiff = '';
  597. }
  598. $user = self::cleanupForIRC( $rc_user_text );
  599. if( $rc_type == RC_LOG ) {
  600. $targetText = $this->getTitle()->getPrefixedText();
  601. $comment = self::cleanupForIRC( str_replace("[[$targetText]]","[[\00302$targetText\00310]]",$actionComment) );
  602. $flag = $rc_log_action;
  603. } else {
  604. $comment = self::cleanupForIRC( $rc_comment );
  605. $flag = '';
  606. if( !$rc_patrolled && ($wgUseRCPatrol || $rc_new && $wgUseNPPatrol) ) {
  607. $flag .= '!';
  608. }
  609. $flag .= ($rc_new ? "N" : "") . ($rc_minor ? "M" : "") . ($rc_bot ? "B" : "");
  610. }
  611. if ( $wgRC2UDPInterwikiPrefix === true ) {
  612. $prefix = $wgLocalInterwiki;
  613. } elseif ( $wgRC2UDPInterwikiPrefix ) {
  614. $prefix = $wgRC2UDPInterwikiPrefix;
  615. } else {
  616. $prefix = false;
  617. }
  618. if ( $prefix !== false ) {
  619. $titleString = "\00314[[\00303$prefix:\00307$title\00314]]";
  620. } else {
  621. $titleString = "\00314[[\00307$title\00314]]";
  622. }
  623. # see http://www.irssi.org/documentation/formats for some colour codes. prefix is \003,
  624. # no colour (\003) switches back to the term default
  625. $fullString = "$titleString\0034 $flag\00310 " .
  626. "\00302$url\003 \0035*\003 \00303$user\003 \0035*\003 $szdiff \00310$comment\003\n";
  627. return $fullString;
  628. }
  629. /**
  630. * Returns the change size (HTML).
  631. * The lengths can be given optionally.
  632. */
  633. public function getCharacterDifference( $old = 0, $new = 0 ) {
  634. if( $old === 0 ) {
  635. $old = $this->mAttribs['rc_old_len'];
  636. }
  637. if( $new === 0 ) {
  638. $new = $this->mAttribs['rc_new_len'];
  639. }
  640. if( $old === NULL || $new === NULL ) {
  641. return '';
  642. }
  643. return ChangesList::showCharacterDifference( $old, $new );
  644. }
  645. }