SpecialDeletedContributions.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. <?php
  2. /**
  3. * Implements Special:DeletedContributions to display archived revisions
  4. * @ingroup SpecialPage
  5. */
  6. class DeletedContribsPager extends IndexPager {
  7. public $mDefaultDirection = true;
  8. var $messages, $target;
  9. var $namespace = '', $mDb;
  10. function __construct( $target, $namespace = false ) {
  11. parent::__construct();
  12. foreach( explode( ' ', 'deletionlog undeletebtn minoreditletter diff' ) as $msg ) {
  13. $this->messages[$msg] = wfMsgExt( $msg, array( 'escape') );
  14. }
  15. $this->target = $target;
  16. $this->namespace = $namespace;
  17. $this->mDb = wfGetDB( DB_SLAVE, 'contributions' );
  18. }
  19. function getDefaultQuery() {
  20. $query = parent::getDefaultQuery();
  21. $query['target'] = $this->target;
  22. return $query;
  23. }
  24. function getQueryInfo() {
  25. global $wgUser;
  26. list( $index, $userCond ) = $this->getUserCond();
  27. $conds = array_merge( $userCond, $this->getNamespaceCond() );
  28. // Paranoia: avoid brute force searches (bug 17792)
  29. if( !$wgUser->isAllowed( 'suppressrevision' ) ) {
  30. $conds[] = 'ar_deleted & ' . Revision::DELETED_USER . ' = 0';
  31. }
  32. return array(
  33. 'tables' => array( 'archive' ),
  34. 'fields' => array(
  35. 'ar_rev_id', 'ar_namespace', 'ar_title', 'ar_timestamp', 'ar_comment', 'ar_minor_edit',
  36. 'ar_user', 'ar_user_text', 'ar_deleted'
  37. ),
  38. 'conds' => $conds,
  39. 'options' => array( 'USE INDEX' => $index )
  40. );
  41. }
  42. function getUserCond() {
  43. $condition = array();
  44. $condition['ar_user_text'] = $this->target;
  45. $index = 'usertext_timestamp';
  46. return array( $index, $condition );
  47. }
  48. function getIndexField() {
  49. return 'ar_timestamp';
  50. }
  51. function getStartBody() {
  52. return "<ul>\n";
  53. }
  54. function getEndBody() {
  55. return "</ul>\n";
  56. }
  57. function getNavigationBar() {
  58. global $wgLang;
  59. if ( isset( $this->mNavigationBar ) ) {
  60. return $this->mNavigationBar;
  61. }
  62. $linkTexts = array(
  63. 'prev' => wfMsgHtml( 'pager-newer-n', $this->mLimit ),
  64. 'next' => wfMsgHtml( 'pager-older-n', $this->mLimit ),
  65. 'first' => wfMsgHtml( 'histlast' ),
  66. 'last' => wfMsgHtml( 'histfirst' )
  67. );
  68. $pagingLinks = $this->getPagingLinks( $linkTexts );
  69. $limitLinks = $this->getLimitLinks();
  70. $limits = $wgLang->pipeList( $limitLinks );
  71. $this->mNavigationBar = "(" . $wgLang->pipeList( array( $pagingLinks['first'], $pagingLinks['last'] ) ) . ") " .
  72. wfMsgExt( 'viewprevnext', array( 'parsemag' ), $pagingLinks['prev'], $pagingLinks['next'], $limits );
  73. return $this->mNavigationBar;
  74. }
  75. function getNamespaceCond() {
  76. if ( $this->namespace !== '' ) {
  77. return array( 'ar_namespace' => (int)$this->namespace );
  78. } else {
  79. return array();
  80. }
  81. }
  82. /**
  83. * Generates each row in the contributions list.
  84. *
  85. * Contributions which are marked "top" are currently on top of the history.
  86. * For these contributions, a [rollback] link is shown for users with sysop
  87. * privileges. The rollback link restores the most recent version that was not
  88. * written by the target user.
  89. *
  90. * @todo This would probably look a lot nicer in a table.
  91. */
  92. function formatRow( $row ) {
  93. wfProfileIn( __METHOD__ );
  94. global $wgLang, $wgUser;
  95. $sk = $this->getSkin();
  96. $rev = new Revision( array(
  97. 'id' => $row->ar_rev_id,
  98. 'comment' => $row->ar_comment,
  99. 'user' => $row->ar_user,
  100. 'user_text' => $row->ar_user_text,
  101. 'timestamp' => $row->ar_timestamp,
  102. 'minor_edit' => $row->ar_minor_edit,
  103. 'deleted' => $row->ar_deleted,
  104. ) );
  105. $page = Title::makeTitle( $row->ar_namespace, $row->ar_title );
  106. $undelete = SpecialPage::getTitleFor( 'Undelete' );
  107. $logs = SpecialPage::getTitleFor( 'Log' );
  108. $dellog = $sk->makeKnownLinkObj( $logs,
  109. $this->messages['deletionlog'],
  110. 'type=delete&page=' . $page->getPrefixedUrl() );
  111. $reviewlink = $sk->makeKnownLinkObj( SpecialPage::getTitleFor( 'Undelete', $page->getPrefixedDBkey() ),
  112. $this->messages['undeletebtn'] );
  113. $link = $sk->makeKnownLinkObj( $undelete,
  114. htmlspecialchars( $page->getPrefixedText() ),
  115. 'target=' . $page->getPrefixedUrl() .
  116. '&timestamp=' . $rev->getTimestamp() );
  117. $last = $sk->makeKnownLinkObj( $undelete,
  118. $this->messages['diff'],
  119. "target=" . $page->getPrefixedUrl() .
  120. "&timestamp=" . $rev->getTimestamp() .
  121. "&diff=prev" );
  122. $comment = $sk->revComment( $rev );
  123. $d = $wgLang->timeanddate( $rev->getTimestamp(), true );
  124. if( $rev->isDeleted( Revision::DELETED_TEXT ) ) {
  125. $d = '<span class="history-deleted">' . $d . '</span>';
  126. } else {
  127. $link = $sk->makeKnownLinkObj( $undelete, $d,
  128. 'target=' . $page->getPrefixedUrl() .
  129. '&timestamp=' . $rev->getTimestamp() );
  130. }
  131. $pagelink = $sk->makeLinkObj( $page );
  132. if( $rev->isMinor() ) {
  133. $mflag = '<span class="minor">' . $this->messages['minoreditletter'] . '</span> ';
  134. } else {
  135. $mflag = '';
  136. }
  137. $ret = "{$link} ($last) ({$dellog}) ({$reviewlink}) . . {$mflag} {$pagelink} {$comment}";
  138. if( $rev->isDeleted( Revision::DELETED_TEXT ) ) {
  139. $ret .= ' ' . wfMsgHtml( 'deletedrev' );
  140. }
  141. $ret = "<li>$ret</li>\n";
  142. wfProfileOut( __METHOD__ );
  143. return $ret;
  144. }
  145. /**
  146. * Get the Database object in use
  147. *
  148. * @return Database
  149. */
  150. public function getDatabase() {
  151. return $this->mDb;
  152. }
  153. }
  154. class DeletedContributionsPage extends SpecialPage {
  155. function __construct() {
  156. parent::__construct( 'DeletedContributions', 'deletedhistory',
  157. /*listed*/ true, /*function*/ false, /*file*/ false );
  158. }
  159. /**
  160. * Special page "deleted user contributions".
  161. * Shows a list of the deleted contributions of a user.
  162. *
  163. * @return none
  164. * @param $par String: (optional) user name of the user for which to show the contributions
  165. */
  166. function execute( $par ) {
  167. global $wgUser;
  168. $this->setHeaders();
  169. if ( !$this->userCanExecute( $wgUser ) ) {
  170. $this->displayRestrictionError();
  171. return;
  172. }
  173. global $wgUser, $wgOut, $wgLang, $wgRequest;
  174. $wgOut->setPageTitle( wfMsgExt( 'deletedcontributions-title', array( 'parsemag' ) ) );
  175. $options = array();
  176. if ( isset( $par ) ) {
  177. $target = $par;
  178. } else {
  179. $target = $wgRequest->getVal( 'target' );
  180. }
  181. if ( !strlen( $target ) ) {
  182. $wgOut->addHTML( $this->getForm( '' ) );
  183. return;
  184. }
  185. $options['limit'] = $wgRequest->getInt( 'limit', 50 );
  186. $options['target'] = $target;
  187. $nt = Title::makeTitleSafe( NS_USER, $target );
  188. if ( !$nt ) {
  189. $wgOut->addHTML( $this->getForm( '' ) );
  190. return;
  191. }
  192. $id = User::idFromName( $nt->getText() );
  193. $target = $nt->getText();
  194. $wgOut->setSubtitle( $this->getSubTitle( $nt, $id ) );
  195. if ( ( $ns = $wgRequest->getVal( 'namespace', null ) ) !== null && $ns !== '' ) {
  196. $options['namespace'] = intval( $ns );
  197. } else {
  198. $options['namespace'] = '';
  199. }
  200. $wgOut->addHTML( $this->getForm( $options ) );
  201. $pager = new DeletedContribsPager( $target, $options['namespace'] );
  202. if ( !$pager->getNumRows() ) {
  203. $wgOut->addWikiText( wfMsg( 'nocontribs' ) );
  204. return;
  205. }
  206. # Show a message about slave lag, if applicable
  207. if( ( $lag = $pager->getDatabase()->getLag() ) > 0 )
  208. $wgOut->showLagWarning( $lag );
  209. $wgOut->addHTML(
  210. '<p>' . $pager->getNavigationBar() . '</p>' .
  211. $pager->getBody() .
  212. '<p>' . $pager->getNavigationBar() . '</p>' );
  213. # If there were contributions, and it was a valid user or IP, show
  214. # the appropriate "footer" message - WHOIS tools, etc.
  215. if( $target != 'newbies' ) {
  216. $message = IP::isIPAddress( $target )
  217. ? 'sp-contributions-footer-anon'
  218. : 'sp-contributions-footer';
  219. $text = wfMsgNoTrans( $message, $target );
  220. if( !wfEmptyMsg( $message, $text ) && $text != '-' ) {
  221. $wgOut->addHTML( '<div class="mw-contributions-footer">' );
  222. $wgOut->addWikiText( $text );
  223. $wgOut->addHTML( '</div>' );
  224. }
  225. }
  226. }
  227. /**
  228. * Generates the subheading with links
  229. * @param $nt @see Title object for the target
  230. */
  231. function getSubTitle( $nt, $id ) {
  232. global $wgSysopUserBans, $wgLang, $wgUser;
  233. $sk = $wgUser->getSkin();
  234. if ( 0 == $id ) {
  235. $user = $nt->getText();
  236. } else {
  237. $user = $sk->makeLinkObj( $nt, htmlspecialchars( $nt->getText() ) );
  238. }
  239. $talk = $nt->getTalkPage();
  240. if( $talk ) {
  241. # Talk page link
  242. $tools[] = $sk->makeLinkObj( $talk, wfMsgHtml( 'talkpagelinktext' ) );
  243. if( ( $id != 0 && $wgSysopUserBans ) || ( $id == 0 && User::isIP( $nt->getText() ) ) ) {
  244. # Block link
  245. if( $wgUser->isAllowed( 'block' ) )
  246. $tools[] = $sk->makeKnownLinkObj( SpecialPage::getTitleFor( 'Blockip', $nt->getDBkey() ),
  247. wfMsgHtml( 'blocklink' ) );
  248. # Block log link
  249. $tools[] = $sk->makeKnownLinkObj( SpecialPage::getTitleFor( 'Log' ),
  250. wfMsgHtml( 'sp-contributions-blocklog' ), 'type=block&page=' . $nt->getPrefixedUrl() );
  251. }
  252. # Other logs link
  253. $tools[] = $sk->makeKnownLinkObj( SpecialPage::getTitleFor( 'Log' ),
  254. wfMsgHtml( 'log' ), 'user=' . $nt->getPartialUrl() );
  255. # Link to undeleted contributions
  256. $tools[] = $sk->makeKnownLinkObj( SpecialPage::getTitleFor( 'Contributions', $nt->getDBkey() ),
  257. wfMsgHtml( 'contributions' ) );
  258. wfRunHooks( 'ContributionsToolLinks', array( $id, $nt, &$tools ) );
  259. $links = $wgLang->pipeList( $tools );
  260. }
  261. // Old message 'contribsub' had one parameter, but that doesn't work for
  262. // languages that want to put the "for" bit right after $user but before
  263. // $links. If 'contribsub' is around, use it for reverse compatibility,
  264. // otherwise use 'contribsub2'.
  265. if( wfEmptyMsg( 'contribsub', wfMsg( 'contribsub' ) ) ) {
  266. return wfMsgHtml( 'contribsub2', $user, $links );
  267. } else {
  268. return wfMsgHtml( 'contribsub', "$user ($links)" );
  269. }
  270. }
  271. /**
  272. * Generates the namespace selector form with hidden attributes.
  273. * @param $options Array: the options to be included.
  274. */
  275. function getForm( $options ) {
  276. global $wgScript, $wgTitle, $wgRequest;
  277. $options['title'] = $wgTitle->getPrefixedText();
  278. if ( !isset( $options['target'] ) ) {
  279. $options['target'] = '';
  280. } else {
  281. $options['target'] = str_replace( '_' , ' ' , $options['target'] );
  282. }
  283. if ( !isset( $options['namespace'] ) ) {
  284. $options['namespace'] = '';
  285. }
  286. if ( !isset( $options['contribs'] ) ) {
  287. $options['contribs'] = 'user';
  288. }
  289. if ( $options['contribs'] == 'newbie' ) {
  290. $options['target'] = '';
  291. }
  292. $f = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) );
  293. foreach ( $options as $name => $value ) {
  294. if ( in_array( $name, array( 'namespace', 'target', 'contribs' ) ) ) {
  295. continue;
  296. }
  297. $f .= "\t" . Xml::hidden( $name, $value ) . "\n";
  298. }
  299. $f .= Xml::openElement( 'fieldset' ) .
  300. Xml::element( 'legend', array(), wfMsg( 'sp-contributions-search' ) ) .
  301. Xml::tags( 'label', array( 'for' => 'target' ), wfMsgExt( 'sp-contributions-username', 'parseinline' ) ) . ' ' .
  302. Xml::input( 'target', 20, $options['target']) . ' '.
  303. Xml::label( wfMsg( 'namespace' ), 'namespace' ) . ' ' .
  304. Xml::namespaceSelector( $options['namespace'], '' ) . ' ' .
  305. Xml::submitButton( wfMsg( 'sp-contributions-submit' ) ) .
  306. Xml::closeElement( 'fieldset' ) .
  307. Xml::closeElement( 'form' );
  308. return $f;
  309. }
  310. }