r61638 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r61637‎ | r61638 | r61639 >
Date:16:18, 28 January 2010
Author:platonides
Status:deferred
Tags:
Comment:
Use MediaWiki functions for $_REQUEST, database call and linking to the special page.
Modified paths:
  • /trunk/extensions/LastUserLogin/LastUserLogin_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/LastUserLogin/LastUserLogin_body.php
@@ -15,7 +15,7 @@
1616 * @param $par Mixed: parameter passed to the page or null
1717 */
1818 public function execute( $par ) {
19 - global $wgUser, $wgOut, $wgLang;
 19+ global $wgUser, $wgOut, $wgLang, $wgRequest;
2020 wfLoadExtensionMessages( 'LastUserLogin' );
2121
2222 # If user is blocked, s/he doesn't need to access this page
@@ -43,68 +43,66 @@
4444 'user_email' => 'lastuserlogin_useremail',
4545 'user_touched' => 'lastuserlogin_lastlogin'
4646 );
 47+
4748
48 - // Get order by and check it
49 - if ( isset( $_REQUEST['order_by'] ) ) {
50 - if ( isset( $fields[$_REQUEST['order_by']] ) ) {
51 - $orderby = $_REQUEST['order_by'];
52 - } else {
53 - $orderby = 'user_name';
54 - }
55 - } else {
 49+ # Get order by and check it
 50+ $orderby = $wgRequest->getVal('order_by', 'user_name');
 51+
 52+ # Only field names are acceptable
 53+ if ( !isset( $fields[ $orderby ] ) ) {
5654 $orderby = 'user_name';
5755 }
58 -
59 - // Get order type and check it
60 - if ( isset( $_REQUEST['order_type'] ) ) {
61 - if ( $_REQUEST['order_type'] == 'DESC' ) {
62 - $ordertype = $_REQUEST['order_type'];
63 - } else {
64 - $ordertype = 'ASC';
65 - }
66 - } else {
 56+
 57+
 58+ # Get order type and check it
 59+ $ordertype = $wgRequest->getVal('order_type', 'ASC');
 60+
 61+ # $ordertype must be ASC or DESC
 62+ if ( $ordertype != 'DESC' ) {
6763 $ordertype = 'ASC';
6864 }
69 -
70 - $query = "SELECT user_name, user_real_name, user_email, user_touched FROM " . $dbr->tableName( 'user' ) . " ORDER BY " . $orderby . " " . $ordertype;
71 - $ordertype = $ordertype == 'ASC' ? 'DESC' : 'ASC';
72 -
73 - if ( $result = $dbr->doQuery( $query ) ) {
 65+ /* This will get ALL users. Should be paginated. */
 66+
 67+ $result = $dbr->select( 'user', array_keys($fields) , '', __METHOD__, array( 'ORDER BY' => $orderby . " " . $ordertype ) );
 68+ if ( $result !== false ) {
 69+ $ordertype = ($ordertype == 'ASC') ? 'DESC' : 'ASC'; # Invert the order
 70+
7471 $out = '<table width="100%" cellpadding="3" ' . $style . '><tr>';
75 -
 72+
 73+ $title = Title::makeTitle( NS_SPECIAL, 'LastUserLogin' );
 74+
7675 foreach ( $fields as $key => $value ) {
77 - $out .= '<th ' . $style . '><a href="?order_by=' . $key . '&order_type=' . $ordertype . '">' . wfMsg( $value ) . '</a></th>';
 76+ $out .= '<th ' . $style . '><a href="' . $title->escapeLocalURL( array("order_by"=>$key, "order_type"=>$ordertype) ) . '">' . wfMsg( $value ) . '</a></th>';
7877 }
79 -
8078 $out .= "<th $style>" . wfMsg( 'lastuserlogin_daysago' ) . "</th>";
 79+
8180 $out .= '</tr>';
8281
8382 while ( $row = $dbr->fetchRow( $result ) ) {
8483 $out .= '<tr>';
85 - foreach ( $fields as $key => $value ) {
86 -
87 - if ( $key == 'user_touched' ) {
88 - $style = 'style="border:1px solid #000"';
89 - $out .= "<td $style>" . $wgLang->timeanddate( wfTimestamp( TS_MW, $row[$key] ), true ) .
90 - '</td><td style="border: 1px solid #000; text-align:right;">' .
91 - $wgLang->formatNum( round( ( mktime() - wfTimestamp( TS_UNIX, $row[$key] ) ) / 3600 / 24, 2 ), 2 ) . "</td>";
 84+ foreach ( $fields as $key => $value ) {
 85+ if ( $key == 'user_touched' ) {
 86+ $style = 'style="border:1px solid #000"';
 87+ $out .= "<td $style>" . $wgLang->timeanddate( wfTimestamp( TS_MW, $row[$key] ), true ) .
 88+ '</td><td style="border: 1px solid #000; text-align:right;">' .
 89+ $wgLang->formatNum( round( ( mktime() - wfTimestamp( TS_UNIX, $row[$key] ) ) / 3600 / 24, 2 ), 2 ) . "</td>";
 90+ } else {
 91+ if ( $key == 'user_name' ) {
 92+ $userPage = Title::makeTitle( NS_USER, $row[$key] );
 93+ $name = $skin->makeLinkObj( $userPage, htmlspecialchars( $userPage->getText() ) );
 94+ $out .= '<td ' . $style . '>' . $name . '</a></td>';
9295 } else {
93 - if ( $key == 'user_name' ) {
94 - $userPage = Title::makeTitle( NS_USER, htmlspecialchars( $row[$key] ) );
95 - $name = $skin->makeLinkObj( $userPage, htmlspecialchars( $userPage->getText() ) );
96 - $out .= '<td ' . $style . '>' . $name . '</a></td>';
97 - } else {
98 - $out .= '<td ' . $style . '>' . htmlspecialchars( $row[$key] ) . '&nbsp;</td>';
99 - }
 96+ $out .= '<td ' . $style . '>' . htmlspecialchars( $row[$key] ) . '&nbsp;</td>';
10097 }
10198 }
 99+ }
102100 $out .= '</tr>';
103101 }
 102+ $dbr->freeResult($res);
104103 }
105104
106 - $out .= '</table>';
107 - $wgOut->addHTML( $out );
108 -
 105+ $out .= '</table>';
 106+ $wgOut->addHTML( $out );
 107+
109108 }
110109 }
111 -

Status & tagging log