Index: branches/robchurch/pr_timestamp/includes/SpecialProtectedpages.php |
— | — | @@ -39,13 +39,13 @@ |
40 | 40 | Title::purgeExpiredRestrictions(); |
41 | 41 | } |
42 | 42 | |
43 | | - $type = $wgRequest->getVal( 'type' ); |
| 43 | + $type = $wgRequest->getVal( 'type', 'edit' ); |
44 | 44 | $level = $wgRequest->getVal( 'level' ); |
45 | 45 | $sizetype = $wgRequest->getVal( 'sizetype' ); |
46 | 46 | $size = $wgRequest->getIntOrNull( 'size' ); |
47 | 47 | $NS = $wgRequest->getIntOrNull( 'namespace' ); |
48 | 48 | |
49 | | - $pager = new ProtectedPagesPager( $this, array(), $type, $level, $NS, $sizetype, $size ); |
| 49 | + $pager = new ProtectedPagesPager( $type, $level, $NS, $sizetype, $size ); |
50 | 50 | |
51 | 51 | $wgOut->addHTML( $this->showOptions( $NS, $type, $level, $sizetype, $size ) ); |
52 | 52 | |
— | — | @@ -61,46 +61,6 @@ |
62 | 62 | } |
63 | 63 | |
64 | 64 | /** |
65 | | - * Formatting callback |
66 | | - * |
67 | | - * @param object $row Result row |
68 | | - * @return string |
69 | | - */ |
70 | | - public function formatRow( $row ) { |
71 | | - global $wgUser, $wgLang; |
72 | | - wfProfileIn( __METHOD__ ); |
73 | | - |
74 | | - $skin = $wgUser->getSkin(); |
75 | | - |
76 | | - # Date and time |
77 | | - $timestamp = $row->pr_timestamp |
78 | | - ? '(' . $wgLang->timeAndDate( $row->pr_timestamp ) . ')' |
79 | | - : ''; |
80 | | - |
81 | | - # Page link and action text |
82 | | - $title = Title::makeTitleSafe( $row->page_namespace, $row->page_title ); |
83 | | - $page = $skin->makeLinkObj( $title ); |
84 | | - |
85 | | - # Size indicator |
86 | | - $size = $row->page_len |
87 | | - ? '<small>' . wfMsgHtml( 'historysize', $wgLang->formatNum( $row->page_len ) ) . '</small> ' |
88 | | - : ''; |
89 | | - |
90 | | - # Protection level |
91 | | - $level = wfMsgHtml( 'restriction-level-' . $row->pr_level ); |
92 | | - |
93 | | - # Expiration |
94 | | - $expire = ''; |
95 | | - if( $row->pr_expiry && $row->pr_expiry != 'infinity' ) { |
96 | | - $exptime = Block::decodeExpiry( $row->pr_expiry ); |
97 | | - $expire = ', ' . wfMsgHtml( 'protect-expiring', $wgLang->timeAndDate( $exptime ) ); |
98 | | - } |
99 | | - |
100 | | - wfProfileOut( __METHOD__ ); |
101 | | - return "<li>{$timestamp} {$page} {$size}({$level}{$expire})</li>"; |
102 | | - } |
103 | | - |
104 | | - /** |
105 | 65 | * Build the filtering option panel |
106 | 66 | * |
107 | 67 | * @param int $namespace Pre-select namespace |
— | — | @@ -217,70 +177,5 @@ |
218 | 178 | |
219 | 179 | } |
220 | 180 | |
221 | | -/** |
222 | | - * @todo document |
223 | | - * @addtogroup Pager |
224 | | - */ |
225 | | -class ProtectedPagesPager extends AlphabeticPager { |
226 | | - public $mForm, $mConds; |
227 | 181 | |
228 | | - function __construct( $form, $conds = array(), $type, $level, $namespace, $sizetype='', $size=0 ) { |
229 | | - $this->mForm = $form; |
230 | | - $this->mConds = $conds; |
231 | | - $this->type = ( $type ) ? $type : 'edit'; |
232 | | - $this->level = $level; |
233 | | - $this->namespace = $namespace; |
234 | | - $this->sizetype = $sizetype; |
235 | | - $this->size = intval($size); |
236 | | - parent::__construct(); |
237 | | - } |
238 | | - |
239 | | - function getStartBody() { |
240 | | - wfProfileIn( __METHOD__ ); |
241 | | - # Do a link batch query |
242 | | - $this->mResult->seek( 0 ); |
243 | | - $lb = new LinkBatch; |
244 | | - |
245 | | - while ( $row = $this->mResult->fetchObject() ) { |
246 | | - $lb->add( $row->page_namespace, $row->page_title ); |
247 | | - } |
248 | | - |
249 | | - $lb->execute(); |
250 | | - wfProfileOut( __METHOD__ ); |
251 | | - return ''; |
252 | | - } |
253 | | - |
254 | | - function formatRow( $row ) { |
255 | | - $block = new Block; |
256 | | - return $this->mForm->formatRow( $row ); |
257 | | - } |
258 | | - |
259 | | - function getQueryInfo() { |
260 | | - $conds = $this->mConds; |
261 | | - $conds[] = 'pr_expiry>' . $this->mDb->addQuotes( $this->mDb->timestamp() ); |
262 | | - $conds[] = 'page_id=pr_page'; |
263 | | - $conds[] = 'pr_type=' . $this->mDb->addQuotes( $this->type ); |
264 | | - |
265 | | - if( $this->sizetype=='min' ) { |
266 | | - $conds[] = 'page_len>=' . $this->size; |
267 | | - } else if( $this->sizetype=='max' ) { |
268 | | - $conds[] = 'page_len<=' . $this->size; |
269 | | - } |
270 | | - |
271 | | - if( $this->level ) |
272 | | - $conds[] = 'pr_level=' . $this->mDb->addQuotes( $this->level ); |
273 | | - if( !is_null($this->namespace) ) |
274 | | - $conds[] = 'page_namespace=' . $this->mDb->addQuotes( $this->namespace ); |
275 | | - return array( |
276 | | - 'tables' => array( 'page_restrictions', 'page' ), |
277 | | - 'fields' => 'pr_id,page_namespace,page_title,page_len,pr_type,pr_level,pr_timestamp,pr_expiry', |
278 | | - 'conds' => $conds |
279 | | - ); |
280 | | - } |
281 | | - |
282 | | - function getIndexField() { |
283 | | - return 'pr_id'; |
284 | | - } |
285 | | -} |
286 | | - |
287 | 182 | ?> |
Index: branches/robchurch/pr_timestamp/includes/ProtectedPagesPager.php |
— | — | @@ -0,0 +1,142 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Pager for Special:Protectedpages |
| 6 | + * |
| 7 | + * @addtogroup Pager |
| 8 | + */ |
| 9 | +class ProtectedPagesPager extends AlphabeticPager { |
| 10 | + |
| 11 | + /** |
| 12 | + * Filtering options |
| 13 | + */ |
| 14 | + private $type = ''; |
| 15 | + private $level = ''; |
| 16 | + private $namespace = null; |
| 17 | + private $sizetype = ''; |
| 18 | + private $size = 0; |
| 19 | + |
| 20 | + /** |
| 21 | + * Constructor |
| 22 | + * |
| 23 | + * @param string $type |
| 24 | + * @param string $level |
| 25 | + * @param int $namespace |
| 26 | + * @param string $sizetype |
| 27 | + * @param int $size |
| 28 | + */ |
| 29 | + public function __construct( $type, $level, $namespace, $sizetype = '', $size = 0 ) { |
| 30 | + parent::__construct(); |
| 31 | + $this->type = $type; |
| 32 | + $this->level = $level; |
| 33 | + $this->namespace = $namespace; |
| 34 | + $this->sizetype = $sizetype; |
| 35 | + $this->size = $size; |
| 36 | + } |
| 37 | + |
| 38 | + /** |
| 39 | + * Pre-process results; do a batch existence check on all pages |
| 40 | + * and their associated talk pages |
| 41 | + * |
| 42 | + * @param ResultWrapper $result Result wrapper |
| 43 | + */ |
| 44 | + protected function preprocessResults( $result ) { |
| 45 | + $batch = new LinkBatch(); |
| 46 | + while( $row = $result->fetchObject() ) { |
| 47 | + $title = Title::makeTitleSafe( $row->page_namespace, $row->page_title ); |
| 48 | + if( $title instanceof Title ) { |
| 49 | + $batch->addObj( $title->getSubjectPage() ); |
| 50 | + $batch->addObj( $title->getTalkPage() ); |
| 51 | + } |
| 52 | + } |
| 53 | + $batch->execute(); |
| 54 | + $result->rewind(); |
| 55 | + } |
| 56 | + |
| 57 | + /** |
| 58 | + * Format a single result row |
| 59 | + * |
| 60 | + * @param object $row Result row |
| 61 | + * @return string |
| 62 | + */ |
| 63 | + public function formatRow( $row ) { |
| 64 | + global $wgUser, $wgLang; |
| 65 | + wfProfileIn( __METHOD__ ); |
| 66 | + |
| 67 | + $skin = $wgUser->getSkin(); |
| 68 | + |
| 69 | + # Date and time |
| 70 | + $timestamp = $row->pr_timestamp |
| 71 | + ? '(' . $wgLang->timeAndDate( $row->pr_timestamp ) . ')' |
| 72 | + : ''; |
| 73 | + |
| 74 | + # Page and talk page links |
| 75 | + $title = Title::makeTitleSafe( $row->page_namespace, $row->page_title ); |
| 76 | + $page = $skin->makeLinkObj( $title ); |
| 77 | + if( !$title->isTalkPage() ) |
| 78 | + $page .= ' (' . $skin->makeLinkObj( $title->getTalkPage(), wfMsgHtml( 'talkpagelinktext' ) ) . ')'; |
| 79 | + |
| 80 | + # Size indicator |
| 81 | + $size = $row->page_len |
| 82 | + ? '<small>' . wfMsgHtml( 'historysize', $wgLang->formatNum( $row->page_len ) ) . '</small> ' |
| 83 | + : ''; |
| 84 | + |
| 85 | + # Protection level |
| 86 | + $level = wfMsgHtml( 'restriction-level-' . $row->pr_level ); |
| 87 | + |
| 88 | + # Expiration |
| 89 | + $expire = ''; |
| 90 | + if( $row->pr_expiry && $row->pr_expiry != 'infinity' ) { |
| 91 | + $exptime = Block::decodeExpiry( $row->pr_expiry ); |
| 92 | + $expire = ', ' . wfMsgHtml( 'protect-expiring', $wgLang->timeAndDate( $exptime ) ); |
| 93 | + } |
| 94 | + |
| 95 | + wfProfileOut( __METHOD__ ); |
| 96 | + return "<li>{$timestamp} {$page} {$size}({$level}{$expire})</li>"; |
| 97 | + } |
| 98 | + |
| 99 | + /** |
| 100 | + * Get query information |
| 101 | + * |
| 102 | + * @return array |
| 103 | + */ |
| 104 | + public function getQueryInfo() { |
| 105 | + // Core conditions |
| 106 | + $conds = array( |
| 107 | + 'pr_expiry > ' . $this->mDb->addQuotes( $this->mDb->timestamp() ), |
| 108 | + 'page_id = pr_page', |
| 109 | + 'pr_type = ' . $this->mDb->addQuotes( $this->type ), |
| 110 | + ); |
| 111 | + |
| 112 | + // Protection level |
| 113 | + if( $this->level ) |
| 114 | + $conds['pr_level'] = $this->level; |
| 115 | + |
| 116 | + // Namespace |
| 117 | + if( !is_null( $this->namespace ) ) |
| 118 | + $conds['page_namespace'] = $this->namespace; |
| 119 | + |
| 120 | + // Size limit |
| 121 | + if( $this->sizetype == 'min' ) { |
| 122 | + $conds[] = 'page_len >= ' . intval( $this->size ); |
| 123 | + } elseif( $this->sizetype == 'max' ) { |
| 124 | + $conds[] = 'page_len <= ' . intval( $this->size ); |
| 125 | + } |
| 126 | + |
| 127 | + return array( |
| 128 | + 'tables' => array( 'page_restrictions', 'page' ), |
| 129 | + 'fields' => 'pr_id,page_namespace,page_title,page_len,pr_type,pr_level,pr_timestamp,pr_expiry', |
| 130 | + 'conds' => $conds |
| 131 | + ); |
| 132 | + } |
| 133 | + |
| 134 | + /** |
| 135 | + * Get the name of the paging column |
| 136 | + * |
| 137 | + * @return string |
| 138 | + */ |
| 139 | + public function getIndexField() { |
| 140 | + return 'pr_id'; |
| 141 | + } |
| 142 | + |
| 143 | +} |
\ No newline at end of file |
Property changes on: branches/robchurch/pr_timestamp/includes/ProtectedPagesPager.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 144 | + native |
Index: branches/robchurch/pr_timestamp/includes/AutoLoader.php |
— | — | @@ -201,7 +201,7 @@ |
202 | 202 | 'IncludableSpecialPage' => 'includes/SpecialPage.php', |
203 | 203 | 'PopularPagesPage' => 'includes/SpecialPopularpages.php', |
204 | 204 | 'SpecialProtectedPages' => 'includes/SpecialProtectedpages.php', |
205 | | - 'ProtectedPagesPager' => 'includes/Specialprotectedpages.php', |
| 205 | + 'ProtectedPagesPager' => 'includes/ProtectedPagesPager.php', |
206 | 206 | 'PreferencesForm' => 'includes/SpecialPreferences.php', |
207 | 207 | 'SpecialPrefixindex' => 'includes/SpecialPrefixindex.php', |
208 | 208 | 'PasswordResetForm' => 'includes/SpecialResetpass.php', |
Index: branches/robchurch/pr_timestamp/includes/Pager.php |
— | — | @@ -106,6 +106,9 @@ |
107 | 107 | $this->mResult = $this->reallyDoQuery( $this->mOffset, $queryLimit, $descending ); |
108 | 108 | $this->extractResultInfo( $this->mOffset, $queryLimit, $this->mResult ); |
109 | 109 | $this->mQueryDone = true; |
| 110 | + |
| 111 | + $this->preprocessResults( $this->mResult ); |
| 112 | + $this->mResult->rewind(); // Paranoia |
110 | 113 | |
111 | 114 | wfProfileOut( $fname ); |
112 | 115 | } |
— | — | @@ -190,6 +193,13 @@ |
191 | 194 | } |
192 | 195 | |
193 | 196 | /** |
| 197 | + * Pre-process results; useful for performing batch existence checks, etc. |
| 198 | + * |
| 199 | + * @param ResultWrapper $result Result wrapper |
| 200 | + */ |
| 201 | + protected function preprocessResults( $result ) {} |
| 202 | + |
| 203 | + /** |
194 | 204 | * Get the formatted result list. Calls getStartBody(), formatRow() and |
195 | 205 | * getEndBody(), concatenates the results and returns them. |
196 | 206 | */ |