* @return array
*/
private function extractTitles( $list ) {
- $titles = array();
$list = explode( "\n", trim( $list ) );
if( !is_array( $list ) ) {
return array();
}
+ $titles = array();
foreach( $list as $text ) {
$text = trim( $text );
if( strlen( $text ) > 0 ) {
$title = Title::newFromText( $text );
if( $title instanceof Title && $title->isWatchable() ) {
- $titles[] = $title->getPrefixedText();
+ $titles[] = $title;
}
}
}
- return array_unique( $titles );
+
+ GenderCache::singleton()->doTitlesArray( $titles );
+
+ $list = array();
+ foreach( $titles as $title ) {
+ $list[] = $title->getPrefixedText();
+ }
+ return array_unique( $list );
}
public function submitRaw( $data ){
$dbr = wfGetDB( DB_MASTER );
$res = $dbr->select(
'watchlist',
- '*',
array(
+ 'wl_namespace', 'wl_title'
+ ), array(
'wl_user' => $this->getUser()->getId(),
),
__METHOD__
);
if( $res->numRows() > 0 ) {
+ $titles = array();
foreach ( $res as $row ) {
$title = Title::makeTitleSafe( $row->wl_namespace, $row->wl_title );
if ( $this->checkTitle( $title, $row->wl_namespace, $row->wl_title )
&& !$title->isTalkPage()
) {
- $list[] = $title->getPrefixedText();
+ $titles[] = $title;
}
}
$res->free();
+
+ GenderCache::singleton()->doTitlesArray( $titles );
+
+ foreach( $titles as $title ) {
+ $list[] = $title->getPrefixedText();
+ }
}
$this->cleanupWatchlist();
return $list;
* Attempts to clean up broken items
*/
private function cleanupWatchlist() {
+ if( !count( $this->badItems ) ) {
+ return; //nothing to do
+ }
$dbw = wfGetDB( DB_MASTER );
+ $user = $this->getUser();
foreach ( $this->badItems as $row ) {
list( $title, $namespace, $dbKey ) = $row;
- wfDebug( "User {$this->getUser()} has broken watchlist item ns($namespace):$dbKey, "
+ wfDebug( "User {$user->getName()} has broken watchlist item ns($namespace):$dbKey, "
. ( $title ? 'cleaning up' : 'deleting' ) . ".\n"
);
$dbw->delete( 'watchlist',
array(
- 'wl_user' => $this->getUser()->getId(),
+ 'wl_user' => $user->getId(),
'wl_namespace' => $namespace,
'wl_title' => $dbKey,
),
// Can't just do an UPDATE instead of DELETE/INSERT due to unique index
if ( $title ) {
- $this->getUser()->addWatch( $title );
+ $user->addWatch( $title );
}
}
}
$title = Title::makeTitleSafe( $namespace, $dbkey );
if ( $this->checkTitle( $title, $namespace, $dbkey ) ) {
$text = $this->buildRemoveLine( $title );
- $fields['TitlesNs'.$namespace]['options'][$text] = $title->getEscapedText();
+ $fields['TitlesNs'.$namespace]['options'][$text] = htmlspecialchars( $title->getPrefixedText() );
$count++;
}
}