Index: trunk/extensions/LastUserLogin/LastUserLogin_body.php |
— | — | @@ -15,7 +15,7 @@ |
16 | 16 | * @param $par Mixed: parameter passed to the page or null |
17 | 17 | */ |
18 | 18 | public function execute( $par ) { |
19 | | - global $wgUser, $wgOut, $wgLang; |
| 19 | + global $wgUser, $wgOut, $wgLang, $wgRequest; |
20 | 20 | wfLoadExtensionMessages( 'LastUserLogin' ); |
21 | 21 | |
22 | 22 | # If user is blocked, s/he doesn't need to access this page |
— | — | @@ -43,68 +43,66 @@ |
44 | 44 | 'user_email' => 'lastuserlogin_useremail', |
45 | 45 | 'user_touched' => 'lastuserlogin_lastlogin' |
46 | 46 | ); |
| 47 | + |
47 | 48 | |
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 ] ) ) { |
56 | 54 | $orderby = 'user_name'; |
57 | 55 | } |
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' ) { |
67 | 63 | $ordertype = 'ASC'; |
68 | 64 | } |
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 | + |
74 | 71 | $out = '<table width="100%" cellpadding="3" ' . $style . '><tr>'; |
75 | | - |
| 72 | + |
| 73 | + $title = Title::makeTitle( NS_SPECIAL, 'LastUserLogin' ); |
| 74 | + |
76 | 75 | 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>'; |
78 | 77 | } |
79 | | - |
80 | 78 | $out .= "<th $style>" . wfMsg( 'lastuserlogin_daysago' ) . "</th>"; |
| 79 | + |
81 | 80 | $out .= '</tr>'; |
82 | 81 | |
83 | 82 | while ( $row = $dbr->fetchRow( $result ) ) { |
84 | 83 | $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>'; |
92 | 95 | } 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] ) . ' </td>'; |
99 | | - } |
| 96 | + $out .= '<td ' . $style . '>' . htmlspecialchars( $row[$key] ) . ' </td>'; |
100 | 97 | } |
101 | 98 | } |
| 99 | + } |
102 | 100 | $out .= '</tr>'; |
103 | 101 | } |
| 102 | + $dbr->freeResult($res); |
104 | 103 | } |
105 | 104 | |
106 | | - $out .= '</table>'; |
107 | | - $wgOut->addHTML( $out ); |
108 | | - |
| 105 | + $out .= '</table>'; |
| 106 | + $wgOut->addHTML( $out ); |
| 107 | + |
109 | 108 | } |
110 | 109 | } |
111 | | - |