ChangesList.php 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007
  1. <?php
  2. /**
  3. * @todo document
  4. */
  5. class RCCacheEntry extends RecentChange {
  6. var $secureName, $link;
  7. var $curlink , $difflink, $lastlink, $usertalklink, $versionlink;
  8. var $userlink, $timestamp, $watched;
  9. static function newFromParent( $rc ) {
  10. $rc2 = new RCCacheEntry;
  11. $rc2->mAttribs = $rc->mAttribs;
  12. $rc2->mExtra = $rc->mExtra;
  13. return $rc2;
  14. }
  15. }
  16. /**
  17. * Class to show various lists of changes:
  18. * - what links here
  19. * - related changes
  20. * - recent changes
  21. */
  22. class ChangesList {
  23. # Called by history lists and recent changes
  24. public $skin;
  25. /**
  26. * Changeslist contructor
  27. * @param Skin $skin
  28. */
  29. public function __construct( &$skin ) {
  30. $this->skin =& $skin;
  31. $this->preCacheMessages();
  32. }
  33. /**
  34. * Fetch an appropriate changes list class for the specified user
  35. * Some users might want to use an enhanced list format, for instance
  36. *
  37. * @param $user User to fetch the list class for
  38. * @return ChangesList derivative
  39. */
  40. public static function newFromUser( &$user ) {
  41. $sk = $user->getSkin();
  42. $list = NULL;
  43. if( wfRunHooks( 'FetchChangesList', array( &$user, &$sk, &$list ) ) ) {
  44. return $user->getOption( 'usenewrc' ) ?
  45. new EnhancedChangesList( $sk ) : new OldChangesList( $sk );
  46. } else {
  47. return $list;
  48. }
  49. }
  50. /**
  51. * As we use the same small set of messages in various methods and that
  52. * they are called often, we call them once and save them in $this->message
  53. */
  54. private function preCacheMessages() {
  55. if( !isset( $this->message ) ) {
  56. foreach( explode(' ', 'cur diff hist minoreditletter newpageletter last '.
  57. 'blocklink history boteditletter semicolon-separator' ) as $msg ) {
  58. $this->message[$msg] = wfMsgExt( $msg, array( 'escapenoentities' ) );
  59. }
  60. }
  61. }
  62. /**
  63. * Returns the appropriate flags for new page, minor change and patrolling
  64. * @param bool $new
  65. * @param bool $minor
  66. * @param bool $patrolled
  67. * @param string $nothing, string to use for empty space
  68. * @param bool $bot
  69. * @return string
  70. */
  71. protected function recentChangesFlags( $new, $minor, $patrolled, $nothing = '&nbsp;', $bot = false ) {
  72. $f = $new ?
  73. '<span class="newpage">' . $this->message['newpageletter'] . '</span>' : $nothing;
  74. $f .= $minor ?
  75. '<span class="minor">' . $this->message['minoreditletter'] . '</span>' : $nothing;
  76. $f .= $bot ? '<span class="bot">' . $this->message['boteditletter'] . '</span>' : $nothing;
  77. $f .= $patrolled ? '<span class="unpatrolled">!</span>' : $nothing;
  78. return $f;
  79. }
  80. /**
  81. * Returns text for the start of the tabular part of RC
  82. * @return string
  83. */
  84. public function beginRecentChangesList() {
  85. $this->rc_cache = array();
  86. $this->rcMoveIndex = 0;
  87. $this->rcCacheIndex = 0;
  88. $this->lastdate = '';
  89. $this->rclistOpen = false;
  90. return '';
  91. }
  92. /**
  93. * Show formatted char difference
  94. * @param int $old bytes
  95. * @param int $new bytes
  96. * @returns string
  97. */
  98. public static function showCharacterDifference( $old, $new ) {
  99. global $wgRCChangedSizeThreshold, $wgLang;
  100. $szdiff = $new - $old;
  101. $formatedSize = wfMsgExt( 'rc-change-size', array( 'parsemag', 'escape' ), $wgLang->formatNum( $szdiff ) );
  102. if( abs( $szdiff ) > abs( $wgRCChangedSizeThreshold ) ) {
  103. $tag = 'strong';
  104. } else {
  105. $tag = 'span';
  106. }
  107. if( $szdiff === 0 ) {
  108. return "<$tag class='mw-plusminus-null'>($formatedSize)</$tag>";
  109. } elseif( $szdiff > 0 ) {
  110. return "<$tag class='mw-plusminus-pos'>(+$formatedSize)</$tag>";
  111. } else {
  112. return "<$tag class='mw-plusminus-neg'>($formatedSize)</$tag>";
  113. }
  114. }
  115. /**
  116. * Returns text for the end of RC
  117. * @return string
  118. */
  119. public function endRecentChangesList() {
  120. if( $this->rclistOpen ) {
  121. return "</ul>\n";
  122. } else {
  123. return '';
  124. }
  125. }
  126. protected function insertMove( &$s, $rc ) {
  127. # Diff
  128. $s .= '(' . $this->message['diff'] . ') (';
  129. # Hist
  130. $s .= $this->skin->makeKnownLinkObj( $rc->getMovedToTitle(), $this->message['hist'],
  131. 'action=history' ) . ') . . ';
  132. # "[[x]] moved to [[y]]"
  133. $msg = ( $rc->mAttribs['rc_type'] == RC_MOVE ) ? '1movedto2' : '1movedto2_redir';
  134. $s .= wfMsg( $msg, $this->skin->makeKnownLinkObj( $rc->getTitle(), '', 'redirect=no' ),
  135. $this->skin->makeKnownLinkObj( $rc->getMovedToTitle(), '' ) );
  136. }
  137. protected function insertDateHeader( &$s, $rc_timestamp ) {
  138. global $wgLang;
  139. # Make date header if necessary
  140. $date = $wgLang->date( $rc_timestamp, true, true );
  141. if( $date != $this->lastdate ) {
  142. if( '' != $this->lastdate ) {
  143. $s .= "</ul>\n";
  144. }
  145. $s .= '<h4>'.$date."</h4>\n<ul class=\"special\">";
  146. $this->lastdate = $date;
  147. $this->rclistOpen = true;
  148. }
  149. }
  150. protected function insertLog( &$s, $title, $logtype ) {
  151. $logname = LogPage::logName( $logtype );
  152. $s .= '(' . $this->skin->makeKnownLinkObj($title, $logname ) . ')';
  153. }
  154. protected function insertDiffHist( &$s, &$rc, $unpatrolled ) {
  155. # Diff link
  156. if( $rc->mAttribs['rc_type'] == RC_NEW || $rc->mAttribs['rc_type'] == RC_LOG ) {
  157. $diffLink = $this->message['diff'];
  158. } else if( !$this->userCan($rc,Revision::DELETED_TEXT) ) {
  159. $diffLink = $this->message['diff'];
  160. } else {
  161. $rcidparam = $unpatrolled ? array( 'rcid' => $rc->mAttribs['rc_id'] ) : array();
  162. $diffLink = $this->skin->makeKnownLinkObj( $rc->getTitle(), $this->message['diff'],
  163. wfArrayToCGI( array(
  164. 'curid' => $rc->mAttribs['rc_cur_id'],
  165. 'diff' => $rc->mAttribs['rc_this_oldid'],
  166. 'oldid' => $rc->mAttribs['rc_last_oldid'] ),
  167. $rcidparam ),
  168. '', '', ' tabindex="'.$rc->counter.'"');
  169. }
  170. $s .= '('.$diffLink.') (';
  171. # History link
  172. $s .= $this->skin->makeKnownLinkObj( $rc->getTitle(), $this->message['hist'],
  173. wfArrayToCGI( array(
  174. 'curid' => $rc->mAttribs['rc_cur_id'],
  175. 'action' => 'history' ) ) );
  176. $s .= ') . . ';
  177. }
  178. protected function insertArticleLink( &$s, &$rc, $unpatrolled, $watched ) {
  179. global $wgContLang;
  180. # If it's a new article, there is no diff link, but if it hasn't been
  181. # patrolled yet, we need to give users a way to do so
  182. $params = ( $unpatrolled && $rc->mAttribs['rc_type'] == RC_NEW ) ?
  183. 'rcid='.$rc->mAttribs['rc_id'] : '';
  184. if( $this->isDeleted($rc,Revision::DELETED_TEXT) ) {
  185. $articlelink = $this->skin->makeKnownLinkObj( $rc->getTitle(), '', $params );
  186. $articlelink = '<span class="history-deleted">'.$articlelink.'</span>';
  187. } else {
  188. $articlelink = ' '. $this->skin->makeKnownLinkObj( $rc->getTitle(), '', $params );
  189. }
  190. # Bolden pages watched by this user
  191. if( $watched ) {
  192. $articlelink = "<strong class=\"mw-watched\">{$articlelink}</strong>";
  193. }
  194. # RTL/LTR marker
  195. $articlelink .= $wgContLang->getDirMark();
  196. wfRunHooks( 'ChangesListInsertArticleLink',
  197. array(&$this, &$articlelink, &$s, &$rc, $unpatrolled, $watched) );
  198. $s .= " $articlelink";
  199. }
  200. protected function insertTimestamp( &$s, $rc ) {
  201. global $wgLang;
  202. $s .= $this->message['semicolon-separator'] .
  203. $wgLang->time( $rc->mAttribs['rc_timestamp'], true, true ) . ' . . ';
  204. }
  205. /** Insert links to user page, user talk page and eventually a blocking link */
  206. public function insertUserRelatedLinks( &$s, &$rc ) {
  207. if( $this->isDeleted( $rc, Revision::DELETED_USER ) ) {
  208. $s .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
  209. } else {
  210. $s .= $this->skin->userLink( $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'] );
  211. $s .= $this->skin->userToolLinks( $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'] );
  212. }
  213. }
  214. /** insert a formatted action */
  215. protected function insertAction( &$s, &$rc ) {
  216. if( $rc->mAttribs['rc_type'] == RC_LOG ) {
  217. if( $this->isDeleted( $rc, LogPage::DELETED_ACTION ) ) {
  218. $s .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-event' ) . '</span>';
  219. } else {
  220. $s .= ' '.LogPage::actionText( $rc->mAttribs['rc_log_type'], $rc->mAttribs['rc_log_action'],
  221. $rc->getTitle(), $this->skin, LogPage::extractParams( $rc->mAttribs['rc_params'] ), true, true );
  222. }
  223. }
  224. }
  225. /** insert a formatted comment */
  226. protected function insertComment( &$s, &$rc ) {
  227. if( $rc->mAttribs['rc_type'] != RC_MOVE && $rc->mAttribs['rc_type'] != RC_MOVE_OVER_REDIRECT ) {
  228. if( $this->isDeleted( $rc, Revision::DELETED_COMMENT ) ) {
  229. $s .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-comment' ) . '</span>';
  230. } else {
  231. $s .= $this->skin->commentBlock( $rc->mAttribs['rc_comment'], $rc->getTitle() );
  232. }
  233. }
  234. }
  235. /**
  236. * Check whether to enable recent changes patrol features
  237. * @return bool
  238. */
  239. public static function usePatrol() {
  240. global $wgUser;
  241. return $wgUser->useRCPatrol();
  242. }
  243. /**
  244. * Returns the string which indicates the number of watching users
  245. */
  246. protected function numberofWatchingusers( $count ) {
  247. global $wgLang;
  248. static $cache = array();
  249. if( $count > 0 ) {
  250. if( !isset( $cache[$count] ) ) {
  251. $cache[$count] = wfMsgExt( 'number_of_watching_users_RCview',
  252. array('parsemag', 'escape' ), $wgLang->formatNum( $count ) );
  253. }
  254. return $cache[$count];
  255. } else {
  256. return '';
  257. }
  258. }
  259. /**
  260. * Determine if said field of a revision is hidden
  261. * @param RCCacheEntry $rc
  262. * @param int $field one of DELETED_* bitfield constants
  263. * @return bool
  264. */
  265. public static function isDeleted( $rc, $field ) {
  266. return ( $rc->mAttribs['rc_deleted'] & $field ) == $field;
  267. }
  268. /**
  269. * Determine if the current user is allowed to view a particular
  270. * field of this revision, if it's marked as deleted.
  271. * @param RCCacheEntry $rc
  272. * @param int $field
  273. * @return bool
  274. */
  275. public static function userCan( $rc, $field ) {
  276. if( ( $rc->mAttribs['rc_deleted'] & $field ) == $field ) {
  277. global $wgUser;
  278. $permission = ( $rc->mAttribs['rc_deleted'] & Revision::DELETED_RESTRICTED ) == Revision::DELETED_RESTRICTED
  279. ? 'suppressrevision'
  280. : 'deleterevision';
  281. wfDebug( "Checking for $permission due to $field match on {$rc->mAttribs['rc_deleted']}\n" );
  282. return $wgUser->isAllowed( $permission );
  283. } else {
  284. return true;
  285. }
  286. }
  287. protected function maybeWatchedLink( $link, $watched=false ) {
  288. if( $watched ) {
  289. return '<strong class="mw-watched">' . $link . '</strong>';
  290. } else {
  291. return '<span class="mw-rc-unwatched">' . $link . '</span>';
  292. }
  293. }
  294. /** Inserts a rollback link */
  295. protected function insertRollback( &$s, &$rc ) {
  296. global $wgUser;
  297. if( !$rc->mAttribs['rc_new'] && $rc->mAttribs['rc_this_oldid'] && $rc->mAttribs['rc_cur_id'] ) {
  298. $page = $rc->getTitle();
  299. /** Check for rollback and edit permissions, disallow special pages, and only
  300. * show a link on the top-most revision */
  301. if ($wgUser->isAllowed('rollback') && $rc->mAttribs['page_latest'] == $rc->mAttribs['rc_this_oldid'] )
  302. {
  303. $rev = new Revision( array(
  304. 'id' => $rc->mAttribs['rc_this_oldid'],
  305. 'user' => $rc->mAttribs['rc_user'],
  306. 'user_text' => $rc->mAttribs['rc_user_text'],
  307. 'deleted' => $rc->mAttribs['rc_deleted']
  308. ) );
  309. $rev->setTitle( $page );
  310. $s .= ' '.$this->skin->generateRollback( $rev );
  311. }
  312. }
  313. }
  314. protected function insertTags( &$s, &$rc, &$classes ) {
  315. if ( empty($rc->mAttribs['ts_tags']) )
  316. return;
  317. list($tagSummary, $newClasses) = ChangeTags::formatSummaryRow( $rc->mAttribs['ts_tags'], 'changeslist' );
  318. $classes = array_merge( $classes, $newClasses );
  319. $s .= ' ' . $tagSummary;
  320. }
  321. protected function insertExtra( &$s, &$rc, &$classes ) {
  322. ## Empty, used for subclassers to add anything special.
  323. }
  324. }
  325. /**
  326. * Generate a list of changes using the good old system (no javascript)
  327. */
  328. class OldChangesList extends ChangesList {
  329. /**
  330. * Format a line using the old system (aka without any javascript).
  331. */
  332. public function recentChangesLine( &$rc, $watched = false, $linenumber = NULL ) {
  333. global $wgContLang, $wgLang, $wgRCShowChangedSize, $wgUser;
  334. wfProfileIn( __METHOD__ );
  335. # Should patrol-related stuff be shown?
  336. $unpatrolled = $wgUser->useRCPatrol() && !$rc->mAttribs['rc_patrolled'];
  337. $dateheader = ''; // $s now contains only <li>...</li>, for hooks' convenience.
  338. $this->insertDateHeader( $dateheader, $rc->mAttribs['rc_timestamp'] );
  339. $s = '';
  340. $classes = array();
  341. // use mw-line-even/mw-line-odd class only if linenumber is given (feature from bug 14468)
  342. if( $linenumber ) {
  343. if( $linenumber & 1 ) {
  344. $classes[] = 'mw-line-odd';
  345. }
  346. else {
  347. $classes[] = 'mw-line-even';
  348. }
  349. }
  350. // Moved pages
  351. if( $rc->mAttribs['rc_type'] == RC_MOVE || $rc->mAttribs['rc_type'] == RC_MOVE_OVER_REDIRECT ) {
  352. $this->insertMove( $s, $rc );
  353. // Log entries
  354. } elseif( $rc->mAttribs['rc_log_type'] ) {
  355. $logtitle = Title::newFromText( 'Log/'.$rc->mAttribs['rc_log_type'], NS_SPECIAL );
  356. $this->insertLog( $s, $logtitle, $rc->mAttribs['rc_log_type'] );
  357. // Log entries (old format) or log targets, and special pages
  358. } elseif( $rc->mAttribs['rc_namespace'] == NS_SPECIAL ) {
  359. list( $name, $subpage ) = SpecialPage::resolveAliasWithSubpage( $rc->mAttribs['rc_title'] );
  360. if( $name == 'Log' ) {
  361. $this->insertLog( $s, $rc->getTitle(), $subpage );
  362. }
  363. // Regular entries
  364. } else {
  365. $this->insertDiffHist( $s, $rc, $unpatrolled );
  366. # M, N, b and ! (minor, new, bot and unpatrolled)
  367. $s .= $this->recentChangesFlags( $rc->mAttribs['rc_new'], $rc->mAttribs['rc_minor'],
  368. $unpatrolled, '', $rc->mAttribs['rc_bot'] );
  369. $this->insertArticleLink( $s, $rc, $unpatrolled, $watched );
  370. }
  371. # Edit/log timestamp
  372. $this->insertTimestamp( $s, $rc );
  373. # Bytes added or removed
  374. if( $wgRCShowChangedSize ) {
  375. $cd = $rc->getCharacterDifference();
  376. if( $cd != '' ) {
  377. $s .= "$cd . . ";
  378. }
  379. }
  380. # User tool links
  381. $this->insertUserRelatedLinks( $s, $rc );
  382. # Log action text (if any)
  383. $this->insertAction( $s, $rc );
  384. # Edit or log comment
  385. $this->insertComment( $s, $rc );
  386. # Tags
  387. $this->insertTags( $s, $rc, $classes );
  388. # Rollback
  389. $this->insertRollback( $s, $rc );
  390. # For subclasses
  391. $this->insertExtra( $s, $rc, $classes );
  392. # Mark revision as deleted if so
  393. if( !$rc->mAttribs['rc_log_type'] && $this->isDeleted($rc,Revision::DELETED_TEXT) ) {
  394. $s .= ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
  395. }
  396. # How many users watch this page
  397. if( $rc->numberofWatchingusers > 0 ) {
  398. $s .= ' ' . wfMsgExt( 'number_of_watching_users_RCview',
  399. array( 'parsemag', 'escape' ), $wgLang->formatNum( $rc->numberofWatchingusers ) );
  400. }
  401. wfRunHooks( 'OldChangesListRecentChangesLine', array(&$this, &$s, $rc) );
  402. wfProfileOut( __METHOD__ );
  403. return "$dateheader<li class=\"".implode( ' ', $classes )."\">$s</li>\n";
  404. }
  405. }
  406. /**
  407. * Generate a list of changes using an Enhanced system (uses javascript).
  408. */
  409. class EnhancedChangesList extends ChangesList {
  410. /**
  411. * Add the JavaScript file for enhanced changeslist
  412. * @ return string
  413. */
  414. public function beginRecentChangesList() {
  415. global $wgStylePath, $wgJsMimeType, $wgStyleVersion;
  416. $this->rc_cache = array();
  417. $this->rcMoveIndex = 0;
  418. $this->rcCacheIndex = 0;
  419. $this->lastdate = '';
  420. $this->rclistOpen = false;
  421. $script = Xml::tags( 'script', array(
  422. 'type' => $wgJsMimeType,
  423. 'src' => $wgStylePath . "/common/enhancedchanges.js?$wgStyleVersion" ), '' );
  424. return $script;
  425. }
  426. /**
  427. * Format a line for enhanced recentchange (aka with javascript and block of lines).
  428. */
  429. public function recentChangesLine( &$baseRC, $watched = false ) {
  430. global $wgLang, $wgContLang, $wgUser;
  431. wfProfileIn( __METHOD__ );
  432. # Create a specialised object
  433. $rc = RCCacheEntry::newFromParent( $baseRC );
  434. # Extract fields from DB into the function scope (rc_xxxx variables)
  435. // FIXME: Would be good to replace this extract() call with something
  436. // that explicitly initializes variables.
  437. extract( $rc->mAttribs );
  438. $curIdEq = 'curid=' . $rc_cur_id;
  439. # If it's a new day, add the headline and flush the cache
  440. $date = $wgLang->date( $rc_timestamp, true );
  441. $ret = '';
  442. if( $date != $this->lastdate ) {
  443. # Process current cache
  444. $ret = $this->recentChangesBlock();
  445. $this->rc_cache = array();
  446. $ret .= "<h4>{$date}</h4>\n";
  447. $this->lastdate = $date;
  448. }
  449. # Should patrol-related stuff be shown?
  450. if( $wgUser->useRCPatrol() ) {
  451. $rc->unpatrolled = !$rc_patrolled;
  452. } else {
  453. $rc->unpatrolled = false;
  454. }
  455. $showdifflinks = true;
  456. # Make article link
  457. // Page moves
  458. if( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
  459. $msg = ( $rc_type == RC_MOVE ) ? "1movedto2" : "1movedto2_redir";
  460. $clink = wfMsg( $msg, $this->skin->makeKnownLinkObj( $rc->getTitle(), '', 'redirect=no' ),
  461. $this->skin->makeKnownLinkObj( $rc->getMovedToTitle(), '' ) );
  462. // New unpatrolled pages
  463. } else if( $rc->unpatrolled && $rc_type == RC_NEW ) {
  464. $clink = $this->skin->makeKnownLinkObj( $rc->getTitle(), '', "rcid={$rc_id}" );
  465. // Log entries
  466. } else if( $rc_type == RC_LOG ) {
  467. if( $rc_log_type ) {
  468. $logtitle = SpecialPage::getTitleFor( 'Log', $rc_log_type );
  469. $clink = '(' . $this->skin->makeKnownLinkObj( $logtitle,
  470. LogPage::logName($rc_log_type) ) . ')';
  471. } else {
  472. $clink = $this->skin->makeLinkObj( $rc->getTitle(), '' );
  473. }
  474. $watched = false;
  475. // Log entries (old format) and special pages
  476. } elseif( $rc_namespace == NS_SPECIAL ) {
  477. list( $specialName, $logtype ) = SpecialPage::resolveAliasWithSubpage( $rc_title );
  478. if ( $specialName == 'Log' ) {
  479. # Log updates, etc
  480. $logname = LogPage::logName( $logtype );
  481. $clink = '(' . $this->skin->makeKnownLinkObj( $rc->getTitle(), $logname ) . ')';
  482. } else {
  483. wfDebug( "Unexpected special page in recentchanges\n" );
  484. $clink = '';
  485. }
  486. // Edits
  487. } else {
  488. $clink = $this->skin->makeKnownLinkObj( $rc->getTitle(), '' );
  489. }
  490. # Don't show unusable diff links
  491. if ( !ChangesList::userCan($rc,Revision::DELETED_TEXT) ) {
  492. $showdifflinks = false;
  493. }
  494. $time = $wgContLang->time( $rc_timestamp, true, true );
  495. $rc->watched = $watched;
  496. $rc->link = $clink;
  497. $rc->timestamp = $time;
  498. $rc->numberofWatchingusers = $baseRC->numberofWatchingusers;
  499. # Make "cur" and "diff" links
  500. if( $rc->unpatrolled ) {
  501. $rcIdQuery = "&rcid={$rc_id}";
  502. } else {
  503. $rcIdQuery = '';
  504. }
  505. $querycur = $curIdEq."&diff=0&oldid=$rc_this_oldid";
  506. $querydiff = $curIdEq."&diff=$rc_this_oldid&oldid=$rc_last_oldid$rcIdQuery";
  507. $aprops = ' tabindex="'.$baseRC->counter.'"';
  508. $curLink = $this->skin->makeKnownLinkObj( $rc->getTitle(),
  509. $this->message['cur'], $querycur, '' ,'', $aprops );
  510. # Make "diff" an "cur" links
  511. if( !$showdifflinks ) {
  512. $curLink = $this->message['cur'];
  513. $diffLink = $this->message['diff'];
  514. } else if( in_array( $rc_type, array(RC_NEW,RC_LOG,RC_MOVE,RC_MOVE_OVER_REDIRECT) ) ) {
  515. $curLink = ($rc_type != RC_NEW) ? $this->message['cur'] : $curLink;
  516. $diffLink = $this->message['diff'];
  517. } else {
  518. $diffLink = $this->skin->makeKnownLinkObj( $rc->getTitle(), $this->message['diff'],
  519. $querydiff, '' ,'', $aprops );
  520. }
  521. # Make "last" link
  522. if( !$showdifflinks || !$rc_last_oldid ) {
  523. $lastLink = $this->message['last'];
  524. } else if( $rc_type == RC_LOG || $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
  525. $lastLink = $this->message['last'];
  526. } else {
  527. $lastLink = $this->skin->makeKnownLinkObj( $rc->getTitle(), $this->message['last'],
  528. $curIdEq.'&diff='.$rc_this_oldid.'&oldid='.$rc_last_oldid . $rcIdQuery );
  529. }
  530. # Make user links
  531. if( $this->isDeleted($rc,Revision::DELETED_USER) ) {
  532. $rc->userlink = ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
  533. } else {
  534. $rc->userlink = $this->skin->userLink( $rc_user, $rc_user_text );
  535. $rc->usertalklink = $this->skin->userToolLinks( $rc_user, $rc_user_text );
  536. }
  537. $rc->lastlink = $lastLink;
  538. $rc->curlink = $curLink;
  539. $rc->difflink = $diffLink;
  540. # Put accumulated information into the cache, for later display
  541. # Page moves go on their own line
  542. $title = $rc->getTitle();
  543. $secureName = $title->getPrefixedDBkey();
  544. if( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
  545. # Use an @ character to prevent collision with page names
  546. $this->rc_cache['@@' . ($this->rcMoveIndex++)] = array($rc);
  547. } else {
  548. # Logs are grouped by type
  549. if( $rc_type == RC_LOG ){
  550. $secureName = SpecialPage::getTitleFor( 'Log', $rc_log_type )->getPrefixedDBkey();
  551. }
  552. if( !isset( $this->rc_cache[$secureName] ) ) {
  553. $this->rc_cache[$secureName] = array();
  554. }
  555. array_push( $this->rc_cache[$secureName], $rc );
  556. }
  557. wfProfileOut( __METHOD__ );
  558. return $ret;
  559. }
  560. /**
  561. * Enhanced RC group
  562. */
  563. protected function recentChangesBlockGroup( $block ) {
  564. global $wgLang, $wgContLang, $wgRCShowChangedSize;
  565. wfProfileIn( __METHOD__ );
  566. $r = '<table cellpadding="0" cellspacing="0" border="0" style="background: none"><tr>';
  567. # Collate list of users
  568. $userlinks = array();
  569. # Other properties
  570. $unpatrolled = false;
  571. $isnew = false;
  572. $curId = $currentRevision = 0;
  573. # Some catalyst variables...
  574. $namehidden = true;
  575. $allLogs = true;
  576. foreach( $block as $rcObj ) {
  577. $oldid = $rcObj->mAttribs['rc_last_oldid'];
  578. if( $rcObj->mAttribs['rc_new'] ) {
  579. $isnew = true;
  580. }
  581. // If all log actions to this page were hidden, then don't
  582. // give the name of the affected page for this block!
  583. if( !$this->isDeleted( $rcObj, LogPage::DELETED_ACTION ) ) {
  584. $namehidden = false;
  585. }
  586. $u = $rcObj->userlink;
  587. if( !isset( $userlinks[$u] ) ) {
  588. $userlinks[$u] = 0;
  589. }
  590. if( $rcObj->unpatrolled ) {
  591. $unpatrolled = true;
  592. }
  593. if( $rcObj->mAttribs['rc_type'] != RC_LOG ) {
  594. $allLogs = false;
  595. }
  596. # Get the latest entry with a page_id and oldid
  597. # since logs may not have these.
  598. if( !$curId && $rcObj->mAttribs['rc_cur_id'] ) {
  599. $curId = $rcObj->mAttribs['rc_cur_id'];
  600. }
  601. if( !$currentRevision && $rcObj->mAttribs['rc_this_oldid'] ) {
  602. $currentRevision = $rcObj->mAttribs['rc_this_oldid'];
  603. }
  604. $bot = $rcObj->mAttribs['rc_bot'];
  605. $userlinks[$u]++;
  606. }
  607. # Sort the list and convert to text
  608. krsort( $userlinks );
  609. asort( $userlinks );
  610. $users = array();
  611. foreach( $userlinks as $userlink => $count) {
  612. $text = $userlink;
  613. $text .= $wgContLang->getDirMark();
  614. if( $count > 1 ) {
  615. $text .= ' (' . $wgLang->formatNum( $count ) . '×)';
  616. }
  617. array_push( $users, $text );
  618. }
  619. $users = ' <span class="changedby">[' .
  620. implode( $this->message['semicolon-separator'], $users ) . ']</span>';
  621. # ID for JS visibility toggle
  622. $jsid = $this->rcCacheIndex;
  623. # onclick handler to toggle hidden/expanded
  624. $toggleLink = "onclick='toggleVisibility($jsid); return false'";
  625. # Title for <a> tags
  626. $expandTitle = htmlspecialchars( wfMsg( 'rc-enhanced-expand' ) );
  627. $closeTitle = htmlspecialchars( wfMsg( 'rc-enhanced-hide' ) );
  628. $tl = "<span id='mw-rc-openarrow-$jsid' class='mw-changeslist-expanded' style='visibility:hidden'><a href='#' $toggleLink title='$expandTitle'>" . $this->sideArrow() . "</a></span>";
  629. $tl .= "<span id='mw-rc-closearrow-$jsid' class='mw-changeslist-hidden' style='display:none'><a href='#' $toggleLink title='$closeTitle'>" . $this->downArrow() . "</a></span>";
  630. $r .= '<td valign="top" style="white-space: nowrap"><tt>'.$tl.'&nbsp;';
  631. # Main line
  632. $r .= $this->recentChangesFlags( $isnew, false, $unpatrolled, '&nbsp;', $bot );
  633. # Timestamp
  634. $r .= '&nbsp;'.$block[0]->timestamp.'&nbsp;</tt></td><td>';
  635. # Article link
  636. if( $namehidden ) {
  637. $r .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-event' ) . '</span>';
  638. } else if( $allLogs ) {
  639. $r .= $this->maybeWatchedLink( $block[0]->link, $block[0]->watched );
  640. } else {
  641. $this->insertArticleLink( $r, $block[0], $block[0]->unpatrolled, $block[0]->watched );
  642. }
  643. $r .= $wgContLang->getDirMark();
  644. $curIdEq = 'curid=' . $curId;
  645. # Changes message
  646. $n = count($block);
  647. static $nchanges = array();
  648. if ( !isset( $nchanges[$n] ) ) {
  649. $nchanges[$n] = wfMsgExt( 'nchanges', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) );
  650. }
  651. # Total change link
  652. $r .= ' ';
  653. if( !$allLogs ) {
  654. $r .= '(';
  655. if( !ChangesList::userCan( $rcObj, Revision::DELETED_TEXT ) ) {
  656. $r .= $nchanges[$n];
  657. } else if( $isnew ) {
  658. $r .= $nchanges[$n];
  659. } else {
  660. $r .= $this->skin->makeKnownLinkObj( $block[0]->getTitle(),
  661. $nchanges[$n], $curIdEq."&diff=$currentRevision&oldid=$oldid" );
  662. }
  663. }
  664. # History
  665. if( $allLogs ) {
  666. // don't show history link for logs
  667. } else if( $namehidden || !$block[0]->getTitle()->exists() ) {
  668. $r .= $this->message['semicolon-separator'] . $this->message['hist'] . ')';
  669. } else {
  670. $r .= $this->message['semicolon-separator'] . $this->skin->makeKnownLinkObj( $block[0]->getTitle(),
  671. $this->message['hist'], $curIdEq . '&action=history' ) . ')';
  672. }
  673. $r .= ' . . ';
  674. # Character difference (does not apply if only log items)
  675. if( $wgRCShowChangedSize && !$allLogs ) {
  676. $last = 0;
  677. $first = count($block) - 1;
  678. # Some events (like logs) have an "empty" size, so we need to skip those...
  679. while( $last < $first && $block[$last]->mAttribs['rc_new_len'] === NULL ) {
  680. $last++;
  681. }
  682. while( $first > $last && $block[$first]->mAttribs['rc_old_len'] === NULL ) {
  683. $first--;
  684. }
  685. # Get net change
  686. $chardiff = $rcObj->getCharacterDifference( $block[$first]->mAttribs['rc_old_len'],
  687. $block[$last]->mAttribs['rc_new_len'] );
  688. if( $chardiff == '' ) {
  689. $r .= ' ';
  690. } else {
  691. $r .= ' ' . $chardiff. ' . . ';
  692. }
  693. }
  694. $r .= $users;
  695. $r .= $this->numberofWatchingusers($block[0]->numberofWatchingusers);
  696. $r .= "</td></tr></table>\n";
  697. # Sub-entries
  698. $r .= '<div id="mw-rc-subentries-'.$jsid.'" class="mw-changeslist-hidden">';
  699. $r .= '<table cellpadding="0" cellspacing="0" border="0" style="background: none">';
  700. foreach( $block as $rcObj ) {
  701. # Extract fields from DB into the function scope (rc_xxxx variables)
  702. // FIXME: Would be good to replace this extract() call with something
  703. // that explicitly initializes variables.
  704. # Classes to apply -- TODO implement
  705. $classes = array();
  706. extract( $rcObj->mAttribs );
  707. #$r .= '<tr><td valign="top">'.$this->spacerArrow();
  708. $r .= '<tr><td valign="top">';
  709. $r .= '<tt>'.$this->spacerIndent() . $this->spacerIndent();
  710. $r .= $this->recentChangesFlags( $rc_new, $rc_minor, $rcObj->unpatrolled, '&nbsp;', $rc_bot );
  711. $r .= '&nbsp;</tt></td><td valign="top">';
  712. $o = '';
  713. if( $rc_this_oldid != 0 ) {
  714. $o = 'oldid='.$rc_this_oldid;
  715. }
  716. # Log timestamp
  717. if( $rc_type == RC_LOG ) {
  718. $link = '<tt>'.$rcObj->timestamp.'</tt> ';
  719. # Revision link
  720. } else if( !ChangesList::userCan($rcObj,Revision::DELETED_TEXT) ) {
  721. $link = '<span class="history-deleted"><tt>'.$rcObj->timestamp.'</tt></span> ';
  722. } else {
  723. $rcIdEq = ($rcObj->unpatrolled && $rc_type == RC_NEW) ?
  724. '&rcid='.$rcObj->mAttribs['rc_id'] : '';
  725. $link = '<tt>'.$this->skin->makeKnownLinkObj( $rcObj->getTitle(),
  726. $rcObj->timestamp, $curIdEq.'&'.$o.$rcIdEq ).'</tt>';
  727. if( $this->isDeleted($rcObj,Revision::DELETED_TEXT) )
  728. $link = '<span class="history-deleted">'.$link.'</span> ';
  729. }
  730. $r .= $link;
  731. if ( !$rc_type == RC_LOG || $rc_type == RC_NEW ) {
  732. $r .= ' (';
  733. $r .= $rcObj->curlink;
  734. $r .= $this->message['semicolon-separator'];
  735. $r .= $rcObj->lastlink;
  736. $r .= ')';
  737. }
  738. $r .= ' . . ';
  739. # Character diff
  740. if( $wgRCShowChangedSize ) {
  741. $r .= ( $rcObj->getCharacterDifference() == '' ? '' : $rcObj->getCharacterDifference() . ' . . ' ) ;
  742. }
  743. # User links
  744. $r .= $rcObj->userlink;
  745. $r .= $rcObj->usertalklink;
  746. // log action
  747. $this->insertAction( $r, $rcObj );
  748. // log comment
  749. $this->insertComment( $r, $rcObj );
  750. # Rollback
  751. $this->insertRollback( $r, $rcObj );
  752. # Tags
  753. $this->insertTags( $r, $rcObj, $classes );
  754. # Mark revision as deleted
  755. if( !$rc_log_type && $this->isDeleted($rcObj,Revision::DELETED_TEXT) ) {
  756. $r .= ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
  757. }
  758. $r .= "</td></tr>\n";
  759. }
  760. $r .= "</table></div>\n";
  761. $this->rcCacheIndex++;
  762. wfProfileOut( __METHOD__ );
  763. return $r;
  764. }
  765. /**
  766. * Generate HTML for an arrow or placeholder graphic
  767. * @param string $dir one of '', 'd', 'l', 'r'
  768. * @param string $alt text
  769. * @param string $title text
  770. * @return string HTML <img> tag
  771. */
  772. protected function arrow( $dir, $alt='', $title='' ) {
  773. global $wgStylePath;
  774. $encUrl = htmlspecialchars( $wgStylePath . '/common/images/Arr_' . $dir . '.png' );
  775. $encAlt = htmlspecialchars( $alt );
  776. $encTitle = htmlspecialchars( $title );
  777. return "<img src=\"$encUrl\" width=\"12\" height=\"12\" alt=\"$encAlt\" title=\"$encTitle\" />";
  778. }
  779. /**
  780. * Generate HTML for a right- or left-facing arrow,
  781. * depending on language direction.
  782. * @return string HTML <img> tag
  783. */
  784. protected function sideArrow() {
  785. global $wgContLang;
  786. $dir = $wgContLang->isRTL() ? 'l' : 'r';
  787. return $this->arrow( $dir, '+', wfMsg( 'rc-enhanced-expand' ) );
  788. }
  789. /**
  790. * Generate HTML for a down-facing arrow
  791. * depending on language direction.
  792. * @return string HTML <img> tag
  793. */
  794. protected function downArrow() {
  795. return $this->arrow( 'd', '-', wfMsg( 'rc-enhanced-hide' ) );
  796. }
  797. /**
  798. * Generate HTML for a spacer image
  799. * @return string HTML <img> tag
  800. */
  801. protected function spacerArrow() {
  802. return $this->arrow( '', codepointToUtf8( 0xa0 ) ); // non-breaking space
  803. }
  804. /**
  805. * Add a set of spaces
  806. * @return string HTML <td> tag
  807. */
  808. protected function spacerIndent() {
  809. return '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  810. }
  811. /**
  812. * Enhanced RC ungrouped line.
  813. * @return string a HTML formated line (generated using $r)
  814. */
  815. protected function recentChangesBlockLine( $rcObj ) {
  816. global $wgContLang, $wgRCShowChangedSize;
  817. wfProfileIn( __METHOD__ );
  818. # Extract fields from DB into the function scope (rc_xxxx variables)
  819. // FIXME: Would be good to replace this extract() call with something
  820. // that explicitly initializes variables.
  821. $classes = array(); // TODO implement
  822. extract( $rcObj->mAttribs );
  823. $curIdEq = "curid={$rc_cur_id}";
  824. $r = '<table cellspacing="0" cellpadding="0" border="0" style="background: none"><tr>';
  825. $r .= '<td valign="top" style="white-space: nowrap"><tt>' . $this->spacerArrow() . '&nbsp;';
  826. # Flag and Timestamp
  827. if( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
  828. $r .= '&nbsp;&nbsp;&nbsp;&nbsp;'; // 4 flags -> 4 spaces
  829. } else {
  830. $r .= $this->recentChangesFlags( $rc_type == RC_NEW, $rc_minor, $rcObj->unpatrolled, '&nbsp;', $rc_bot );
  831. }
  832. $r .= '&nbsp;'.$rcObj->timestamp.'&nbsp;</tt></td><td>';
  833. # Article or log link
  834. if( $rc_log_type ) {
  835. $logtitle = Title::newFromText( "Log/$rc_log_type", NS_SPECIAL );
  836. $logname = LogPage::logName( $rc_log_type );
  837. $r .= '(' . $this->skin->makeKnownLinkObj($logtitle, $logname ) . ')';
  838. } else {
  839. $this->insertArticleLink( $r, $rcObj, $rcObj->unpatrolled, $rcObj->watched );
  840. }
  841. # Diff and hist links
  842. if ( $rc_type != RC_LOG ) {
  843. $r .= ' ('. $rcObj->difflink . $this->message['semicolon-separator'];
  844. $r .= $this->skin->makeKnownLinkObj( $rcObj->getTitle(), $this->message['hist'],
  845. $curIdEq.'&action=history' ) . ')';
  846. }
  847. $r .= ' . . ';
  848. # Character diff
  849. if( $wgRCShowChangedSize && ($cd = $rcObj->getCharacterDifference()) ) {
  850. $r .= "$cd . . ";
  851. }
  852. # User/talk
  853. $r .= ' '.$rcObj->userlink . $rcObj->usertalklink;
  854. # Log action (if any)
  855. if( $rc_log_type ) {
  856. if( $this->isDeleted($rcObj,LogPage::DELETED_ACTION) ) {
  857. $r .= ' <span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
  858. } else {
  859. $r .= ' ' . LogPage::actionText( $rc_log_type, $rc_log_action, $rcObj->getTitle(),
  860. $this->skin, LogPage::extractParams($rc_params), true, true );
  861. }
  862. }
  863. $this->insertComment( $r, $rcObj );
  864. $this->insertRollback( $r, $rcObj );
  865. # Tags
  866. $this->insertTags( $r, $rcObj, $classes );
  867. # Show how many people are watching this if enabled
  868. $r .= $this->numberofWatchingusers($rcObj->numberofWatchingusers);
  869. $r .= "</td></tr></table>\n";
  870. wfProfileOut( __METHOD__ );
  871. return $r;
  872. }
  873. /**
  874. * If enhanced RC is in use, this function takes the previously cached
  875. * RC lines, arranges them, and outputs the HTML
  876. */
  877. protected function recentChangesBlock() {
  878. if( count ( $this->rc_cache ) == 0 ) {
  879. return '';
  880. }
  881. wfProfileIn( __METHOD__ );
  882. $blockOut = '';
  883. foreach( $this->rc_cache as $block ) {
  884. if( count( $block ) < 2 ) {
  885. $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
  886. } else {
  887. $blockOut .= $this->recentChangesBlockGroup( $block );
  888. }
  889. }
  890. wfProfileOut( __METHOD__ );
  891. return '<div>'.$blockOut.'</div>';
  892. }
  893. /**
  894. * Returns text for the end of RC
  895. * If enhanced RC is in use, returns pretty much all the text
  896. */
  897. public function endRecentChangesList() {
  898. return $this->recentChangesBlock() . parent::endRecentChangesList();
  899. }
  900. }