Umherirrender has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/98252


Change subject: Use TablePager on Special:ProtectedTitles
......................................................................

Use TablePager on Special:ProtectedTitles

Also add the timestamp, the reason and the protecting user to the
output, the values are already in the database.

Change-Id: I06f66f44b623dbebf599bd1ea5416820c448d825
---
M RELEASE-NOTES-1.23
M includes/specials/SpecialProtectedtitles.php
M languages/messages/MessagesEn.php
M languages/messages/MessagesQqq.php
M maintenance/language/messages.inc
M resources/mediawiki.special/mediawiki.special.css
6 files changed, 160 insertions(+), 69 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/52/98252/1

diff --git a/RELEASE-NOTES-1.23 b/RELEASE-NOTES-1.23
index 2d89dd2..6d701c7 100644
--- a/RELEASE-NOTES-1.23
+++ b/RELEASE-NOTES-1.23
@@ -39,6 +39,8 @@
   hide their (unrelated) log entries.
 * Added $wgOpenSearchDefaultLimit defining the default number of entries to 
show
   on action=opensearch API call.
+* Special:ProtectedTitles shows now a table. The timestamp, the reason and
+  the protecting user is also shown.
 
 === Bug fixes in 1.23 ===
 * (bug 41759) The "updated since last visit" markers (on history pages, recent
diff --git a/includes/specials/SpecialProtectedtitles.php 
b/includes/specials/SpecialProtectedtitles.php
index 078e7b1..169ad3c 100644
--- a/includes/specials/SpecialProtectedtitles.php
+++ b/includes/specials/SpecialProtectedtitles.php
@@ -37,6 +37,7 @@
        function execute( $par ) {
                $this->setHeaders();
                $this->outputHeader();
+               $this->getOutput()->addModuleStyles( 'mediawiki.special' );
 
                // Purge expired entries on one in every 10 queries
                if ( !mt_rand( 0, 10 ) ) {
@@ -57,72 +58,12 @@
                if ( $pager->getNumRows() ) {
                        $this->getOutput()->addHTML(
                                $pager->getNavigationBar() .
-                                       '<ul>' . $pager->getBody() . '</ul>' .
+                                       $pager->getBody() .
                                        $pager->getNavigationBar()
                        );
                } else {
                        $this->getOutput()->addWikiMsg( 'protectedtitlesempty' 
);
                }
-       }
-
-       /**
-        * Callback function to output a restriction
-        *
-        * @param object $row Database row
-        * @return string
-        */
-       function formatRow( $row ) {
-               wfProfileIn( __METHOD__ );
-
-               static $infinity = null;
-
-               if ( is_null( $infinity ) ) {
-                       $infinity = wfGetDB( DB_SLAVE )->getInfinity();
-               }
-
-               $title = Title::makeTitleSafe( $row->pt_namespace, 
$row->pt_title );
-               if ( !$title ) {
-                       wfProfileOut( __METHOD__ );
-
-                       return Html::rawElement(
-                               'li',
-                               array(),
-                               Html::element(
-                                       'span',
-                                       array( 'class' => 'mw-invalidtitle' ),
-                                       Linker::getInvalidTitleDescription(
-                                               $this->getContext(),
-                                               $row->pt_namespace,
-                                               $row->pt_title
-                                       )
-                               )
-                       ) . "\n";
-               }
-
-               $link = Linker::link( $title );
-               $description_items = array();
-               // Messages: restriction-level-sysop, 
restriction-level-autoconfirmed
-               $protType = $this->msg( 'restriction-level-' . 
$row->pt_create_perm )->escaped();
-               $description_items[] = $protType;
-               $lang = $this->getLanguage();
-               $expiry = strlen( $row->pt_expiry ) ?
-                       $lang->formatExpiry( $row->pt_expiry, TS_MW ) :
-                       $infinity;
-
-               if ( $expiry != $infinity ) {
-                       $user = $this->getUser();
-                       $description_items[] = $this->msg(
-                               'protect-expiring-local',
-                               $lang->userTimeAndDate( $expiry, $user ),
-                               $lang->userDate( $expiry, $user ),
-                               $lang->userTime( $expiry, $user )
-                       )->escaped();
-               }
-
-               wfProfileOut( __METHOD__ );
-
-               // @todo i18n: This should use a comma separator instead of a 
hard coded comma, right?
-               return '<li>' . $lang->specialList( $link, implode( 
$description_items, ', ' ) ) . "</li>\n";
        }
 
        /**
@@ -215,7 +156,7 @@
  * @todo document
  * @ingroup Pager
  */
-class ProtectedTitlesPager extends AlphabeticPager {
+class ProtectedTitlesPager extends TablePager {
        public $mForm, $mConds;
 
        function __construct( $form, $conds = array(), $type, $level, 
$namespace,
@@ -229,14 +170,25 @@
                parent::__construct( $form->getContext() );
        }
 
-       function getStartBody() {
+       function preprocessResults( $result ) {
                wfProfileIn( __METHOD__ );
                # Do a link batch query
-               $this->mResult->seek( 0 );
                $lb = new LinkBatch;
+               $userids = array();
 
-               foreach ( $this->mResult as $row ) {
+               foreach ( $result as $row ) {
                        $lb->add( $row->pt_namespace, $row->pt_title );
+                       $userids[] = $row->pt_user;
+               }
+
+               $userCache = UserCache::singleton();
+               $userCache->doQuery( $userids, array(), __METHOD__ );
+               foreach ( $userids as $userid ) {
+                       $name = $userCache->getProp( $userid, 'name' );
+                       if ( $name !== false ) {
+                               $lb->add( NS_USER, $name );
+                               $lb->add( NS_USER_TALK, $name );
+                       }
                }
 
                $lb->execute();
@@ -252,8 +204,97 @@
                return $this->mForm->getTitle();
        }
 
-       function formatRow( $row ) {
-               return $this->mForm->formatRow( $row );
+       function getFieldNames() {
+               static $headers = null;
+
+               if ( $headers == array() ) {
+                       $headers = array(
+                               'pt_timestamp' => 'protectedtitles-timestamp',
+                               'pt_page' => 'protectedtitles-page',
+                               'pt_expiry' => 'protectedtitles-expiry',
+                               'pt_user' => 'protectedtitles-user',
+                               'pt_params' => 'protectedtitles-params',
+                               'pt_reason' => 'protectedtitles-reason',
+                       );
+                       foreach ( $headers as $key => $val ) {
+                               $headers[$key] = $this->msg( $val )->text();
+                       }
+               }
+
+               return $headers;
+       }
+
+       function formatValue( $name, $value ) {
+               /** @var $row object */
+               $row = $this->mCurrentRow;
+
+               $formatted = '';
+
+               switch ( $name ) {
+                       case 'pt_timestamp':
+                               $formatted = 
$this->getLanguage()->userTimeAndDate( $value, $this->getUser() );
+                               break;
+
+                       case 'pt_page':
+                               $title = Title::makeTitleSafe( 
$row->pt_namespace, $row->pt_title );
+                               if ( !$title ) {
+                                       $formatted = Html::element(
+                                               'span',
+                                               array( 'class' => 
'mw-invalidtitle' ),
+                                               
Linker::getInvalidTitleDescription(
+                                                       $this->getContext(),
+                                                       $row->pt_namespace,
+                                                       $row->pt_title
+                                               )
+                                       );
+                               } else {
+                                       $formatted = Linker::link( $title );
+                               }
+                               break;
+
+                       case 'pt_expiry':
+                               $formatted = 
$this->getLanguage()->formatExpiry( $value, /* User preference timezone */true 
);
+                               $title = Title::makeTitleSafe( 
$row->pt_namespace, $row->pt_title );
+                               if ( $this->getUser()->isAllowed( 'protect' ) 
&& $title ) {
+                                       $changeProtection = Linker::linkKnown(
+                                               $title,
+                                               $this->msg( 'protect_change' 
)->escaped(),
+                                               array(),
+                                               array( 'action' => 'unprotect' )
+                                       );
+                                       $formatted .= ' ' . Html::rawElement(
+                                               'span',
+                                               array( 'class' => 
'mw-protectedtitles-actions' ),
+                                               $this->msg( 'parentheses' 
)->rawParams( $changeProtection )->escaped()
+                                       );
+                               }
+                               break;
+
+                       case 'pt_user':
+                               $username = UserCache::singleton()->getProp( 
$value, 'name' );
+                               if ( $username === false ) {
+                                       $formatted = htmlspecialchars( $value );
+                               } else {
+                                       $formatted = Linker::userLink( $value, 
$username )
+                                               . Linker::userToolLinks( 
$value, $username );
+                               }
+                               break;
+
+                       case 'pt_reason':
+                               $formatted = Linker::formatComment( $value );
+                               break;
+
+                       case 'pt_params':
+                               // Messages: restriction-level-sysop, 
restriction-level-autoconfirmed
+                               $formatted = $this->msg( 'restriction-level-' . 
$row->pt_create_perm )->escaped();
+                               break;
+
+                       default:
+                               $formatted = "Unable to format $name";
+                               break;
+               }
+
+               return $formatted;
        }
 
        /**
@@ -272,13 +313,33 @@
 
                return array(
                        'tables' => 'protected_titles',
-                       'fields' => array( 'pt_namespace', 'pt_title', 
'pt_create_perm',
-                               'pt_expiry', 'pt_timestamp' ),
+                       'fields' => array(
+                               'pt_namespace',
+                               'pt_title',
+                               'pt_create_perm',
+                               'pt_expiry',
+                               'pt_timestamp',
+                               'pt_user',
+                               'pt_reason',
+                       ),
                        'conds' => $conds
                );
        }
 
+       public function getTableClass() {
+               return 'TablePager mw-protectedtitles';
+       }
+
        function getIndexField() {
                return 'pt_timestamp';
        }
+
+       function getDefaultSort() {
+               return 'pt_timestamp';
+       }
+
+       function isFieldSortable( $name ) {
+               // no index for sorting exists
+               return false;
+       }
 }
diff --git a/languages/messages/MessagesEn.php 
b/languages/messages/MessagesEn.php
index 5b48e7d..7cef7c7 100644
--- a/languages/messages/MessagesEn.php
+++ b/languages/messages/MessagesEn.php
@@ -2778,6 +2778,12 @@
 'protectedtitles-summary'         => '', # do not translate or duplicate this 
message to other languages
 'protectedtitlestext'             => 'The following titles are protected from 
creation',
 'protectedtitlesempty'            => 'No titles are currently protected with 
these parameters.',
+'protectedtitles-timestamp'       => 'Timestamp',
+'protectedtitles-page'            => 'Page',
+'protectedtitles-expiry'          => 'Expires',
+'protectedtitles-user'            => 'Protecting user',
+'protectedtitles-params'          => 'Protect parameters',
+'protectedtitles-reason'          => 'Reason',
 'listusers'                       => 'User list',
 'listusers-summary'               => '', # do not translate or duplicate this 
message to other languages
 'listusers-editsonly'             => 'Show only users with edits',
diff --git a/languages/messages/MessagesQqq.php 
b/languages/messages/MessagesQqq.php
index 755ccbe..99d142e 100644
--- a/languages/messages/MessagesQqq.php
+++ b/languages/messages/MessagesQqq.php
@@ -4961,6 +4961,15 @@
 'protectedtitles' => '{{doc-special|ProtectedTitles}}',
 'protectedtitlestext' => 'Shown on top of list of titles on 
[[Special:ProtectedTitles]]. If the list is empty the message 
[[MediaWiki:Protectedtitlesempty]] appears instead of this. See the 
[[mw:Project:Protected_titles|help page on MediaWiki]] for more information.',
 'protectedtitlesempty' => 'Used on [[Special:ProtectedTitles]]. This text 
appears if the list of protected titles is empty. See the 
[[mw:Project:Protected_titles|help page on MediaWiki]] for more information.',
+'protectedtitles-timestamp' => 'This is a column header for dates and times in 
the table on the page [[Special:ProtectedTitles]].
+{{Identical|Timestamp}}',
+'protectedtitles-page' => 'This is a column header in the table on the page 
[[Special:ProtectedTitles]].,
+'protectedtitles-expiry' => 'This is a column header in the table on the page 
[[Special:ProtectedTitles]].
+{{Identical|Expire}}',
+'protectedtitles-user' => 'This is a column header in the table on the page 
[[Special:ProtectedTitles]].',
+'protectedtitles-params' => 'This is a column header in the table on the page 
[[Special:ProtectedTitles]].',
+'protectedtitles-reason' => 'This is a column header in the table on the page 
[[Special:ProtectedTitles]].
+{{Identical|Reason}}',
 'listusers' => '{{doc-special|ListUsers}}',
 'listusers-editsonly' => 'Option in [[Special:ListUsers]].',
 'listusers-creationsort' => 'Option in [[Special:ListUsers]].',
diff --git a/maintenance/language/messages.inc 
b/maintenance/language/messages.inc
index 0451263..8d6f1f0 100644
--- a/maintenance/language/messages.inc
+++ b/maintenance/language/messages.inc
@@ -1833,6 +1833,12 @@
                'protectedtitles-summary',
                'protectedtitlestext',
                'protectedtitlesempty',
+               'protectedtitles-timestamp',
+               'protectedtitles-page',
+               'protectedtitles-expiry',
+               'protectedtitles-user',
+               'protectedtitles-params',
+               'protectedtitles-reason',
                'listusers',
                'listusers-summary',
                'listusers-editsonly',
diff --git a/resources/mediawiki.special/mediawiki.special.css 
b/resources/mediawiki.special/mediawiki.special.css
index 3cd9739..872f92e 100644
--- a/resources/mediawiki.special/mediawiki.special.css
+++ b/resources/mediawiki.special/mediawiki.special.css
@@ -264,6 +264,13 @@
        text-align: right;
 }
 
+/**** Special:ProtectedTitles ****/
+table.mw-protectedtitles span.mw-usertoollinks,
+span.mw-protectedtitles-actions{
+       white-space: nowrap;
+       font-size: 90%;
+}
+
 /**** Special:UserRights ****/
 .mw-userrights-disabled {
        color: #888;

-- 
To view, visit https://gerrit.wikimedia.org/r/98252
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I06f66f44b623dbebf599bd1ea5416820c448d825
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Umherirrender <umherirrender_de...@web.de>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to