* (bug 27020) API: Allow title prefix search of logevents (only when not in miser...
authorSam Reed <reedy@users.mediawiki.org>
Sun, 13 Mar 2011 21:43:20 +0000 (21:43 +0000)
committerSam Reed <reedy@users.mediawiki.org>
Sun, 13 Mar 2011 21:43:20 +0000 (21:43 +0000)
Won't work on WMF wiki's as miser mode is enabled, but won't show as an available option either

RELEASE-NOTES
includes/api/ApiQueryLogEvents.php

index 5cb268b..dfa6e38 100644 (file)
@@ -253,6 +253,8 @@ PHP if you have not done so prior to upgrading MediaWiki.
 * (bug 27203) add fato param to list=filearchive
 * (bug 27341) Add drto param to list=deletedrevs
 * (bug 26630) Add api for Special:ActiveUsers
+* (bug 27020) API: Allow title prefix search of logevents (only when not in
+  miser mode)
 
 === Languages updated in 1.18 ===
 
index e0d87d7..fa27761 100644 (file)
@@ -148,6 +148,20 @@ class ApiQueryLogEvents extends ApiQueryBase {
                        $index['logging'] = is_null( $user ) ? 'page_time' : array( 'page_time', 'user_time' );
                }
 
+               global $wgMiserMode;
+               if ( !$wgMiserMode ) {
+                       $prefix = $params['prefix'];
+
+                       if ( !is_null( $prefix ) ) {
+                               $title = Title::newFromText( $prefix );
+                               if ( is_null( $title ) ) {
+                                       $this->dieUsage( "Bad title value '$prefix'", 'param_prefix' );
+                               }
+                               $this->addWhereFld( 'log_namespace',  $title->getNamespace() );
+                               $this->addWhere( 'log_title ' . $db->buildLike( $title->getDBkey(), $db->anyString() ) );
+                       }
+               }
+
                $this->addOption( 'USE INDEX', $index );
 
                // Paranoia: avoid brute force searches (bug 17342)
@@ -334,7 +348,7 @@ class ApiQueryLogEvents extends ApiQueryBase {
 
        public function getAllowedParams() {
                global $wgLogTypes, $wgLogActions;
-               return array(
+               $ret = array(
                        'prop' => array(
                                ApiBase::PARAM_ISMULTI => true,
                                ApiBase::PARAM_DFLT => 'ids|title|type|user|timestamp|comment|details',
@@ -381,11 +395,17 @@ class ApiQueryLogEvents extends ApiQueryBase {
                                ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
                        )
                );
+               global $wgMiserMode;
+               if ( !$wgMiserMode ) {
+                       $ret['prefix'] = null;
+               }
+
+               return $ret;
        }
 
        public function getParamDescription() {
                $p = $this->getModulePrefix();
-               return array(
+               $ret = array(
                        'prop' => array(
                                'Which properties to get',
                                ' ids            - Adds the ID of the log event',
@@ -409,6 +429,13 @@ class ApiQueryLogEvents extends ApiQueryBase {
                        'limit' => 'How many total event entries to return',
                        'tag' => 'Only list event entries tagged with this tag',
                );
+
+               global $wgMiserMode;
+               if ( !$wgMiserMode ) {
+                       $ret['prefix'] = 'Filter entries that start with this prefix';
+               }
+
+               return $ret;
        }
 
        public function getDescription() {
@@ -419,6 +446,7 @@ class ApiQueryLogEvents extends ApiQueryBase {
                return array_merge( parent::getPossibleErrors(), array(
                        array( 'code' => 'param_user', 'info' => 'User name $user not found' ),
                        array( 'code' => 'param_title', 'info' => 'Bad title value \'title\'' ),
+                       array( 'code' => 'param_prefix', 'info' => 'Bad title value \'prefix\'' ),
                ) );
        }