r56251 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r56250‎ | r56251 | r56252 >
Date:02:07, 13 September 2009
Author:churchofemacs
Status:resolved (Comments)
Tags:
Comment:
Creating new function wgOutput->showLogs and including new information on viewing non-existant user pages. In detail:
Instead of copy&pasting the code in different files, there is now one function for showing logs.
This function is currently used for:
* Article and EditPage: Show deletion / move log
* Article: Show rename log on user(talk)pages (NEW in this revision)
* SpecialContributions: Show block log for blocked users
(Note: I removed the condition "log_action != 'revision'". AFAIK it isn't needed, log lists are checked for permission somewhere)

Additionally, on user (talk) pages a note is displayed, if the user does not exist.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/Article.php (modified) (history)
  • /trunk/phase3/includes/EditPage.php (modified) (history)
  • /trunk/phase3/includes/OutputPage.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialContributions.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)
  • /trunk/phase3/maintenance/language/messages.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/language/messages.inc
@@ -540,6 +540,7 @@
541541 'noarticletext-nopermission',
542542 'noarticletextanon',
543543 'userpage-userdoesnotexist',
 544+ 'userpage-userdoesnotexist-view',
544545 'clearyourcache',
545546 'usercssyoucanpreview',
546547 'userjsyoucanpreview',
@@ -588,6 +589,7 @@
589590 'permissionserrorstext-withaction',
590591 'recreate-moveddeleted-warn',
591592 'moveddeleted-notice',
 593+ 'renamed-notice',
592594 'log-fulllog',
593595 'edit-hook-aborted',
594596 'edit-gone-missing',
Index: trunk/phase3/includes/Article.php
@@ -1200,8 +1200,23 @@
12011201 */
12021202 public function showMissingArticle() {
12031203 global $wgOut, $wgRequest, $wgUser;
 1204+
 1205+ # Show info in user (talk) namespace. Does the user exist and if not, has he been renamed.
 1206+ if ( $this->mTitle->getNamespace() == NS_USER || $this->mTitle->getNamespace() == NS_USER_TALK ) {
 1207+ $id = User::idFromName( $this->mTitle->getBaseText() );
 1208+ $ip = User::isIP( $this->mTitle->getBaseText() );
 1209+ if ( $id == 0 && !$ip ) { # User does not exist
 1210+ $wgOut->wrapWikiMsg( '<div class="mw-userpage-userdoesnotexist error">$1</div>',
 1211+ array( 'userpage-userdoesnotexist-view', $this->mTitle->getBaseText() ) );
 1212+
 1213+ # Show rename log because user does not exist.
 1214+ $parent = $this->mTitle->getNsText() . ":" . $this->mTitle->getBaseText();
 1215+ $wgOut->showLogs( $parent, '', array( 'renameuser' ), 'renamed-notice' );
 1216+ }
 1217+
 1218+ }
12041219 # Show delete and move logs
1205 - $this->showLogs();
 1220+ $wgOut->showLogs( $this->mTitle->getPrefixedText(), '', array( 'delete', 'move' ), 'moveddeleted-notice' );
12061221
12071222 # Show error message
12081223 $oldid = $this->getOldID();
@@ -1266,36 +1281,6 @@
12671282 }
12681283 }
12691284
1270 - /**
1271 - * Show an excerpt from the deletion and move logs. To be called from the
1272 - * header section on page views of missing pages.
1273 - */
1274 - public function showLogs() {
1275 - global $wgUser, $wgOut;
1276 - $loglist = new LogEventsList( $wgUser->getSkin(), $wgOut );
1277 - $pager = new LogPager( $loglist, array('move', 'delete'), false,
1278 - $this->mTitle->getPrefixedText(), '', array( "log_action != 'revision'" ) );
1279 - if( $pager->getNumRows() > 0 ) {
1280 - $pager->mLimit = 10;
1281 - $wgOut->addHTML( '<div class="mw-warning-with-logexcerpt">' );
1282 - $wgOut->addWikiMsg( 'moveddeleted-notice' );
1283 - $wgOut->addHTML(
1284 - $loglist->beginLogEventsList() .
1285 - $pager->getBody() .
1286 - $loglist->endLogEventsList()
1287 - );
1288 - if( $pager->getNumRows() > 10 ) {
1289 - $wgOut->addHTML( $wgUser->getSkin()->link(
1290 - SpecialPage::getTitleFor( 'Log' ),
1291 - wfMsgHtml( 'log-fulllog' ),
1292 - array(),
1293 - array( 'page' => $this->mTitle->getPrefixedText() )
1294 - ) );
1295 - }
1296 - $wgOut->addHTML( '</div>' );
1297 - }
1298 - }
1299 -
13001285 /*
13011286 * Should the parser cache be used?
13021287 */
Index: trunk/phase3/includes/EditPage.php
@@ -730,7 +730,7 @@
731731 }
732732 # Give a notice if the user is editing a deleted/moved page...
733733 if ( !$this->mTitle->exists() ) {
734 - $this->showLogs( $wgOut );
 734+ $wgOut->showLogs( $this->mTitle->getPrefixedText(), '', array( 'delete', 'move' ), 'recreate-moveddeleted-warn' );
735735 }
736736 }
737737
@@ -2482,42 +2482,6 @@
24832483 }
24842484
24852485 /**
2486 - * If there are rows in the deletion/move log for this page, show them,
2487 - * along with a nice little note for the user
2488 - *
2489 - * @param OutputPage $out
2490 - */
2491 - protected function showLogs( $out ) {
2492 - global $wgUser;
2493 - $loglist = new LogEventsList( $wgUser->getSkin(), $out );
2494 - $pager = new LogPager( $loglist, array('move', 'delete'), false,
2495 - $this->mTitle->getPrefixedText(), '', array( "log_action != 'revision'" ) );
2496 -
2497 - $count = $pager->getNumRows();
2498 - if ( $count > 0 ) {
2499 - $pager->mLimit = 10;
2500 - $out->addHTML( '<div class="mw-warning-with-logexcerpt">' );
2501 - $out->addWikiMsg( 'recreate-moveddeleted-warn' );
2502 - $out->addHTML(
2503 - $loglist->beginLogEventsList() .
2504 - $pager->getBody() .
2505 - $loglist->endLogEventsList()
2506 - );
2507 - if($count > 10){
2508 - $out->addHTML( $wgUser->getSkin()->link(
2509 - SpecialPage::getTitleFor( 'Log' ),
2510 - wfMsgHtml( 'log-fulllog' ),
2511 - array(),
2512 - array( 'page' => $this->mTitle->getPrefixedText() ) ) );
2513 - }
2514 - $out->addHTML( '</div>' );
2515 - return true;
2516 - }
2517 -
2518 - return false;
2519 - }
2520 -
2521 - /**
25222486 * Attempt submission
25232487 * @return bool false if output is done, true if the rest of the form should be displayed
25242488 */
Index: trunk/phase3/includes/OutputPage.php
@@ -2115,4 +2115,55 @@
21162116 }
21172117 $this->addHTML( $this->parse( $s, /*linestart*/true, /*uilang*/true ) );
21182118 }
 2119+ /*
 2120+ * Show log excerpt. All parameters are optional
 2121+ * (but it makes sense to define at least $page OR $user)
 2122+ * @param String $page Page title for filtering the log
 2123+ * @param String $user Username for filtering the log
 2124+ * @param String $logtypes Log types, like delete, move, etc.
 2125+ * May be a single log type or an array of log types
 2126+ * @param int $numEntries Number of log entries to show at maximum (default: 10)
 2127+ * If there are too many entries, a "View full log" link is displayed
 2128+ * @return boolean Returns true if there was something in the log
 2129+ */
 2130+ public function showLogs( $page = '', $user = '', $logtypes = array(), $msgKey = '' , $numEntries = 10 ) {
 2131+ global $wgUser, $wgOut;
 2132+ $loglist = new LogEventsList( $wgUser->getSkin(), $wgOut );
 2133+ $pager = new LogPager( $loglist, $logtypes, $user, $page);
 2134+ if( $pager->getNumRows() > 0 ) {
 2135+ $pager->mLimit = $numEntries;
 2136+ $wgOut->addHTML( '<div class="mw-warning-with-logexcerpt">' );
 2137+ if ( $msgKey )
 2138+ $wgOut->addWikiMsg( $msgKey );
 2139+ $wgOut->addHTML(
 2140+ $loglist->beginLogEventsList() .
 2141+ $pager->getBody() .
 2142+ $loglist->endLogEventsList()
 2143+ );
 2144+ if( $pager->getNumRows() > $numEntries ) { # Show "Full log" link
 2145+ $urlParam = array();
 2146+ if ( $page != '')
 2147+ $urlParam['page'] = $page;
 2148+ if ( $user != '')
 2149+ $urlParam['user'] = $user;
 2150+ if ( !is_array( $logtypes ) ) # Make it an array, if it isn't
 2151+ $logtypes = array( $logtypes );
 2152+ # If there is exactly one log type, we can link to Special:Log/type
 2153+ if ( count( $logtypes ) == 1 )
 2154+ $urlParam['type'] = $logtypes[0];
 2155+ $wgOut->addHTML( $wgUser->getSkin()->link(
 2156+ SpecialPage::getTitleFor( 'Log' ),
 2157+ wfMsgHtml( 'log-fulllog' ),
 2158+ array(),
 2159+ $urlParam
 2160+ ) );
 2161+
 2162+ }
 2163+ $wgOut->addHTML( '</div>' );
 2164+ return true;
 2165+ }
 2166+ return false;
 2167+ }
 2168+
 2169+
21192170 }
Index: trunk/phase3/includes/specials/SpecialContributions.php
@@ -147,7 +147,7 @@
148148 * @return String: appropriately-escaped HTML to be output literally
149149 */
150150 protected function contributionsSub( $nt, $id ) {
151 - global $wgSysopUserBans, $wgLang, $wgUser;
 151+ global $wgSysopUserBans, $wgLang, $wgUser, $wgOut;
152152
153153 $sk = $wgUser->getSkin();
154154
@@ -223,7 +223,11 @@
224224 wfRunHooks( 'ContributionsToolLinks', array( $id, $nt, &$tools ) );
225225
226226 $links = $wgLang->pipeList( $tools );
227 - $this->showBlock( $nt, $id );
 227+
 228+ // Show a note if the user is blocked and display the last block log entry.
 229+ if ( User::newFromID( $id )->isBlocked() )
 230+ $wgOut->showLogs( $nt->getPrefixedText(), '', array( 'block' ),
 231+ 'sp-contributions-blocked-notice', 1 );
228232 }
229233
230234 // Old message 'contribsub' had one parameter, but that doesn't work for
@@ -238,40 +242,6 @@
239243 }
240244
241245 /**
242 - * Show a note if the user is blocked and display the last block log entry.
243 - * @param Title $title Title object for the target
244 - * @param $userId ID of the user
245 - */
246 - protected function showBlock( $title, $userId ) {
247 - global $wgUser, $wgOut;
248 - if ( !User::newFromID( $userId )->isBlocked() )
249 - return; # User is not blocked, nothing to do here
250 - $loglist = new LogEventsList( $wgUser->getSkin(), $wgOut );
251 - $pager = new LogPager( $loglist, 'block', false, $title->getPrefixedText() );
252 - // Check if there is something in the block log.
253 - // If this is not the case, either the user is not blocked,
254 - // or the account has been hidden via hideuser.
255 - if( $pager->getNumRows() > 0 ) {
256 - $pager->mLimit = 1; # Show only latest log entry.
257 - $wgOut->addHTML( '<div class="mw-warning-with-logexcerpt">' );
258 - $wgOut->addWikiMsg( 'sp-contributions-blocked-notice' );
259 - $wgOut->addHTML(
260 - $loglist->beginLogEventsList() .
261 - $pager->getBody() .
262 - $loglist->endLogEventsList()
263 - );
264 - if( $pager->getNumRows() > $pager->mLimit ) {
265 - $wgOut->addHTML( $wgUser->getSkin()->link(
266 - SpecialPage::getTitleFor( 'Log', 'block' ),
267 - wfMsgHtml( 'log-fulllog' ),
268 - array(),
269 - array( 'page' => $title->getPrefixedText() )
270 - ) );
271 - }
272 - $wgOut->addHTML( '</div>' );
273 - }
274 - }
275 - /**
276246 * Generates the namespace selector form with hidden attributes.
277247 * @param $this->opts Array: the options to be included.
278248 */
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -1253,6 +1253,7 @@
12541254 'noarticletextanon' => '{{int:noarticletext}}', # do not translate or duplicate this message to other languages
12551255 'userpage-userdoesnotexist' => 'User account "$1" is not registered.
12561256 Please check if you want to create/edit this page.',
 1257+'userpage-userdoesnotexist-view' => 'User account "$1" is not registered.',
12571258 'clearyourcache' => "'''Note - After saving, you may have to bypass your browser's cache to see the changes.'''
12581259 '''Mozilla / Firefox / Safari:''' hold ''Shift'' while clicking ''Reload'', or press either ''Ctrl-F5'' or ''Ctrl-R'' (''Command-R'' on a Macintosh);
12591260 '''Konqueror: '''click ''Reload'' or press ''F5'';
@@ -1341,6 +1342,8 @@
13421343 The deletion and move log for this page are provided here for convenience:",
13431344 'moveddeleted-notice' => 'This page has been deleted.
13441345 The deletion and move log for the page are provided below for reference.',
 1346+'renamed-notice' => 'This user has been renamed.
 1347+The rename log is provided below for reference.',
13451348 'log-fulllog' => 'View full log',
13461349 'edit-hook-aborted' => 'Edit aborted by hook.
13471350 It gave no explanation.',
Index: trunk/phase3/RELEASE-NOTES
@@ -222,6 +222,8 @@
223223 excerpt from the block log.
224224 * (bug 19646) New hook: ImgAuthBeforeStream for tests and functionality before
225225 file is streamed to user, but only when using img_auth
 226+* Note on non-existing user and user talk pages if user does not exist and show
 227+ renameuser log if the user has been renamed
226228
227229 === Bug fixes in 1.16 ===
228230

Follow-up revisions

RevisionCommit summaryAuthorDate
r56284Follow-up on r56251 - merging showLogs and showLogExtractchurchofemacs22:21, 13 September 2009
r56317Replace the user rename log display for non-existent userpages with a hook (f...mrzman18:10, 14 September 2009
r56420Follow-up on r56284: LogEventsList::showLogExtract gets associative array for...churchofemacs17:17, 16 September 2009

Comments

#Comment by Aaron Schulz (talk | contribs)   04:34, 13 September 2009

That was not a permission check...it was a condition filter.

#Comment by Mr.Z-man (talk | contribs)   06:45, 13 September 2009

LogEventsList has a showLogExtract() function. I haven't compared them in detail, but I'm guessing this mostly duplicates it.

Also, if its a non-static function in OutputPage, it shouldn't be using $wgOut, it should just be using $this.

#Comment by Church of emacs (talk | contribs)   16:16, 13 September 2009

I'm working on a merger of those two functions. My function differs in the following aspects from showLogExtract: (a) it displays a box and a message, (b) it provides a "Show full log" link if necessary, (c) it does not display anything, if the log is empty. So they have some different design choices, but I think we can control that via additional parameters.

#Comment by Church of emacs (talk | contribs)   22:23, 13 September 2009

In r56284: Restored condition filter, merged showLogs into showLogExtract, changed all references of showLogs to showLogExtract. Is this okay now? :)

#Comment by Mr.Z-man (talk | contribs)   02:19, 14 September 2009

Renameuser is an extension. Rather than adding a reference to it to core, we should probably just provide a hook so that the extension can add the log.

#Comment by Mr.Z-man (talk | contribs)   18:21, 14 September 2009

Did it myself in r56317 + r56318

#Comment by Church of emacs (talk | contribs)   18:32, 14 September 2009

Thanks. Renameuser is such an important function for me that I forgot it isn't included in the core (btw: _why_ isn't it included in the core? ;))

#Comment by Siebrand (talk | contribs)   17:47, 16 September 2009

Status & tagging log