Nasty has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/337570 )
Change subject: Refactor to remove raw queries.
......................................................................
Refactor to remove raw queries.
Fixed issue from ERM5474 and T152910
Change-Id: Iafa50459dc60d65a70f9101b572e5e70247c99dd
---
M RSSStandards/RSSStandards.class.php
1 file changed, 64 insertions(+), 62 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/BlueSpiceExtensions
refs/changes/70/337570/1
diff --git a/RSSStandards/RSSStandards.class.php
b/RSSStandards/RSSStandards.class.php
index c082671..e963fa1 100644
--- a/RSSStandards/RSSStandards.class.php
+++ b/RSSStandards/RSSStandards.class.php
@@ -55,8 +55,13 @@
}
/**
- * Hook-Handler for BlueSpice hook BSRSSFeederGetRegisteredFeeds
- * @param Array $aFeed Feed array.
+ * Hook-Handler for MediaWiki hook MediaWikiPerformAction
+ * @param OutputPage $wgOut MediaWiki Outpupage object.
+ * @param Article $article MediaWiki article object.
+ * @param Title $title MediaWiki title object.
+ * @param User $user MediaWiki user object.
+ * @param Request $request MediaWiki request object.
+ * @param mediaWiki $mediaWiki MediaWiki mediaWiki object.
* @return bool Always true.
*/
public function onBSRSSFeederGetRegisteredFeeds( $aFeeds ) {
@@ -145,11 +150,7 @@
)
);
- $oChannel = RSSCreator::createChannel(
- RSSCreator::xmlEncode( $wgSitename . ' - ' . $sPageName
),
- 'http://' . $_SERVER['HTTP_HOST'] .
$_SERVER['PHP_SELF'],
- wfMessage( 'bs-rssstandards-desc-page' )->plain()
- );
+ $oChannel = RSSCreator::createChannel(RSSCreator::xmlEncode(
$wgSitename . ' - ' . $sPageName),
'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'], wfMessage(
'bs-rssstandards-desc-page' )->plain() );
while( $row = $res->fetchObject() ) {
$title = Title::makeTitle( $row->rc_namespace,
$row->rc_title );
$entry = RSSItemCreator::createItem(
@@ -191,11 +192,7 @@
$res = false;
}
- $channel = RSSCreator::createChannel(
- RSSCreator::xmlEncode( $wgSitename . ' - ' . wfMessage(
'bs-rssstandards-title-own' )->plain() ),
- 'http://' . $_SERVER['HTTP_HOST'] .
$_SERVER['PHP_SELF'],
- wfMessage( 'bs-rssstandards-desc-own' )->plain()
- );
+ $channel = RSSCreator::createChannel(RSSCreator::xmlEncode(
$wgSitename . ' - ' . wfMessage( 'bs-rssstandards-title-own' )->plain() ),
'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'], wfMessage(
'bs-rssstandards-desc-own' )->plain() );
if ( $res ) {
while ( $obj = $res->fetchObject() ) {
$title = Title::makeTitle( $obj->rc_namespace,
$obj->rc_title );
@@ -214,43 +211,58 @@
}
public function buildRssCat() {
- global $wgRequest, $wgSitename, $wgDBprefix;
-
+ global $wgRequest, $wgSitename;
$dbr = wfGetDB( DB_SLAVE );
$_showLimit = 10;
$cat = $wgRequest->getVal( 'cat', '' );
- $channel = RSSCreator::createChannel(
- $wgSitename . ' - ' . wfMessage(
'bs-rssstandards-title-cat' )->plain() . ' ' . addslashes( $cat ),
- 'http://' . $_SERVER['HTTP_HOST'] .
$_SERVER['PHP_SELF'],
- wfMessage( 'bs-rssstandards-desc-cat' )->plain()
+ $channel = RSSCreator::createChannel($wgSitename . ' - ' .
wfMessage( 'bs-rssstandards-title-cat' )->plain() . ' ' . addslashes( $cat ),
'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'], wfMessage(
'bs-rssstandards-desc-cat' )->plain() );
+
+ $res = $dbr->select(
+ "categorylinks",
+ "cl_from",
+ array( "cl_to" => $cat )
);
- $res = $dbr->query( "select cl_from FROM " .
$wgDBprefix."categorylinks WHERE cl_to = '" . addslashes( $cat ). "'" );
-
$entryIds = Array();
- while ( $row = $dbr->fetchRow( $res ) ) {
- $entryIds[] = $row['cl_from'];
+
+ foreach ( $res as $row ) {
+ $entryIds[] = $row->cl_from;
}
if ( count( $entryIds ) ) {
- $query = "SELECT Min(r.rev_id) as rid, r.rev_page,
r.rev_timestamp, r.rev_user_text FROM " .
- $wgDBprefix ."revision as r WHERE r.rev_page In ("
- . implode( ", ", $entryIds ) .
- ") GROUP BY r.rev_page, r.rev_timestamp,
r.rev_user_text ORDER BY rid DESC";
- $res = $dbr->query( $query );
+ $aTable = array( 'r' => 'revision' );
+ $aFields = array(
+ 'rid' => "MIN(r.rev_id)",
+ "r.rev_page",
+ "r.rev_timestamp",
+ "r.rev_user_text"
+ );
+ $aConditions = array( "r.rev_page" => $entryIds );
+ $aOptions = array(
+ "group by" => array(
+ "r.rev_page",
+ "r.rev_timestamp",
+ "r.rev_user_text"
+ ),
+ "order by" => "rid DESC"
+ );
+
+ $res = $dbr->select( $aTable, $aFields, $aConditions,
__METHOD__, $aOptions );
$numberOfEntries = $dbr->numRows( $res );
-
$paramShowAll = $wgRequest->getFuzzyBool( 'showall',
false ); // Sole importance is the existence of param 'showall'
- if ( !$paramShowAll ) $query .= ' LIMIT '.$_showLimit;
// if (!$_REQUEST['showall']) $query .= ' LIMIT '.$_showLimit;
- $res = $dbr->query( $query );
+ if ( !$paramShowAll ) {
+ $aOptions['LIMIT'] = $_showLimit;
+ }
- while ( $row = $dbr->fetchRow( $res ) ) {
- $title = Title::newFromID( $row['rev_page'] );
- $page = WikiPage::factory( $title );
+ $res = $dbr->select( $aTable, $aFields, $aConditions,
__METHOD__, $aOptions );
+
+ foreach ( $res as $row ) {
+ $title = Title::newFromID( $row->rev_page );
+ $article = new Article( $title );
if ( !$title->userCan( 'read' ) ) {
$numberOfEntries--;
continue;
@@ -258,18 +270,23 @@
$_title = str_replace( "_", " ",
$title->getText() );
$_link = $title->getFullURL();
- $_description =
SecureFileStore::secureFilesInText(
- preg_replace(
- "#\[<a\
href\=\"(.*)action\=edit(.*)\"\ title\=\"(.*)\">(.*)<\/a>\]#",
- "",
- $this->mCore->parseWikiText(
$page->getContent()->getNativeData(), $this->getTitle() )
- )
+
+ $_description = preg_replace(
+ "#\[<a\ href\=\"(.*)action\=edit(.*)\"\
title\=\"(.*)\">(.*)<\/a>\]#",
+ "",
+ $this->mCore->parseWikiText(
$article->getContent(), $this->getTitle() )
);
+
+ if( BsExtensionManager::isContextActive(
'MW::SecureFileStore::Active' ) ) {
+ $_description =
SecureFileStore::secureFilesInText( $_description );
+ }
+
$item = RSSItemCreator::createItem( $_title,
$_link, $_description );
+
if ( $item ) {
- $item->setPubDate( wfTimestamp(
TS_UNIX,$row['rev_timestamp'] ) );
+ $item->setPubDate( wfTimestamp(
TS_UNIX, $row->rev_timestamp ) );
$item->setComments(
$title->getTalkPage()->getFullURL() );
- $item->setGUID( $title->getFullURL(
"oldid=".$page->getRevision()->getId() ), 'true' );
+ $item->setGUID( $title->getFullURL(
"oldid=".$article->getRevIdFetched() ), 'true' );
$channel->addItem( $item );
}
}
@@ -294,11 +311,7 @@
$aNamespaces = $wgLang->getNamespaces();
- $channel = RSSCreator::createChannel(
- $wgSitename . ' - ' . wfMessage( 'bs-ns' )->plain() . '
' . $aNamespaces[$ns],
- 'http://' . $_SERVER['HTTP_HOST'] .
$_SERVER['PHP_SELF'],
- wfMessage( 'bs-rssstandards-desc-ns' )->plain()
- );
+ $channel = RSSCreator::createChannel( $wgSitename . ' - ' .
wfMessage( 'bs-ns' )->plain() . ' ' . $aNamespaces[$ns],
'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'], wfMessage(
'bs-rssstandards-desc-ns' )->plain() );
$res = $dbr->query( "select page_id from ".$wgDBprefix."page
where page_namespace = ".$ns );
@@ -308,10 +321,7 @@
}
if ( count( $entryIds ) ) {
- $query = "SELECT Min(r.rev_id) as rid, r.rev_page,
r.rev_timestamp, r.rev_user_text FROM " .
- $wgDBprefix ."revision as r WHERE r.rev_page In ("
- . join( ", ", $entryIds ) .
- ") GROUP BY r.rev_page, r.rev_timestamp,
r.rev_user_text ORDER BY rid DESC";
+ $query = "SELECT Min(r.rev_id) as rid, r.rev_page,
r.rev_timestamp, r.rev_user_text FROM ".$wgDBprefix."revision as r WHERE
r.rev_page In (".join(",",$entryIds).") GROUP BY r.rev_page, r.rev_timestamp,
r.rev_user_text ORDER BY rid DESC";
$res = $dbr->query( $query );
$numberOfEntries = $dbr->numRows( $res );
@@ -321,7 +331,7 @@
while ( $row = $dbr->fetchRow( $res ) ) {
$title = Title::newFromID( $row['rev_page'] );
- $page = WikiPage::factory( $title );
+ $article = new Article( $title );
if ( !$title->userCan( 'read' ) ) {
$numberOfEntries--;
continue;
@@ -329,11 +339,7 @@
$_title = str_replace( "_", " ",
$title->getText() );
$_link = $title->getFullURL();
- $_tmpText = preg_replace(
- "#\[<a\ href\=\"(.*)action\=edit(.*)\"\
title\=\"(.*)\">(.*)<\/a>\]#",
- "",
- $this->mCore->parseWikiText(
$page->getContent()->getNativeData(), $this->getTitle() )
- );
+ $_tmpText = preg_replace( "#\[<a\
href\=\"(.*)action\=edit(.*)\"\ title\=\"(.*)\">(.*)<\/a>\]#", "",
$this->mCore->parseWikiText( $article->getContent(), $this->getTitle() ) );
if ( class_exists( 'SecureFileStore' ) ) {
$_description =
SecureFileStore::secureFilesInText($_tmpText);
} else {
@@ -345,7 +351,7 @@
if ( $item ) {
$item->setPubDate( wfTimestamp(
TS_UNIX, $row['rev_timestamp'] ) );
$item->setComments(
$title->getTalkPage()->getFullURL() );
- $item->setGUID( $title->getFullURL(
"oldid=".$page->getRevision()->getId() ), 'true' );
+ $item->setGUID( $title->getFullURL(
"oldid=".$article->getRevIdFetched() ), 'true' );
$channel->addItem( $item );
}
}
@@ -557,11 +563,7 @@
$list = ChangesList::newFromContext( $skin->getContext() );
//Thanks to Bartosz DziewoĆski (https://gerrit.wikimedia.org/r/#/c/94082/)
- $channel = RSSCreator::createChannel(
- SpecialPage::getTitleFor( 'Watchlist' ) . ' (' .
$user->getName(). ')',
- 'http://' . $_SERVER['HTTP_HOST'] .
$_SERVER['PHP_SELF'],
- wfMessage( 'bs-rssstandards-desc-watch' )->plain()
- );
+ $channel = RSSCreator::createChannel( SpecialPage::getTitleFor(
'Watchlist' ).' ('.$user->getName().')',
'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'], wfMessage(
'bs-rssstandards-desc-watch' )->plain() );
$html = $list->beginRecentChangesList();
$counter = 1;
--
To view, visit https://gerrit.wikimedia.org/r/337570
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Iafa50459dc60d65a70f9101b572e5e70247c99dd
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/BlueSpiceExtensions
Gerrit-Branch: master
Gerrit-Owner: Nasty <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits