* (bug 8919) Suppress paging links and related messages where there are no
[lhc/web/wiklou.git] / includes / SpecialProtectedpages.php
1 <?php
2 /**
3 *
4 * @addtogroup SpecialPage
5 */
6
7 /**
8 *
9 * @addtogroup SpecialPage
10 */
11 class ProtectedPagesForm {
12 function showList( $msg = '' ) {
13 global $wgOut;
14
15 $wgOut->setPagetitle( wfMsg( "protectedpages" ) );
16 if ( "" != $msg ) {
17 $wgOut->setSubtitle( $msg );
18 }
19
20 // Purge expired entries on one in every 10 queries
21 if ( !mt_rand( 0, 10 ) ) {
22 Title::purgeExpiredRestrictions();
23 }
24
25 $pager = new ProtectedPagesPager( $this );
26
27 if ( $pager->getNumRows() ) {
28 $s = $pager->getNavigationBar();
29 $s .= "<ul>" .
30 $pager->getBody() .
31 "</ul>";
32 $s .= $pager->getNavigationBar();
33 } else {
34 $s = '<hr><p>' . wfMsgHTML( 'protectedpagesempty' ) . '</p>';
35 }
36 $wgOut->addHTML( $s );
37 }
38
39 /**
40 * Callback function to output a restriction
41 */
42 function formatRow( $row ) {
43 global $wgUser, $wgLang;
44
45 wfProfileIn( __METHOD__ );
46
47 static $skin=null;
48
49 if( is_null( $skin ) )
50 $skin = $wgUser->getSkin();
51
52 $title = Title::makeTitleSafe( $row->page_namespace, $row->page_title );
53 $link = $skin->makeLinkObj( $title );
54
55 $description_items = array ();
56
57 $protType = wfMsg( 'restriction-level-' . $row->pr_level );
58
59 $description_items[] = $protType;
60
61 $expiry_description = '';
62
63 if ( $row->pr_expiry != 'infinity' && strlen($row->pr_expiry) ) {
64 $expiry = Block::decodeExpiry( $row->pr_expiry );
65
66 $expiry_description = wfMsgForContent( 'protect-expiring', $wgLang->timeanddate( $expiry ) );
67
68 $description_items[] = $expiry_description;
69 }
70
71 wfProfileOut( __METHOD__ );
72
73 return '<li>' . wfSpecialList( $link, implode( $description_items, ', ' ) ) . "</li>\n";
74 }
75 }
76
77 /**
78 *
79 *
80 */
81 class ProtectedPagesPager extends ReverseChronologicalPager {
82 public $mForm, $mConds;
83
84 function __construct( $form, $conds = array() ) {
85 $this->mForm = $form;
86 $this->mConds = $conds;
87 parent::__construct();
88 }
89
90 function getStartBody() {
91 wfProfileIn( __METHOD__ );
92 # Do a link batch query
93 $this->mResult->seek( 0 );
94 $lb = new LinkBatch;
95
96 while ( $row = $this->mResult->fetchObject() ) {
97 $name = str_replace( ' ', '_', $row->page_title );
98 $lb->add( $row->page_namespace, $name );
99 }
100
101 $lb->execute();
102 wfProfileOut( __METHOD__ );
103 return '';
104 }
105
106 function formatRow( $row ) {
107 $block = new Block;
108 return $this->mForm->formatRow( $row );
109 }
110
111 function getQueryInfo() {
112 $conds = $this->mConds;
113 $conds[] = 'pr_expiry>' . $this->mDb->addQuotes( $this->mDb->timestamp() );
114 $conds[] = 'page_id=pr_page';
115 return array(
116 'tables' => array( 'page_restrictions', 'page' ),
117 'fields' => 'page_id, ' . $this->mDb->tableName( 'page_restrictions' ) . '.*, page_title,page_namespace',
118 'conds' => $conds,
119 'options' => array( 'GROUP BY' => 'page_id' ),
120 );
121 }
122
123 function getIndexField() {
124 return 'pr_id';
125 }
126 }
127
128 /**
129 * Constructor
130 */
131 function wfSpecialProtectedpages() {
132
133 list( $limit, $offset ) = wfCheckLimits();
134
135 $ppForm = new ProtectedPagesForm();
136
137 $ppForm->showList();
138 }
139
140 ?>