Go to the documentation of this file.
35 parent::__construct(
'Booksources' );
48 $isbn = $isbn ?: $this->
getRequest()->getText(
'isbn' );
49 $isbn = trim( $isbn );
54 if ( !self::isValidISBN( $isbn ) ) {
56 "<div class=\"error\">\n$1\n</div>",
57 'booksources-invalid-isbn'
74 if ( strlen( $isbn ) == 13 ) {
75 for ( $i = 0; $i < 12; $i++ ) {
76 if ( $isbn[$i] ===
'X' ) {
78 } elseif ( $i % 2 == 0 ) {
81 $sum += 3 * $isbn[$i];
85 $check = ( 10 - ( $sum % 10 ) ) % 10;
86 if ( (
string)$check === $isbn[12] ) {
89 } elseif ( strlen( $isbn ) == 10 ) {
90 for ( $i = 0; $i < 9; $i++ ) {
91 if ( $isbn[$i] ===
'X' ) {
94 $sum += $isbn[$i] * ( $i + 1 );
101 if ( (
string)$check === $isbn[9] ) {
116 return trim( preg_replace(
'![^0-9X]!',
'', $isbn ) );
129 'label-message' =>
'booksources-isbn',
139 ->setWrapperLegendMsg(
'booksources-search-legend' )
140 ->setSubmitTextMsg(
'booksources-search' )
143 ->displayForm(
false );
158 # Hook to allow extensions to insert additional HTML,
159 # e.g. for API-interacting plugins and so on
160 Hooks::run(
'BookInformation', [ $isbn, $out ] );
162 # Check for a local page such as Project:Book_sources and use that if available
163 $page = $this->
msg(
'booksources' )->inContentLanguage()->text();
173 $out->addWikiTextAsInterface( str_replace(
'MAGICNUMBER', $isbn, $text ) );
177 throw new MWException(
"Unexpected content type for book sources: " .
$content->getModel() );
181 # Fall back to the defaults given in the language file
182 $out->addWikiMsg(
'booksources-text' );
183 $out->addHTML(
'<ul>' );
184 $items = MediaWikiServices::getInstance()->getContentLanguage()->getBookstoreList();
185 foreach ( $items as $label => $url ) {
186 $out->addHTML( $this->
makeListItem( $isbn, $label, $url ) );
188 $out->addHTML(
'</ul>' );
202 $url = str_replace(
'$1', $isbn, $url );
204 return Html::rawElement(
'li', [],
205 Html::element(
'a', [
'href' => $url,
'class' =>
'external' ], $label )
getPageTitle( $subpage=false)
Get a self-referential title object.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getOutput()
Get the OutputPage being used for this instance.
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
showList( $isbn)
Determine where to get the list of book sources from, format and output them.
static newFromTitle(LinkTarget $linkTarget, $id=0, $flags=0)
Load either the current, or a specified, revision that's attached to a given link target.
An IContextSource implementation which will inherit context from another source but allow individual ...
static isValidISBN( $isbn)
Return whether a given ISBN (10 or 13) is valid.
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getContext()
Gets the context this SpecialPage is executed in.
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
buildForm( $isbn)
Generate a form to allow users to enter an ISBN.
Parent class for all special pages.
getRequest()
Get the WebRequest being used for this instance.
Special page outputs information on sourcing a book with a particular ISBN The parser creates links t...
Content object implementation for representing flat text.
static cleanIsbn( $isbn)
Trim ISBN and remove characters which aren't required.
makeListItem( $isbn, $label, $url)
Format a book source list item.
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...