Robert Vogel has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/196212

Change subject: SmartList: 'whatlinkshere' now supports 'cat'
......................................................................

SmartList: 'whatlinkshere' now supports 'cat'

Added support for 'cat' and 'catmode' parameters to 'whatlinkshere' mode.

\    /\
 )  ( ')
 (  /  )
  \(__)|

Change-Id: I4a0c911e1f9a29d2ac8be09922707de18e4f248f
---
M SmartList/SmartList.class.php
1 file changed, 33 insertions(+), 29 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/BlueSpiceExtensions 
refs/changes/12/196212/1

diff --git a/SmartList/SmartList.class.php b/SmartList/SmartList.class.php
index f20d600..cf765dd 100644
--- a/SmartList/SmartList.class.php
+++ b/SmartList/SmartList.class.php
@@ -707,16 +707,6 @@
                if ( $aArgs['mode'] == 'recentchanges' ) {
                        $dbr = wfGetDB( DB_SLAVE );
                        $aConditions = array();
-                       // TODO RBV (17.05.11 16:52): Put this into abstraction 
layer
-                       if ( $aArgs['categories'] != '-' && 
$aArgs['categories'] != '' ) {
-                               $aCategories = explode( ',', 
$aArgs['categories'] );
-                               $iCnt = count( $aCategories );
-                               for ( $i = 0; $i < $iCnt; $i++ ) {
-                                       $aCategories[$i] = str_replace( ' ', 
'_', $aCategories[$i] );
-                                       $aCategories[$i] = "'" . trim( ucfirst( 
$aCategories[$i] ) ) . "'";
-                               }
-                               $aArgs['categories'] = implode( ',', 
$aCategories );
-                       }
 
                        switch ( $aArgs['period'] ) {
                                case 'month': $sMinTimestamp = $dbr->timestamp( 
time() - 30 * 24 * 60 * 60 );
@@ -744,15 +734,7 @@
                                );
                        }
 
-                       if ( $aArgs['categories'] != '-' && 
$aArgs['categories'] != '' ) {
-                               if ( $aArgs['categoryMode'] == 'OR' ) {
-                                       $aConditions[] = 'rc_cur_id IN ( SELECT 
cl_from FROM ' . $dbr->tableName( 'categorylinks' ) . ' WHERE cl_to IN (' . 
$aArgs['categories'] . ') )';
-                               } else {
-                                       foreach ( $aCategories as $sCategory ) {
-                                               $aConditions[] = 'rc_cur_id IN 
( SELECT cl_from FROM ' . $dbr->tableName( 'categorylinks' ) . ' WHERE cl_to = 
' . $sCategory . ' )';
-                                       }
-                               }
-                       }
+                       $this->makeCategoriesFilterCondition( $aConditions, 
$aArgs, 'rc_cur_id' );
 
                        switch ( $aArgs['sort'] ) {
                                case 'title':
@@ -839,7 +821,7 @@
                                return $oErrorListView->execute();
                        }
 
-                       $oDbr = wfGetDB( DB_SLAVE );
+                       $dbr = wfGetDB( DB_SLAVE );
                        $aTables = array(
                                'pagelinks',
                                'page',
@@ -874,6 +856,8 @@
                                return $oErrorListView->execute();
                        }
 
+                       $this->makeCategoriesFilterCondition( $aConditions, 
$aArgs, 'page_id' );
+
                        //Default: time
                        $aOptions['ORDER BY'] = $aArgs['sort'] == 'title'
                                ? 'page_title'
@@ -886,7 +870,7 @@
                                : ' DESC'
                        ;
 
-                       $oRes = $oDbr->select(
+                       $res = $dbr->select(
                                $aTables,
                                $aFields,
                                $aConditions,
@@ -895,27 +879,26 @@
                        );
 
                        $iCount = 0;
-                       foreach( $oRes as $o ) {
+                       foreach( $res as $row ) {
                                if( $iCount == $aArgs['count'] ) {
                                        break;
                                }
 
-                               $oTitle = Title::makeTitleSafe( $o->namespace, 
$o->title );
+                               $oTitle = Title::makeTitleSafe( 
$row->namespace, $row->title );
                                if( !$oTitle || !$oTitle->quickUserCan( 'read' 
) ) {
                                        continue;
                                }
 
-                               $aObjectList[] = $o;
+                               $aObjectList[] = $row;
                                $iCount++;
                        }
 
-                       $oDbr->freeResult( $oRes );
+                       $dbr->freeResult( $res );
 
                } else {
-                       wfRunHooks( 'BSSmartListCustomMode', array(
-                               &$aObjectList,
-                               $aArgs
-                       ));
+                       wfRunHooks(
+                               'BSSmartListCustomMode', array( &$aObjectList, 
$aArgs, $this )
+                       );
                }
 
                if ( $oErrorListView->hasEntries() ) {
@@ -1336,4 +1319,25 @@
                return true;
        }
 
+       public function makeCategoriesFilterCondition( &$aConditions, $aArgs, 
$sPageIdFileName) {
+               if ( $aArgs['categories'] != '-' && $aArgs['categories'] != '' 
) {
+                       $aCategories = explode( ',', $aArgs['categories'] );
+                       $iCnt = count( $aCategories );
+                       for ( $i = 0; $i < $iCnt; $i++ ) {
+                               $aCategories[$i] = str_replace( ' ', '_', 
$aCategories[$i] );
+                               $aCategories[$i] = "'" . trim( ucfirst( 
$aCategories[$i] ) ) . "'";
+                       }
+                       $aArgs['categories'] = implode( ',', $aCategories );
+
+                       $dbr = wfGetDB( DB_SLAVE );
+                       if ( $aArgs['categoryMode'] == 'OR' ) {
+                               $aConditions[] = $sPageIdFileName.' IN ( SELECT 
cl_from FROM ' . $dbr->tableName( 'categorylinks' ) . ' WHERE cl_to IN (' . 
$aArgs['categories'] . ') )';
+                       } else {
+                               foreach ( $aCategories as $sCategory ) {
+                                       $aConditions[] = $sPageIdFileName.' IN 
( SELECT cl_from FROM ' . $dbr->tableName( 'categorylinks' ) . ' WHERE cl_to = 
' . $sCategory . ' )';
+                               }
+                       }
+               }
+       }
+
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/196212
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I4a0c911e1f9a29d2ac8be09922707de18e4f248f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/BlueSpiceExtensions
Gerrit-Branch: master
Gerrit-Owner: Robert Vogel <vo...@hallowelt.biz>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to