titleFactory = $titleFactory; } /** * @inheritDoc */ public function filterForForm( $value ) { $ids = array_map( 'intval', preg_split( '/\n/', $value, -1, PREG_SPLIT_NO_EMPTY ) ); $titles = $ids ? $this->getTitleFactory()->newFromIDs( $ids ) : []; if ( !$titles ) { return ''; } return implode( "\n", array_map( function ( Title $title ) { return $title->getPrefixedText(); }, $titles ) ); } /** * @inheritDoc */ public function filterFromForm( $titles ) { $titles = trim( $titles ); if ( $titles !== '' ) { $titles = preg_split( '/\n/', $titles, -1, PREG_SPLIT_NO_EMPTY ); $ids = array_map( function ( $text ) { $title = $this->getTitleFactory()->newFromText( $text ); if ( $title instanceof \Title && $title->getArticleID() > 0 ) { return $title->getArticleID(); } return false; }, $titles ); if ( $ids ) { return implode( "\n", $ids ); } } // If the titles list is null, it should be null (don't save) rather than an empty string. return null; } /** * @return TitleFactory */ private function getTitleFactory() :TitleFactory { $this->titleFactory = $this->titleFactory ?? new TitleFactory(); return $this->titleFactory; } }