setHeaders(); parent::execute( $par ); if ( $this->title instanceof Title ) { $id = $this->getRequest()->getInt( 'id' ); $this->showCitations( $this->title, $id ); } } protected function alterForm( HTMLForm $form ) { $form->setMethod( 'get' ); } protected function getFormFields() { if ( isset( $this->par ) ) { $default = $this->par; } else { $default = ''; } return [ 'page' => [ 'name' => 'page', 'type' => 'title', 'default' => $default, 'label-message' => 'citethispage-change-target' ] ]; } public function onSubmit( array $data ) { // GET forms are "submitted" on every view, so check // that some data was put in for page, as empty string // will pass validation if ( strlen( $data['page'] ) ) { $this->title = Title::newFromText( $data['page'] ); } return true; } /** * Return an array of subpages beginning with $search that this special page will accept. * * @param string $search Prefix to search for * @param int $limit Maximum number of results to return (usually 10) * @param int $offset Number of results to skip (usually 0) * @return string[] Matching subpages */ public function prefixSearchSubpages( $search, $limit, $offset ) { $title = Title::newFromText( $search ); if ( !$title || !$title->canExist() ) { // No prefix suggestion in special and media namespace return []; } // Autocomplete subpage the same as a normal search $result = SearchEngine::completionSearch( $search ); return array_map( function ( $sub ) { return $sub->getSuggestedTitle(); }, $result->getSuggestions() ); } protected function getGroupName() { return 'pagetools'; } private function showCitations( Title $title, $revId ) { if ( !$revId ) { $revId = $title->getLatestRevID(); } $out = $this->getOutput(); $revision = Revision::newFromTitle( $title, $revId ); if ( !$revision ) { $out->wrapWikiMsg( '
tags to // be generated around the output of the CiteThisPageOutput // class TODO FIXME. $parserOptions->setTidy( false ); return $parserOptions; } /** * Implements thetag. * * This is a hack to allow content that is typically parsed * using the page's timestamp/pagetitle to use the current * request's time and title * * @param string $text * @param array $params * @param Parser $parser * @return string */ public function citationTag( $text, $params, Parser $parser ) { $parserOptions = $this->getParserOptions(); $ret = $this->citationParser->parse( $text, $this->getPageTitle(), $parserOptions, /* $linestart = */ false ); return $ret->getText( [ 'enableSectionEditLinks' => false, // This will be inserted into the output of another parser, so there will actually be a wrapper 'unwrap' => true, ] ); } protected function getDisplayFormat() { return 'ooui'; } public function requiresUnblock() { return false; } public function requiresWrite() { return false; } }