r23340 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23339‎ | r23340 | r23341 >
Date:01:59, 25 June 2007
Author:robchurch
Status:old
Tags:
Comment:
* Fix various issues with namespace selector, namespace filtering, etc. when no namespace specified
* Reports can now override Report::getDefaultNamespace() to set a specific default
* Include content namespaces in UncategorisedPagesReport
Modified paths:
  • /branches/robchurch/reports/includes/reports/CachedReportPager.php (modified) (history)
  • /branches/robchurch/reports/includes/reports/Report.php (modified) (history)
  • /branches/robchurch/reports/includes/reports/ReportPager.php (modified) (history)
  • /branches/robchurch/reports/includes/reports/UncategorisedPagesReport.php (modified) (history)

Diff [purge]

Index: branches/robchurch/reports/includes/reports/ReportPager.php
@@ -43,7 +43,7 @@
4444 # Base conditions
4545 $conds = $this->report->getExtraConditions( $this->mDb );
4646 if( ( $ns = $this->getNamespace() ) !== false )
47 - $conds[] = $this->report->getNamespaceClause( $ns );
 47+ $conds[] = $this->report->getNamespaceClause( intval( $ns ) );
4848 if( !$this->getRedirects() || $this->report->excludeRedirects() )
4949 $conds[] = $this->report->getRedirectClause();
5050
@@ -136,18 +136,13 @@
137137 }
138138
139139 /**
140 - * Get the namespace to filter results for
141 - * (Returns false if all namespaces should be used)
 140+ * Get the namespace to filter results for, or false
 141+ * to omit filtering
142142 *
143143 * @return mixed
144144 */
145145 public function getNamespace() {
146 - if( $this->report->allowNamespaceFilter() ) {
147 - $ns = $this->mRequest->getVal( 'namespace', '' );
148 - return $ns !== '' ? intval( $ns ) : false;
149 - } else {
150 - return false;
151 - }
 146+ return $this->report->getNamespace();
152147 }
153148
154149 /**
Index: branches/robchurch/reports/includes/reports/Report.php
@@ -80,6 +80,18 @@
8181 }
8282
8383 /**
 84+ * Get the default namespace to filter on;
 85+ * false to indicate no filtering per default
 86+ *
 87+ * @return bool
 88+ */
 89+ public function getDefaultNamespace() {
 90+ return ( $ns = $this->getApplicableNamespaces() ) !== false
 91+ ? $ns[0]
 92+ : false;
 93+ }
 94+
 95+ /**
8496 * Is there a more appropriate title to show when
8597 * a particular namespace is selected? Return the
8698 * message name here
@@ -181,11 +193,12 @@
182194 public function execute( $par = false ) {
183195 global $wgOut, $wgRequest, $wgLang;
184196 $this->setHeaders();
 197+ # Namespace and redirect filter values
 198+ $namespace = $this->getNamespace();
 199+ $redirects = $wgRequest->getCheck( 'redirects' );
185200 # Per-namespace title variants
186 - if( ( $ns = $wgRequest->getVal( 'namespace', false ) ) !== false ) {
187 - if( ( $msg = $this->getNamespaceTitleVariant( $ns ) ) !== false )
188 - $wgOut->setPageTitle( wfMsg( $msg ) );
189 - }
 201+ if( ( $msg = $this->getNamespaceTitleVariant( $namespace ) ) !== false )
 202+ $wgOut->setPageTitle( wfMsg( $msg ) );
190203 # Cache information, etc.
191204 $pager = $this->getPager();
192205 if( $this->isDisabled() ) {
@@ -194,12 +207,7 @@
195208 $wgOut->addHtml( $this->getCacheInfo() );
196209 }
197210 # Filtering UI
198 - $wgOut->addHtml(
199 - $this->buildFilterUI(
200 - $wgRequest->getVal( 'namespace', '' ),
201 - $wgRequest->getCheck( 'redirects' )
202 - )
203 - );
 211+ $wgOut->addHtml( $this->buildFilterUI( $namespace, $redirects ) );
204212 # Report results
205213 if( ( $count = $pager->getNumRows() ) > 0 ) {
206214 $wgOut->addHtml( $pager->getNavigationBar() );
@@ -221,6 +229,23 @@
222230 ? new CachedReportPager( $this )
223231 : new ReportPager( $this );
224232 }
 233+
 234+ /**
 235+ * Get the namespace to filter results for, or false
 236+ * to omit filtering
 237+ *
 238+ * @return mixed
 239+ */
 240+ public function getNamespace() {
 241+ global $wgRequest;
 242+ if( $this->allowNamespaceFilter() ) {
 243+ return $wgRequest->getCheck( 'namespace' )
 244+ ? $wgRequest->getInt( 'namespace' )
 245+ : $this->getDefaultNamespace();
 246+ } else {
 247+ return false;
 248+ }
 249+ }
225250
226251 /**
227252 * Build the filtering form for the top of the page
@@ -241,7 +266,6 @@
242267 # Namespace selector
243268 if( $this->allowNamespaceFilter() ) {
244269 $form .= '<tr><td>' . Xml::label( wfMsg( 'report-filter-namespace' ), 'namespace' ) . '</td>';
245 - #$form .= '<td>' . Xml::namespaceSelector( $namespace, '' ) . '</td></tr>';
246270 $form .= '<td>' . $this->buildNamespaceSelector( $namespace ) . '</td></tr>';
247271 }
248272 # Redirect toggle
@@ -271,7 +295,7 @@
272296 $html = Xml::openElement( 'select', array( 'id' => 'namespace', 'name' => 'namespace' ) );
273297 $namespaces = $this->getApplicableNamespaces();
274298 if( $namespaces === false ) {
275 - $html .= Xml::option( wfMsg( 'report-filter-namespace-all' ), '' );
 299+ $html .= Xml::option( wfMsg( 'report-filter-namespace-all' ), '', $select === false );
276300 $namespaces = array_keys( $wgContLang->getNamespaces() );
277301 }
278302 foreach( $namespaces as $index ) {
@@ -279,7 +303,7 @@
280304 $label = $index != 0
281305 ? $wgContLang->getFormattedNsText( $index )
282306 : wfMsg( 'blanknamespace' );
283 - $html .= Xml::option( $label, $index, $select !== '' && $select == $index );
 307+ $html .= Xml::option( $label, $index, $select === $index );
284308 }
285309 }
286310 $html .= Xml::closeElement( 'select' );
Index: branches/robchurch/reports/includes/reports/CachedReportPager.php
@@ -28,7 +28,7 @@
2929 # Base conditions
3030 $conds['rp_report'] = $this->report->getName();
3131 if( ( $ns = $this->getNamespace() ) !== false )
32 - $conds['rp_namespace'] = $ns;
 32+ $conds['rp_namespace'] = intval( $ns );
3333 if( !$this->getRedirects() || $this->report->excludeRedirects() )
3434 $conds['rp_redirect'] = 0;
3535
Index: branches/robchurch/reports/includes/reports/UncategorisedPagesReport.php
@@ -46,7 +46,7 @@
4747 NS_IMAGE,
4848 NS_TEMPLATE,
4949 NS_CATEGORY
50 - );
 50+ ) + $GLOBALS['wgContentNamespaces'];
5151 }
5252
5353 /**

Status & tagging log