Revert changes to SpecialSearch.php in r70608 because Special:Search didn't load...
[lhc/web/wiklou.git] / includes / api / ApiQueryIWLinks.php
index 84b3185..90eb751 100644 (file)
@@ -20,7 +20,7 @@
  *
  * You should have received a copy of the GNU General Public License along
  * with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  * http://www.gnu.org/copyleft/gpl.html
  */
 
@@ -54,6 +54,7 @@ class ApiQueryIWLinks extends ApiQueryBase {
 
                $this->addTables( 'iwlinks' );
                $this->addWhereFld( 'iwl_from', array_keys( $this->getPageSet()->getGoodTitles() ) );
+
                if ( !is_null( $params['continue'] ) ) {
                        $cont = explode( '|', $params['continue'] );
                        if ( count( $cont ) != 3 ) {
@@ -82,8 +83,7 @@ class ApiQueryIWLinks extends ApiQueryBase {
                $res = $this->select( __METHOD__ );
 
                $count = 0;
-               $db = $this->getDB();
-               while ( $row = $db->fetchObject( $res ) ) {
+               foreach ( $res as $row ) {
                        if ( ++$count > $params['limit'] ) {
                                // We've reached the one extra which shows that
                                // there are additional pages to be had. Stop here...
@@ -91,6 +91,14 @@ class ApiQueryIWLinks extends ApiQueryBase {
                                break;
                        }
                        $entry = array( 'prefix' => $row->iwl_prefix );
+
+                       if ( !is_null( $params['url'] ) ) {
+                               $title = Title::newFromText( "{$row->iwl_prefix}:{$row->iwl_title}" );
+                               if ( $title ) {
+                                       $entry = array_merge( $entry, array( 'url' => $title->getFullURL() ) );
+                               }
+                       }
+
                        ApiResult::setContent( $entry, $row->iwl_title );
                        $fit = $this->addPageSubItem( $row->iwl_from, $entry );
                        if ( !$fit ) {
@@ -98,11 +106,15 @@ class ApiQueryIWLinks extends ApiQueryBase {
                                break;
                        }
                }
-               $db->freeResult( $res );
+       }
+
+       public function getCacheMode( $params ) {
+               return 'public';
        }
 
        public function getAllowedParams() {
                return array(
+                       'url' => null,
                        'limit' => array(
                                ApiBase::PARAM_DFLT => 10,
                                ApiBase::PARAM_TYPE => 'limit',
@@ -116,6 +128,7 @@ class ApiQueryIWLinks extends ApiQueryBase {
 
        public function getParamDescription() {
                return array(
+                       'url' => 'Whether to get the full URL',
                        'limit' => 'How many interwiki links to return',
                        'continue' => 'When more results are available, use this to continue',
                );
@@ -141,4 +154,4 @@ class ApiQueryIWLinks extends ApiQueryBase {
        public function getVersion() {
                return __CLASS__ . ': $Id$';
        }
-}
\ No newline at end of file
+}