From c69affc4f07eb82571383260650d097e1bcabf7f Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Thu, 28 Jan 2010 21:58:50 +0000 Subject: [PATCH] Step one in fixing OutputPage's documentation: * Groupped methods by function * Added documentation * Fixed some doxygen warnings * Some little style fixes (more to come) --- includes/OutputPage.php | 406 +++++++++++++++++++++++++++++++++------- 1 file changed, 336 insertions(+), 70 deletions(-) diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 4b447aef4a..f87a6d90ce 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -57,6 +57,7 @@ class OutputPage { private $mVaryHeader = array( 'Accept-Encoding' => array('list-contains=gzip'), 'Cookie' => null ); + /** * Constructor * Initialise private variables @@ -66,12 +67,23 @@ class OutputPage { $this->mAllowUserJs = $wgAllowUserJs; } + /** + * Redirect to $url rather than displaying the normal page + * + * @param $url String: URL + * @param $responsecode String: HTTP status code + */ public function redirect( $url, $responsecode = '302' ) { # Strip newlines as a paranoia check for header injection in PHP<5.1.2 $this->mRedirect = str_replace( "\n", '', $url ); $this->mRedirectCode = $responsecode; } + /** + * Get the URL to redirect to, or an empty string if not redirect URL set + * + * @return String + */ public function getRedirect() { return $this->mRedirect; } @@ -79,10 +91,13 @@ class OutputPage { /** * Set the HTTP status code to send with the output. * - * @param int $statusCode + * @param $statusCode Integer * @return nothing */ - function setStatusCode( $statusCode ) { $this->mStatusCode = $statusCode; } + public function setStatusCode( $statusCode ) { + $this->mStatusCode = $statusCode; + } + /** * Add a new tag @@ -95,19 +110,56 @@ class OutputPage { array_push( $this->mMetatags, array( $name, $val ) ); } + /** + * Add a keyword or a list of keywords in the page header + * + * @param $text String or array of strings + */ function addKeyword( $text ) { - if( is_array( $text )) { + if( is_array( $text ) ) { $this->mKeywords = array_merge( $this->mKeywords, $text ); } else { array_push( $this->mKeywords, $text ); } } + + /** + * Add a new \ tag to the page header + * + * @param $linkarr Array: associative array of attributes. + */ + function addLink( $linkarr ) { + array_push( $this->mLinktags, $linkarr ); + } + + /** + * Add a new \ with "rel" attribute set to "meta" + * + * @param $linkarr Array: associative array mapping attribute names to their + * values, both keys and values will be escaped, and the + * "rel" attribute will be automatically added + */ + function addMetadataLink( $linkarr ) { + # note: buggy CC software only reads first "meta" link + static $haveMeta = false; + $linkarr['rel'] = $haveMeta ? 'alternate meta' : 'meta'; + $this->addLink( $linkarr ); + $haveMeta = true; + } + + + /** + * Add raw HTML to the list of scripts (including \ tag, etc.) + * + * @param $script String: raw HTML + */ function addScript( $script ) { $this->mScripts .= $script . "\n"; } /** * Register and add a stylesheet from an extension directory. + * * @param $url String path to sheet. Provide either a full url (beginning * with 'http', etc) or a relative path from the document root * (beginning with '/'). Otherwise it behaves identically to @@ -117,11 +169,22 @@ class OutputPage { array_push( $this->mExtStyles, $url ); } + /** + * Get all links added by extensions + * + * @return Array + */ + function getExtStyle() { + return $this->mExtStyles; + } + /** * Add a JavaScript file out of skins/common, or a given relative path. - * @param string $file filename in skins/common or complete on-server path (/foo/bar.js) + * + * @param $file String: filename in skins/common or complete on-server path + * (/foo/bar.js) */ - function addScriptFile( $file ) { + public function addScriptFile( $file ) { global $wgStylePath, $wgStyleVersion; if( substr( $file, 0, 1 ) == '/' ) { $path = $file; @@ -133,19 +196,27 @@ class OutputPage { /** * Add a self-contained script tag with the given contents - * @param string $script JavaScript text, no