]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blobdiff - includes/api/ApiQueryLinks.php
MediaWiki 1.16.0
[autoinstallsdev/mediawiki.git] / includes / api / ApiQueryLinks.php
index 94b7980c9b15721b038d1770259a1235350497e9..52dfd591daf1566050ca23029a4e6259f42a6115 100644 (file)
@@ -23,9 +23,9 @@
  * http://www.gnu.org/copyleft/gpl.html
  */
 
-if (!defined('MEDIAWIKI')) {
+if ( !defined( 'MEDIAWIKI' ) ) {
        // Eclipse helper - will be ignored in production
-       require_once ("ApiQueryBase.php");
+       require_once ( "ApiQueryBase.php" );
 }
 
 /**
@@ -40,9 +40,9 @@ class ApiQueryLinks extends ApiQueryGeneratorBase {
 
        private $table, $prefix, $description;
 
-       public function __construct($query, $moduleName) {
+       public function __construct( $query, $moduleName ) {
 
-               switch ($moduleName) {
+               switch ( $moduleName ) {
                        case self::LINKS :
                                $this->table = 'pagelinks';
                                $this->prefix = 'pl';
@@ -54,10 +54,10 @@ class ApiQueryLinks extends ApiQueryGeneratorBase {
                                $this->description = 'template';
                                break;
                        default :
-                               ApiBase :: dieDebug(__METHOD__, 'Unknown module name');
+                               ApiBase :: dieDebug( __METHOD__, 'Unknown module name' );
                }
 
-               parent :: __construct($query, $moduleName, $this->prefix);
+               parent :: __construct( $query, $moduleName, $this->prefix );
        }
 
        public function execute() {
@@ -68,101 +68,101 @@ class ApiQueryLinks extends ApiQueryGeneratorBase {
                return 'public';
        }
 
-       public function executeGenerator($resultPageSet) {
-               $this->run($resultPageSet);
+       public function executeGenerator( $resultPageSet ) {
+               $this->run( $resultPageSet );
        }
 
-       private function run($resultPageSet = null) {
+       private function run( $resultPageSet = null ) {
 
-               if ($this->getPageSet()->getGoodTitleCount() == 0)
+               if ( $this->getPageSet()->getGoodTitleCount() == 0 )
                        return; // nothing to do
 
                $params = $this->extractRequestParams();
 
-               $this->addFields(array (
+               $this->addFields( array (
                        $this->prefix . '_from AS pl_from',
                        $this->prefix . '_namespace AS pl_namespace',
                        $this->prefix . '_title AS pl_title'
-               ));
-
-               $this->addTables($this->table);
-               $this->addWhereFld($this->prefix . '_from', array_keys($this->getPageSet()->getGoodTitles()));
-               $this->addWhereFld($this->prefix . '_namespace', $params['namespace']);
-
-               if(!is_null($params['continue'])) {
-                       $cont = explode('|', $params['continue']);
-                       if(count($cont) != 3)
-                               $this->dieUsage("Invalid continue param. You should pass the " .
-                                       "original value returned by the previous query", "_badcontinue");
-                       $plfrom = intval($cont[0]);
-                       $plns = intval($cont[1]);
-                       $pltitle = $this->getDB()->strencode($this->titleToKey($cont[2]));
-                       $this->addWhere("{$this->prefix}_from > $plfrom OR ".
-                                       "({$this->prefix}_from = $plfrom AND ".
-                                       "({$this->prefix}_namespace > $plns OR ".
-                                       "({$this->prefix}_namespace = $plns AND ".
-                                       "{$this->prefix}_title >= '$pltitle')))");
+               ) );
+
+               $this->addTables( $this->table );
+               $this->addWhereFld( $this->prefix . '_from', array_keys( $this->getPageSet()->getGoodTitles() ) );
+               $this->addWhereFld( $this->prefix . '_namespace', $params['namespace'] );
+
+               if ( !is_null( $params['continue'] ) ) {
+                       $cont = explode( '|', $params['continue'] );
+                       if ( count( $cont ) != 3 )
+                               $this->dieUsage( "Invalid continue param. You should pass the " .
+                                       "original value returned by the previous query", "_badcontinue" );
+                       $plfrom = intval( $cont[0] );
+                       $plns = intval( $cont[1] );
+                       $pltitle = $this->getDB()->strencode( $this->titleToKey( $cont[2] ) );
+                       $this->addWhere( "{$this->prefix}_from > $plfrom OR " .
+                                       "({$this->prefix}_from = $plfrom AND " .
+                                       "({$this->prefix}_namespace > $plns OR " .
+                                       "({$this->prefix}_namespace = $plns AND " .
+                                       "{$this->prefix}_title >= '$pltitle')))" );
                }
 
-               # Here's some MySQL craziness going on: if you use WHERE foo='bar'
-               # and later ORDER BY foo MySQL doesn't notice the ORDER BY is pointless
-               # but instead goes and filesorts, because the index for foo was used
-               # already. To work around this, we drop constant fields in the WHERE
-               # clause from the ORDER BY clause
+               // Here's some MySQL craziness going on: if you use WHERE foo='bar'
+               // and later ORDER BY foo MySQL doesn't notice the ORDER BY is pointless
+               // but instead goes and filesorts, because the index for foo was used
+               // already. To work around this, we drop constant fields in the WHERE
+               // clause from the ORDER BY clause
                $order = array();
-               if(count($this->getPageSet()->getGoodTitles()) != 1)
+               if ( count( $this->getPageSet()->getGoodTitles() ) != 1 )
                        $order[] = "{$this->prefix}_from";
-               if(count($params['namespace']) != 1)
+               if ( count( $params['namespace'] ) != 1 )
                        $order[] = "{$this->prefix}_namespace";
+
                $order[] = "{$this->prefix}_title";
-               $this->addOption('ORDER BY', implode(", ", $order));
-               $this->addOption('USE INDEX', "{$this->prefix}_from");
-               $this->addOption('LIMIT', $params['limit'] + 1);
+               $this->addOption( 'ORDER BY', implode( ", ", $order ) );
+               $this->addOption( 'USE INDEX', "{$this->prefix}_from" );
+               $this->addOption( 'LIMIT', $params['limit'] + 1 );
 
                $db = $this->getDB();
-               $res = $this->select(__METHOD__);
+               $res = $this->select( __METHOD__ );
 
-               if (is_null($resultPageSet)) {
+               if ( is_null( $resultPageSet ) ) {
                        $count = 0;
-                       while ($row = $db->fetchObject($res)) {
-                               if(++$count > $params['limit']) {
+                       while ( $row = $db->fetchObject( $res ) ) {
+                               if ( ++$count > $params['limit'] ) {
                                        // We've reached the one extra which shows that
                                        // there are additional pages to be had. Stop here...
-                                       $this->setContinueEnumParameter('continue',
+                                       $this->setContinueEnumParameter( 'continue',
                                                "{$row->pl_from}|{$row->pl_namespace}|" .
-                                               $this->keyToTitle($row->pl_title));
+                                               $this->keyToTitle( $row->pl_title ) );
                                        break;
                                }
                                $vals = array();
-                               ApiQueryBase :: addTitleInfo($vals, Title :: makeTitle($row->pl_namespace, $row->pl_title));
-                               $fit = $this->addPageSubItem($row->pl_from, $vals);
-                               if(!$fit)
+                               ApiQueryBase :: addTitleInfo( $vals, Title :: makeTitle( $row->pl_namespace, $row->pl_title ) );
+                               $fit = $this->addPageSubItem( $row->pl_from, $vals );
+                               if ( !$fit )
                                {
-                                       $this->setContinueEnumParameter('continue',
+                                       $this->setContinueEnumParameter( 'continue',
                                                "{$row->pl_from}|{$row->pl_namespace}|" .
-                                               $this->keyToTitle($row->pl_title));
+                                               $this->keyToTitle( $row->pl_title ) );
                                        break;
                                }
                        }
                } else {
-
                        $titles = array();
                        $count = 0;
-                       while ($row = $db->fetchObject($res)) {
-                               if(++$count > $params['limit']) {
+                       while ( $row = $db->fetchObject( $res ) ) {
+                               if ( ++$count > $params['limit'] ) {
                                        // We've reached the one extra which shows that
                                        // there are additional pages to be had. Stop here...
-                                       $this->setContinueEnumParameter('continue',
+                                       $this->setContinueEnumParameter( 'continue',
                                                "{$row->pl_from}|{$row->pl_namespace}|" .
-                                               $this->keyToTitle($row->pl_title));
+                                               $this->keyToTitle( $row->pl_title ) );
                                        break;
                                }
-                               $titles[] = Title :: makeTitle($row->pl_namespace, $row->pl_title);
+                               $titles[] = Title :: makeTitle( $row->pl_namespace, $row->pl_title );
                        }
-                       $resultPageSet->populateFromTitles($titles);
+                       $resultPageSet->populateFromTitles( $titles );
                }
 
-               $db->freeResult($res);
+               $db->freeResult( $res );
        }
 
        public function getAllowedParams()
@@ -208,6 +208,6 @@ class ApiQueryLinks extends ApiQueryGeneratorBase {
        }
 
        public function getVersion() {
-               return __CLASS__ . ': $Id: ApiQueryLinks.php 69986 2010-07-27 03:57:39Z tstarling $';
+               return __CLASS__ . ': $Id: ApiQueryLinks.php 69932 2010-07-26 08:03:21Z tstarling $';
        }
 }